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.149 by root, Tue Jan 13 00:01:48 2009 UTC vs.
Revision 1.156 by root, Sat Dec 19 05:06:57 2009 UTC

397 397
398sub scroll { 398sub scroll {
399 my ($self, $dx, $dy) = @_; 399 my ($self, $dx, $dy) = @_;
400 400
401 $::MAP->scroll ($dx, $dy); 401 $::MAP->scroll ($dx, $dy);
402
403 $self->movement_update; 402 $self->movement_update;
404 403
405 $self->{sdx} += $dx * $self->{tilesize}; # smooth displacement 404 $self->{sdx} += $dx * $self->{tilesize}; # smooth displacement
406 $self->{sdy} += $dy * $self->{tilesize}; 405 $self->{sdy} += $dy * $self->{tilesize};
406
407 $self->{last_fow_texture} = $self->{fow_texture};
408 $self->{ldx} = $self->{sdx};
409 $self->{ldy} = $self->{sdy};
410
407} 411}
408 412
409sub set_magicmap { 413sub set_magicmap {
410 my ($self, $w, $h, $x, $y, $data) = @_; 414 my ($self, $w, $h, $x, $y, $data) = @_;
411 415
482 486
483 my $dx = $self->{dx} = DC::ceil 0.5 * ($::MAP->w - $sw) - $sx; 487 my $dx = $self->{dx} = DC::ceil 0.5 * ($::MAP->w - $sw) - $sx;
484 my $dy = $self->{dy} = DC::ceil 0.5 * ($::MAP->h - $sh) - $sy; 488 my $dy = $self->{dy} = DC::ceil 0.5 * ($::MAP->h - $sh) - $sy;
485 489
486 if ($::CFG->{fow_enable}) { 490 if ($::CFG->{fow_enable}) {
487 $sdx_t = $sdy_t = 0;#d# 491 my ($sdx_t, $sdy_t);#d# do not anchor at player
492
488 my ($w, $h, $data) = $::MAP->fow_texture ( 493 my ($w, $h, $data) = $::MAP->fow_texture (
489 $dx + (min 0, $sdx_t), 494 $dx + (min 0, $sdx_t),
490 $dy + (min 0, $sdy_t), 495 $dy + (min 0, $sdy_t),
491 $sw + abs $sdx_t, 496 $sw + abs $sdx_t,
492 $sh + abs $sdy_t 497 $sh + abs $sdy_t
512 $::MAP->draw ($dx, $dy, $sw, $sh, 517 $::MAP->draw ($dx, $dy, $sw, $sh,
513 $self->{tilesize}, 518 $self->{tilesize},
514 $::CONN->{player}{tag}, 519 $::CONN->{player}{tag},
515 -$self->{sdx}, -$self->{sdy}); 520 -$self->{sdx}, -$self->{sdy});
516 521
517 #glTranslate -$self->{sdx}, -$self->{sdy}; # anchor fow at player 522 #d#glTranslate -$self->{sdx}, -$self->{sdy}; # anchor fow at player
518 glScale $self->{tilesize}, $self->{tilesize}; 523 glScale $self->{tilesize}, $self->{tilesize};
519 524
520 if (my $tex = $self->{fow_texture}) { 525 if (my $tex = $self->{fow_texture}) {
521 glPushMatrix; 526 if ($DC::OpenGL::GL_MULTITEX && $self->{last_fow_texture} && 0) {#d#
527 my $d1 = ($self->{sdx} ** 2 + $self->{sdy} ** 2) ** 0.5;
528 my $d2 = ($self->{ldx} ** 2 + $self->{ldy} ** 2) ** 0.5;
529
530 if ($d1 * $d2) {
531 DC::Texture::draw_fow_texture
532 $::CFG->{fow_intensity},
533 @{$self->{fow_texture}}{qw(name s t w h)},
534 $d1 / $d2,
535 $sdx_t - $self->{ldx} / $tilesize, $sdy_t - $self->{ldy} / $tilesize,
536 @{$self->{last_fow_texture}}{qw(name s t w h)};
537 } else {
538 delete $self->{last_fow_texture};
539
540 # same as a few lines below :/
541 DC::Texture::draw_fow_texture
542 $::CFG->{fow_intensity},
543 @{$self->{fow_texture}}{qw(name s t w h)};
544 }
545 } else {
522 glTranslate +(min 0, $sdx_t), (min 0, $sdy_t); 546 #d#glTranslate +(min 0, $sdx_t), (min 0, $sdy_t); # anchor at player
523 glScale 1/3, 1/3; 547 DC::Texture::draw_fow_texture
524 glEnable GL_TEXTURE_2D; 548 $::CFG->{fow_intensity},
525 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 549 @{$self->{fow_texture}}{qw(name s t w h)};
526 550 }
527 glColor +($::CFG->{fow_intensity}) x 3, 0.9;
528 $self->{fow_texture}->draw_quad_alpha (0, 0);
529
530 glDisable GL_TEXTURE_2D;
531 glPopMatrix;
532 } 551 }
533 552
534 if ($self->{magicmap}) { 553 if ($self->{magicmap}) {
535 my ($x, $y, $w, $h, $data) = @{ $self->{magicmap} }; 554 my ($x, $y, $w, $h, $data) = @{ $self->{magicmap} };
536 555
846 my $text = $self->{entry}->get_text; 865 my $text = $self->{entry}->get_text;
847 866
848 length $text 867 length $text
849 or return $self->hide; 868 or return $self->hide;
850 869
851 my ($cmd, $arg) = $text =~ /^\s*([^[:space:]]*)(.*)$/;
852
853 if ($text ne $self->{last_search}) { 870 if ($text ne $self->{last_search}) {
854 my @match; 871 my @match;
855 872
856 if ($text =~ /^(.*?)\s+$/) { 873 if ($text =~ /^(.*?)\s+$/) {
874 my ($cmd, $arg) = $text =~ /^\s*([^[:space:]]*)(.*)$/;
857 @match = [$cmd, "(appended whitespace suppresses completion)"]; 875 @match = ([[$cmd,'(appended whitespace suppresses completion)'],$text]);
858 } else { 876 } else {
877 # @match is [command, penalty, command with arguments] until sort
878
879 my ($cmd, $arg) = $text =~ /^\s*([^[:space:]]*)(.*)$/;
880
859 my $regexp = do { 881 my $regexp_abbrev = do {
860 my ($beg, @chr) = split //, lc $cmd; 882 my ($beg, @chr) = split //, lc $cmd;
861 883
862 # the following regex is used to match our "completion entry" 884 # the following regex is used to match our "completion entry"
863 # to an actual command - the parentheses match kind of "overhead" 885 # to an actual command - the parentheses match kind of "overhead"
864 # - the more characters the parentheses match, the less attractive 886 # - the more characters the parentheses match, the less attractive
866 my $regexp = "^\Q$beg\E" 888 my $regexp = "^\Q$beg\E"
867 . join "", map "(?:.*?[ \\\\]\Q$_\E|(.*?)\Q$_\E)", @chr; 889 . join "", map "(?:.*?[ \\\\]\Q$_\E|(.*?)\Q$_\E)", @chr;
868 qr<$regexp> 890 qr<$regexp>
869 }; 891 };
870 892
871 my @penalty; 893 my $regexp_partial = do {
894 my $regexp = "^\Q$text\E(.*)";
895 qr<$regexp>
896 };
872 897
873 for (keys %{$self->{command}}) { 898 for (keys %{$self->{command}}) {
874 if (@penalty = $_ =~ $regexp) { 899 my @scores;
875 push @match, [$_, length join "", map "::$_", grep defined, @penalty]; 900
901 # 1. Complete command [with args]
902 # command is a prefix of the text
903 # score is length of complete command matched
904 # e.g. "invoke summon pet monster bat"
905 # "invoke" "summon pet monster bat" = 6
906 # "invoke summon pet monster" "bat" = 25
907 if ($text =~ /^\Q$_\E(.*)/) {
908 push @scores, [$_, length $_, $text];
876 } 909 }
910
911 # 2. Partial command
912 # text is a prefix of the full command
913 # score is the length of the input text
914 # e.g. "invoke s"
915 # "invoke small fireball" = 8
916 # "invoke summon pet monster" = 8
917
918 if ($_ =~ $regexp_partial) {
919 push @scores, [$_, length $text, $_];
920 }
921
922 # 3. Abbreviation match
923 # attempts to use first word of text as an abbreviated command
924 # score is length of word + 1 - 3 per non-word-initial character
925
926 if (my @penalty = $_ =~ $regexp_abbrev) {
927 push @scores, [$_, (length $cmd) + 1 - (length join "", map "::$_", grep defined, @penalty), "$_$arg"];
928 }
929
930 # Pick the best option for this command
931 push @match, (sort {
932 $b->[1] <=> $a->[1]
933 } @scores)[0];
877 } 934 }
878 935
936 # @match is now [command object, command with arguments]
879 @match = map $self->{command}{$_->[0]}, 937 @match = map [$self->{command}{$_->[0]}, $_->[2]],
880 sort { 938 sort {
881 $a->[1] <=> $b->[1] 939 $b->[1] <=> $a->[1]
882 or $self->{command}{$a->[0]}[4] <=> $self->{command}{$b->[0]}[4] 940 or $self->{command}{$a->[0]}[4] <=> $self->{command}{$b->[0]}[4]
883 or (length $b->[0]) <=> (length $a->[0]) 941 or (length $b->[0]) <=> (length $a->[0])
884 } @match; 942 } @match;
885 } 943 }
886 944
905 $label->{fg} = [1, 1, 1, 1]; 963 $label->{fg} = [1, 1, 1, 1];
906 $label->{bg} = [0, 0, 0, 0]; 964 $label->{bg} = [0, 0, 0, 0];
907 } 965 }
908 966
909 if (@matches) { 967 if (@matches) {
910 $self->{select} = "$matches[0][0]$arg"; 968 $self->{select} = "$matches[0][1]";
911 969
912 $labels[0]->{fg} = [0, 0, 0, 1]; 970 $labels[0]->{fg} = [0, 0, 0, 1];
913 $labels[0]->{bg} = [1, 1, 1, 0.8]; 971 $labels[0]->{bg} = [1, 1, 1, 0.8];
914 } else { 972 } else {
915 $self->{select} = "$cmd$arg"; 973 $self->{select} = "$text";
916 } 974 }
917 975
918 for my $match (@matches) { 976 for my $match (@matches) {
919 my $label = shift @labels; 977 my $label = shift @labels;
920 978
921 if (@labels) { 979 if (@labels) {
922 $label->set_text ("$match->[0]$arg"); 980 $label->set_text ("$match->[1]");
923 $label->set_tooltip ($match->[1]); 981 $label->set_tooltip ("$match->[0][1]");
924 } else { 982 } else {
925 $label->set_text ("..."); 983 $label->set_text ("...");
926 $label->set_tooltip ("Use Cursor-Down to view more matches"); 984 $label->set_tooltip ("Use Cursor-Down to view more matches");
927 last; 985 last;
928 } 986 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines