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.108 by root, Wed Apr 25 01:12:31 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.05, 0.13, 0.05,
31 0.13, 0.30, 0.13, 30 0.13, 0.30, 0.13,
32 0.05, 0.13, 0.05, 31 0.05, 0.13, 0.05,
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;
494 500
495 glPushMatrix; 501 glPushMatrix;
496 glTranslate $sx0, $sy0; 502 glTranslate $sx0, $sy0;
497 glScale $::CFG->{map_scale}, $::CFG->{map_scale}; 503 glScale $::CFG->{map_scale}, $::CFG->{map_scale};
498 504
499 $::MAP->draw ($dx, $dy, $sw, $sh, ::T); 505 $::MAP->draw ($dx, $dy, $sw, $sh, $self->{tilesize});
500 506
501 glScale ::T, ::T; 507 glScale $self->{tilesize}, $self->{tilesize};
502 508
503 if (my $tex = $self->{fow_texture}) { 509 if (my $tex = $self->{fow_texture}) {
504 glEnable GL_TEXTURE_2D; 510 glEnable GL_TEXTURE_2D;
505 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 511 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
506 512
550 $self->SUPER::DESTROY; 556 $self->SUPER::DESTROY;
551} 557}
552 558
553package CFPlus::MapWidget::MapMap; 559package CFPlus::MapWidget::MapMap;
554 560
561use strict;
562use utf8;
563
555our @ISA = CFPlus::UI::Base::; 564our @ISA = CFPlus::UI::Base::;
556 565
557use Time::HiRes qw(time); 566use Time::HiRes qw(time);
558use CFPlus::OpenGL; 567use CFPlus::OpenGL;
559 568
581 590
582 $::MAP or return; 591 $::MAP or return;
583 592
584 my ($w, $h) = @$self{qw(w h)}; 593 my ($w, $h) = @$self{qw(w h)};
585 594
586 my $sw = int $::WIDTH / (::T * $::CFG->{map_scale}) + 0.99; 595 my $sw = int $::WIDTH / ($::MAPWIDGET->{tilesize} * $::CFG->{map_scale}) + 0.99;
587 my $sh = int $::HEIGHT / (::T * $::CFG->{map_scale}) + 0.99; 596 my $sh = int $::HEIGHT / ($::MAPWIDGET->{tilesize} * $::CFG->{map_scale}) + 0.99;
588 597
589 my $sx = int $::CFG->{map_shift_x} / ::T; 598 my $sx = int $::CFG->{map_shift_x} / $::MAPWIDGET->{tilesize};
590 my $sy = int $::CFG->{map_shift_y} / ::T; 599 my $sy = int $::CFG->{map_shift_y} / $::MAPWIDGET->{tilesize};
591 600
592 my $ox = 0.5 * ($w - $sw); 601 my $ox = 0.5 * ($w - $sw);
593 my $oy = 0.5 * ($h - $sh); 602 my $oy = 0.5 * ($h - $sh);
594 603
595 glEnable GL_BLEND; 604 glEnable GL_BLEND;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines