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.124 by root, Wed Dec 26 18:09:30 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
85 print "preparing editor startup...\n"; 72 print "preparing editor startup...\n";
86 73
87 my $server = $editsup->{gameserver} || "default"; 74 my $server = $editsup->{gameserver} || "default";
88 $server =~ s/([^a-zA-Z0-9_\-])/sprintf "=%x=", ord $1/ge; 75 $server =~ s/([^a-zA-Z0-9_\-])/sprintf "=%x=", ord $1/ge;
89 76
90 local $ENV{CROSSFIRE_MAPDIR} = my $mapdir = "$Crossfire::VARDIR/map.$server"; mkdir $mapdir; 77 local $ENV{CROSSFIRE_MAPDIR} = my $mapdir = "$Deliantra::VARDIR/map.$server"; mkdir $mapdir;
91 local $ENV{CROSSFIRE_LIBDIR} = my $libdir = "$Crossfire::VARDIR/lib.$server"; mkdir $libdir; 78 local $ENV{CROSSFIRE_LIBDIR} = my $libdir = "$Deliantra::VARDIR/lib.$server"; mkdir $libdir;
92 79
93 print "map directory is $mapdir\n"; 80 print "map directory is $mapdir\n";
94 print "lib directory is $libdir\n"; 81 print "lib directory is $libdir\n";
95 82
96 my $ua = CFPlus::lwp_useragent; 83 my $ua = CFPlus::lwp_useragent;
133 require File::Path; 120 require File::Path;
134 121
135 File::Path::mkpath (File::Basename::dirname ($mappath)); 122 File::Path::mkpath (File::Basename::dirname ($mappath));
136 open my $fh, ">:raw:perlio", "$mappath.meta" 123 open my $fh, ">:raw:perlio", "$mappath.meta"
137 or die "$mappath.meta: $!\n"; 124 or die "$mappath.meta: $!\n";
138 print $fh CFPlus::to_json $meta; 125 print $fh CFPlus::encode_json $meta;
139 close $fh; 126 close $fh;
140 open my $fh, ">:raw:perlio:utf8", $mappath 127 open my $fh, ">:raw:perlio:utf8", $mappath
141 or die "$mappath: $!\n"; 128 or die "$mappath: $!\n";
142 print $fh $map; 129 print $fh $map;
143 close $fh; 130 close $fh;
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->[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
411 $::CONN->user_send ("fire_stop"); 354 $::CONN->user_send ("fire_stop");
412 delete $self->{fire_dir}; 355 delete $self->{fire_dir};
413 $res = 1; 356 $res = 1;
414 } 357 }
415 } else { 358 } else {
416 if (exists $DIR{$sym} && delete $self->{shft}) { 359 if (exists $DIR{(!!($mod & CFPlus::KMOD_ALT)) . ",$sym"} && delete $self->{shft}) {
417 $::CONN->user_send ("fire_stop"); 360 $::CONN->user_send ("fire_stop");
418 delete $self->{fire_dir}; 361 delete $self->{fire_dir};
419 $res = 1; 362 $res = 1;
420 } elsif (($sym == CFPlus::SDLK_LSHIFT || $sym == CFPlus::SDLK_RSHIFT) && delete $self->{shft}) { # XXX: is RSHIFT ok? 363 } elsif (($sym == CFPlus::SDLK_LSHIFT || $sym == CFPlus::SDLK_RSHIFT)
364 && delete $self->{shft}) { # XXX: is RSHIFT ok?
421 $::CONN->user_send ("fire_stop"); 365 $::CONN->user_send ("fire_stop");
422 delete $self->{fire_dir}; 366 delete $self->{fire_dir};
423 $res = 1; 367 $res = 1;
424 } 368 }
425 } 369 }
452} 396}
453 397
454sub refresh_hook { 398sub refresh_hook {
455 my ($self) = @_; 399 my ($self) = @_;
456 400
457 return unless $::MAP; 401 if ($::MAP && $::CONN) {
458
459 if (delete $self->{need_update}) { 402 if (delete $self->{need_update}) {
460 my $tilesize = $self->{ctilesize} = (int $self->{tilesize} * $::CFG->{map_scale}) || 1; 403 my $tilesize = $self->{ctilesize} = (int $self->{tilesize} * $::CFG->{map_scale}) || 1;
461 404
462 my $sw = $self->{sw} = 1 + CFPlus::ceil $self->{w} / $tilesize; 405 my $sw = $self->{sw} = 1 + CFPlus::ceil $self->{w} / $tilesize;
463 my $sh = $self->{sh} = 1 + CFPlus::ceil $self->{h} / $tilesize; 406 my $sh = $self->{sh} = 1 + CFPlus::ceil $self->{h} / $tilesize;
464 407
465 my $sx = CFPlus::ceil $::CFG->{map_shift_x} / $tilesize; 408 my $sx = CFPlus::ceil $::CFG->{map_shift_x} / $tilesize;
466 my $sy = CFPlus::ceil $::CFG->{map_shift_y} / $tilesize; 409 my $sy = CFPlus::ceil $::CFG->{map_shift_y} / $tilesize;
467 410
468 my $sx0 = $self->{sx0} = $::CFG->{map_shift_x} - $sx * $tilesize; 411 my $sx0 = $self->{sx0} = $::CFG->{map_shift_x} - $sx * $tilesize;
469 my $sy0 = $self->{sy0} = $::CFG->{map_shift_y} - $sy * $tilesize; 412 my $sy0 = $self->{sy0} = $::CFG->{map_shift_y} - $sy * $tilesize;
470 413
471 my $dx = $self->{dx} = CFPlus::ceil 0.5 * ($::MAP->w - $sw) - $sx; 414 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; 415 my $dy = $self->{dy} = CFPlus::ceil 0.5 * ($::MAP->h - $sh) - $sy;
473 416
474 if ($::CFG->{fow_enable}) { 417 if ($::CFG->{fow_enable}) {
475 my ($w, $h, $data) = $::MAP->fow_texture ( 418 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 419
481 $self->{fow_texture} = new CFPlus::Texture 420 $self->{fow_texture} = new CFPlus::Texture
482 w => $w, 421 w => $w,
483 h => $h, 422 h => $h,
484 data => $data, 423 data => $data,
485 internalformat => GL_ALPHA, 424 internalformat => GL_ALPHA,
486 format => GL_ALPHA; 425 format => GL_ALPHA;
487 } else { 426 } else {
488 delete $self->{fow_texture}; 427 delete $self->{fow_texture};
489 } 428 }
490 429
491 glNewList $self->{list}; 430 glNewList ($self->{list} ||= glGenList);
492 431
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; 432 glPushMatrix;
503 #glScale 1/3, 1/3 if $::CFG->{fow_smooth}; 433 glTranslate $sx0, $sy0;
434 glScale $::CFG->{map_scale}, $::CFG->{map_scale};
435
436 $::MAP->draw ($dx, $dy, $sw, $sh, $self->{tilesize});
437
438 glScale $self->{tilesize}, $self->{tilesize};
439
440 if (my $tex = $self->{fow_texture}) {
441 glPushMatrix;
442 glScale 1/3, 1/3;
504 glEnable GL_TEXTURE_2D; 443 glEnable GL_TEXTURE_2D;
505 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 444 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
506 445
507 glColor +($::CFG->{fow_intensity}) x 3, 0.9; 446 glColor +($::CFG->{fow_intensity}) x 3, 0.9;
508 $self->{fow_texture}->draw_quad_alpha (0, 0); 447 $self->{fow_texture}->draw_quad_alpha (0, 0);
509 448
510 glDisable GL_TEXTURE_2D; 449 glDisable GL_TEXTURE_2D;
450 glPopMatrix;
451 }
452
453 if ($self->{magicmap}) {
454 my ($x, $y, $w, $h, $data) = @{ $self->{magicmap} };
455
456 $x += $::MAP->ox + $self->{dx};
457 $y += $::MAP->oy + $self->{dy};
458
459 glTranslate - $x - 1, - $y - 1;
460 glBindTexture GL_TEXTURE_2D, $magicmap_tex->{name};
461 $::MAP->draw_magicmap ($x, $y, $w, $h, $data);
462 }
463
511 glPopMatrix; 464 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; 465 glEndList;
466 }
467 } else {
468 glDeleteList delete $self->{list}
469 if $self->{list};
527 } 470 }
528
529} 471}
530 472
531sub draw { 473sub draw {
532 my ($self) = @_; 474 my ($self) = @_;
533 475
534 $self->{root}->on_post_alloc (prepare => sub { $self->refresh_hook }); 476 $self->{root}->on_post_alloc (prepare => sub { $self->refresh_hook });
535 477
536 return unless $self->{list}; 478 return unless $self->{list};
537 479
538 my $focused = $CFPlus::UI::FOCUS == $self 480 my $focused = $CFPlus::UI::FOCUS == $self
539 || $CFPlus::UI::FOCUS == $self->{completer}{entry}; 481 || $CFPlus::UI::FOCUS == $::COMPLETER->{entry};
540 482
541 return 483 return
542 unless $focused || !$::FAST; 484 unless $focused || !$::FAST;
543 485
544 glCallList $self->{list}; 486 glCallList $self->{list};
545 487
546 # TNT2 emulates logops in software (or worse :) 488 # TNT2 emulates logops in software (or worse :)
547 unless ($focused) { 489 unless ($focused) {
548 glColor 0.4, 0.2, 0.2, 0.6; 490 glColor_premultiply 0, 0, 1, 0.25;
549 glEnable GL_BLEND; 491 glEnable GL_BLEND;
550 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 492 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
551 glBegin GL_QUADS; 493 glBegin GL_QUADS;
552 glVertex 0, 0; 494 glVertex 0, 0;
553 glVertex 0, $::HEIGHT; 495 glVertex 0, $::HEIGHT;
554 glVertex $::WIDTH, $::HEIGHT; 496 glVertex $::WIDTH, $::HEIGHT;
555 glVertex $::WIDTH, 0; 497 glVertex $::WIDTH, 0;
575 517
576use Time::HiRes qw(time); 518use Time::HiRes qw(time);
577use CFPlus::OpenGL; 519use CFPlus::OpenGL;
578 520
579sub size_request { 521sub size_request {
580 ($::HEIGHT * 0.25, $::HEIGHT * 0.25) 522 ($::HEIGHT * 0.2, $::HEIGHT * 0.2)
581} 523}
582 524
583sub refresh_hook { 525sub refresh_hook {
584 my ($self) = @_; 526 my ($self) = @_;
585 527

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines