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.111 by root, Thu Jul 19 14:54:50 2007 UTC vs.
Revision 1.119 by root, Tue Aug 28 01:23:47 2007 UTC

20 my $class = shift; 20 my $class = shift;
21 21
22 my $self = $class->SUPER::new ( 22 my $self = $class->SUPER::new (
23 z => -1, 23 z => -1,
24 can_focus => 1, 24 can_focus => 1,
25 list => glGenList,
26 tilesize => 32, 25 tilesize => 32,
27 @_ 26 @_
28 ); 27 );
29 28
30 $self->{completer} = new CFPlus::MapWidget::Command::
31 command => $self->{command},
32 tooltip => "#completer_help",
33 ;
34
35 $self 29 $self
36} 30}
37 31
38sub set_tilesize { 32sub set_tilesize {
39 my ($self, $tilesize) = @_; 33 my ($self, $tilesize) = @_;
48 42
49 $tooltip =~ s/^\s+//; 43 $tooltip =~ s/^\s+//;
50 $tooltip = "<big>$data</big>\n\n$tooltip"; 44 $tooltip = "<big>$data</big>\n\n$tooltip";
51 $tooltip =~ s/\s+$//; 45 $tooltip =~ s/\s+$//;
52 46
53 $self->{completer}{command}{$command} = [$data, $tooltip, $widget, $cb, ++$self->{command_id}]; 47 $::COMPLETER->{command}{$command} = [$data, $tooltip, $widget, $cb, ++$self->{command_id}];
54} 48}
55 49
56sub clr_commands { 50sub clr_commands {
57 my ($self) = @_; 51 my ($self) = @_;
58 52
59 %{$self->{completer}{command}} = (); 53 %{$::COMPLETER->{command}} = ();
60 54
61 $self->{completer}->hide 55 $::COMPLETER->hide
62 if $self->{completer}; 56 if $::COMPLETER;
63} 57}
64 58
65sub server_login { 59sub server_login {
66 my ($server) = @_; 60 my ($server) = @_;
67 61
184 178
185 $x -= CFPlus::floor $::MAP->w * 0.5; 179 $x -= CFPlus::floor $::MAP->w * 0.5;
186 $y -= CFPlus::floor $::MAP->h * 0.5; 180 $y -= CFPlus::floor $::MAP->h * 0.5;
187 181
188 if ($::CONN) { 182 if ($::CONN) {
189 if ($::IN_BUILD_MODE) {
190 $::CONN->buildat ($::IN_BUILD_MODE, $x, $y);
191 } else {
192 $::CONN->lookat ($x, $y) 183 $::CONN->lookat ($x, $y)
193 }
194 } 184 }
195 185
196 } elsif ($ev->{button} == 2) { 186 } elsif ($ev->{button} == 2) {
197 $self->grab_focus; 187 $self->grab_focus;
198 return unless $::CONN; 188 return unless $::CONN;
301 $self->{need_update} = 1; 291 $self->{need_update} = 1;
302 $self->SUPER::update; 292 $self->SUPER::update;
303} 293}
304 294
305my %DIR = ( 295my %DIR = (
306 CFPlus::SDLK_KP5, [0, "stay fire"], 296 ( "," . CFPlus::SDLK_KP5 ), [0, "stay fire"],
307 CFPlus::SDLK_KP8, [1, "north"], 297 ( "," . CFPlus::SDLK_KP8 ), [1, "north"],
308 CFPlus::SDLK_KP9, [2, "northeast"], 298 ( "," . CFPlus::SDLK_KP9 ), [2, "northeast"],
309 CFPlus::SDLK_KP6, [3, "east"], 299 ( "," . CFPlus::SDLK_KP6 ), [3, "east"],
310 CFPlus::SDLK_KP3, [4, "southeast"], 300 ( "," . CFPlus::SDLK_KP3 ), [4, "southeast"],
311 CFPlus::SDLK_KP2, [5, "south"], 301 ( "," . CFPlus::SDLK_KP2 ), [5, "south"],
312 CFPlus::SDLK_KP1, [6, "southwest"], 302 ( "," . CFPlus::SDLK_KP1 ), [6, "southwest"],
313 CFPlus::SDLK_KP4, [7, "west"], 303 ( "," . CFPlus::SDLK_KP4 ), [7, "west"],
314 CFPlus::SDLK_KP7, [8, "northwest"], 304 ( "," . CFPlus::SDLK_KP7 ), [8, "northwest"],
315 305
316 CFPlus::SDLK_UP, [1, "north"], 306 ( "," . CFPlus::SDLK_UP ), [1, "north"],
307 ("1," . CFPlus::SDLK_UP ), [2, "northeast"],
317 CFPlus::SDLK_RIGHT, [3, "east"], 308 ( "," . CFPlus::SDLK_RIGHT), [3, "east"],
309 ("1," . CFPlus::SDLK_RIGHT), [4, "southeast"],
318 CFPlus::SDLK_DOWN, [5, "south"], 310 ( "," . CFPlus::SDLK_DOWN ), [5, "south"],
311 ("1," . CFPlus::SDLK_DOWN ), [6, "southwest"],
319 CFPlus::SDLK_LEFT, [7, "west"], 312 ( "," . CFPlus::SDLK_LEFT ), [7, "west"],
313 ("1," . CFPlus::SDLK_LEFT ), [8, "northwest"],
320); 314);
321 315
322sub invoke_key_down { 316sub invoke_key_down {
323 my ($self, $ev) = @_; 317 my ($self, $ev) = @_;
324 318
326 my $sym = $ev->{sym}; 320 my $sym = $ev->{sym};
327 my $uni = $ev->{unicode}; 321 my $uni = $ev->{unicode};
328 322
329 $mod &= CFPlus::KMOD_CTRL | CFPlus::KMOD_ALT | CFPlus::KMOD_SHIFT; 323 $mod &= CFPlus::KMOD_CTRL | CFPlus::KMOD_ALT | CFPlus::KMOD_SHIFT;
330 324
331 if ($sym == 9) { 325 if ($::CONN && (my $dir = $DIR{(!!($mod & CFPlus::KMOD_ALT)) . ",$sym"})) {
332 ($mod & CFPlus::KMOD_SHIFT ? $::CONSOLE->{window} : $::PL_WINDOW)->toggle_visibility;
333 } elsif ($sym == CFPlus::SDLK_F1 && !$mod) {
334 $::HELP_WINDOW->toggle_visibility;
335 } elsif ($sym == CFPlus::SDLK_F2 && !$mod) {
336 ::toggle_player_page ($::STATS_PAGE);
337 } elsif ($sym == CFPlus::SDLK_F3 && !$mod) {
338 ::toggle_player_page ($::SKILL_PAGE);
339 } elsif ($sym == CFPlus::SDLK_F4 && !$mod) {
340 ::toggle_player_page ($::SPELL_PAGE);
341 } elsif ($sym == CFPlus::SDLK_F5 && !$mod) {
342 ::toggle_player_page ($::INVENTORY_PAGE);
343 } elsif ($sym == CFPlus::SDLK_F9 && !$mod) {
344 $::SETUP_DIALOG->toggle_visibility;
345 } elsif (!$::CONN) {
346 return 0; # bindings further down need a valid connection
347
348 } elsif ($uni == ord ",") {
349 $::CONN->user_send ("take");
350 } elsif ($uni == ord " ") {
351 $::CONN->user_send ("apply");
352 } elsif ($uni == 13) {
353 $::CONN->user_send ("examine");
354 } elsif ($uni == ord ".") {
355 $::CONN->user_send ($self->{completer}{last_command})
356 if exists $self->{completer}{last_command};
357 } elsif (my @macros = CFPlus::Macro::match_event $ev) {
358 $::CONN->macro_send ($_) for @macros;
359 } elsif (($sym == CFPlus::SDLK_KP_PLUS && !$mod) || $uni == ord "+") {
360 $::CONN->user_send ("rotateshoottype +");
361 } elsif (($sym == CFPlus::SDLK_KP_MINUS && !$mod) || $uni == ord "-") {
362 $::CONN->user_send ("rotateshoottype -");
363 } elsif ($uni == ord '!') {
364 $self->{completer}->set_prefix ("shout ");
365 $self->{completer}->show;
366 } elsif ($uni == ord '"') {
367 $self->{completer}->set_prefix ("$::CFG->{say_command} ");
368 $self->{completer}->show;
369 } elsif ($uni == ord "'") {
370 $self->{completer}->set_prefix ("");
371 $self->{completer}->show;
372 } elsif (exists $DIR{$sym}) {
373 if ($mod & CFPlus::KMOD_SHIFT) { 326 if ($mod & CFPlus::KMOD_SHIFT) {
374 $self->{shft}++; 327 $self->{shft}++;
375 if ($DIR{$sym}[0] != $self->{fire_dir}) { 328 if ($dir->[0] != $self->{fire_dir}) {
376 $::CONN->user_send ("fire $DIR{$sym}[0]"); 329 $::CONN->user_send ("fire $dir->[0]");
377 } 330 }
378 $self->{fire_dir} = $DIR{$sym}[0]; 331 $self->{fire_dir} = $DIR{$sym}[0];
379 } elsif ($mod & CFPlus::KMOD_CTRL) { 332 } elsif ($mod & CFPlus::KMOD_CTRL) {
380 $self->{ctrl}++; 333 $self->{ctrl}++;
381 $::CONN->user_send ("run $DIR{$sym}[0]"); 334 $::CONN->user_send ("run $dir->[0]");
382 } else { 335 } else {
383 $::CONN->user_send ("$DIR{$sym}[1]"); 336 $::CONN->user_send ("$dir->[1]");
384 } 337 }
385 } elsif ((ord 'a') <= $uni && $uni <= (ord 'z')) { 338
386 $self->{completer}->inject_key_down ($ev);
387 $self->{completer}->show;
388 } else {
389 return 0; 339 return 1;
390 }
391
392 1 340 }
341
342 0
393} 343}
394 344
395sub invoke_key_up { 345sub invoke_key_up {
396 my ($self, $ev) = @_; 346 my ($self, $ev) = @_;
397 347
445} 395}
446 396
447sub refresh_hook { 397sub refresh_hook {
448 my ($self) = @_; 398 my ($self) = @_;
449 399
450 return unless $::MAP; 400 if ($::MAP && $::CONN) {
451
452 if (delete $self->{need_update}) { 401 if (delete $self->{need_update}) {
453 my $tilesize = $self->{ctilesize} = (int $self->{tilesize} * $::CFG->{map_scale}) || 1; 402 my $tilesize = $self->{ctilesize} = (int $self->{tilesize} * $::CFG->{map_scale}) || 1;
454 403
455 my $sw = $self->{sw} = 1 + CFPlus::ceil $self->{w} / $tilesize; 404 my $sw = $self->{sw} = 1 + CFPlus::ceil $self->{w} / $tilesize;
456 my $sh = $self->{sh} = 1 + CFPlus::ceil $self->{h} / $tilesize; 405 my $sh = $self->{sh} = 1 + CFPlus::ceil $self->{h} / $tilesize;
457 406
458 my $sx = CFPlus::ceil $::CFG->{map_shift_x} / $tilesize; 407 my $sx = CFPlus::ceil $::CFG->{map_shift_x} / $tilesize;
459 my $sy = CFPlus::ceil $::CFG->{map_shift_y} / $tilesize; 408 my $sy = CFPlus::ceil $::CFG->{map_shift_y} / $tilesize;
460 409
461 my $sx0 = $self->{sx0} = $::CFG->{map_shift_x} - $sx * $tilesize; 410 my $sx0 = $self->{sx0} = $::CFG->{map_shift_x} - $sx * $tilesize;
462 my $sy0 = $self->{sy0} = $::CFG->{map_shift_y} - $sy * $tilesize; 411 my $sy0 = $self->{sy0} = $::CFG->{map_shift_y} - $sy * $tilesize;
463 412
464 my $dx = $self->{dx} = CFPlus::ceil 0.5 * ($::MAP->w - $sw) - $sx; 413 my $dx = $self->{dx} = CFPlus::ceil 0.5 * ($::MAP->w - $sw) - $sx;
465 my $dy = $self->{dy} = CFPlus::ceil 0.5 * ($::MAP->h - $sh) - $sy; 414 my $dy = $self->{dy} = CFPlus::ceil 0.5 * ($::MAP->h - $sh) - $sy;
466 415
467 if ($::CFG->{fow_enable}) { 416 if ($::CFG->{fow_enable}) {
468 my ($w, $h, $data) = $::MAP->fow_texture ($dx, $dy, $sw, $sh); 417 my ($w, $h, $data) = $::MAP->fow_texture ($dx, $dy, $sw, $sh);
469 418
470 $self->{fow_texture} = new CFPlus::Texture 419 $self->{fow_texture} = new CFPlus::Texture
471 w => $w, 420 w => $w,
472 h => $h, 421 h => $h,
473 data => $data, 422 data => $data,
474 internalformat => GL_ALPHA, 423 internalformat => GL_ALPHA,
475 format => GL_ALPHA; 424 format => GL_ALPHA;
476 } else { 425 } else {
477 delete $self->{fow_texture}; 426 delete $self->{fow_texture};
478 } 427 }
479 428
480 glNewList $self->{list}; 429 glNewList ($self->{list} ||= glGenList);
481 430
482 glPushMatrix;
483 glTranslate $sx0, $sy0;
484 glScale $::CFG->{map_scale}, $::CFG->{map_scale};
485
486 $::MAP->draw ($dx, $dy, $sw, $sh, $self->{tilesize});
487
488 glScale $self->{tilesize}, $self->{tilesize};
489
490 if (my $tex = $self->{fow_texture}) {
491 glPushMatrix; 431 glPushMatrix;
432 glTranslate $sx0, $sy0;
433 glScale $::CFG->{map_scale}, $::CFG->{map_scale};
434
435 $::MAP->draw ($dx, $dy, $sw, $sh, $self->{tilesize});
436
437 glScale $self->{tilesize}, $self->{tilesize};
438
439 if (my $tex = $self->{fow_texture}) {
440 glPushMatrix;
492 glScale 1/3, 1/3; 441 glScale 1/3, 1/3;
493 glEnable GL_TEXTURE_2D; 442 glEnable GL_TEXTURE_2D;
494 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 443 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
495 444
496 glColor +($::CFG->{fow_intensity}) x 3, 0.9; 445 glColor +($::CFG->{fow_intensity}) x 3, 0.9;
497 $self->{fow_texture}->draw_quad_alpha (0, 0); 446 $self->{fow_texture}->draw_quad_alpha (0, 0);
498 447
499 glDisable GL_TEXTURE_2D; 448 glDisable GL_TEXTURE_2D;
449 glPopMatrix;
450 }
451
452 if ($self->{magicmap}) {
453 my ($x, $y, $w, $h, $data) = @{ $self->{magicmap} };
454
455 $x += $::MAP->ox + $self->{dx};
456 $y += $::MAP->oy + $self->{dy};
457
458 glTranslate - $x - 1, - $y - 1;
459 glBindTexture GL_TEXTURE_2D, $magicmap_tex->{name};
460 $::MAP->draw_magicmap ($x, $y, $w, $h, $data);
461 }
462
500 glPopMatrix; 463 glPopMatrix;
501 }
502
503 if ($self->{magicmap}) {
504 my ($x, $y, $w, $h, $data) = @{ $self->{magicmap} };
505
506 $x += $::MAP->ox + $self->{dx};
507 $y += $::MAP->oy + $self->{dy};
508
509 glTranslate - $x - 1, - $y - 1;
510 glBindTexture GL_TEXTURE_2D, $magicmap_tex->{name};
511 $::MAP->draw_magicmap ($x, $y, $w, $h, $data);
512 }
513
514 glPopMatrix;
515 glEndList; 464 glEndList;
465 }
466 } else {
467 glDeleteList delete $self->{list}
468 if $self->{list};
516 } 469 }
517
518} 470}
519 471
520sub draw { 472sub draw {
521 my ($self) = @_; 473 my ($self) = @_;
522 474
523 $self->{root}->on_post_alloc (prepare => sub { $self->refresh_hook }); 475 $self->{root}->on_post_alloc (prepare => sub { $self->refresh_hook });
524 476
525 return unless $self->{list}; 477 return unless $self->{list};
526 478
527 my $focused = $CFPlus::UI::FOCUS == $self 479 my $focused = $CFPlus::UI::FOCUS == $self
528 || $CFPlus::UI::FOCUS == $self->{completer}{entry}; 480 || $CFPlus::UI::FOCUS == $::COMPLETER{entry};
529 481
530 return 482 return
531 unless $focused || !$::FAST; 483 unless $focused || !$::FAST;
532 484
533 glCallList $self->{list}; 485 glCallList $self->{list};

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines