ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/MapWidget.pm
Revision: 1.5
Committed: Wed Apr 19 23:43:07 2006 UTC (18 years, 1 month ago) by root
Branch: MAIN
Changes since 1.4: +7 -7 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 package CFClient::MapWidget;
2
3 use strict;
4
5 use List::Util qw(min max);
6
7 use CFClient::OpenGL;
8
9 our @ISA = CFClient::UI::Base::;
10
11 sub new {
12 my $class = shift;
13
14 $class->SUPER::new (
15 z => -1,
16 can_focus => 1,
17 list => glGenList,
18 @_
19 )
20 }
21
22 sub DESTROY {
23 my $self = shift;
24
25 glDeleteList $self->{list};
26
27 $self->SUPER::DESTROY;
28 }
29
30 sub key_down {
31 print "MAPKEYDOWN\n";
32 }
33
34 sub key_up {
35 }
36
37 sub button_down {
38 my ($self, $ev, $x, $y) = @_;
39
40 $self->focus_in;
41
42 if ($ev->{button} == 2) {
43 my ($ox, $oy) = ($ev->{x}, $ev->{y});
44 my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y});
45
46 $self->{motion} = sub {
47 my ($ev, $x, $y) = @_;
48
49 ($x, $y) = ($ev->{x}, $ev->{y});
50
51 $::CFG->{map_shift_x} = $bw + $x - $ox;
52 $::CFG->{map_shift_y} = $bh + $y - $oy;
53
54 $self->update;
55 };
56 }
57 }
58
59 sub button_up {
60 my ($self, $ev, $x, $y) = @_;
61
62 delete $self->{motion};
63 }
64
65 sub mouse_motion {
66 my ($self, $ev, $x, $y) = @_;
67
68 $self->{motion}->($ev, $x, $y) if $self->{motion};
69 }
70
71 sub size_request {
72 (
73 1 + 32 * int $::WIDTH / 32,
74 1 + 32 * int $::HEIGHT / 32,
75 )
76 }
77
78 sub update {
79 my ($self) = @_;
80
81 $self->{need_update} = 1;
82 $self->SUPER::update;
83 }
84
85 sub draw {
86 my ($self) = @_;
87
88 if (delete $self->{need_update}) {
89 glNewList $self->{list};
90
91 if ($::MAP) {
92 my $sw = int $::WIDTH / 32;
93 my $sh = int $::HEIGHT / 32;
94
95 my $sx = $::CFG->{map_shift_x}; my $sx0 = $sx & 31; $sx = ($sx - $sx0) / 32;
96 my $sy = $::CFG->{map_shift_y}; my $sy0 = $sy & 31; $sy = ($sy - $sy0) / 32;
97
98 glTranslate $sx0 - 32, $sy0 - 32, 0;
99
100 my ($w, $h, $data) = $::MAP->draw ($sx, $sy, 0, 0, $sw + 1, $sh + 1);
101
102 if ($::CFG->{fow_enable}) {
103 if ($::CFG->{fow_smooth} && $CFClient::GL_VERSION >= 1.2) { # smooth fog of war
104 glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER);
105 glConvolutionFilter2D (
106 GL_CONVOLUTION_2D,
107 GL_ALPHA,
108 3, 3,
109 GL_ALPHA, GL_FLOAT,
110 pack "f*",
111 0.1, 0.1, 0.1,
112 0.1, 0.2, 0.1,
113 0.1, 0.1, 0.1,
114 );
115 glEnable GL_CONVOLUTION_2D;
116 }
117
118 $self->{fow_texture} = new CFClient::Texture
119 w => $w,
120 h => $h,
121 data => $data,
122 internalformat => GL_ALPHA,
123 format => GL_ALPHA;
124
125 glDisable GL_CONVOLUTION_2D if $::CFG->{fow_smooth};
126
127 glEnable GL_BLEND;
128 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
129 glEnable GL_TEXTURE_2D;
130 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
131
132 glColor +($::CFG->{fow_intensity}) x 3, 1;
133 $self->{fow_texture}->draw_quad (0, 0, $w * 32, $h * 32);
134
135 glDisable GL_TEXTURE_2D;
136 glDisable GL_BLEND;
137 }
138
139 # HACK BEGIN
140 {
141 glTranslate -($sx0 - 32), -($sy0 - 32), 0;#remove
142 my ($w, $h) = (250, 250);
143
144 glEnable GL_BLEND;
145 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
146 glEnable GL_TEXTURE_2D;
147 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
148
149 $self->{mapmap_texture} =
150 new CFClient::Texture
151 w => $w,
152 h => $h,
153 data => $::MAP->mapmap ($w, $h),
154 type => $CFClient::GL_VERSION >= 1.2 ? GL_UNSIGNED_INT_8_8_8_8_REV : GL_UNSIGNED_BYTE;
155
156 $self->{mapmap_texture}->draw_quad (100, 100);
157
158 glDisable GL_TEXTURE_2D;
159 glDisable GL_BLEND;
160 }
161 # HACK END
162 }
163
164 glEndList;
165 }
166
167 glPushMatrix;
168 glCallList $self->{list};
169 glPopMatrix;
170
171 if ($CFClient::UI::FOCUS != $self) {
172 glColor 64/255, 64/255, 64/255;
173 glLogicOp GL_AND;
174 glEnable GL_COLOR_LOGIC_OP;
175 glBegin GL_QUADS;
176 glVertex 0, 0;
177 glVertex 0, $::HEIGHT;
178 glVertex $::WIDTH, $::HEIGHT;
179 glVertex $::WIDTH, 0;
180 glEnd;
181 glDisable GL_COLOR_LOGIC_OP;
182 }
183 }
184
185 my %DIR = (
186 CFClient::SDLK_KP8, [1, "north"],
187 CFClient::SDLK_KP9, [2, "northeast"],
188 CFClient::SDLK_KP6, [3, "east"],
189 CFClient::SDLK_KP3, [4, "southeast"],
190 CFClient::SDLK_KP2, [5, "south"],
191 CFClient::SDLK_KP1, [6, "southwest"],
192 CFClient::SDLK_KP4, [7, "west"],
193 CFClient::SDLK_KP7, [8, "northwest"],
194
195 CFClient::SDLK_UP, [1, "north"],
196 CFClient::SDLK_RIGHT, [3, "east"],
197 CFClient::SDLK_DOWN, [5, "south"],
198 CFClient::SDLK_LEFT, [7, "west"],
199 );
200
201 sub key_down {
202 my ($self, $ev) = @_;
203
204 my $mod = $ev->{mod};
205 my $sym = $ev->{sym};
206
207 if ($sym == CFClient::SDLK_KP5) {
208 $::CONN->user_send ("stay fire");
209 } elsif ($sym == ord "a") {
210 $::CONN->user_send ("apply");
211 } elsif ($sym == ord "'") {
212 $self->emit ('activate_console');
213 } elsif ($sym == ord "/") {
214 $self->emit ('activate_console' => '/');
215 } elsif (exists $DIR{$sym}) {
216 if ($mod & CFClient::KMOD_SHIFT) {
217 $self->{shft}++;
218 $::CONN->user_send ("fire $DIR{$sym}[0]");
219 } elsif ($mod & CFClient::KMOD_CTRL) {
220 $self->{ctrl}++;
221 $::CONN->user_send ("run $DIR{$sym}[0]");
222 } else {
223 $::CONN->user_send ("$DIR{$sym}[1]");
224 }
225 }
226 }
227
228 sub key_up {
229 my ($self, $ev) = @_;
230
231 my $mod = $ev->{mod};
232 my $sym = $ev->{sym};
233
234 if (!($mod & CFClient::KMOD_SHIFT) && delete $self->{shft}) {
235 $::CONN->user_send ("fire_stop");
236 }
237 if (!($mod & CFClient::KMOD_CTRL ) && delete $self->{ctrl}) {
238 $::CONN->user_send ("run_stop");
239 }
240 }
241
242 sub add_command {
243 my ($self, $command, $widget, $cb) = @_;
244
245 (my $abbrev = $command) =~ s/(\S)[^[:space:]_]*[[:space:]_]+/$1/g;
246 warn "$command|$abbrev|$widget\n";#d#
247 }
248
249 1