ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/UI.pm
(Generate patch)

Comparing deliantra/Deliantra-Client/DC/UI.pm (file contents):
Revision 1.64 by root, Tue Apr 11 13:38:22 2006 UTC vs.
Revision 1.65 by root, Tue Apr 11 14:04:27 2006 UTC

73} 73}
74 74
75sub new { 75sub new {
76 my $class = shift; 76 my $class = shift;
77 77
78 bless { @_ }, $class 78 bless {
79 x => 0,
80 y => 0,
81 z => 0,
82 @_
83 }, $class
79} 84}
80 85
81sub move { 86sub move {
82 my ($self, $x, $y, $z) = @_; 87 my ($self, $x, $y, $z) = @_;
83 $self->{x} = $x; 88 $self->{x} = $x;
219sub new { 224sub new {
220 my ($class, %arg) = @_; 225 my ($class, %arg) = @_;
221 226
222 my $children = delete $arg{children} || []; 227 my $children = delete $arg{children} || [];
223 228
224 my $self = $class->SUPER::new (children => []); 229 my $self = $class->SUPER::new (children => [], %arg);
225 $self->add ($_) for @$children; 230 $self->add ($_) for @$children;
226 231
227 $self 232 $self
228} 233}
229 234
786our @ISA = CFClient::Widget::; 791our @ISA = CFClient::Widget::;
787 792
788sub new { 793sub new {
789 my $class = shift; 794 my $class = shift;
790 795
791 $class->SUPER::new (z => -1, @_) 796 $class->SUPER::new (
797 z => -1,
798 list => (glGenLists 1),
799 @_
800 )
792} 801}
793 802
794sub key_down { 803sub key_down {
795 print "MAPKEYDOWN\n"; 804 print "MAPKEYDOWN\n";
796} 805}
803 1 + int $::WIDTH / 32, 812 1 + int $::WIDTH / 32,
804 1 + int $::HEIGHT / 32, 813 1 + int $::HEIGHT / 32,
805 ) 814 )
806} 815}
807 816
817sub update {
818 my ($self) = @_;
819
820 $self->{need_update} = 1;
821}
822
808sub _draw { 823sub _draw {
809 my ($self) = @_; 824 my ($self) = @_;
810 825
826 if (delete $self->{need_update}) {
827 glNewList $self->{list}, GL_COMPILE;
828
811 my $mx = $::CONN->{mapx}; 829 my $mx = $::CONN->{mapx};
812 my $my = $::CONN->{mapy}; 830 my $my = $::CONN->{mapy};
813 831
814 my $map = $::CONN->{map}; 832 my $map = $::CONN->{map};
815 833
816 my ($xofs, $yofs); 834 my ($xofs, $yofs);
817 835
818 my $sw = 1 + int $::WIDTH / 32; 836 my $sw = 1 + int $::WIDTH / 32;
819 my $sh = 1 + int $::HEIGHT / 32; 837 my $sh = 1 + int $::HEIGHT / 32;
820 838
821 if ($::CONN->{mapw} > $sw) { 839 if ($::CONN->{mapw} > $sw) {
822 $xofs = $mx + ($::CONN->{mapw} - $sw) * 0.5; 840 $xofs = $mx + ($::CONN->{mapw} - $sw) * 0.5;
823 } else { 841 } else {
824 $xofs = $self->{xofs} = min $mx, max $mx + $::CONN->{mapw} - $sw + 1, $self->{xofs}; 842 $xofs = $self->{xofs} = min $mx, max $mx + $::CONN->{mapw} - $sw + 1, $self->{xofs};
825 } 843 }
826 844
827 if ($::CONN->{maph} > $sh) { 845 if ($::CONN->{maph} > $sh) {
828 $yofs = $my + ($::CONN->{maph} - $sh) * 0.5; 846 $yofs = $my + ($::CONN->{maph} - $sh) * 0.5;
829 } else { 847 } else {
830 $yofs = $self->{yofs} = min $my, max $my + $::CONN->{maph} - $sh + 1, $self->{yofs}; 848 $yofs = $self->{yofs} = min $my, max $my + $::CONN->{maph} - $sh + 1, $self->{yofs};
831 } 849 }
832 850
833 glEnable GL_TEXTURE_2D; 851 glEnable GL_TEXTURE_2D;
834 glEnable GL_BLEND; 852 glEnable GL_BLEND;
835 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 853 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
836 854
837 my $sw4 = ($sw + 3) & ~3; 855 my $sw4 = ($sw + 3) & ~3;
838 my $darkness = "\x00" x ($sw4 * $sh); 856 my $darkness = "\x00" x ($sw4 * $sh);
839 857
840 for my $x (0 .. $sw - 1) { 858 for my $x (0 .. $sw - 1) {
841 my $row = $map->[$x + $xofs]; 859 my $row = $map->[$x + $xofs];
842 for my $y (0 .. $sh - 1) { 860 for my $y (0 .. $sh - 1) {
843 861
844 my $cell = $row->[$y + $yofs] 862 my $cell = $row->[$y + $yofs]
845 or next; 863 or next;
846 864
847 my $dark = $cell->[0]; 865 my $dark = $cell->[0];
848 if ($dark < 0) { 866 if ($dark < 0) {
849 substr $darkness, $y * $sw4 + $x, 1, chr 224; 867 substr $darkness, $y * $sw4 + $x, 1, chr 224;
850 } else { 868 } else {
851 substr $darkness, $y * $sw4 + $x, 1, chr 255 - $dark; 869 substr $darkness, $y * $sw4 + $x, 1, chr 255 - $dark;
852 } 870 }
853 871
854 for my $num (grep $_, @$cell[1,2,3]) { 872 for my $num (grep $_, @$cell[1,2,3]) {
855 my $tex = $::CONN->{face}[$num]{texture} || next; 873 my $tex = $::CONN->{face}[$num]{texture} || next;
856 874
857 my $w = $tex->{width}; 875 my $w = $tex->{width};
858 my $h = $tex->{height}; 876 my $h = $tex->{height};
859 877
860 $tex->draw_quad (($x + 1) * 32 - $w, ($y + 1) * 32 - $h, $w, $h); 878 $tex->draw_quad (($x + 1) * 32 - $w, ($y + 1) * 32 - $h, $w, $h);
879 }
861 } 880 }
862 } 881 }
863 }
864 882
865# if (1) { # higher quality darkness 883# if (1) { # higher quality darkness
866# $lighting =~ s/(.)/$1$1$1/gs; 884# $lighting =~ s/(.)/$1$1$1/gs;
867# my $pb = new_from_data Gtk2::Gdk::Pixbuf $lighting, "rgb", 0, 8, $sw4, $sh, $sw4 * 3; 885# my $pb = new_from_data Gtk2::Gdk::Pixbuf $lighting, "rgb", 0, 8, $sw4, $sh, $sw4 * 3;
868# 886#
870# 888#
871# $lighting = $pb->get_pixels; 889# $lighting = $pb->get_pixels;
872# $lighting =~ s/(.)../$1/gs; 890# $lighting =~ s/(.)../$1/gs;
873# } 891# }
874 892
875 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 893 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
876 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 894 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
877 895
878 $darkness = new CFClient::Texture 896 $darkness = new CFClient::Texture
879 width => $sw4, 897 width => $sw4,
880 height => $sh, 898 height => $sh,
881 data => $darkness, 899 data => $darkness,
882 internalformat => GL_ALPHA, 900 internalformat => GL_ALPHA,
883 format => GL_ALPHA; 901 format => GL_ALPHA;
884 902
885 glColor 0.45, 0.45, 0.45, 1; 903 glColor 0.45, 0.45, 0.45, 1;
886 $darkness->draw_quad (0, 0, $sw4 * 32, $sh * 32); 904 $darkness->draw_quad (0, 0, $sw4 * 32, $sh * 32);
887 905
888 glDisable GL_TEXTURE_2D; 906 glDisable GL_TEXTURE_2D;
889 glDisable GL_BLEND; 907 glDisable GL_BLEND;
908
909 glEndList;
910 }
911
912 glCallList $self->{list};
890} 913}
891 914
892my %DIR = ( 915my %DIR = (
893 SDLK_KP8, [1, "north"], 916 SDLK_KP8, [1, "north"],
894 SDLK_KP9, [2, "northeast"], 917 SDLK_KP9, [2, "northeast"],

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines