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

Comparing deliantra/Deliantra-Client/DC/MapWidget.pm (file contents):
Revision 1.53 by root, Sun Jun 11 17:30:53 2006 UTC vs.
Revision 1.60 by root, Thu Jun 15 08:29:18 2006 UTC

61} 61}
62 62
63sub button_down { 63sub button_down {
64 my ($self, $ev, $x, $y) = @_; 64 my ($self, $ev, $x, $y) = @_;
65 65
66 return unless $::CONN;
67
66 $self->focus_in; 68 $self->focus_in;
67 69
68 if ($ev->{button} == 1) { 70 if ($ev->{button} == 1) {
69 my $sw = int $::WIDTH / (32 * $::CFG->{map_scale}) + 0.99; 71 my $x = CFClient::floor +($ev->{x} - $self->{sx0}) / $self->{tilesize} - $self->{sx};
70 my $sh = int $::HEIGHT / (32 * $::CFG->{map_scale}) + 0.99; 72 my $y = CFClient::floor +($ev->{y} - $self->{sy0}) / $self->{tilesize} - $self->{sy};
71 73
72 my $fx = int +($ev->{x} - $::CFG->{map_shift_x}) / (32 * $::CFG->{map_scale}) - 0.5 * $sw + 0.99; 74 $x -= int 0.5 * $self->{sw};
73 my $fy = int +($ev->{y} - $::CFG->{map_shift_y}) / (32 * $::CFG->{map_scale}) - 0.5 * $sh + 0.99; 75 $y -= int 0.5 * $self->{sh};
74 76
75 $::CONN->send (sprintf "lookat %d %d", $fx, $fy) 77 $::CONN->lookat ($x, $y)
76 if $::CONN; 78 if $::CONN;
77 79
78 } elsif ($ev->{button} == 2) { 80 } elsif ($ev->{button} == 2) {
79 my ($ox, $oy) = ($ev->{x}, $ev->{y}); 81 my ($ox, $oy) = ($ev->{x}, $ev->{y});
80 my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y}); 82 my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y});
175 $self->{completer}->set_prefix (""); 177 $self->{completer}->set_prefix ("");
176 $self->{completer}->show; 178 $self->{completer}->show;
177 } elsif (exists $DIR{$sym}) { 179 } elsif (exists $DIR{$sym}) {
178 if ($mod & CFClient::KMOD_SHIFT) { 180 if ($mod & CFClient::KMOD_SHIFT) {
179 $self->{shft}++; 181 $self->{shft}++;
182 if ($DIR{$sym}[0] != $self->{fire_dir}) {
180 $::CONN->user_send ("fire $DIR{$sym}[0]"); 183 $::CONN->user_send ("fire $DIR{$sym}[0]");
184 }
185 $self->{fire_dir} = $DIR{$sym}[0];
181 } elsif ($mod & CFClient::KMOD_CTRL) { 186 } elsif ($mod & CFClient::KMOD_CTRL) {
182 $self->{ctrl}++; 187 $self->{ctrl}++;
183 $::CONN->user_send ("run $DIR{$sym}[0]"); 188 $::CONN->user_send ("run $DIR{$sym}[0]");
184 } else { 189 } else {
185 $::CONN->user_send ("$DIR{$sym}[1]"); 190 $::CONN->user_send ("$DIR{$sym}[1]");
213 218
214 my $res = 0; 219 my $res = 0;
215 my $mod = $ev->{mod}; 220 my $mod = $ev->{mod};
216 my $sym = $ev->{sym}; 221 my $sym = $ev->{sym};
217 222
223 if ($::CFG->{shift_fire_stop}) {
218 if (!($mod & CFClient::KMOD_SHIFT) && delete $self->{shft}) { 224 if (!($mod & CFClient::KMOD_SHIFT) && delete $self->{shft}) {
219 $::CONN->user_send ("fire_stop"); 225 $::CONN->user_send ("fire_stop");
226 delete $self->{fire_dir};
220 $res = 1; 227 $res = 1;
228 }
229 } else {
230 if (exists $DIR{$sym} && delete $self->{shft}) {
231 $::CONN->user_send ("fire_stop");
232 delete $self->{fire_dir};
233 $res = 1;
234 } elsif (($sym == CFClient::SDLK_LSHIFT || $sym == CFClient::SDLK_RSHIFT) && delete $self->{shft}) { # XXX: is RSHIFT ok?
235 $::CONN->user_send ("fire_stop");
236 delete $self->{fire_dir};
237 $res = 1;
238 }
221 } 239 }
222 240
223 if (!($mod & CFClient::KMOD_CTRL ) && delete $self->{ctrl}) { 241 if (!($mod & CFClient::KMOD_CTRL ) && delete $self->{ctrl}) {
224 $::CONN->user_send ("run_stop"); 242 $::CONN->user_send ("run_stop");
225 $res = 1; 243 $res = 1;
229} 247}
230 248
231sub draw { 249sub draw {
232 my ($self) = @_; 250 my ($self) = @_;
233 251
252 return unless $::MAP;
253
234 my $focused = $CFClient::UI::FOCUS == $self 254 my $focused = $CFClient::UI::FOCUS == $self
235 || $CFClient::UI::FOCUS == $self->{completer}{entry}; 255 || $CFClient::UI::FOCUS == $self->{completer}{entry};
236 256
237 return 257 return
238 unless $focused || !$::FAST; 258 unless $focused || !$::FAST;
239 259
240 if (delete $self->{need_update}) { 260 if (delete $self->{need_update}) {
261 my $tilesize = $self->{tilesize} = int 32 * $::CFG->{map_scale};
262
263 my $sx = $self->{sx} = CFClient::ceil $::CFG->{map_shift_x} / $tilesize;
264 my $sy = $self->{sy} = CFClient::ceil $::CFG->{map_shift_y} / $tilesize;
265
266 my $sx0 = $self->{sx0} = $::CFG->{map_shift_x} - $sx * $tilesize;
267 my $sy0 = $self->{sy0} = $::CFG->{map_shift_y} - $sy * $tilesize;
268
269 my $sw = $self->{sw} = 1 + CFClient::ceil $::WIDTH / $tilesize;
270 my $sh = $self->{sh} = 1 + CFClient::ceil $::HEIGHT / $tilesize;
271
272 if ($::CFG->{fow_enable}) {
273 my ($w, $h, $data) = $::MAP->fow_texture ($sx, $sy, 0, 0, $sw, $sh);
274
275 if ($::CFG->{fow_smooth} && $CFClient::OpenGL::GL_VERSION >= 1.2) { # smooth fog of war
276 glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER);
277 glConvolutionFilter2D (
278 GL_CONVOLUTION_2D,
279 GL_ALPHA,
280 3, 3,
281 GL_ALPHA, GL_FLOAT,
282 (pack "f*", @{ $self->{smooth_matrix} }),
283 );
284 glEnable GL_CONVOLUTION_2D;
285 }
286
287 $self->{fow_texture} = new CFClient::Texture
288 w => $w,
289 h => $h,
290 data => $data,
291 internalformat => GL_ALPHA,
292 format => GL_ALPHA;
293
294 glDisable GL_CONVOLUTION_2D if $::CFG->{fow_smooth};
295 } else {
296 delete $self->{fow_texture};
297 }
298
241 glNewList $self->{list}; 299 glNewList $self->{list};
242 300
243 if ($::MAP) {
244 my $sw = int $::WIDTH / (32 * $::CFG->{map_scale}) + 0.99;
245 my $sh = int $::HEIGHT / (32 * $::CFG->{map_scale}) + 0.99;
246
247 my $sx = $::CFG->{map_shift_x} / $::CFG->{map_scale}; my $sx0 = $sx & 31; $sx = ($sx - $sx0) / 32;
248 my $sy = $::CFG->{map_shift_y} / $::CFG->{map_scale}; my $sy0 = $sy & 31; $sy = ($sy - $sy0) / 32;
249
250 glPushMatrix; 301 glPushMatrix;
302 glTranslate $sx0, $sy0;
251 glScale $::CFG->{map_scale}, $::CFG->{map_scale}; 303 glScale $::CFG->{map_scale}, $::CFG->{map_scale};
252 304
253 glTranslate $sx0 - 32, $sy0 - 32, 0; 305 $::MAP->draw ($sx, $sy, 0, 0, $sw, $sh);
254 306
255 my ($w, $h, $data) = $::MAP->draw ($sx, $sy, 0, 0, $sw + 1, $sh + 1); 307 if (my $tex = $self->{fow_texture}) {
256
257 if ($::CFG->{fow_enable}) {
258 if ($::CFG->{fow_smooth} && $CFClient::OpenGL::GL_VERSION >= 1.2) { # smooth fog of war
259 glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER);
260 glConvolutionFilter2D (
261 GL_CONVOLUTION_2D,
262 GL_ALPHA,
263 3, 3,
264 GL_ALPHA, GL_FLOAT,
265 (pack "f*", @{ $self->{smooth_matrix} }),
266 );
267 glEnable GL_CONVOLUTION_2D;
268 }
269
270 $self->{fow_texture_name} ||= glGenTexture;
271 # try to re-use the texture name: TODO improve texture class instead
272
273 $self->{fow_texture} = new CFClient::Texture
274 w => $w,
275 h => $h,
276 data => $data,
277 name => $self->{fow_texture_name},
278 internalformat => GL_ALPHA,
279 format => GL_ALPHA;
280
281 glDisable GL_CONVOLUTION_2D if $::CFG->{fow_smooth};
282
283 glEnable GL_TEXTURE_2D; 308 glEnable GL_TEXTURE_2D;
284 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 309 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
285 310
311 glScale 32, 32;
286 glColor +($::CFG->{fow_intensity}) x 3, 0.8; 312 glColor +($::CFG->{fow_intensity}) x 3, 0.9;
287 $self->{fow_texture}->draw_quad_alpha (0, 0, $w * 32, $h * 32); 313 $self->{fow_texture}->draw_quad_alpha (0, 0);
288 314
289 glDisable GL_TEXTURE_2D; 315 glDisable GL_TEXTURE_2D;
290 } 316 }
291 317
292 glPopMatrix; 318 glPopMatrix;
293 }
294 319
295 glEndList; 320 glEndList;
296 } 321 }
297 322
298 glPushMatrix; 323 glPushMatrix;
299 glCallList $self->{list}; 324 glCallList $self->{list};
300 glPopMatrix; 325 glPopMatrix;
301 326
302 # TNT2 emulates logops in software (or worse :) 327 # TNT2 emulates logops in software (or worse :)
303 if ($focused) { 328 unless ($focused) {
304 (delete $self->{out_of_focus})->destroy
305 if $self->{out_of_focus};
306 } else {
307 glColor 0.4, 0.2, 0.2, 0.6; 329 glColor 0.4, 0.2, 0.2, 0.6;
308 glEnable GL_BLEND; 330 glEnable GL_BLEND;
309 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 331 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
310 glBegin GL_QUADS; 332 glBegin GL_QUADS;
311 glVertex 0, 0; 333 glVertex 0, 0;
312 glVertex 0, $::HEIGHT; 334 glVertex 0, $::HEIGHT;
313 glVertex $::WIDTH, $::HEIGHT; 335 glVertex $::WIDTH, $::HEIGHT;
314 glVertex $::WIDTH, 0; 336 glVertex $::WIDTH, 0;
315 glEnd; 337 glEnd;
316 glDisable GL_BLEND; 338 glDisable GL_BLEND;
317
318# $self->{out_of_focus} ||= do {
319# my $label = new CFClient::UI::Label
320# x => 0,
321# y => 0,
322# z => 1,
323# ellipsise => 0,
324# text => "map out of focus (click map to play)";
325#
326# $label->show;
327# $label->update;
328#
329# $CFClient::UI::ROOT->on_post_alloc ("$self$label" => sub {
330# $label->move_abs (
331# ($::WIDTH - $label->{w}) * 0.5,
332# ($::HEIGHT - $label->{h}) * 0.5,
333# );
334# });
335#
336# $label
337# };
338 } 339 }
339} 340}
340 341
341sub DESTROY { 342sub DESTROY {
342 my $self = shift; 343 my $self = shift;
454 ]; 455 ];
455 456
456 $self->{entry} = new CFClient::UI::Entry 457 $self->{entry} = new CFClient::UI::Entry
457 on_changed => sub { 458 on_changed => sub {
458 $self->update_labels; 459 $self->update_labels;
460 },
461 on_button_down => sub {
462 my ($entry, $ev, $x, $y) = @_;
463
464 if ($ev->{button} == 3) {
465 (new CFClient::UI::Menu
466 items => [
467 ["bind to a key" => sub { $::BIND_EDITOR->do_quick_binding ([$self->{select}], sub { $entry->focus_in }) }]
468 ],
469 )->popup ($ev);
470 return 1;
471 }
472 0
459 }, 473 },
460 on_key_down => sub { 474 on_key_down => sub {
461 my ($entry, $ev) = @_; 475 my ($entry, $ev) = @_;
462 476
463 my $self = $entry->{parent}{parent}; 477 my $self = $entry->{parent}{parent};

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines