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.97 by root, Sat Dec 9 22:28:11 2006 UTC vs.
Revision 1.111 by root, Thu Jul 19 14:54:50 2007 UTC

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, 25 list => glGenList,
26 26 tilesize => 32,
27 smooth_matrix => [
28 0.05, 0.13, 0.05,
29 0.13, 0.30, 0.13,
30 0.05, 0.13, 0.05,
31 ],
32
33 @_ 27 @_
34 ); 28 );
35 29
36 $self->{completer} = new CFPlus::MapWidget::Command:: 30 $self->{completer} = new CFPlus::MapWidget::Command::
37 command => $self->{command}, 31 command => $self->{command},
38 tooltip => "#completer_help", 32 tooltip => "#completer_help",
39 ; 33 ;
40 34
41 $self 35 $self
36}
37
38sub set_tilesize {
39 my ($self, $tilesize) = @_;
40
41 $self->{tilesize} = $tilesize;
42} 42}
43 43
44sub add_command { 44sub add_command {
45 my ($self, $command, $tooltip, $widget, $cb) = @_; 45 my ($self, $command, $tooltip, $widget, $cb) = @_;
46 46
177 177
178 if ($ev->{button} == 1) { 178 if ($ev->{button} == 1) {
179 $self->grab_focus; 179 $self->grab_focus;
180 return unless $::CONN; 180 return unless $::CONN;
181 181
182 my $x = $self->{dx} + CFPlus::floor +($ev->{x} - $self->{sx0}) / $self->{tilesize}; 182 my $x = $self->{dx} + CFPlus::floor +($ev->{x} - $self->{sx0}) / $self->{ctilesize};
183 my $y = $self->{dy} + CFPlus::floor +($ev->{y} - $self->{sy0}) / $self->{tilesize}; 183 my $y = $self->{dy} + CFPlus::floor +($ev->{y} - $self->{sy0}) / $self->{ctilesize};
184 184
185 $x -= CFPlus::floor $::MAP->w * 0.5; 185 $x -= CFPlus::floor $::MAP->w * 0.5;
186 $y -= CFPlus::floor $::MAP->h * 0.5; 186 $y -= CFPlus::floor $::MAP->h * 0.5;
187 187
188 if ($::CONN) { 188 if ($::CONN) {
285 285
286 1 286 1
287} 287}
288 288
289sub size_request { 289sub size_request {
290 my ($self) = @_;
291
290 ( 292 (
291 32 * CFPlus::ceil $::WIDTH / 32, 293 $self->{tilesize} * CFPlus::ceil $::WIDTH / $self->{tilesize},
292 32 * CFPlus::ceil $::HEIGHT / 32, 294 $self->{tilesize} * CFPlus::ceil $::HEIGHT / $self->{tilesize},
293 ) 295 )
294} 296}
295 297
296sub update { 298sub update {
297 my ($self) = @_; 299 my ($self) = @_;
299 $self->{need_update} = 1; 301 $self->{need_update} = 1;
300 $self->SUPER::update; 302 $self->SUPER::update;
301} 303}
302 304
303my %DIR = ( 305my %DIR = (
306 CFPlus::SDLK_KP5, [0, "stay fire"],
304 CFPlus::SDLK_KP8, [1, "north"], 307 CFPlus::SDLK_KP8, [1, "north"],
305 CFPlus::SDLK_KP9, [2, "northeast"], 308 CFPlus::SDLK_KP9, [2, "northeast"],
306 CFPlus::SDLK_KP6, [3, "east"], 309 CFPlus::SDLK_KP6, [3, "east"],
307 CFPlus::SDLK_KP3, [4, "southeast"], 310 CFPlus::SDLK_KP3, [4, "southeast"],
308 CFPlus::SDLK_KP2, [5, "south"], 311 CFPlus::SDLK_KP2, [5, "south"],
323 my $sym = $ev->{sym}; 326 my $sym = $ev->{sym};
324 my $uni = $ev->{unicode}; 327 my $uni = $ev->{unicode};
325 328
326 $mod &= CFPlus::KMOD_CTRL | CFPlus::KMOD_ALT | CFPlus::KMOD_SHIFT; 329 $mod &= CFPlus::KMOD_CTRL | CFPlus::KMOD_ALT | CFPlus::KMOD_SHIFT;
327 330
328 if ($uni == ord "\t") { 331 if ($sym == 9) {
329 $::PL_WINDOW->toggle_visibility; 332 ($mod & CFPlus::KMOD_SHIFT ? $::CONSOLE->{window} : $::PL_WINDOW)->toggle_visibility;
330 } elsif ($sym == CFPlus::SDLK_F1 && !$mod) { 333 } elsif ($sym == CFPlus::SDLK_F1 && !$mod) {
331 $::HELP_WINDOW->toggle_visibility; 334 $::HELP_WINDOW->toggle_visibility;
332 } elsif ($sym == CFPlus::SDLK_F2 && !$mod) { 335 } elsif ($sym == CFPlus::SDLK_F2 && !$mod) {
333 ::toggle_player_page ($::STATS_PAGE); 336 ::toggle_player_page ($::STATS_PAGE);
334 } elsif ($sym == CFPlus::SDLK_F3 && !$mod) { 337 } elsif ($sym == CFPlus::SDLK_F3 && !$mod) {
340 } elsif ($sym == CFPlus::SDLK_F9 && !$mod) { 343 } elsif ($sym == CFPlus::SDLK_F9 && !$mod) {
341 $::SETUP_DIALOG->toggle_visibility; 344 $::SETUP_DIALOG->toggle_visibility;
342 } elsif (!$::CONN) { 345 } elsif (!$::CONN) {
343 return 0; # bindings further down need a valid connection 346 return 0; # bindings further down need a valid connection
344 347
345 } elsif ($sym == CFPlus::SDLK_KP5 && !$mod) {
346 $::CONN->user_send ("stay fire");
347 } elsif ($uni == ord ",") { 348 } elsif ($uni == ord ",") {
348 $::CONN->user_send ("take"); 349 $::CONN->user_send ("take");
349 } elsif ($uni == ord " ") { 350 } elsif ($uni == ord " ") {
350 $::CONN->user_send ("apply"); 351 $::CONN->user_send ("apply");
351 } elsif ($uni == 13) { 352 } elsif ($uni == 13) {
352 $::CONN->user_send ("examine"); 353 $::CONN->user_send ("examine");
353 } elsif ($uni == ord ".") { 354 } elsif ($uni == ord ".") {
354 $::CONN->user_send ($self->{completer}{last_command}) 355 $::CONN->user_send ($self->{completer}{last_command})
355 if exists $self->{completer}{last_command}; 356 if exists $self->{completer}{last_command};
356 } elsif (my @macros = CFPlus::Macro::match_event $ev) { 357 } elsif (my @macros = CFPlus::Macro::match_event $ev) {
357 warn "<@macros>\n";#d#
358 $::CONN->macro_send ($_) for @macros; 358 $::CONN->macro_send ($_) for @macros;
359 } elsif (($sym == CFPlus::SDLK_KP_PLUS && !$mod) || $uni == ord "+") { 359 } elsif (($sym == CFPlus::SDLK_KP_PLUS && !$mod) || $uni == ord "+") {
360 $::CONN->user_send ("rotateshoottype +"); 360 $::CONN->user_send ("rotateshoottype +");
361 } elsif (($sym == CFPlus::SDLK_KP_MINUS && !$mod) || $uni == ord "-") { 361 } elsif (($sym == CFPlus::SDLK_KP_MINUS && !$mod) || $uni == ord "-") {
362 $::CONN->user_send ("rotateshoottype -"); 362 $::CONN->user_send ("rotateshoottype -");
363 } elsif ($uni == ord '!') {
364 $self->{completer}->set_prefix ("shout ");
365 $self->{completer}->show;
363 } elsif ($uni == ord '"') { 366 } elsif ($uni == ord '"') {
364 $self->{completer}->set_prefix ("$::CFG->{say_command} "); 367 $self->{completer}->set_prefix ("$::CFG->{say_command} ");
365 $self->{completer}->show; 368 $self->{completer}->show;
366 } elsif ($uni == ord "'") { 369 } elsif ($uni == ord "'") {
367 $self->{completer}->set_prefix (""); 370 $self->{completer}->set_prefix ("");
420 } 423 }
421 424
422 $res 425 $res
423} 426}
424 427
428sub invoke_visibility_change {
429 my ($self) = @_;
430
431 $self->refresh_hook;
432
433 0
434}
435
425sub set_magicmap { 436sub set_magicmap {
426 my ($self, $w, $h, $x, $y, $data) = @_; 437 my ($self, $w, $h, $x, $y, $data) = @_;
427 438
428 $x -= $::MAP->ox + 1 + int 0.5 * $::MAP->w; 439 $x -= $::MAP->ox + 1 + int 0.5 * $::MAP->w;
429 $y -= $::MAP->oy + 1 + int 0.5 * $::MAP->h; 440 $y -= $::MAP->oy + 1 + int 0.5 * $::MAP->h;
431 $self->{magicmap} = [$x, $y, $w, $h, $data]; 442 $self->{magicmap} = [$x, $y, $w, $h, $data];
432 443
433 $self->update; 444 $self->update;
434} 445}
435 446
436sub draw { 447sub refresh_hook {
437 my ($self) = @_; 448 my ($self) = @_;
438 449
439 return unless $::MAP; 450 return unless $::MAP;
440 451
441 my $focused = $CFPlus::UI::FOCUS == $self
442 || $CFPlus::UI::FOCUS == $self->{completer}{entry};
443
444 return
445 unless $focused || !$::FAST;
446
447 if (delete $self->{need_update}) { 452 if (delete $self->{need_update}) {
448 my $tilesize = $self->{tilesize} = int 32 * $::CFG->{map_scale}; 453 my $tilesize = $self->{ctilesize} = (int $self->{tilesize} * $::CFG->{map_scale}) || 1;
449 454
450 my $sw = $self->{sw} = 1 + CFPlus::ceil $self->{w} / $tilesize; 455 my $sw = $self->{sw} = 1 + CFPlus::ceil $self->{w} / $tilesize;
451 my $sh = $self->{sh} = 1 + CFPlus::ceil $self->{h} / $tilesize; 456 my $sh = $self->{sh} = 1 + CFPlus::ceil $self->{h} / $tilesize;
452 457
453 my $sx = CFPlus::ceil $::CFG->{map_shift_x} / $tilesize; 458 my $sx = CFPlus::ceil $::CFG->{map_shift_x} / $tilesize;
459 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;
460 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;
461 466
462 if ($::CFG->{fow_enable}) { 467 if ($::CFG->{fow_enable}) {
463 my ($w, $h, $data) = $::MAP->fow_texture ($dx, $dy, $sw, $sh); 468 my ($w, $h, $data) = $::MAP->fow_texture ($dx, $dy, $sw, $sh);
464
465 if ($::CFG->{fow_smooth} && $CFPlus::OpenGL::GL_VERSION >= 1.2) { # smooth fog of war
466 glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER);
467 glConvolutionFilter2D (
468 GL_CONVOLUTION_2D,
469 GL_ALPHA,
470 3, 3,
471 GL_ALPHA, GL_FLOAT,
472 (pack "f*", @{ $self->{smooth_matrix} }),
473 );
474 glEnable GL_CONVOLUTION_2D;
475 }
476 469
477 $self->{fow_texture} = new CFPlus::Texture 470 $self->{fow_texture} = new CFPlus::Texture
478 w => $w, 471 w => $w,
479 h => $h, 472 h => $h,
480 data => $data, 473 data => $data,
481 internalformat => GL_ALPHA, 474 internalformat => GL_ALPHA,
482 format => GL_ALPHA; 475 format => GL_ALPHA;
483
484 glDisable GL_CONVOLUTION_2D if $::CFG->{fow_smooth};
485 } else { 476 } else {
486 delete $self->{fow_texture}; 477 delete $self->{fow_texture};
487 } 478 }
488 479
489 glNewList $self->{list}; 480 glNewList $self->{list};
490 481
491 glPushMatrix; 482 glPushMatrix;
492 glTranslate $sx0, $sy0; 483 glTranslate $sx0, $sy0;
493 glScale $::CFG->{map_scale}, $::CFG->{map_scale}; 484 glScale $::CFG->{map_scale}, $::CFG->{map_scale};
494 485
495 $::MAP->draw ($dx, $dy, $sw, $sh); 486 $::MAP->draw ($dx, $dy, $sw, $sh, $self->{tilesize});
496 487
497 glScale 32, 32; 488 glScale $self->{tilesize}, $self->{tilesize};
498 489
499 if (my $tex = $self->{fow_texture}) { 490 if (my $tex = $self->{fow_texture}) {
491 glPushMatrix;
492 glScale 1/3, 1/3;
500 glEnable GL_TEXTURE_2D; 493 glEnable GL_TEXTURE_2D;
501 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 494 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
502 495
503 glColor +($::CFG->{fow_intensity}) x 3, 0.9; 496 glColor +($::CFG->{fow_intensity}) x 3, 0.9;
504 $self->{fow_texture}->draw_quad_alpha (0, 0); 497 $self->{fow_texture}->draw_quad_alpha (0, 0);
505 498
506 glDisable GL_TEXTURE_2D; 499 glDisable GL_TEXTURE_2D;
500 glPopMatrix;
507 } 501 }
508 502
509 if ($self->{magicmap}) { 503 if ($self->{magicmap}) {
510 my ($x, $y, $w, $h, $data) = @{ $self->{magicmap} }; 504 my ($x, $y, $w, $h, $data) = @{ $self->{magicmap} };
511 505
518 } 512 }
519 513
520 glPopMatrix; 514 glPopMatrix;
521 glEndList; 515 glEndList;
522 } 516 }
517
518}
519
520sub draw {
521 my ($self) = @_;
522
523 $self->{root}->on_post_alloc (prepare => sub { $self->refresh_hook });
524
525 return unless $self->{list};
526
527 my $focused = $CFPlus::UI::FOCUS == $self
528 || $CFPlus::UI::FOCUS == $self->{completer}{entry};
529
530 return
531 unless $focused || !$::FAST;
523 532
524 glCallList $self->{list}; 533 glCallList $self->{list};
525 534
526 # TNT2 emulates logops in software (or worse :) 535 # TNT2 emulates logops in software (or worse :)
527 unless ($focused) { 536 unless ($focused) {
546 $self->SUPER::DESTROY; 555 $self->SUPER::DESTROY;
547} 556}
548 557
549package CFPlus::MapWidget::MapMap; 558package CFPlus::MapWidget::MapMap;
550 559
560use strict;
561use utf8;
562
551our @ISA = CFPlus::UI::Base::; 563our @ISA = CFPlus::UI::Base::;
552 564
553use Time::HiRes qw(time); 565use Time::HiRes qw(time);
554use CFPlus::OpenGL; 566use CFPlus::OpenGL;
555 567
556sub size_request { 568sub size_request {
557 ($::HEIGHT * 0.25, $::HEIGHT * 0.25) 569 ($::HEIGHT * 0.2, $::HEIGHT * 0.2)
558} 570}
559 571
560sub invoke_size_allocate { 572sub refresh_hook {
561 my ($self, $w, $h) = @_; 573 my ($self) = @_;
562 574
563 $self->update; 575 if ($::MAP && $self->{texture_atime} < time) {
564
565 1
566}
567
568sub update {
569 my ($self) = @_;
570
571 delete $self->{texture_atime};
572 $self->SUPER::update;
573}
574
575sub _draw {
576 my ($self) = @_;
577
578 $::MAP or return;
579
580 my ($w, $h) = @$self{qw(w h)}; 576 my ($w, $h) = @$self{qw(w h)};
581 577
582 my $sw = int $::WIDTH / (32 * $::CFG->{map_scale}) + 0.99; 578 my $sw = int $::WIDTH / ($::MAPWIDGET->{tilesize} * $::CFG->{map_scale}) + 0.99;
583 my $sh = int $::HEIGHT / (32 * $::CFG->{map_scale}) + 0.99; 579 my $sh = int $::HEIGHT / ($::MAPWIDGET->{tilesize} * $::CFG->{map_scale}) + 0.99;
584 580
585 my $sx = int $::CFG->{map_shift_x} / 32;
586 my $sy = int $::CFG->{map_shift_y} / 32;
587
588 my $ox = 0.5 * ($w - $sw); 581 my $ox = 0.5 * ($w - $sw);
589 my $oy = 0.5 * ($h - $sh); 582 my $oy = 0.5 * ($h - $sh);
590 583
591 glEnable GL_BLEND; 584 my $sx = int $::CFG->{map_shift_x} / $::MAPWIDGET->{tilesize};
592 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 585 my $sy = int $::CFG->{map_shift_y} / $::MAPWIDGET->{tilesize};
593 glEnable GL_TEXTURE_2D;
594 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
595 586
596 if ($self->{texture_atime} < time) { 587 #TODO: map scale is completely borked
588
589 my $x0 = int $ox - $sx + 0.5;
590 my $y0 = int $oy - $sy + 0.5;
591
592 $self->{sw} = $sw;
593 $self->{sh} = $sh;
594
595 $self->{x0} = $x0;
596 $self->{y0} = $y0;
597
597 $self->{texture_atime} = time + 1/3; 598 $self->{texture_atime} = time + 1/3;
598 599
599 $self->{texture} = 600 $self->{texture} =
600 new CFPlus::Texture 601 new CFPlus::Texture
601 w => $w, 602 w => $w,
602 h => $h, 603 h => $h,
603 data => $::MAP->mapmap (-$ox, -$oy, $w, $h), 604 data => $::MAP->mapmap (-$ox, -$oy, $w, $h),
604 type => $CFPlus::GL_VERSION >= 1.2 ? GL_UNSIGNED_INT_8_8_8_8_REV : GL_UNSIGNED_BYTE; 605 type => $CFPlus::GL_VERSION >= 1.2 ? GL_UNSIGNED_INT_8_8_8_8_REV : GL_UNSIGNED_BYTE;
605 } 606 }
607}
608
609sub invoke_visibility_change {
610 my ($self) = @_;
611
612 $self->refresh_hook;
613
614 0
615}
616
617sub invoke_size_allocate {
618 my ($self, $w, $h) = @_;
619
620 $self->update;
621
622 1
623}
624
625sub update {
626 my ($self) = @_;
627
628 delete $self->{texture_atime};
629 $self->SUPER::update;
630}
631
632sub _draw {
633 my ($self) = @_;
634
635 $self->{root}->on_post_alloc (texture => sub { $self->refresh_hook });
636
637 $self->{texture} or return;
638
639 glEnable GL_BLEND;
640 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
641 glEnable GL_TEXTURE_2D;
642 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
606 643
607 $self->{texture}->draw_quad (0, 0); 644 $self->{texture}->draw_quad (0, 0);
608 645
609 glDisable GL_TEXTURE_2D; 646 glDisable GL_TEXTURE_2D;
610 647
611 glTranslate 0.375, 0.375; 648 glTranslate 0.375, 0.375;
612
613 #TODO: map scale is completely borked
614
615 my $x0 = int $ox - $sx + 0.5;
616 my $y0 = int $oy - $sy + 0.5;
617 649
618 glColor 1, 1, 0, 1; 650 glColor 1, 1, 0, 1;
619 glBegin GL_LINE_LOOP; 651 glBegin GL_LINE_LOOP;
620 glVertex $x0 , $y0 ; 652 glVertex $self->{x0} , $self->{y0} ;
621 glVertex $x0 , $y0 + $sh; 653 glVertex $self->{x0} , $self->{y0} + $self->{sh};
622 glVertex $x0 + $sw, $y0 + $sh; 654 glVertex $self->{x0} + $self->{sw}, $self->{y0} + $self->{sh};
623 glVertex $x0 + $sw, $y0 ; 655 glVertex $self->{x0} + $self->{sw}, $self->{y0} ;
624 glEnd; 656 glEnd;
625 657
626 glDisable GL_BLEND; 658 glDisable GL_BLEND;
627} 659}
628 660

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines