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.147 by root, Mon Dec 22 02:33:30 2008 UTC vs.
Revision 1.150 by elmex, Wed Aug 12 18:41:39 2009 UTC

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>",
511 glNewList ($self->{list} ||= glGenList); 505 glNewList ($self->{list} ||= glGenList);
512 506
513 glPushMatrix; 507 glPushMatrix;
514 glTranslate $sx0, $sy0; 508 glTranslate $sx0, $sy0;
515 glScale $::CFG->{map_scale}, $::CFG->{map_scale}; 509 glScale $::CFG->{map_scale}, $::CFG->{map_scale};
516 glTranslate $self->{sdx}, $self->{sdy}; 510 glTranslate DC::ceil $self->{sdx}, DC::ceil $self->{sdy};
517 511
518 $::MAP->draw ($dx, $dy, $sw, $sh, 512 $::MAP->draw ($dx, $dy, $sw, $sh,
519 $self->{tilesize}, 513 $self->{tilesize},
520 $::CONN->{player}{tag}, 514 $::CONN->{player}{tag},
521 -$self->{sdx}, -$self->{sdy}); 515 -$self->{sdx}, -$self->{sdy});
852 my $text = $self->{entry}->get_text; 846 my $text = $self->{entry}->get_text;
853 847
854 length $text 848 length $text
855 or return $self->hide; 849 or return $self->hide;
856 850
857 my ($cmd, $arg) = $text =~ /^\s*([^[:space:]]*)(.*)$/;
858
859 if ($text ne $self->{last_search}) { 851 if ($text ne $self->{last_search}) {
860 my @match; 852 my @match;
861 853
862 if ($text =~ /^(.*?)\s+$/) { 854 if ($text =~ /^(.*?)\s+$/) {
855 my ($cmd, $arg) = $text =~ /^\s*([^[:space:]]*)(.*)$/;
863 @match = [$cmd, "(appended whitespace suppresses completion)"]; 856 @match = ([[$cmd,'(appended whitespace suppresses completion)'],$text]);
864 } else { 857 } else {
858 # @match is [command, penalty, command with arguments] until sort
859
860 my ($cmd, $arg) = $text =~ /^\s*([^[:space:]]*)(.*)$/;
861
865 my $regexp = do { 862 my $regexp_abbrev = do {
866 my ($beg, @chr) = split //, lc $cmd; 863 my ($beg, @chr) = split //, lc $cmd;
867 864
868 # the following regex is used to match our "completion entry" 865 # the following regex is used to match our "completion entry"
869 # to an actual command - the parentheses match kind of "overhead" 866 # to an actual command - the parentheses match kind of "overhead"
870 # - the more characters the parentheses match, the less attractive 867 # - the more characters the parentheses match, the less attractive
872 my $regexp = "^\Q$beg\E" 869 my $regexp = "^\Q$beg\E"
873 . join "", map "(?:.*?[ \\\\]\Q$_\E|(.*?)\Q$_\E)", @chr; 870 . join "", map "(?:.*?[ \\\\]\Q$_\E|(.*?)\Q$_\E)", @chr;
874 qr<$regexp> 871 qr<$regexp>
875 }; 872 };
876 873
877 my @penalty; 874 my $regexp_partial = do {
875 my $regexp = "^\Q$text\E(.*)";
876 qr<$regexp>
877 };
878 878
879 for (keys %{$self->{command}}) { 879 for (keys %{$self->{command}}) {
880 if (@penalty = $_ =~ $regexp) { 880 my @scores;
881 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];
882 } 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];
883 } 915 }
884 916
917 # @match is now [command object, command with arguments]
885 @match = map $self->{command}{$_->[0]}, 918 @match = map [$self->{command}{$_->[0]}, $_->[2]],
886 sort { 919 sort {
887 $a->[1] <=> $b->[1] 920 $b->[1] <=> $a->[1]
888 or $self->{command}{$a->[0]}[4] <=> $self->{command}{$b->[0]}[4] 921 or $self->{command}{$a->[0]}[4] <=> $self->{command}{$b->[0]}[4]
889 or (length $b->[0]) <=> (length $a->[0]) 922 or (length $b->[0]) <=> (length $a->[0])
890 } @match; 923 } @match;
891 } 924 }
892 925
911 $label->{fg} = [1, 1, 1, 1]; 944 $label->{fg} = [1, 1, 1, 1];
912 $label->{bg} = [0, 0, 0, 0]; 945 $label->{bg} = [0, 0, 0, 0];
913 } 946 }
914 947
915 if (@matches) { 948 if (@matches) {
916 $self->{select} = "$matches[0][0]$arg"; 949 $self->{select} = "$matches[0][1]";
917 950
918 $labels[0]->{fg} = [0, 0, 0, 1]; 951 $labels[0]->{fg} = [0, 0, 0, 1];
919 $labels[0]->{bg} = [1, 1, 1, 0.8]; 952 $labels[0]->{bg} = [1, 1, 1, 0.8];
920 } else { 953 } else {
921 $self->{select} = "$cmd$arg"; 954 $self->{select} = "$text";
922 } 955 }
923 956
924 for my $match (@matches) { 957 for my $match (@matches) {
925 my $label = shift @labels; 958 my $label = shift @labels;
926 959
927 if (@labels) { 960 if (@labels) {
928 $label->set_text ("$match->[0]$arg"); 961 $label->set_text ("$match->[1]");
929 $label->set_tooltip ($match->[1]); 962 $label->set_tooltip ("$match->[0][1]");
930 } else { 963 } else {
931 $label->set_text ("..."); 964 $label->set_text ("...");
932 $label->set_tooltip ("Use Cursor-Down to view more matches"); 965 $label->set_tooltip ("Use Cursor-Down to view more matches");
933 last; 966 last;
934 } 967 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines