… | |
… | |
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 | @_ |
26 | @_ |
28 | ); |
27 | ); |
29 | |
28 | |
30 | $self->{completer} = new CFPlus::MapWidget::Command:: |
|
|
31 | command => $self->{command}, |
|
|
32 | tooltip => "#completer_help", |
|
|
33 | ; |
|
|
34 | |
|
|
35 | $self |
29 | $self |
36 | } |
30 | } |
37 | |
31 | |
38 | sub set_tilesize { |
32 | sub set_tilesize { |
39 | my ($self, $tilesize) = @_; |
33 | my ($self, $tilesize) = @_; |
… | |
… | |
48 | |
42 | |
49 | $tooltip =~ s/^\s+//; |
43 | $tooltip =~ s/^\s+//; |
50 | $tooltip = "<big>$data</big>\n\n$tooltip"; |
44 | $tooltip = "<big>$data</big>\n\n$tooltip"; |
51 | $tooltip =~ s/\s+$//; |
45 | $tooltip =~ s/\s+$//; |
52 | |
46 | |
53 | $self->{completer}{command}{$command} = [$data, $tooltip, $widget, $cb, ++$self->{command_id}]; |
47 | $::COMPLETER->{command}{$command} = [$data, $tooltip, $widget, $cb, ++$self->{command_id}]; |
54 | } |
48 | } |
55 | |
49 | |
56 | sub clr_commands { |
50 | sub clr_commands { |
57 | my ($self) = @_; |
51 | my ($self) = @_; |
58 | |
52 | |
59 | %{$self->{completer}{command}} = (); |
53 | %{$::COMPLETER->{command}} = (); |
60 | |
54 | |
61 | $self->{completer}->hide |
55 | $::COMPLETER->hide |
62 | if $self->{completer}; |
56 | if $::COMPLETER; |
63 | } |
57 | } |
64 | |
58 | |
65 | sub server_login { |
59 | sub server_login { |
66 | my ($server) = @_; |
60 | my ($server) = @_; |
67 | |
61 | |
… | |
… | |
126 | require File::Path; |
120 | require File::Path; |
127 | |
121 | |
128 | File::Path::mkpath (File::Basename::dirname ($mappath)); |
122 | File::Path::mkpath (File::Basename::dirname ($mappath)); |
129 | open my $fh, ">:raw:perlio", "$mappath.meta" |
123 | open my $fh, ">:raw:perlio", "$mappath.meta" |
130 | or die "$mappath.meta: $!\n"; |
124 | or die "$mappath.meta: $!\n"; |
131 | print $fh CFPlus::to_json $meta; |
125 | print $fh CFPlus::encode_json $meta; |
132 | close $fh; |
126 | close $fh; |
133 | open my $fh, ">:raw:perlio:utf8", $mappath |
127 | open my $fh, ">:raw:perlio:utf8", $mappath |
134 | or die "$mappath: $!\n"; |
128 | or die "$mappath: $!\n"; |
135 | print $fh $map; |
129 | print $fh $map; |
136 | close $fh; |
130 | close $fh; |
… | |
… | |
184 | |
178 | |
185 | $x -= CFPlus::floor $::MAP->w * 0.5; |
179 | $x -= CFPlus::floor $::MAP->w * 0.5; |
186 | $y -= CFPlus::floor $::MAP->h * 0.5; |
180 | $y -= CFPlus::floor $::MAP->h * 0.5; |
187 | |
181 | |
188 | if ($::CONN) { |
182 | if ($::CONN) { |
189 | if ($::IN_BUILD_MODE) { |
|
|
190 | $::CONN->buildat ($::IN_BUILD_MODE, $x, $y); |
|
|
191 | } else { |
|
|
192 | $::CONN->lookat ($x, $y) |
183 | $::CONN->lookat ($x, $y) |
193 | } |
|
|
194 | } |
184 | } |
195 | |
185 | |
196 | } elsif ($ev->{button} == 2) { |
186 | } elsif ($ev->{button} == 2) { |
197 | $self->grab_focus; |
187 | $self->grab_focus; |
198 | return unless $::CONN; |
188 | return unless $::CONN; |
… | |
… | |
330 | my $sym = $ev->{sym}; |
320 | my $sym = $ev->{sym}; |
331 | my $uni = $ev->{unicode}; |
321 | my $uni = $ev->{unicode}; |
332 | |
322 | |
333 | $mod &= CFPlus::KMOD_CTRL | CFPlus::KMOD_ALT | CFPlus::KMOD_SHIFT; |
323 | $mod &= CFPlus::KMOD_CTRL | CFPlus::KMOD_ALT | CFPlus::KMOD_SHIFT; |
334 | |
324 | |
335 | if ($sym == 9) { |
|
|
336 | ($mod & CFPlus::KMOD_SHIFT ? $::CONSOLE->{window} : $::PL_WINDOW)->toggle_visibility; |
|
|
337 | } elsif ($sym == CFPlus::SDLK_F1 && !$mod) { |
|
|
338 | $::HELP_WINDOW->toggle_visibility; |
|
|
339 | } elsif ($sym == CFPlus::SDLK_F2 && !$mod) { |
|
|
340 | ::toggle_player_page ($::STATS_PAGE); |
|
|
341 | } elsif ($sym == CFPlus::SDLK_F3 && !$mod) { |
|
|
342 | ::toggle_player_page ($::SKILL_PAGE); |
|
|
343 | } elsif ($sym == CFPlus::SDLK_F4 && !$mod) { |
|
|
344 | ::toggle_player_page ($::SPELL_PAGE); |
|
|
345 | } elsif ($sym == CFPlus::SDLK_F5 && !$mod) { |
|
|
346 | ::toggle_player_page ($::INVENTORY_PAGE); |
|
|
347 | } elsif ($sym == CFPlus::SDLK_F9 && !$mod) { |
|
|
348 | $::SETUP_DIALOG->toggle_visibility; |
|
|
349 | } elsif (!$::CONN) { |
|
|
350 | return 0; # bindings further down need a valid connection |
|
|
351 | |
|
|
352 | } elsif ($uni == ord ",") { |
|
|
353 | $::CONN->user_send ("take"); |
|
|
354 | } elsif ($uni == ord " ") { |
|
|
355 | $::CONN->user_send ("apply"); |
|
|
356 | } elsif ($uni == 13) { |
|
|
357 | $::CONN->user_send ("examine"); |
|
|
358 | } elsif ($uni == ord ".") { |
|
|
359 | $::CONN->user_send ($self->{completer}{last_command}) |
|
|
360 | if exists $self->{completer}{last_command}; |
|
|
361 | } elsif (my @macros = CFPlus::Macro::match_event $ev) { |
|
|
362 | $::CONN->macro_send ($_) for @macros; |
|
|
363 | } elsif (($sym == CFPlus::SDLK_KP_PLUS && !$mod) || $uni == ord "+") { |
|
|
364 | $::CONN->user_send ("rotateshoottype +"); |
|
|
365 | } elsif (($sym == CFPlus::SDLK_KP_MINUS && !$mod) || $uni == ord "-") { |
|
|
366 | $::CONN->user_send ("rotateshoottype -"); |
|
|
367 | } elsif ($uni == ord '!') { |
|
|
368 | $self->{completer}->set_prefix ("shout "); |
|
|
369 | $self->{completer}->show; |
|
|
370 | } elsif ($uni == ord '"') { |
|
|
371 | $self->{completer}->set_prefix ("$::CFG->{say_command} "); |
|
|
372 | $self->{completer}->show; |
|
|
373 | } elsif ($uni == ord "'") { |
|
|
374 | $self->{completer}->set_prefix (""); |
|
|
375 | $self->{completer}->show; |
|
|
376 | } elsif (my $dir = $DIR{(!!($mod & CFPlus::KMOD_ALT)) . ",$sym"}) { |
325 | if ($::CONN && (my $dir = $DIR{(!!($mod & CFPlus::KMOD_ALT)) . ",$sym"})) { |
377 | if ($mod & CFPlus::KMOD_SHIFT) { |
326 | if ($mod & CFPlus::KMOD_SHIFT) { |
378 | $self->{shft}++; |
327 | $self->{shft}++; |
379 | if ($dir->[0] != $self->{fire_dir}) { |
328 | if ($dir->[0] != $self->{fire_dir}) { |
380 | $::CONN->user_send ("fire $dir->[0]"); |
329 | $::CONN->user_send ("fire $dir->[0]"); |
381 | } |
330 | } |
382 | $self->{fire_dir} = $DIR{$sym}[0]; |
331 | $self->{fire_dir} = $dir->[0]; |
383 | } elsif ($mod & CFPlus::KMOD_CTRL) { |
332 | } elsif ($mod & CFPlus::KMOD_CTRL) { |
384 | $self->{ctrl}++; |
333 | $self->{ctrl}++; |
385 | $::CONN->user_send ("run $dir->[0]"); |
334 | $::CONN->user_send ("run $dir->[0]"); |
386 | } else { |
335 | } else { |
387 | $::CONN->user_send ("$dir->[1]"); |
336 | $::CONN->user_send ("$dir->[1]"); |
388 | } |
337 | } |
389 | } elsif ((ord 'a') <= $uni && $uni <= (ord 'z')) { |
338 | |
390 | $self->{completer}->inject_key_down ($ev); |
|
|
391 | $self->{completer}->show; |
|
|
392 | } else { |
|
|
393 | return 0; |
339 | return 1; |
394 | } |
|
|
395 | |
|
|
396 | 1 |
340 | } |
|
|
341 | |
|
|
342 | 0 |
397 | } |
343 | } |
398 | |
344 | |
399 | sub invoke_key_up { |
345 | sub invoke_key_up { |
400 | my ($self, $ev) = @_; |
346 | my ($self, $ev) = @_; |
401 | |
347 | |
… | |
… | |
408 | $::CONN->user_send ("fire_stop"); |
354 | $::CONN->user_send ("fire_stop"); |
409 | delete $self->{fire_dir}; |
355 | delete $self->{fire_dir}; |
410 | $res = 1; |
356 | $res = 1; |
411 | } |
357 | } |
412 | } else { |
358 | } else { |
413 | if (exists $DIR{$sym} && delete $self->{shft}) { |
359 | if (exists $DIR{(!!($mod & CFPlus::KMOD_ALT)) . ",$sym"} && delete $self->{shft}) { |
414 | $::CONN->user_send ("fire_stop"); |
360 | $::CONN->user_send ("fire_stop"); |
415 | delete $self->{fire_dir}; |
361 | delete $self->{fire_dir}; |
416 | $res = 1; |
362 | $res = 1; |
417 | } 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? |
418 | $::CONN->user_send ("fire_stop"); |
365 | $::CONN->user_send ("fire_stop"); |
419 | delete $self->{fire_dir}; |
366 | delete $self->{fire_dir}; |
420 | $res = 1; |
367 | $res = 1; |
421 | } |
368 | } |
422 | } |
369 | } |
… | |
… | |
449 | } |
396 | } |
450 | |
397 | |
451 | sub refresh_hook { |
398 | sub refresh_hook { |
452 | my ($self) = @_; |
399 | my ($self) = @_; |
453 | |
400 | |
454 | return unless $::MAP; |
401 | if ($::MAP && $::CONN) { |
455 | |
|
|
456 | if (delete $self->{need_update}) { |
402 | if (delete $self->{need_update}) { |
457 | my $tilesize = $self->{ctilesize} = (int $self->{tilesize} * $::CFG->{map_scale}) || 1; |
403 | my $tilesize = $self->{ctilesize} = (int $self->{tilesize} * $::CFG->{map_scale}) || 1; |
458 | |
404 | |
459 | my $sw = $self->{sw} = 1 + CFPlus::ceil $self->{w} / $tilesize; |
405 | my $sw = $self->{sw} = 1 + CFPlus::ceil $self->{w} / $tilesize; |
460 | my $sh = $self->{sh} = 1 + CFPlus::ceil $self->{h} / $tilesize; |
406 | my $sh = $self->{sh} = 1 + CFPlus::ceil $self->{h} / $tilesize; |
461 | |
407 | |
462 | my $sx = CFPlus::ceil $::CFG->{map_shift_x} / $tilesize; |
408 | my $sx = CFPlus::ceil $::CFG->{map_shift_x} / $tilesize; |
463 | my $sy = CFPlus::ceil $::CFG->{map_shift_y} / $tilesize; |
409 | my $sy = CFPlus::ceil $::CFG->{map_shift_y} / $tilesize; |
464 | |
410 | |
465 | my $sx0 = $self->{sx0} = $::CFG->{map_shift_x} - $sx * $tilesize; |
411 | my $sx0 = $self->{sx0} = $::CFG->{map_shift_x} - $sx * $tilesize; |
466 | my $sy0 = $self->{sy0} = $::CFG->{map_shift_y} - $sy * $tilesize; |
412 | my $sy0 = $self->{sy0} = $::CFG->{map_shift_y} - $sy * $tilesize; |
467 | |
413 | |
468 | 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; |
469 | 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; |
470 | |
416 | |
471 | if ($::CFG->{fow_enable}) { |
417 | if ($::CFG->{fow_enable}) { |
472 | my ($w, $h, $data) = $::MAP->fow_texture ($dx, $dy, $sw, $sh); |
418 | my ($w, $h, $data) = $::MAP->fow_texture ($dx, $dy, $sw, $sh); |
473 | |
419 | |
474 | $self->{fow_texture} = new CFPlus::Texture |
420 | $self->{fow_texture} = new CFPlus::Texture |
475 | w => $w, |
421 | w => $w, |
476 | h => $h, |
422 | h => $h, |
477 | data => $data, |
423 | data => $data, |
478 | internalformat => GL_ALPHA, |
424 | internalformat => GL_ALPHA, |
479 | format => GL_ALPHA; |
425 | format => GL_ALPHA; |
480 | } else { |
426 | } else { |
481 | delete $self->{fow_texture}; |
427 | delete $self->{fow_texture}; |
482 | } |
428 | } |
483 | |
429 | |
484 | glNewList $self->{list}; |
430 | glNewList ($self->{list} ||= glGenList); |
485 | |
431 | |
486 | glPushMatrix; |
|
|
487 | glTranslate $sx0, $sy0; |
|
|
488 | glScale $::CFG->{map_scale}, $::CFG->{map_scale}; |
|
|
489 | |
|
|
490 | $::MAP->draw ($dx, $dy, $sw, $sh, $self->{tilesize}); |
|
|
491 | |
|
|
492 | glScale $self->{tilesize}, $self->{tilesize}; |
|
|
493 | |
|
|
494 | if (my $tex = $self->{fow_texture}) { |
|
|
495 | glPushMatrix; |
432 | glPushMatrix; |
|
|
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; |
496 | glScale 1/3, 1/3; |
442 | glScale 1/3, 1/3; |
497 | glEnable GL_TEXTURE_2D; |
443 | glEnable GL_TEXTURE_2D; |
498 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
444 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
499 | |
445 | |
500 | glColor +($::CFG->{fow_intensity}) x 3, 0.9; |
446 | glColor +($::CFG->{fow_intensity}) x 3, 0.9; |
501 | $self->{fow_texture}->draw_quad_alpha (0, 0); |
447 | $self->{fow_texture}->draw_quad_alpha (0, 0); |
502 | |
448 | |
503 | 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 | |
504 | glPopMatrix; |
464 | glPopMatrix; |
505 | } |
|
|
506 | |
|
|
507 | if ($self->{magicmap}) { |
|
|
508 | my ($x, $y, $w, $h, $data) = @{ $self->{magicmap} }; |
|
|
509 | |
|
|
510 | $x += $::MAP->ox + $self->{dx}; |
|
|
511 | $y += $::MAP->oy + $self->{dy}; |
|
|
512 | |
|
|
513 | glTranslate - $x - 1, - $y - 1; |
|
|
514 | glBindTexture GL_TEXTURE_2D, $magicmap_tex->{name}; |
|
|
515 | $::MAP->draw_magicmap ($x, $y, $w, $h, $data); |
|
|
516 | } |
|
|
517 | |
|
|
518 | glPopMatrix; |
|
|
519 | glEndList; |
465 | glEndList; |
|
|
466 | } |
|
|
467 | } else { |
|
|
468 | glDeleteList delete $self->{list} |
|
|
469 | if $self->{list}; |
520 | } |
470 | } |
521 | |
|
|
522 | } |
471 | } |
523 | |
472 | |
524 | sub draw { |
473 | sub draw { |
525 | my ($self) = @_; |
474 | my ($self) = @_; |
526 | |
475 | |
527 | $self->{root}->on_post_alloc (prepare => sub { $self->refresh_hook }); |
476 | $self->{root}->on_post_alloc (prepare => sub { $self->refresh_hook }); |
528 | |
477 | |
529 | return unless $self->{list}; |
478 | return unless $self->{list}; |
530 | |
479 | |
531 | my $focused = $CFPlus::UI::FOCUS == $self |
480 | my $focused = $CFPlus::UI::FOCUS == $self |
532 | || $CFPlus::UI::FOCUS == $self->{completer}{entry}; |
481 | || $CFPlus::UI::FOCUS == $::COMPLETER->{entry}; |
533 | |
482 | |
534 | return |
483 | return |
535 | unless $focused || !$::FAST; |
484 | unless $focused || !$::FAST; |
536 | |
485 | |
537 | glCallList $self->{list}; |
486 | glCallList $self->{list}; |
538 | |
487 | |
539 | # TNT2 emulates logops in software (or worse :) |
488 | # TNT2 emulates logops in software (or worse :) |
540 | unless ($focused) { |
489 | unless ($focused) { |
541 | glColor 0.4, 0.2, 0.2, 0.6; |
490 | glColor_premultiply 0, 0, 1, 0.25; |
542 | glEnable GL_BLEND; |
491 | glEnable GL_BLEND; |
543 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
492 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
544 | glBegin GL_QUADS; |
493 | glBegin GL_QUADS; |
545 | glVertex 0, 0; |
494 | glVertex 0, 0; |
546 | glVertex 0, $::HEIGHT; |
495 | glVertex 0, $::HEIGHT; |
547 | glVertex $::WIDTH, $::HEIGHT; |
496 | glVertex $::WIDTH, $::HEIGHT; |
548 | glVertex $::WIDTH, 0; |
497 | glVertex $::WIDTH, 0; |