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.113 by elmex, Sat Jul 21 20:30:41 2007 UTC vs.
Revision 1.118 by elmex, Tue Aug 14 13:25:25 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:: 29 $self->{completer} = new CFPlus::MapWidget::Command::
184 183
185 $x -= CFPlus::floor $::MAP->w * 0.5; 184 $x -= CFPlus::floor $::MAP->w * 0.5;
186 $y -= CFPlus::floor $::MAP->h * 0.5; 185 $y -= CFPlus::floor $::MAP->h * 0.5;
187 186
188 if ($::CONN) { 187 if ($::CONN) {
189 if ($::IN_BUILD_MODE) {
190 $::CONN->buildat ($::IN_BUILD_MODE, $x, $y);
191 } else {
192 $::CONN->lookat ($x, $y) 188 $::CONN->lookat ($x, $y)
193 }
194 } 189 }
195 190
196 } elsif ($ev->{button} == 2) { 191 } elsif ($ev->{button} == 2) {
197 $self->grab_focus; 192 $self->grab_focus;
198 return unless $::CONN; 193 return unless $::CONN;
344 ::toggle_player_page ($::SPELL_PAGE); 339 ::toggle_player_page ($::SPELL_PAGE);
345 } elsif ($sym == CFPlus::SDLK_F5 && !$mod) { 340 } elsif ($sym == CFPlus::SDLK_F5 && !$mod) {
346 ::toggle_player_page ($::INVENTORY_PAGE); 341 ::toggle_player_page ($::INVENTORY_PAGE);
347 } elsif ($sym == CFPlus::SDLK_F9 && !$mod) { 342 } elsif ($sym == CFPlus::SDLK_F9 && !$mod) {
348 $::SETUP_DIALOG->toggle_visibility; 343 $::SETUP_DIALOG->toggle_visibility;
344 } elsif ($uni >= ord "0" && $uni <= ord "9" && $mod & CFPlus::KMOD_ALT) {
345 $::MESSAGE_WINDOW->user_switch_to_page (chr $uni);
349 } elsif (!$::CONN) { 346 } elsif (!$::CONN) {
350 return 0; # bindings further down need a valid connection 347 return 0; # bindings further down need a valid connection
351 348
352 } elsif ($uni == ord ",") { 349 } elsif ($uni == ord ",") {
353 $::CONN->user_send ("take"); 350 $::CONN->user_send ("take");
354 } elsif ($uni == ord " ") { 351 } elsif ($uni == ord " ") {
355 $::CONN->user_send ("apply"); 352 $::CONN->user_send ("apply");
356 } elsif ($uni == 13) { 353 } elsif ($uni == 13) {
357 $::CONN->user_send ("examine"); 354 $::MESSAGE_WINDOW->activate_current;
358 } elsif ($uni == ord ".") { 355 } elsif ($uni == ord ".") {
359 $::CONN->user_send ($self->{completer}{last_command}) 356 $::CONN->user_send ($self->{completer}{last_command})
360 if exists $self->{completer}{last_command}; 357 if exists $self->{completer}{last_command};
361 } elsif (my @macros = CFPlus::Macro::match_event $ev) { 358 } elsif (my @macros = CFPlus::Macro::match_event $ev) {
362 $::CONN->macro_send ($_) for @macros; 359 $::CONN->macro_send ($_) for @macros;
449} 446}
450 447
451sub refresh_hook { 448sub refresh_hook {
452 my ($self) = @_; 449 my ($self) = @_;
453 450
454 return unless $::MAP; 451 if ($::MAP && $::CONN) {
455
456 if (delete $self->{need_update}) { 452 if (delete $self->{need_update}) {
457 my $tilesize = $self->{ctilesize} = (int $self->{tilesize} * $::CFG->{map_scale}) || 1; 453 my $tilesize = $self->{ctilesize} = (int $self->{tilesize} * $::CFG->{map_scale}) || 1;
458 454
459 my $sw = $self->{sw} = 1 + CFPlus::ceil $self->{w} / $tilesize; 455 my $sw = $self->{sw} = 1 + CFPlus::ceil $self->{w} / $tilesize;
460 my $sh = $self->{sh} = 1 + CFPlus::ceil $self->{h} / $tilesize; 456 my $sh = $self->{sh} = 1 + CFPlus::ceil $self->{h} / $tilesize;
461 457
462 my $sx = CFPlus::ceil $::CFG->{map_shift_x} / $tilesize; 458 my $sx = CFPlus::ceil $::CFG->{map_shift_x} / $tilesize;
463 my $sy = CFPlus::ceil $::CFG->{map_shift_y} / $tilesize; 459 my $sy = CFPlus::ceil $::CFG->{map_shift_y} / $tilesize;
464 460
465 my $sx0 = $self->{sx0} = $::CFG->{map_shift_x} - $sx * $tilesize; 461 my $sx0 = $self->{sx0} = $::CFG->{map_shift_x} - $sx * $tilesize;
466 my $sy0 = $self->{sy0} = $::CFG->{map_shift_y} - $sy * $tilesize; 462 my $sy0 = $self->{sy0} = $::CFG->{map_shift_y} - $sy * $tilesize;
467 463
468 my $dx = $self->{dx} = CFPlus::ceil 0.5 * ($::MAP->w - $sw) - $sx; 464 my $dx = $self->{dx} = CFPlus::ceil 0.5 * ($::MAP->w - $sw) - $sx;
469 my $dy = $self->{dy} = CFPlus::ceil 0.5 * ($::MAP->h - $sh) - $sy; 465 my $dy = $self->{dy} = CFPlus::ceil 0.5 * ($::MAP->h - $sh) - $sy;
470 466
471 if ($::CFG->{fow_enable}) { 467 if ($::CFG->{fow_enable}) {
472 my ($w, $h, $data) = $::MAP->fow_texture ($dx, $dy, $sw, $sh); 468 my ($w, $h, $data) = $::MAP->fow_texture ($dx, $dy, $sw, $sh);
473 469
474 $self->{fow_texture} = new CFPlus::Texture 470 $self->{fow_texture} = new CFPlus::Texture
475 w => $w, 471 w => $w,
476 h => $h, 472 h => $h,
477 data => $data, 473 data => $data,
478 internalformat => GL_ALPHA, 474 internalformat => GL_ALPHA,
479 format => GL_ALPHA; 475 format => GL_ALPHA;
480 } else { 476 } else {
481 delete $self->{fow_texture}; 477 delete $self->{fow_texture};
482 } 478 }
483 479
484 glNewList $self->{list}; 480 glNewList ($self->{list} ||= glGenList);
485 481
486 glPushMatrix;
487 glTranslate $sx0, $sy0;
488 glScale $::CFG->{map_scale}, $::CFG->{map_scale};
489
490 $::MAP->draw ($dx, $dy, $sw, $sh, $self->{tilesize});
491
492 glScale $self->{tilesize}, $self->{tilesize};
493
494 if (my $tex = $self->{fow_texture}) {
495 glPushMatrix; 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;
496 glScale 1/3, 1/3; 492 glScale 1/3, 1/3;
497 glEnable GL_TEXTURE_2D; 493 glEnable GL_TEXTURE_2D;
498 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 494 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
499 495
500 glColor +($::CFG->{fow_intensity}) x 3, 0.9; 496 glColor +($::CFG->{fow_intensity}) x 3, 0.9;
501 $self->{fow_texture}->draw_quad_alpha (0, 0); 497 $self->{fow_texture}->draw_quad_alpha (0, 0);
502 498
503 glDisable GL_TEXTURE_2D; 499 glDisable GL_TEXTURE_2D;
500 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
504 glPopMatrix; 514 glPopMatrix;
505 }
506
507 if ($self->{magicmap}) {
508 my ($x, $y, $w, $h, $data) = @{ $self->{magicmap} };
509
510 $x += $::MAP->ox + $self->{dx};
511 $y += $::MAP->oy + $self->{dy};
512
513 glTranslate - $x - 1, - $y - 1;
514 glBindTexture GL_TEXTURE_2D, $magicmap_tex->{name};
515 $::MAP->draw_magicmap ($x, $y, $w, $h, $data);
516 }
517
518 glPopMatrix;
519 glEndList; 515 glEndList;
516 }
517 } else {
518 glDeleteList delete $self->{list}
519 if $self->{list};
520 } 520 }
521
522} 521}
523 522
524sub draw { 523sub draw {
525 my ($self) = @_; 524 my ($self) = @_;
526 525

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines