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.148 by root, Sun Jan 11 22:11:23 2009 UTC vs.
Revision 1.157 by root, Mon Dec 21 03:30:23 2009 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines