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.145 by root, Wed Sep 24 01:03:05 2008 UTC vs.
Revision 1.154 by root, Fri Dec 4 15:04:56 2009 UTC

163sub invoke_button_down { 163sub 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>",
404sub scroll { 398sub scroll {
405 my ($self, $dx, $dy) = @_; 399 my ($self, $dx, $dy) = @_;
406 400
407 $::MAP->scroll ($dx, $dy); 401 $::MAP->scroll ($dx, $dy);
408 402
403 $self->{last_fow_texture} = $self->{fow_texture};
404 $self->{ldx} = $self->{sdx} + $dx * $self->{tilesize}; # smooth displacement
405 $self->{ldy} = $self->{sdy} + $dy * $self->{tilesize};
406
409 $self->movement_update; 407 $self->movement_update;
410 408
411 $self->{sdx} += $dx * $self->{tilesize}; # smooth displacement 409 $self->{sdx} += $dx * $self->{tilesize}; # smooth displacement
412 $self->{sdy} += $dy * $self->{tilesize}; 410 $self->{sdy} += $dy * $self->{tilesize};
413} 411}
488 486
489 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;
490 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;
491 489
492 if ($::CFG->{fow_enable}) { 490 if ($::CFG->{fow_enable}) {
493 $sdx_t = $sdy_t = 0;#d# 491 my ($sdx_t, $sdy_t);#d# do not anchor at player
492
494 my ($w, $h, $data) = $::MAP->fow_texture ( 493 my ($w, $h, $data) = $::MAP->fow_texture (
495 $dx + (min 0, $sdx_t), 494 $dx + (min 0, $sdx_t),
496 $dy + (min 0, $sdy_t), 495 $dy + (min 0, $sdy_t),
497 $sw + abs $sdx_t, 496 $sw + abs $sdx_t,
498 $sh + abs $sdy_t 497 $sh + abs $sdy_t
511 glNewList ($self->{list} ||= glGenList); 510 glNewList ($self->{list} ||= glGenList);
512 511
513 glPushMatrix; 512 glPushMatrix;
514 glTranslate $sx0, $sy0; 513 glTranslate $sx0, $sy0;
515 glScale $::CFG->{map_scale}, $::CFG->{map_scale}; 514 glScale $::CFG->{map_scale}, $::CFG->{map_scale};
516 glTranslate $self->{sdx}, $self->{sdy}; 515 glTranslate DC::ceil $self->{sdx}, DC::ceil $self->{sdy};
517 516
518 $::MAP->draw ($dx, $dy, $sw, $sh, 517 $::MAP->draw ($dx, $dy, $sw, $sh,
519 $self->{tilesize}, 518 $self->{tilesize},
520 $::CONN->{player}{tag}, 519 $::CONN->{player}{tag},
521 -$self->{sdx}, -$self->{sdy}); 520 -$self->{sdx}, -$self->{sdy});
522 521
523 #glTranslate -$self->{sdx}, -$self->{sdy}; # anchro fow at player 522 #d#glTranslate -$self->{sdx}, -$self->{sdy}; # anchor fow at player
524 glScale $self->{tilesize}, $self->{tilesize}; 523 glScale $self->{tilesize}, $self->{tilesize};
525 524
526 if (my $tex = $self->{fow_texture}) { 525 if (my $tex = $self->{fow_texture}) {
526 glEnable GL_TEXTURE_2D;
527 glEnable GL_BLEND;
528 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
529 glBlendFunc GL_ONE, GL_ZERO;
530
531 my $a1 = 0.9;
532
533 if (0 && $self->{last_fow_texture}) {
534 my $d1 = ($self->{sdx} ** 2 + $self->{sdy} ** 2) ** 0.5;
535 my $d2 = ($self->{ldx} ** 2 + $self->{ldy} ** 2) ** 0.5;
536
537 if ($d1 * $d2) {
538 my $a2 = $d1 / $d2;
539
540 $a1 = 1 - $a2;
541
542 #$a1 *= 0.9;
543 #$a2 *= 0.9;
544
545 printf "%4g %4g %4g %4g\n", $d1, $d2, $a1, $a2;#d#
546
547 #$a1 = 1 - (1-$a1) * 0.707;
548 #$a2 = 1 - (1-$a2) * 0.707;
549
550 glColor 1,0,0,1;
551 glBegin GL_QUADS;
552 glVertex 10 + $sdx_t, 10;
553 glVertex 11 + $sdx_t, 10;
554 glVertex 11 + $sdx_t, 11;
555 glVertex 10 + $sdx_t, 11;
556 glEnd;
557
558 glColor +($::CFG->{fow_intensity}) x 3, $a2;
559 glPushMatrix;
560 glTranslate $sdx_t, $sdy_t; # anchor at player
561 glTranslate $self->{ldx} / -$tilesize, $self->{ldy} / -$tilesize;
562 glScale 1/3, 1/3;
563 $self->{last_fow_texture}->draw_quad_alpha (0, 0);
564 glPopMatrix;
565 } else {
566 delete $self->{last_fow_texture};
567 }
568 }
569
570 glColor +($::CFG->{fow_intensity}) x 3, $a1;
527 glPushMatrix; 571 glPushMatrix;
528 glTranslate +(min 0, $sdx_t), (min 0, $sdy_t); 572 #d#glTranslate +(min 0, $sdx_t), (min 0, $sdy_t); # anchor at player
529 glScale 1/3, 1/3; 573 glScale 1/3, 1/3;
530 glEnable GL_TEXTURE_2D;
531 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
532
533 glColor +($::CFG->{fow_intensity}) x 3, 0.9;
534 $self->{fow_texture}->draw_quad_alpha (0, 0); 574 $self->{fow_texture}->draw_quad_alpha (0, 0);
575 glPopMatrix;
535 576
536 glDisable GL_TEXTURE_2D; 577 glDisable GL_TEXTURE_2D;
537 glPopMatrix; 578 glDisable GL_BLEND;
538 } 579 }
539 580
540 if ($self->{magicmap}) { 581 if ($self->{magicmap}) {
541 my ($x, $y, $w, $h, $data) = @{ $self->{magicmap} }; 582 my ($x, $y, $w, $h, $data) = @{ $self->{magicmap} };
542 583
852 my $text = $self->{entry}->get_text; 893 my $text = $self->{entry}->get_text;
853 894
854 length $text 895 length $text
855 or return $self->hide; 896 or return $self->hide;
856 897
857 my ($cmd, $arg) = $text =~ /^\s*([^[:space:]]*)(.*)$/;
858
859 if ($text ne $self->{last_search}) { 898 if ($text ne $self->{last_search}) {
860 my @match; 899 my @match;
861 900
862 if ($text =~ /^(.*?)\s+$/) { 901 if ($text =~ /^(.*?)\s+$/) {
902 my ($cmd, $arg) = $text =~ /^\s*([^[:space:]]*)(.*)$/;
863 @match = [$cmd, "(appended whitespace suppresses completion)"]; 903 @match = ([[$cmd,'(appended whitespace suppresses completion)'],$text]);
864 } else { 904 } else {
905 # @match is [command, penalty, command with arguments] until sort
906
907 my ($cmd, $arg) = $text =~ /^\s*([^[:space:]]*)(.*)$/;
908
865 my $regexp = do { 909 my $regexp_abbrev = do {
866 my ($beg, @chr) = split //, lc $cmd; 910 my ($beg, @chr) = split //, lc $cmd;
867 911
868 # the following regex is used to match our "completion entry" 912 # the following regex is used to match our "completion entry"
869 # to an actual command - the parentheses match kind of "overhead" 913 # to an actual command - the parentheses match kind of "overhead"
870 # - the more characters the parentheses match, the less attractive 914 # - the more characters the parentheses match, the less attractive
872 my $regexp = "^\Q$beg\E" 916 my $regexp = "^\Q$beg\E"
873 . join "", map "(?:.*?[ \\\\]\Q$_\E|(.*?)\Q$_\E)", @chr; 917 . join "", map "(?:.*?[ \\\\]\Q$_\E|(.*?)\Q$_\E)", @chr;
874 qr<$regexp> 918 qr<$regexp>
875 }; 919 };
876 920
877 my @penalty; 921 my $regexp_partial = do {
922 my $regexp = "^\Q$text\E(.*)";
923 qr<$regexp>
924 };
878 925
879 for (keys %{$self->{command}}) { 926 for (keys %{$self->{command}}) {
880 if (@penalty = $_ =~ $regexp) { 927 my @scores;
881 push @match, [$_, length join "", map "::$_", grep defined, @penalty]; 928
929 # 1. Complete command [with args]
930 # command is a prefix of the text
931 # score is length of complete command matched
932 # e.g. "invoke summon pet monster bat"
933 # "invoke" "summon pet monster bat" = 6
934 # "invoke summon pet monster" "bat" = 25
935 if ($text =~ /^\Q$_\E(.*)/) {
936 push @scores, [$_, length $_, $text];
882 } 937 }
938
939 # 2. Partial command
940 # text is a prefix of the full command
941 # score is the length of the input text
942 # e.g. "invoke s"
943 # "invoke small fireball" = 8
944 # "invoke summon pet monster" = 8
945
946 if ($_ =~ $regexp_partial) {
947 push @scores, [$_, length $text, $_];
948 }
949
950 # 3. Abbreviation match
951 # attempts to use first word of text as an abbreviated command
952 # score is length of word + 1 - 3 per non-word-initial character
953
954 if (my @penalty = $_ =~ $regexp_abbrev) {
955 push @scores, [$_, (length $cmd) + 1 - (length join "", map "::$_", grep defined, @penalty), "$_$arg"];
956 }
957
958 # Pick the best option for this command
959 push @match, (sort {
960 $b->[1] <=> $a->[1]
961 } @scores)[0];
883 } 962 }
884 963
964 # @match is now [command object, command with arguments]
885 @match = map $self->{command}{$_->[0]}, 965 @match = map [$self->{command}{$_->[0]}, $_->[2]],
886 sort { 966 sort {
887 $a->[1] <=> $b->[1] 967 $b->[1] <=> $a->[1]
888 or $self->{command}{$a->[0]}[4] <=> $self->{command}{$b->[0]}[4] 968 or $self->{command}{$a->[0]}[4] <=> $self->{command}{$b->[0]}[4]
889 or (length $b->[0]) <=> (length $a->[0]) 969 or (length $b->[0]) <=> (length $a->[0])
890 } @match; 970 } @match;
891 } 971 }
892 972
911 $label->{fg} = [1, 1, 1, 1]; 991 $label->{fg} = [1, 1, 1, 1];
912 $label->{bg} = [0, 0, 0, 0]; 992 $label->{bg} = [0, 0, 0, 0];
913 } 993 }
914 994
915 if (@matches) { 995 if (@matches) {
916 $self->{select} = "$matches[0][0]$arg"; 996 $self->{select} = "$matches[0][1]";
917 997
918 $labels[0]->{fg} = [0, 0, 0, 1]; 998 $labels[0]->{fg} = [0, 0, 0, 1];
919 $labels[0]->{bg} = [1, 1, 1, 0.8]; 999 $labels[0]->{bg} = [1, 1, 1, 0.8];
920 } else { 1000 } else {
921 $self->{select} = "$cmd$arg"; 1001 $self->{select} = "$text";
922 } 1002 }
923 1003
924 for my $match (@matches) { 1004 for my $match (@matches) {
925 my $label = shift @labels; 1005 my $label = shift @labels;
926 1006
927 if (@labels) { 1007 if (@labels) {
928 $label->set_text ("$match->[0]$arg"); 1008 $label->set_text ("$match->[1]");
929 $label->set_tooltip ($match->[1]); 1009 $label->set_tooltip ("$match->[0][1]");
930 } else { 1010 } else {
931 $label->set_text ("..."); 1011 $label->set_text ("...");
932 $label->set_tooltip ("Use Cursor-Down to view more matches"); 1012 $label->set_tooltip ("Use Cursor-Down to view more matches");
933 last; 1013 last;
934 } 1014 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines