… | |
… | |
163 | sub invoke_button_down { |
163 | sub invoke_button_down { |
164 | my ($self, $ev, $x, $y) = @_; |
164 | my ($self, $ev, $x, $y) = @_; |
165 | |
165 | |
166 | if ($ev->{button} == 1) { |
166 | if ($ev->{button} == 1) { |
167 | $self->grab_focus; |
167 | $self->grab_focus; |
168 | return unless $::CONN; |
168 | return unless $::CONN && $self->{ctilesize}; |
169 | |
169 | |
170 | my $x = $self->{dx} + DC::floor +($ev->{x} - $self->{sx0}) / $self->{ctilesize}; |
170 | my $x = $self->{dx} + DC::floor +($ev->{x} - $self->{sx0}) / $self->{ctilesize}; |
171 | my $y = $self->{dy} + DC::floor +($ev->{y} - $self->{sy0}) / $self->{ctilesize}; |
171 | my $y = $self->{dy} + DC::floor +($ev->{y} - $self->{sy0}) / $self->{ctilesize}; |
172 | |
172 | |
173 | $x -= DC::floor $::MAP->w * 0.5; |
173 | $x -= DC::floor $::MAP->w * 0.5; |
… | |
… | |
201 | ["Skills\tF3", sub { ::toggle_player_page ($::SKILL_PAGE) }], |
201 | ["Skills\tF3", sub { ::toggle_player_page ($::SKILL_PAGE) }], |
202 | ["Spells…\tF4", sub { ::toggle_player_page ($::SPELL_PAGE) }], |
202 | ["Spells…\tF4", sub { ::toggle_player_page ($::SPELL_PAGE) }], |
203 | ["Inventory…\tF5", sub { ::toggle_player_page ($::INVENTORY_PAGE) }], |
203 | ["Inventory…\tF5", sub { ::toggle_player_page ($::INVENTORY_PAGE) }], |
204 | ["Setup… \tF9", sub { $::SETUP_DIALOG->toggle_visibility }], |
204 | ["Setup… \tF9", sub { $::SETUP_DIALOG->toggle_visibility }], |
205 | # ["Server Messages…", sub { $::MESSAGE_WINDOW->toggle_visibility }], |
205 | # ["Server Messages…", sub { $::MESSAGE_WINDOW->toggle_visibility }], |
206 | [ |
|
|
207 | $::PICKUP_ENABLE->{state} |
|
|
208 | ? "Disable automatic pickup" |
|
|
209 | : "Enable automatic pickup", |
|
|
210 | sub { $::PICKUP_ENABLE->toggle } |
|
|
211 | ], |
|
|
212 | ); |
206 | ); |
213 | |
207 | |
214 | if ($::CONN && $::CONN->{editor_support}) { |
208 | if ($::CONN && $::CONN->{editor_support}) { |
215 | # push @items, [ |
209 | # push @items, [ |
216 | # "Edit this map <span size='xx-small'>(" . (DC::asxml $::CONN->{map_info}[0]) . ")</span>", |
210 | # "Edit this map <span size='xx-small'>(" . (DC::asxml $::CONN->{map_info}[0]) . ")</span>", |
… | |
… | |
432 | my $spd = $::CONN->{stat}{DC::Protocol::CS_STAT_SPEED}; |
426 | my $spd = $::CONN->{stat}{DC::Protocol::CS_STAT_SPEED}; |
433 | |
427 | |
434 | # the minimum time for a single tile movement |
428 | # the minimum time for a single tile movement |
435 | my $mintime = DC::Protocol::TICK * DC::ceil 1 / ($spd * DC::Protocol::TICK || 1); |
429 | my $mintime = DC::Protocol::TICK * DC::ceil 1 / ($spd * DC::Protocol::TICK || 1); |
436 | |
430 | |
|
|
431 | $spd *= $self->{tilesize}; |
|
|
432 | |
437 | # jump if "impossibly high" speed |
433 | # jump if "impossibly high" speed |
438 | if ( |
434 | if ( |
439 | (max abs $self->{sdx}, abs $self->{sdy}) |
435 | (max abs $self->{sdx}, abs $self->{sdy}) |
440 | > $spd * $self->{tilesize} * $mintime * 1.1 |
436 | > $spd * $mintime * 2.1 |
441 | ) { |
437 | ) { |
442 | #warn "jump ", (max abs $self->{sdx}, abs $self->{sdy}), " ", $spd * $mintime * 1.0;#d# |
438 | #warn "jump ", (max abs $self->{sdx}, abs $self->{sdy}), " ", $spd * $mintime * 2.1;#d# |
443 | $self->{sdx} = $self->{sdy} = 0; |
439 | $self->{sdx} = $self->{sdy} = 0; |
444 | } else { |
440 | } else { |
445 | $spd *= $self->{tilesize} * $diff * 1.0001; # 1.0001 so that we don't accumulate rounding errors the wrong direction |
441 | $spd *= $diff * 1.0001; # 1.0001 so that we don't accumulate rounding errors the wrong direction |
446 | |
442 | |
447 | my $dx = $self->{sdx} < 0 ? -$spd : $spd; |
443 | my $dx = $self->{sdx} < 0 ? -$spd : $spd; |
448 | my $dy = $self->{sdy} < 0 ? -$spd : $spd; |
444 | my $dy = $self->{sdy} < 0 ? -$spd : $spd; |
449 | |
445 | |
450 | if ($self->{sdx} * ($self->{sdx} - $dx) <= 0) { $self->{sdx} = 0 } else { $self->{sdx} -= $dx } |
446 | if ($self->{sdx} * ($self->{sdx} - $dx) <= 0) { $self->{sdx} = 0 } else { $self->{sdx} -= $dx } |
451 | if ($self->{sdy} * ($self->{sdy} - $dy) <= 0) { $self->{sdy} = 0 } else { $self->{sdy} -= $dy } |
447 | if ($self->{sdy} * ($self->{sdy} - $dy) <= 0) { $self->{sdy} = 0 } else { $self->{sdy} -= $dy } |
452 | |
|
|
453 | $self->update; |
|
|
454 | } |
448 | } |
|
|
449 | |
|
|
450 | $self->update; |
455 | } |
451 | } |
456 | } else { |
452 | } else { |
457 | $self->{sdx} = $self->{sdy} = 0; |
453 | $self->{sdx} = $self->{sdy} = 0; |
458 | } |
454 | } |
459 | |
455 | |
… | |
… | |
509 | glNewList ($self->{list} ||= glGenList); |
505 | glNewList ($self->{list} ||= glGenList); |
510 | |
506 | |
511 | glPushMatrix; |
507 | glPushMatrix; |
512 | glTranslate $sx0, $sy0; |
508 | glTranslate $sx0, $sy0; |
513 | glScale $::CFG->{map_scale}, $::CFG->{map_scale}; |
509 | glScale $::CFG->{map_scale}, $::CFG->{map_scale}; |
514 | glTranslate $self->{sdx}, $self->{sdy}; |
510 | glTranslate DC::ceil $self->{sdx}, DC::ceil $self->{sdy}; |
515 | |
511 | |
516 | $::MAP->draw ($dx, $dy, $sw, $sh, |
512 | $::MAP->draw ($dx, $dy, $sw, $sh, |
517 | $self->{tilesize}, |
513 | $self->{tilesize}, |
518 | $::CONN->{player}{tag}, |
514 | $::CONN->{player}{tag}, |
519 | -$self->{sdx}, -$self->{sdy}); |
515 | -$self->{sdx}, -$self->{sdy}); |
520 | |
516 | |
521 | #glTranslate -$self->{sdx}, -$self->{sdy}; # anchro fow at player |
517 | #glTranslate -$self->{sdx}, -$self->{sdy}; # anchor fow at player |
522 | glScale $self->{tilesize}, $self->{tilesize}; |
518 | glScale $self->{tilesize}, $self->{tilesize}; |
523 | |
519 | |
524 | if (my $tex = $self->{fow_texture}) { |
520 | if (my $tex = $self->{fow_texture}) { |
525 | glPushMatrix; |
521 | glPushMatrix; |
526 | glTranslate +(min 0, $sdx_t), (min 0, $sdy_t); |
522 | glTranslate +(min 0, $sdx_t), (min 0, $sdy_t); |
… | |
… | |
610 | sub refresh_hook { |
606 | sub refresh_hook { |
611 | my ($self) = @_; |
607 | my ($self) = @_; |
612 | |
608 | |
613 | if ($::MAP && $self->{texture_atime} < time) { |
609 | if ($::MAP && $self->{texture_atime} < time) { |
614 | my ($w, $h) = @$self{qw(w h)}; |
610 | my ($w, $h) = @$self{qw(w h)}; |
|
|
611 | |
|
|
612 | return unless $w && $h; |
615 | |
613 | |
616 | my $sw = int $::WIDTH / ($::MAPWIDGET->{tilesize} * $::CFG->{map_scale}) + 0.99; |
614 | my $sw = int $::WIDTH / ($::MAPWIDGET->{tilesize} * $::CFG->{map_scale}) + 0.99; |
617 | my $sh = int $::HEIGHT / ($::MAPWIDGET->{tilesize} * $::CFG->{map_scale}) + 0.99; |
615 | my $sh = int $::HEIGHT / ($::MAPWIDGET->{tilesize} * $::CFG->{map_scale}) + 0.99; |
618 | |
616 | |
619 | my $ox = 0.5 * ($w - $sw); |
617 | my $ox = 0.5 * ($w - $sw); |
… | |
… | |
848 | my $text = $self->{entry}->get_text; |
846 | my $text = $self->{entry}->get_text; |
849 | |
847 | |
850 | length $text |
848 | length $text |
851 | or return $self->hide; |
849 | or return $self->hide; |
852 | |
850 | |
853 | my ($cmd, $arg) = $text =~ /^\s*([^[:space:]]*)(.*)$/; |
|
|
854 | |
|
|
855 | if ($text ne $self->{last_search}) { |
851 | if ($text ne $self->{last_search}) { |
856 | my @match; |
852 | my @match; |
857 | |
853 | |
858 | if ($text =~ /^(.*?)\s+$/) { |
854 | if ($text =~ /^(.*?)\s+$/) { |
|
|
855 | my ($cmd, $arg) = $text =~ /^\s*([^[:space:]]*)(.*)$/; |
859 | @match = [$cmd, "(appended whitespace suppresses completion)"]; |
856 | @match = ([[$cmd,'(appended whitespace suppresses completion)'],$text]); |
860 | } else { |
857 | } else { |
|
|
858 | # @match is [command, penalty, command with arguments] until sort |
|
|
859 | |
|
|
860 | my ($cmd, $arg) = $text =~ /^\s*([^[:space:]]*)(.*)$/; |
|
|
861 | |
861 | my $regexp = do { |
862 | my $regexp_abbrev = do { |
862 | my ($beg, @chr) = split //, lc $cmd; |
863 | my ($beg, @chr) = split //, lc $cmd; |
863 | |
864 | |
864 | # the following regex is used to match our "completion entry" |
865 | # the following regex is used to match our "completion entry" |
865 | # to an actual command - the parentheses match kind of "overhead" |
866 | # to an actual command - the parentheses match kind of "overhead" |
866 | # - the more characters the parentheses match, the less attractive |
867 | # - the more characters the parentheses match, the less attractive |
… | |
… | |
868 | my $regexp = "^\Q$beg\E" |
869 | my $regexp = "^\Q$beg\E" |
869 | . join "", map "(?:.*?[ \\\\]\Q$_\E|(.*?)\Q$_\E)", @chr; |
870 | . join "", map "(?:.*?[ \\\\]\Q$_\E|(.*?)\Q$_\E)", @chr; |
870 | qr<$regexp> |
871 | qr<$regexp> |
871 | }; |
872 | }; |
872 | |
873 | |
873 | my @penalty; |
874 | my $regexp_partial = do { |
|
|
875 | my $regexp = "^\Q$text\E(.*)"; |
|
|
876 | qr<$regexp> |
|
|
877 | }; |
874 | |
878 | |
875 | for (keys %{$self->{command}}) { |
879 | for (keys %{$self->{command}}) { |
876 | if (@penalty = $_ =~ $regexp) { |
880 | my @scores; |
877 | push @match, [$_, length join "", map "::$_", grep defined, @penalty]; |
881 | |
|
|
882 | # 1. Complete command [with args] |
|
|
883 | # command is a prefix of the text |
|
|
884 | # score is length of complete command matched |
|
|
885 | # e.g. "invoke summon pet monster bat" |
|
|
886 | # "invoke" "summon pet monster bat" = 6 |
|
|
887 | # "invoke summon pet monster" "bat" = 25 |
|
|
888 | if ($text =~ /^\Q$_\E(.*)/) { |
|
|
889 | push @scores, [$_, length $_, $text]; |
878 | } |
890 | } |
|
|
891 | |
|
|
892 | # 2. Partial command |
|
|
893 | # text is a prefix of the full command |
|
|
894 | # score is the length of the input text |
|
|
895 | # e.g. "invoke s" |
|
|
896 | # "invoke small fireball" = 8 |
|
|
897 | # "invoke summon pet monster" = 8 |
|
|
898 | |
|
|
899 | if ($_ =~ $regexp_partial) { |
|
|
900 | push @scores, [$_, length $text, $_]; |
|
|
901 | } |
|
|
902 | |
|
|
903 | # 3. Abbreviation match |
|
|
904 | # attempts to use first word of text as an abbreviated command |
|
|
905 | # score is length of word + 1 - 3 per non-word-initial character |
|
|
906 | |
|
|
907 | if (my @penalty = $_ =~ $regexp_abbrev) { |
|
|
908 | push @scores, [$_, (length $cmd) + 1 - (length join "", map "::$_", grep defined, @penalty), "$_$arg"]; |
|
|
909 | } |
|
|
910 | |
|
|
911 | # Pick the best option for this command |
|
|
912 | push @match, (sort { |
|
|
913 | $b->[1] <=> $a->[1] |
|
|
914 | } @scores)[0]; |
879 | } |
915 | } |
880 | |
916 | |
|
|
917 | # @match is now [command object, command with arguments] |
881 | @match = map $self->{command}{$_->[0]}, |
918 | @match = map [$self->{command}{$_->[0]}, $_->[2]], |
882 | sort { |
919 | sort { |
883 | $a->[1] <=> $b->[1] |
920 | $b->[1] <=> $a->[1] |
884 | or $self->{command}{$a->[0]}[4] <=> $self->{command}{$b->[0]}[4] |
921 | or $self->{command}{$a->[0]}[4] <=> $self->{command}{$b->[0]}[4] |
885 | or (length $b->[0]) <=> (length $a->[0]) |
922 | or (length $b->[0]) <=> (length $a->[0]) |
886 | } @match; |
923 | } @match; |
887 | } |
924 | } |
888 | |
925 | |
… | |
… | |
907 | $label->{fg} = [1, 1, 1, 1]; |
944 | $label->{fg} = [1, 1, 1, 1]; |
908 | $label->{bg} = [0, 0, 0, 0]; |
945 | $label->{bg} = [0, 0, 0, 0]; |
909 | } |
946 | } |
910 | |
947 | |
911 | if (@matches) { |
948 | if (@matches) { |
912 | $self->{select} = "$matches[0][0]$arg"; |
949 | $self->{select} = "$matches[0][1]"; |
913 | |
950 | |
914 | $labels[0]->{fg} = [0, 0, 0, 1]; |
951 | $labels[0]->{fg} = [0, 0, 0, 1]; |
915 | $labels[0]->{bg} = [1, 1, 1, 0.8]; |
952 | $labels[0]->{bg} = [1, 1, 1, 0.8]; |
916 | } else { |
953 | } else { |
917 | $self->{select} = "$cmd$arg"; |
954 | $self->{select} = "$text"; |
918 | } |
955 | } |
919 | |
956 | |
920 | for my $match (@matches) { |
957 | for my $match (@matches) { |
921 | my $label = shift @labels; |
958 | my $label = shift @labels; |
922 | |
959 | |
923 | if (@labels) { |
960 | if (@labels) { |
924 | $label->set_text ("$match->[0]$arg"); |
961 | $label->set_text ("$match->[1]"); |
925 | $label->set_tooltip ($match->[1]); |
962 | $label->set_tooltip ("$match->[0][1]"); |
926 | } else { |
963 | } else { |
927 | $label->set_text ("..."); |
964 | $label->set_text ("..."); |
928 | $label->set_tooltip ("Use Cursor-Down to view more matches"); |
965 | $label->set_tooltip ("Use Cursor-Down to view more matches"); |
929 | last; |
966 | last; |
930 | } |
967 | } |