1 | package DC::MapWidget; |
1 | package DC::MapWidget; |
2 | |
2 | |
3 | use strict; |
3 | use common::sense; |
4 | use utf8; |
|
|
5 | |
4 | |
6 | use List::Util qw(min max); |
5 | use List::Util qw(min max); |
|
|
6 | |
|
|
7 | use AnyEvent (); |
7 | |
8 | |
8 | use DC; |
9 | use DC; |
9 | use DC::OpenGL; |
10 | use DC::OpenGL; |
10 | use DC::UI; |
11 | use DC::UI; |
11 | use DC::Macro; |
12 | use DC::Macro; |
… | |
… | |
432 | sub movement_update { |
433 | sub movement_update { |
433 | my ($self) = @_; |
434 | my ($self) = @_; |
434 | |
435 | |
435 | if ($::CFG->{smooth_movement}) { |
436 | if ($::CFG->{smooth_movement}) { |
436 | if ($self->{sdx} || $self->{sdy}) { |
437 | if ($self->{sdx} || $self->{sdy}) { |
437 | my $diff = EV::time - ($self->{last_update} || $::LAST_REFRESH); |
438 | my $diff = AE::time - ($self->{last_update} || $::LAST_REFRESH); |
438 | my $spd = $::CONN->{stat}{DC::Protocol::CS_STAT_SPEED}; |
439 | my $spd = $::CONN->{stat}{DC::Protocol::CS_STAT_SPEED}; |
439 | |
440 | |
440 | # the minimum time for a single tile movement |
441 | # the minimum time for a single tile movement |
441 | my $mintime = DC::Protocol::TICK * DC::ceil 1 / ($spd * DC::Protocol::TICK || 1); |
442 | my $mintime = DC::Protocol::TICK * DC::ceil 1 / ($spd * DC::Protocol::TICK || 1); |
442 | |
443 | |
… | |
… | |
463 | } |
464 | } |
464 | } else { |
465 | } else { |
465 | $self->{sdx} = $self->{sdy} = 0; |
466 | $self->{sdx} = $self->{sdy} = 0; |
466 | } |
467 | } |
467 | |
468 | |
468 | $self->{last_update} = EV::time; |
469 | $self->{last_update} = AE::time; |
469 | } |
470 | } |
470 | |
471 | |
471 | sub refresh_hook { |
472 | sub refresh_hook { |
472 | my ($self) = @_; |
473 | my ($self) = @_; |
473 | |
474 | |
… | |
… | |
515 | glTranslate $sx0, $sy0; |
516 | glTranslate $sx0, $sy0; |
516 | glScale $::CFG->{map_scale}, $::CFG->{map_scale}; |
517 | glScale $::CFG->{map_scale}, $::CFG->{map_scale}; |
517 | glTranslate DC::ceil $self->{sdx}, DC::ceil $self->{sdy}; |
518 | glTranslate DC::ceil $self->{sdx}, DC::ceil $self->{sdy}; |
518 | |
519 | |
519 | $::MAP->draw ($dx, $dy, $sw, $sh, |
520 | $::MAP->draw ($dx, $dy, $sw, $sh, |
520 | $self->{tilesize}, |
521 | ($self->{tilesize}) x 2, |
521 | $::CONN->{player}{tag}, |
522 | $::CONN->{player}{tag}, |
522 | -$self->{sdx}, -$self->{sdy}); |
523 | -$self->{sdx}, -$self->{sdy}); |
523 | |
524 | |
524 | glScale $self->{tilesize}, $self->{tilesize}; |
525 | glScale $self->{tilesize}, $self->{tilesize}; |
525 | |
526 | |
… | |
… | |
608 | $self->SUPER::DESTROY; |
609 | $self->SUPER::DESTROY; |
609 | } |
610 | } |
610 | |
611 | |
611 | package DC::MapWidget::MapMap; |
612 | package DC::MapWidget::MapMap; |
612 | |
613 | |
613 | use strict; |
614 | use common::sense; |
614 | use utf8; |
|
|
615 | |
615 | |
616 | our @ISA = DC::UI::Base::; |
616 | our @ISA = DC::UI::Base::; |
617 | |
617 | |
618 | use Time::HiRes qw(time); |
|
|
619 | use DC::OpenGL; |
618 | use DC::OpenGL; |
620 | |
619 | |
621 | sub size_request { |
620 | sub size_request { |
622 | ($::HEIGHT * 0.2, $::HEIGHT * 0.2) |
621 | ($::HEIGHT * 0.2, $::HEIGHT * 0.2) |
623 | } |
622 | } |
624 | |
623 | |
625 | sub refresh_hook { |
624 | sub refresh_hook { |
626 | my ($self) = @_; |
625 | my ($self) = @_; |
627 | |
626 | |
628 | if ($::MAP && $self->{texture_atime} < time) { |
627 | if ($::MAP && $self->{texture_atime} < AE::now) { |
629 | my ($w, $h) = @$self{qw(w h)}; |
628 | my ($w, $h) = @$self{qw(w h)}; |
630 | |
629 | |
631 | return unless $w && $h; |
630 | return unless $w && $h; |
632 | |
631 | |
633 | my $sw = int $::WIDTH / ($::MAPWIDGET->{tilesize} * $::CFG->{map_scale}) + 0.99; |
632 | my $sw = int $::WIDTH / ($::MAPWIDGET->{tilesize} * $::CFG->{map_scale}) + 0.99; |
… | |
… | |
648 | $self->{sh} = $sh; |
647 | $self->{sh} = $sh; |
649 | |
648 | |
650 | $self->{x0} = $x0; |
649 | $self->{x0} = $x0; |
651 | $self->{y0} = $y0; |
650 | $self->{y0} = $y0; |
652 | |
651 | |
653 | $self->{texture_atime} = time + 1/3; |
652 | $self->{texture_atime} = AE::now + 1/2; |
654 | |
653 | |
655 | $self->{texture} = |
654 | $self->{texture} = |
656 | new DC::Texture |
655 | new DC::Texture |
657 | w => $w, |
656 | w => $w, |
658 | h => $h, |
657 | h => $h, |
… | |
… | |
713 | glDisable GL_BLEND; |
712 | glDisable GL_BLEND; |
714 | } |
713 | } |
715 | |
714 | |
716 | package DC::MapWidget::Command; |
715 | package DC::MapWidget::Command; |
717 | |
716 | |
718 | use strict; |
717 | use common::sense; |
719 | |
718 | |
720 | use DC::OpenGL; |
719 | use DC::OpenGL; |
721 | |
720 | |
722 | our @ISA = DC::UI::Frame::; |
721 | our @ISA = DC::UI::Frame::; |
723 | |
722 | |
… | |
… | |
876 | } else { |
875 | } else { |
877 | # @match is [command, penalty, command with arguments] until sort |
876 | # @match is [command, penalty, command with arguments] until sort |
878 | |
877 | |
879 | my ($cmd, $arg) = $text =~ /^\s*([^[:space:]]*)(.*)$/; |
878 | my ($cmd, $arg) = $text =~ /^\s*([^[:space:]]*)(.*)$/; |
880 | |
879 | |
|
|
880 | my $first_char = substr $cmd, 0, 1; |
|
|
881 | |
881 | my $regexp_abbrev = do { |
882 | my $regexp_abbrev = do { |
882 | my ($beg, @chr) = split //, lc $cmd; |
883 | my ($beg, @chr) = split //, lc $cmd; |
883 | |
884 | |
884 | # the following regex is used to match our "completion entry" |
885 | # the following regex is used to match our "completion entry" |
885 | # to an actual command - the parentheses match kind of "overhead" |
886 | # to an actual command - the parentheses match kind of "overhead" |
886 | # - the more characters the parentheses match, the less attractive |
887 | # - the more characters the parentheses match, the less attractive |
887 | # is the match. |
888 | # is the match. |
888 | my $regexp = "^\Q$beg\E" |
889 | my $regexp = "^\Q$beg\E" |
889 | . join "", map "(?:.*?[ \\\\]\Q$_\E|(.*?)\Q$_\E)", @chr; |
890 | . join "", map "(?:.*?[ \\\\]|(.*?))\Q$_\E", @chr; |
890 | qr<$regexp> |
891 | qr<$regexp> |
891 | }; |
892 | }; |
892 | |
893 | |
893 | my $regexp_partial = do { |
894 | my $regexp_partial = do { |
894 | my $regexp = "^\Q$text\E(.*)"; |
895 | my $regexp = "^\Q$text\E(.*)"; |
895 | qr<$regexp> |
896 | qr<$regexp> |
896 | }; |
897 | }; |
897 | |
898 | |
898 | for (keys %{$self->{command}}) { |
899 | for (keys %{$self->{command}}) { |
|
|
900 | # we only match and score if the first character matches, |
|
|
901 | # so quickly rule out all others first. |
|
|
902 | next unless $first_char = substr $_, 0, 1; |
|
|
903 | |
899 | my @scores; |
904 | my @scores; |
900 | |
905 | |
901 | # 1. Complete command [with args] |
906 | # 1. Complete command [with args] |
902 | # command is a prefix of the text |
907 | # command is a prefix of the text |
903 | # score is length of complete command matched |
908 | # score is length of complete command matched |
904 | # e.g. "invoke summon pet monster bat" |
909 | # e.g. "invoke summon pet monster bat" |
905 | # "invoke" "summon pet monster bat" = 6 |
910 | # "invoke" "summon pet monster bat" = 6 |
906 | # "invoke summon pet monster" "bat" = 25 |
911 | # "invoke summon pet monster" "bat" = 25 |
907 | if ($text =~ /^\Q$_\E(.*)/) { |
912 | if ((substr $text, 0, length $_) eq $_) { |
908 | push @scores, [$_, length $_, $text]; |
913 | push @scores, [$_, length $_, $text]; |
909 | } |
914 | } |
910 | |
915 | |
911 | # 2. Partial command |
916 | # 2. Partial command |
912 | # text is a prefix of the full command |
917 | # text is a prefix of the full command |