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.102 by root, Sun Apr 1 15:08:14 2007 UTC vs.
Revision 1.109 by root, Tue Jul 17 17:39:07 2007 UTC

10use CFPlus::UI; 10use CFPlus::UI;
11use CFPlus::Macro; 11use CFPlus::Macro;
12 12
13our @ISA = CFPlus::UI::Base::; 13our @ISA = CFPlus::UI::Base::;
14 14
15sub ::T() { 64 }
16
17my $magicmap_tex = 15my $magicmap_tex =
18 new_from_file CFPlus::Texture CFPlus::find_rcfile "magicmap.png", 16 new_from_file CFPlus::Texture CFPlus::find_rcfile "magicmap.png",
19 mipmap => 1, wrap => 0, internalformat => GL_ALPHA; 17 mipmap => 1, wrap => 0, internalformat => GL_ALPHA;
20 18
21sub new { 19sub new {
23 21
24 my $self = $class->SUPER::new ( 22 my $self = $class->SUPER::new (
25 z => -1, 23 z => -1,
26 can_focus => 1, 24 can_focus => 1,
27 list => glGenList, 25 list => glGenList,
26 tilesize => 32,
28 27
29 smooth_matrix => [ 28 smooth_matrix => [
30 0.05, 0.13, 0.05, 29 0.30, 0.50, 0.30,
31 0.13, 0.30, 0.13,
32 0.05, 0.13, 0.05, 30 0.50, 0.50, 0.50,
31 0.30, 0.50, 0.30,
33 ], 32 ],
34 33
35 @_ 34 @_
36 ); 35 );
37 36
39 command => $self->{command}, 38 command => $self->{command},
40 tooltip => "#completer_help", 39 tooltip => "#completer_help",
41 ; 40 ;
42 41
43 $self 42 $self
43}
44
45sub set_tilesize {
46 my ($self, $tilesize) = @_;
47
48 $self->{tilesize} = $tilesize;
44} 49}
45 50
46sub add_command { 51sub add_command {
47 my ($self, $command, $tooltip, $widget, $cb) = @_; 52 my ($self, $command, $tooltip, $widget, $cb) = @_;
48 53
179 184
180 if ($ev->{button} == 1) { 185 if ($ev->{button} == 1) {
181 $self->grab_focus; 186 $self->grab_focus;
182 return unless $::CONN; 187 return unless $::CONN;
183 188
184 my $x = $self->{dx} + CFPlus::floor +($ev->{x} - $self->{sx0}) / $self->{tilesize}; 189 my $x = $self->{dx} + CFPlus::floor +($ev->{x} - $self->{sx0}) / $self->{ctilesize};
185 my $y = $self->{dy} + CFPlus::floor +($ev->{y} - $self->{sy0}) / $self->{tilesize}; 190 my $y = $self->{dy} + CFPlus::floor +($ev->{y} - $self->{sy0}) / $self->{ctilesize};
186 191
187 $x -= CFPlus::floor $::MAP->w * 0.5; 192 $x -= CFPlus::floor $::MAP->w * 0.5;
188 $y -= CFPlus::floor $::MAP->h * 0.5; 193 $y -= CFPlus::floor $::MAP->h * 0.5;
189 194
190 if ($::CONN) { 195 if ($::CONN) {
287 292
288 1 293 1
289} 294}
290 295
291sub size_request { 296sub size_request {
297 my ($self) = @_;
298
292 ( 299 (
293 ::T * CFPlus::ceil $::WIDTH / ::T, 300 $self->{tilesize} * CFPlus::ceil $::WIDTH / $self->{tilesize},
294 ::T * CFPlus::ceil $::HEIGHT / ::T, 301 $self->{tilesize} * CFPlus::ceil $::HEIGHT / $self->{tilesize},
295 ) 302 )
296} 303}
297 304
298sub update { 305sub update {
299 my ($self) = @_; 306 my ($self) = @_;
301 $self->{need_update} = 1; 308 $self->{need_update} = 1;
302 $self->SUPER::update; 309 $self->SUPER::update;
303} 310}
304 311
305my %DIR = ( 312my %DIR = (
313 CFPlus::SDLK_KP5, [0, "stay fire"],
306 CFPlus::SDLK_KP8, [1, "north"], 314 CFPlus::SDLK_KP8, [1, "north"],
307 CFPlus::SDLK_KP9, [2, "northeast"], 315 CFPlus::SDLK_KP9, [2, "northeast"],
308 CFPlus::SDLK_KP6, [3, "east"], 316 CFPlus::SDLK_KP6, [3, "east"],
309 CFPlus::SDLK_KP3, [4, "southeast"], 317 CFPlus::SDLK_KP3, [4, "southeast"],
310 CFPlus::SDLK_KP2, [5, "south"], 318 CFPlus::SDLK_KP2, [5, "south"],
342 } elsif ($sym == CFPlus::SDLK_F9 && !$mod) { 350 } elsif ($sym == CFPlus::SDLK_F9 && !$mod) {
343 $::SETUP_DIALOG->toggle_visibility; 351 $::SETUP_DIALOG->toggle_visibility;
344 } elsif (!$::CONN) { 352 } elsif (!$::CONN) {
345 return 0; # bindings further down need a valid connection 353 return 0; # bindings further down need a valid connection
346 354
347 } elsif ($sym == CFPlus::SDLK_KP5 && !$mod) {
348 $::CONN->user_send ("stay fire");
349 } elsif ($uni == ord ",") { 355 } elsif ($uni == ord ",") {
350 $::CONN->user_send ("take"); 356 $::CONN->user_send ("take");
351 } elsif ($uni == ord " ") { 357 } elsif ($uni == ord " ") {
352 $::CONN->user_send ("apply"); 358 $::CONN->user_send ("apply");
353 } elsif ($uni == 13) { 359 } elsif ($uni == 13) {
447 453
448 return 454 return
449 unless $focused || !$::FAST; 455 unless $focused || !$::FAST;
450 456
451 if (delete $self->{need_update}) { 457 if (delete $self->{need_update}) {
452 my $tilesize = $self->{tilesize} = int ::T * $::CFG->{map_scale}; 458 my $tilesize = $self->{ctilesize} = (int $self->{tilesize} * $::CFG->{map_scale}) || 1;
453 459
454 my $sw = $self->{sw} = 1 + CFPlus::ceil $self->{w} / $tilesize; 460 my $sw = $self->{sw} = 1 + CFPlus::ceil $self->{w} / $tilesize;
455 my $sh = $self->{sh} = 1 + CFPlus::ceil $self->{h} / $tilesize; 461 my $sh = $self->{sh} = 1 + CFPlus::ceil $self->{h} / $tilesize;
456 462
457 my $sx = CFPlus::ceil $::CFG->{map_shift_x} / $tilesize; 463 my $sx = CFPlus::ceil $::CFG->{map_shift_x} / $tilesize;
462 468
463 my $dx = $self->{dx} = CFPlus::ceil 0.5 * ($::MAP->w - $sw) - $sx; 469 my $dx = $self->{dx} = CFPlus::ceil 0.5 * ($::MAP->w - $sw) - $sx;
464 my $dy = $self->{dy} = CFPlus::ceil 0.5 * ($::MAP->h - $sh) - $sy; 470 my $dy = $self->{dy} = CFPlus::ceil 0.5 * ($::MAP->h - $sh) - $sy;
465 471
466 if ($::CFG->{fow_enable}) { 472 if ($::CFG->{fow_enable}) {
467 my ($w, $h, $data) = $::MAP->fow_texture ($dx, $dy, $sw, $sh); 473 my ($w, $h, $data) = $::MAP->fow_texture (
468 474 $dx, $dy, $sw, $sh,
469 if ($::CFG->{fow_smooth} && $CFPlus::OpenGL::GL_VERSION >= 1.2) { # smooth fog of war 475 $::CFG->{fow_smooth},
470 glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER);
471 glConvolutionFilter2D (
472 GL_CONVOLUTION_2D,
473 GL_ALPHA,
474 3, 3,
475 GL_ALPHA, GL_FLOAT,
476 (pack "f*", @{ $self->{smooth_matrix} }), 476 pack "f*", @{ $self->{smooth_matrix} },
477 ); 477 );
478 glEnable GL_CONVOLUTION_2D;
479 }
480 478
481 $self->{fow_texture} = new CFPlus::Texture 479 $self->{fow_texture} = new CFPlus::Texture
482 w => $w, 480 w => $w,
483 h => $h, 481 h => $h,
484 data => $data, 482 data => $data,
485 internalformat => GL_ALPHA, 483 internalformat => GL_ALPHA,
486 format => GL_ALPHA; 484 format => GL_ALPHA;
487
488 glDisable GL_CONVOLUTION_2D if $::CFG->{fow_smooth};
489 } else { 485 } else {
490 delete $self->{fow_texture}; 486 delete $self->{fow_texture};
491 } 487 }
492 488
493 glNewList $self->{list}; 489 glNewList $self->{list};
494 490
495 glPushMatrix; 491 glPushMatrix;
496 glTranslate $sx0, $sy0; 492 glTranslate $sx0, $sy0;
497 glScale $::CFG->{map_scale}, $::CFG->{map_scale}; 493 glScale $::CFG->{map_scale}, $::CFG->{map_scale};
498 494
499 $::MAP->draw ($dx, $dy, $sw, $sh, ::T); 495 $::MAP->draw ($dx, $dy, $sw, $sh, $self->{tilesize});
500 496
501 glScale ::T, ::T; 497 glScale $self->{tilesize}, $self->{tilesize};
502 498
503 if (my $tex = $self->{fow_texture}) { 499 if (my $tex = $self->{fow_texture}) {
500 glPushMatrix;
501 #glScale 1/3, 1/3 if $::CFG->{fow_smooth};
504 glEnable GL_TEXTURE_2D; 502 glEnable GL_TEXTURE_2D;
505 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 503 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
506 504
507 glColor +($::CFG->{fow_intensity}) x 3, 0.9; 505 glColor +($::CFG->{fow_intensity}) x 3, 0.9;
508 $self->{fow_texture}->draw_quad_alpha (0, 0); 506 $self->{fow_texture}->draw_quad_alpha (0, 0);
509 507
510 glDisable GL_TEXTURE_2D; 508 glDisable GL_TEXTURE_2D;
509 glPopMatrix;
511 } 510 }
512 511
513 if ($self->{magicmap}) { 512 if ($self->{magicmap}) {
514 my ($x, $y, $w, $h, $data) = @{ $self->{magicmap} }; 513 my ($x, $y, $w, $h, $data) = @{ $self->{magicmap} };
515 514
550 $self->SUPER::DESTROY; 549 $self->SUPER::DESTROY;
551} 550}
552 551
553package CFPlus::MapWidget::MapMap; 552package CFPlus::MapWidget::MapMap;
554 553
554use strict;
555use utf8;
556
555our @ISA = CFPlus::UI::Base::; 557our @ISA = CFPlus::UI::Base::;
556 558
557use Time::HiRes qw(time); 559use Time::HiRes qw(time);
558use CFPlus::OpenGL; 560use CFPlus::OpenGL;
559 561
581 583
582 $::MAP or return; 584 $::MAP or return;
583 585
584 my ($w, $h) = @$self{qw(w h)}; 586 my ($w, $h) = @$self{qw(w h)};
585 587
586 my $sw = int $::WIDTH / (::T * $::CFG->{map_scale}) + 0.99; 588 my $sw = int $::WIDTH / ($::MAPWIDGET->{tilesize} * $::CFG->{map_scale}) + 0.99;
587 my $sh = int $::HEIGHT / (::T * $::CFG->{map_scale}) + 0.99; 589 my $sh = int $::HEIGHT / ($::MAPWIDGET->{tilesize} * $::CFG->{map_scale}) + 0.99;
588 590
589 my $sx = int $::CFG->{map_shift_x} / ::T; 591 my $sx = int $::CFG->{map_shift_x} / $::MAPWIDGET->{tilesize};
590 my $sy = int $::CFG->{map_shift_y} / ::T; 592 my $sy = int $::CFG->{map_shift_y} / $::MAPWIDGET->{tilesize};
591 593
592 my $ox = 0.5 * ($w - $sw); 594 my $ox = 0.5 * ($w - $sw);
593 my $oy = 0.5 * ($h - $sh); 595 my $oy = 0.5 * ($h - $sh);
594 596
595 glEnable GL_BLEND; 597 glEnable GL_BLEND;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines