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.167 by root, Tue Nov 20 14:32:12 2012 UTC vs.
Revision 1.171 by root, Mon Nov 26 13:14:43 2012 UTC

31 tilesize => 32, 31 tilesize => 32,
32 @_ 32 @_
33 ); 33 );
34 34
35 $self 35 $self
36}
37
38sub add_command {#d# remove
39 my ($self, $command, $tooltip, $widget, $cb) = @_;
40
41 (my $data = $command) =~ s/\\//g;
42
43 $tooltip =~ s/^\s+//;
44 $tooltip = "<big>$data</big>\n\n$tooltip";
45 $tooltip =~ s/\s+$//;
46
47 $::COMPLETER->{command}{$command} = [$data, $tooltip, $widget, $cb, ++$self->{command_id}];
48} 36}
49 37
50sub server_login { 38sub server_login {
51 my ($server) = @_; 39 my ($server) = @_;
52 40
713 701
714sub new { 702sub new {
715 my $class = shift; 703 my $class = shift;
716 704
717 my $self = $class->SUPER::new ( 705 my $self = $class->SUPER::new (
706 min_w => $::WIDTH * 0.25, # workaround for layout problems #d#
718 bg => [0, 0, 0, 0.8], 707 bg => [0, 0, 0, 0.8],
719 @_, 708 @_,
720 ); 709 );
721 710
722 $self->add ($self->{vbox} = new DC::UI::VBox); 711 $self->add ($self->{vbox} = new DC::UI::VBox);
813 802
814sub reset { 803sub reset {
815 my ($self) = @_; 804 my ($self) = @_;
816 805
817 $self->hide; 806 $self->hide;
807 delete $self->{command_lists};
818 delete $self->{command_list}; 808 delete $self->{command_list};
819} 809}
820 810
821sub set_prefix { 811sub set_prefix {
822 my ($self, $prefix) = @_; 812 my ($self, $prefix) = @_;
856 $self->{entry}->emit (key_down => $ev); 846 $self->{entry}->emit (key_down => $ev);
857} 847}
858 848
859sub update_labels { 849sub update_labels {
860 my ($self) = @_; 850 my ($self) = @_;
851
852 use sort qw(stable);
861 853
862 my $text = $self->{entry}->get_text; 854 my $text = $self->{entry}->get_text;
863 855
864 length $text 856 length $text
865 or return $self->hide; 857 or return $self->hide;
875 if ($text ne $self->{last_search}) { 867 if ($text ne $self->{last_search}) {
876 my @match; 868 my @match;
877 869
878 if ($text =~ /^(.*?)\s+$/) { 870 if ($text =~ /^(.*?)\s+$/) {
879 my ($cmd, $arg) = $text =~ /^\s*([^[:space:]]*)(.*)$/; 871 my ($cmd, $arg) = $text =~ /^\s*([^[:space:]]*)(.*)$/;
880 @match = ([[$cmd,'(appended whitespace suppresses completion)'],$text]); 872 @match = ([[$cmd,' (appended whitespace suppresses completion)'], $text]);
881 } else { 873 } else {
882 # @match is [command, penalty, command with arguments] until sort 874 # @match is [command, penalty, command with arguments] until sort
883 875
884 my ($cmd, $arg) = $text =~ /^\s*([^[:space:]]*)(.*)$/; 876 my ($cmd, $arg) = $text =~ /^\s*([^[:space:]]*)(.*)$/;
885 877
900 my $regexp_partial = do { 892 my $regexp_partial = do {
901 my $regexp = "^\Q$text\E(.*)"; 893 my $regexp = "^\Q$text\E(.*)";
902 qr<$regexp> 894 qr<$regexp>
903 }; 895 };
904 896
905 for my $list (values %{ $self->{command_list} }) { 897 for my $list (@{ $self->{command_lists} }, "spells") {
906 for (@$list) { 898 for (@{ $self->{command_list}{$list} }) {
907 # we only match and score if the first character matches, 899 # we only match and score if the first character matches,
908 # so quickly rule out all others first. 900 # so quickly rule out all others first.
909 next unless $first_char = substr $_, 0, 1; 901 next unless $first_char = substr $_, 0, 1;
910 902
911 my @scores; 903 my @scores;
938 if (my @penalty = $_ =~ $regexp_abbrev) { 930 if (my @penalty = $_ =~ $regexp_abbrev) {
939 push @scores, [$_, (length $cmd) + 1 - (length join "", map "::$_", grep defined, @penalty), "$_$arg"]; 931 push @scores, [$_, (length $cmd) + 1 - (length join "", map "::$_", grep defined, @penalty), "$_$arg"];
940 } 932 }
941 933
942 # Pick the best option for this command 934 # Pick the best option for this command
943 push @match, (sort { 935 push @match, (sort { $b->[1] <=> $a->[1] } @scores)[0];
944 $b->[1] <=> $a->[1]
945 } @scores)[0];
946 } 936 }
947 } 937 }
948 938
949 # @match is now [command object, command with arguments] 939 # @match is now [command object, command with arguments]
950 @match = map [$self->{command}{$_->[0]}, $_->[2]], 940 @match = map [$_->[0], $_->[2]],
951 sort {
952 $b->[1] <=> $a->[1] 941 sort { $b->[1] <=> $a->[1] }
953 or $self->{command}{$a->[0]}[4] <=> $self->{command}{$b->[0]}[4]
954 or (length $b->[0]) <=> (length $a->[0])
955 } @match; 942 @match;
956 } 943 }
957 944
958 $self->{last_search} = $text; 945 $self->{last_search} = $text;
959 $self->{last_match} = \@match; 946 $self->{last_match} = \@match;
960 947
989 for my $match (@matches) { 976 for my $match (@matches) {
990 my $label = shift @labels; 977 my $label = shift @labels;
991 978
992 if (@labels) { 979 if (@labels) {
993 $label->set_text ("$match->[1]"); 980 $label->set_text ("$match->[1]");
994 $label->set_tooltip ("$match->[0][1]"); 981 $label->set_tooltip ("#(command/$match->[1])");
995 } else { 982 } else {
996 $label->set_text ("..."); 983 $label->set_text ("...");
997 $label->set_tooltip ("Use Cursor-Down to view more matches"); 984 $label->set_tooltip ("Use Cursor-Down to view more matches");
998 last; 985 last;
999 } 986 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines