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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines