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.49 by root, Sat Jun 3 22:50:48 2006 UTC vs.
Revision 1.60 by root, Thu Jun 15 08:29:18 2006 UTC

14 14
15 my $self = $class->SUPER::new ( 15 my $self = $class->SUPER::new (
16 z => -1, 16 z => -1,
17 can_focus => 1, 17 can_focus => 1,
18 list => glGenList, 18 list => glGenList,
19
20 smooth_matrix => [
21 0.05, 0.13, 0.05,
22 0.13, 0.30, 0.13,
23 0.05, 0.13, 0.05,
24 ],
25
19 @_ 26 @_
20 ); 27 );
21 28
22 $self->{completer} = new CFClient::MapWidget::Command:: 29 $self->{completer} = new CFClient::MapWidget::Command::
23 command => $self->{command}, 30 command => $self->{command},
54} 61}
55 62
56sub button_down { 63sub button_down {
57 my ($self, $ev, $x, $y) = @_; 64 my ($self, $ev, $x, $y) = @_;
58 65
66 return unless $::CONN;
67
59 $self->focus_in; 68 $self->focus_in;
60 69
61 if ($ev->{button} == 1) { 70 if ($ev->{button} == 1) {
62 my ($ox, $oy) = ($ev->{x}, $ev->{y}); 71 my $x = CFClient::floor +($ev->{x} - $self->{sx0}) / $self->{tilesize} - $self->{sx};
72 my $y = CFClient::floor +($ev->{y} - $self->{sy0}) / $self->{tilesize} - $self->{sy};
63 73
64 my $fx = int ((($ev->{x} - $::CFG->{map_shift_x}) / (32 * $::CFG->{map_scale})) + 0.99); 74 $x -= int 0.5 * $self->{sw};
65 my $fy = int ((($ev->{y} - $::CFG->{map_shift_y}) / (32 * $::CFG->{map_scale})) + 0.99); 75 $y -= int 0.5 * $self->{sh};
66 $fx += $::MAP->x;
67 $fy += $::MAP->y;
68 76
69 $::CONN->send (sprintf "lookat %d %d", $fx, $fy); 77 $::CONN->lookat ($x, $y)
78 if $::CONN;
70 79
71 warn "FOOX: $fx (".$::MAP->ox.")\n";
72 warn "FOOY: $fy (".$::MAP->oy.")\n";
73 } elsif ($ev->{button} == 2) { 80 } elsif ($ev->{button} == 2) {
74 my ($ox, $oy) = ($ev->{x}, $ev->{y}); 81 my ($ox, $oy) = ($ev->{x}, $ev->{y});
75 my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y}); 82 my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y});
76 83
77 $self->{motion} = sub { 84 $self->{motion} = sub {
170 $self->{completer}->set_prefix (""); 177 $self->{completer}->set_prefix ("");
171 $self->{completer}->show; 178 $self->{completer}->show;
172 } elsif (exists $DIR{$sym}) { 179 } elsif (exists $DIR{$sym}) {
173 if ($mod & CFClient::KMOD_SHIFT) { 180 if ($mod & CFClient::KMOD_SHIFT) {
174 $self->{shft}++; 181 $self->{shft}++;
182 if ($DIR{$sym}[0] != $self->{fire_dir}) {
175 $::CONN->user_send ("fire $DIR{$sym}[0]"); 183 $::CONN->user_send ("fire $DIR{$sym}[0]");
184 }
185 $self->{fire_dir} = $DIR{$sym}[0];
176 } elsif ($mod & CFClient::KMOD_CTRL) { 186 } elsif ($mod & CFClient::KMOD_CTRL) {
177 $self->{ctrl}++; 187 $self->{ctrl}++;
178 $::CONN->user_send ("run $DIR{$sym}[0]"); 188 $::CONN->user_send ("run $DIR{$sym}[0]");
179 } else { 189 } else {
180 $::CONN->user_send ("$DIR{$sym}[1]"); 190 $::CONN->user_send ("$DIR{$sym}[1]");
208 218
209 my $res = 0; 219 my $res = 0;
210 my $mod = $ev->{mod}; 220 my $mod = $ev->{mod};
211 my $sym = $ev->{sym}; 221 my $sym = $ev->{sym};
212 222
223 if ($::CFG->{shift_fire_stop}) {
213 if (!($mod & CFClient::KMOD_SHIFT) && delete $self->{shft}) { 224 if (!($mod & CFClient::KMOD_SHIFT) && delete $self->{shft}) {
214 $::CONN->user_send ("fire_stop"); 225 $::CONN->user_send ("fire_stop");
226 delete $self->{fire_dir};
215 $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 }
216 } 239 }
217 240
218 if (!($mod & CFClient::KMOD_CTRL ) && delete $self->{ctrl}) { 241 if (!($mod & CFClient::KMOD_CTRL ) && delete $self->{ctrl}) {
219 $::CONN->user_send ("run_stop"); 242 $::CONN->user_send ("run_stop");
220 $res = 1; 243 $res = 1;
224} 247}
225 248
226sub draw { 249sub draw {
227 my ($self) = @_; 250 my ($self) = @_;
228 251
252 return unless $::MAP;
253
229 my $focused = $CFClient::UI::FOCUS == $self 254 my $focused = $CFClient::UI::FOCUS == $self
230 || $CFClient::UI::FOCUS == $self->{completer}{entry}; 255 || $CFClient::UI::FOCUS == $self->{completer}{entry};
231 256
232 return 257 return
233 unless $focused || !$::FAST; 258 unless $focused || !$::FAST;
234 259
235 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
236 glNewList $self->{list}; 299 glNewList $self->{list};
237 300
238 if ($::MAP) {
239 my $sw = int $::WIDTH / (32 * $::CFG->{map_scale}) + 0.99;
240 my $sh = int $::HEIGHT / (32 * $::CFG->{map_scale}) + 0.99;
241
242 my $sx = $::CFG->{map_shift_x} / $::CFG->{map_scale}; my $sx0 = $sx & 31; $sx = ($sx - $sx0) / 32;
243 my $sy = $::CFG->{map_shift_y} / $::CFG->{map_scale}; my $sy0 = $sy & 31; $sy = ($sy - $sy0) / 32;
244
245 glPushMatrix; 301 glPushMatrix;
302 glTranslate $sx0, $sy0;
246 glScale $::CFG->{map_scale}, $::CFG->{map_scale}; 303 glScale $::CFG->{map_scale}, $::CFG->{map_scale};
247 304
248 glTranslate $sx0 - 32, $sy0 - 32, 0; 305 $::MAP->draw ($sx, $sy, 0, 0, $sw, $sh);
249 306
250 my ($w, $h, $data) = $::MAP->draw ($sx, $sy, 0, 0, $sw + 1, $sh + 1); 307 if (my $tex = $self->{fow_texture}) {
251
252 if ($::CFG->{fow_enable}) {
253 if ($::CFG->{fow_smooth} && $CFClient::OpenGL::GL_VERSION >= 1.2) { # smooth fog of war
254 glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER);
255 glConvolutionFilter2D (
256 GL_CONVOLUTION_2D,
257 GL_ALPHA,
258 3, 3,
259 GL_ALPHA, GL_FLOAT,
260 pack "f*",
261 0.05, 0.13, 0.05,
262 0.13, 0.30, 0.13,
263 0.05, 0.13, 0.05,
264 );
265 glEnable GL_CONVOLUTION_2D;
266 }
267
268 $self->{fow_texture_name} ||= glGenTexture;
269 # try to re-use the texture name: TODO improve texture class instead
270
271 $self->{fow_texture} = new CFClient::Texture
272 w => $w,
273 h => $h,
274 data => $data,
275 name => $self->{fow_texture_name},
276 internalformat => GL_ALPHA,
277 format => GL_ALPHA;
278
279 glDisable GL_CONVOLUTION_2D if $::CFG->{fow_smooth};
280
281 glEnable GL_TEXTURE_2D; 308 glEnable GL_TEXTURE_2D;
282 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 309 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
283 310
311 glScale 32, 32;
284 glColor +($::CFG->{fow_intensity}) x 3, 0.8; 312 glColor +($::CFG->{fow_intensity}) x 3, 0.9;
285 $self->{fow_texture}->draw_quad_alpha (0, 0, $w * 32, $h * 32); 313 $self->{fow_texture}->draw_quad_alpha (0, 0);
286 314
287 glDisable GL_TEXTURE_2D; 315 glDisable GL_TEXTURE_2D;
288 } 316 }
289 317
290 glPopMatrix; 318 glPopMatrix;
291 }
292 319
293 glEndList; 320 glEndList;
294 } 321 }
295 322
296 glPushMatrix; 323 glPushMatrix;
297 glCallList $self->{list}; 324 glCallList $self->{list};
298 glPopMatrix; 325 glPopMatrix;
299 326
300 # TNT2 emulates logops in software (or worse :) 327 # TNT2 emulates logops in software (or worse :)
301 if ($focused) { 328 unless ($focused) {
302 (delete $self->{out_of_focus})->destroy
303 if $self->{out_of_focus};
304 } else {
305 glColor 0.4, 0.2, 0.2, 0.6; 329 glColor 0.4, 0.2, 0.2, 0.6;
306 glEnable GL_BLEND; 330 glEnable GL_BLEND;
307 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 331 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
308 glBegin GL_QUADS; 332 glBegin GL_QUADS;
309 glVertex 0, 0; 333 glVertex 0, 0;
310 glVertex 0, $::HEIGHT; 334 glVertex 0, $::HEIGHT;
311 glVertex $::WIDTH, $::HEIGHT; 335 glVertex $::WIDTH, $::HEIGHT;
312 glVertex $::WIDTH, 0; 336 glVertex $::WIDTH, 0;
313 glEnd; 337 glEnd;
314 glDisable GL_BLEND; 338 glDisable GL_BLEND;
315
316# $self->{out_of_focus} ||= do {
317# my $label = new CFClient::UI::Label
318# x => 0,
319# y => 0,
320# z => 1,
321# ellipsise => 0,
322# text => "map out of focus (click map to play)";
323#
324# $label->show;
325# $label->update;
326#
327# $CFClient::UI::ROOT->on_post_alloc ("$self$label" => sub {
328# $label->move_abs (
329# ($::WIDTH - $label->{w}) * 0.5,
330# ($::HEIGHT - $label->{h}) * 0.5,
331# );
332# });
333#
334# $label
335# };
336 } 339 }
337} 340}
338 341
339sub DESTROY { 342sub DESTROY {
340 my $self = shift; 343 my $self = shift;
453 456
454 $self->{entry} = new CFClient::UI::Entry 457 $self->{entry} = new CFClient::UI::Entry
455 on_changed => sub { 458 on_changed => sub {
456 $self->update_labels; 459 $self->update_labels;
457 }, 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
473 },
458 on_key_down => sub { 474 on_key_down => sub {
459 my ($entry, $ev) = @_; 475 my ($entry, $ev) = @_;
460 476
461 my $self = $entry->{parent}{parent}; 477 my $self = $entry->{parent}{parent};
462 478
463 if ($ev->{sym} == 13) { 479 if ($ev->{sym} == 13) {
464 if (exists $self->{select}) { 480 if (exists $self->{select}) {
465 $self->{last_command} = $self->{select}; 481 $self->{last_command} = $self->{select};
466 $::CONN->user_send ($self->{select}); 482 $::CONN->user_send ($self->{select});
483
484 unshift @{$self->{history}}, $self->{select};
485 $self->{hist_ptr} = 0;
486
467 $self->hide; 487 $self->hide;
468 } 488 }
469 } elsif ($ev->{sym} == 27) { 489 } elsif ($ev->{sym} == 27) {
490 $self->{hist_ptr} = 0;
470 $self->hide; 491 $self->hide;
471 return; 492 return;
472 } elsif ($ev->{sym} == CFClient::SDLK_DOWN) { 493 } elsif ($ev->{sym} == CFClient::SDLK_DOWN) {
494 if ($self->{hist_ptr} > 1) {
495 $self->{hist_ptr}--;
496 $self->{entry}->set_text ($self->{history}->[$self->{hist_ptr} - 1]);
497 } elsif ($self->{hist_ptr} > 0) {
498 $self->{hist_ptr}--;
499 $self->{entry}->set_text ($self->{hist_saveback});
500 } else {
473 ++$self->{select_offset} 501 ++$self->{select_offset}
474 if $self->{select_offset} < $#{ $self->{last_match} || [] }; 502 if $self->{select_offset} < $#{ $self->{last_match} || [] };
503 }
475 $self->update_labels; 504 $self->update_labels;
476 } elsif ($ev->{sym} == CFClient::SDLK_UP) { 505 } elsif ($ev->{sym} == CFClient::SDLK_UP) {
506 if ($self->{select_offset}) {
477 --$self->{select_offset} 507 --$self->{select_offset}
508 } else {
509 unless ($self->{hist_ptr}) {
510 $self->{hist_saveback} = $self->{entry}->get_text;
511 }
512 if ($self->{hist_ptr} <= $#{$self->{history}}) {
478 if $self->{select_offset}; 513 $self->{hist_ptr}++;
514 }
515 $self->{entry}->set_text ($self->{history}->[$self->{hist_ptr} - 1])
516 if exists $self->{history}->[$self->{hist_ptr} - 1];
517 }
479 $self->update_labels; 518 $self->update_labels;
480 } else { 519 } else {
481 return 0; 520 return 0;
482 } 521 }
483 522

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines