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.159 by root, Tue Dec 22 00:35:44 2009 UTC

9use DC::OpenGL; 9use DC::OpenGL;
10use DC::UI; 10use DC::UI;
11use DC::Macro; 11use DC::Macro;
12 12
13our @ISA = DC::UI::Base::; 13our @ISA = DC::UI::Base::;
14
15our @TEX_HIDDEN = map {
16 new_from_resource DC::Texture # MUST be POT
17 "hidden-$_.png", mipmap => 1, wrap => 1
18 } 0, 1, 2;
14 19
15my $magicmap_tex = 20my $magicmap_tex =
16 new_from_resource DC::Texture "magicmap.png", 21 new_from_resource DC::Texture "magicmap.png",
17 mipmap => 1, wrap => 0, internalformat => GL_ALPHA; 22 mipmap => 1, wrap => 0, internalformat => GL_ALPHA;
18 23
201 ["Skills\tF3", sub { ::toggle_player_page ($::SKILL_PAGE) }], 206 ["Skills\tF3", sub { ::toggle_player_page ($::SKILL_PAGE) }],
202 ["Spells…\tF4", sub { ::toggle_player_page ($::SPELL_PAGE) }], 207 ["Spells…\tF4", sub { ::toggle_player_page ($::SPELL_PAGE) }],
203 ["Inventory…\tF5", sub { ::toggle_player_page ($::INVENTORY_PAGE) }], 208 ["Inventory…\tF5", sub { ::toggle_player_page ($::INVENTORY_PAGE) }],
204 ["Setup… \tF9", sub { $::SETUP_DIALOG->toggle_visibility }], 209 ["Setup… \tF9", sub { $::SETUP_DIALOG->toggle_visibility }],
205# ["Server Messages…", sub { $::MESSAGE_WINDOW->toggle_visibility }], 210# ["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 ); 211 );
213 212
214 if ($::CONN && $::CONN->{editor_support}) { 213 if ($::CONN && $::CONN->{editor_support}) {
215# push @items, [ 214# push @items, [
216# "Edit this map <span size='xx-small'>(" . (DC::asxml $::CONN->{map_info}[0]) . ")</span>", 215# "Edit this map <span size='xx-small'>(" . (DC::asxml $::CONN->{map_info}[0]) . ")</span>",
402} 401}
403 402
404sub scroll { 403sub scroll {
405 my ($self, $dx, $dy) = @_; 404 my ($self, $dx, $dy) = @_;
406 405
407 $::MAP->scroll ($dx, $dy);
408
409 $self->movement_update; 406 $self->movement_update;
410 407
411 $self->{sdx} += $dx * $self->{tilesize}; # smooth displacement 408 $self->{sdx} += $dx * $self->{tilesize}; # smooth displacement
412 $self->{sdy} += $dy * $self->{tilesize}; 409 $self->{sdy} += $dy * $self->{tilesize};
410
411 # save old fow texture, if applicable
412 $self->{last_fow_texture} = $self->{fow_texture}
413 if $::CFG->{smooth_transitions};
414 $self->{lfdx} = $dx;
415 $self->{lfdy} = $dy;
416 $self->{lmdx} = $self->{dx};
417 $self->{lmdy} = $self->{dy};
418
419 $::MAP->scroll ($dx, $dy);
413} 420}
414 421
415sub set_magicmap { 422sub set_magicmap {
416 my ($self, $w, $h, $x, $y, $data) = @_; 423 my ($self, $w, $h, $x, $y, $data) = @_;
417 424
488 495
489 my $dx = $self->{dx} = DC::ceil 0.5 * ($::MAP->w - $sw) - $sx; 496 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; 497 my $dy = $self->{dy} = DC::ceil 0.5 * ($::MAP->h - $sh) - $sy;
491 498
492 if ($::CFG->{fow_enable}) { 499 if ($::CFG->{fow_enable}) {
493 $sdx_t = $sdy_t = 0;#d# 500 # draw_fow_texture REQUIRES the fow texture to stay the same size.
494 my ($w, $h, $data) = $::MAP->fow_texture ( 501 my ($w, $h, $data) = $::MAP->fow_texture ($dx, $dy, $sw, $sh);
495 $dx + (min 0, $sdx_t),
496 $dy + (min 0, $sdy_t),
497 $sw + abs $sdx_t,
498 $sh + abs $sdy_t
499 );
500 502
501 $self->{fow_texture} = new DC::Texture 503 $self->{fow_texture} = new DC::Texture
502 w => $w, 504 w => $w,
503 h => $h, 505 h => $h,
504 data => $data, 506 data => $data,
511 glNewList ($self->{list} ||= glGenList); 513 glNewList ($self->{list} ||= glGenList);
512 514
513 glPushMatrix; 515 glPushMatrix;
514 glTranslate $sx0, $sy0; 516 glTranslate $sx0, $sy0;
515 glScale $::CFG->{map_scale}, $::CFG->{map_scale}; 517 glScale $::CFG->{map_scale}, $::CFG->{map_scale};
516 glTranslate $self->{sdx}, $self->{sdy}; 518 glTranslate DC::ceil $self->{sdx}, DC::ceil $self->{sdy};
517 519
518 $::MAP->draw ($dx, $dy, $sw, $sh, 520 $::MAP->draw ($dx, $dy, $sw, $sh,
519 $self->{tilesize}, 521 $self->{tilesize},
520 $::CONN->{player}{tag}, 522 $::CONN->{player}{tag},
521 -$self->{sdx}, -$self->{sdy}); 523 -$self->{sdx}, -$self->{sdy});
522 524
523 #glTranslate -$self->{sdx}, -$self->{sdy}; # anchor fow at player
524 glScale $self->{tilesize}, $self->{tilesize}; 525 glScale $self->{tilesize}, $self->{tilesize};
525 526
526 if (my $tex = $self->{fow_texture}) { 527 if (my $tex = $self->{fow_texture}) {
527 glPushMatrix; 528 if ($DC::OpenGL::GL_MULTITEX && $self->{last_fow_texture}) {
528 glTranslate +(min 0, $sdx_t), (min 0, $sdy_t); 529 my $d1 = DC::distance $self->{sdx}, $self->{sdy};
529 glScale 1/3, 1/3; 530 my $d2 = (DC::distance $self->{lfdx}, $self->{lfdy}) * $tilesize;
530 glEnable GL_TEXTURE_2D;
531 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
532 531
533 glColor +($::CFG->{fow_intensity}) x 3, 0.9; 532 if ($d1 * $d2) {
534 $self->{fow_texture}->draw_quad_alpha (0, 0); 533 DC::Texture::draw_fow_texture
534 $::CFG->{fow_intensity},
535 $TEX_HIDDEN[$::CFG->{fow_texture}]{name},
536 @{$self->{fow_texture}}{qw(name data s t w h)},
537 (min 1, $d1 / $d2),
538 $self->{lmdx} - $dx - $self->{lfdx},
539 $self->{lmdy} - $dy - $self->{lfdy},
540 @{$self->{last_fow_texture}}{qw(name data)};
541 } else {
542 delete $self->{last_fow_texture};
543 }
544 }
535 545
536 glDisable GL_TEXTURE_2D; 546 unless ($self->{last_fow_texture}) {
537 glPopMatrix; 547 DC::Texture::draw_fow_texture
548 $::CFG->{fow_intensity},
549 $TEX_HIDDEN[$::CFG->{fow_texture}]{name},
550 @{$self->{fow_texture}}{qw(name data s t w h)};
551 }
538 } 552 }
539 553
540 if ($self->{magicmap}) { 554 if ($self->{magicmap}) {
541 my ($x, $y, $w, $h, $data) = @{ $self->{magicmap} }; 555 my ($x, $y, $w, $h, $data) = @{ $self->{magicmap} };
542 556
543 $x += $::MAP->ox + $self->{dx}; 557 $x += $::MAP->ox + $self->{dx};
544 $y += $::MAP->oy + $self->{dy}; 558 $y += $::MAP->oy + $self->{dy};
545 559
546 glTranslate - $x - 1, - $y - 1; 560 glTranslate - $x - 1, - $y - 1;
547 glBindTexture GL_TEXTURE_2D, $magicmap_tex->{name}; 561 glBindTexture GL_TEXTURE_2D, $magicmap_tex->{name};
548 $::MAP->draw_magicmap ($x, $y, $w, $h, $data); 562 $::MAP->draw_magicmap ($w, $h, $data);
549 } 563 }
550 564
551 glPopMatrix; 565 glPopMatrix;
552 glEndList; 566 glEndList;
553 } 567 }
554 } else { 568 } else {
569 delete $self->{last_fow_texture};
570 delete $self->{fow_texture};
571
555 glDeleteList delete $self->{list} 572 glDeleteList delete $self->{list}
556 if $self->{list}; 573 if $self->{list};
557 } 574 }
558} 575}
559 576
852 my $text = $self->{entry}->get_text; 869 my $text = $self->{entry}->get_text;
853 870
854 length $text 871 length $text
855 or return $self->hide; 872 or return $self->hide;
856 873
857 my ($cmd, $arg) = $text =~ /^\s*([^[:space:]]*)(.*)$/;
858
859 if ($text ne $self->{last_search}) { 874 if ($text ne $self->{last_search}) {
860 my @match; 875 my @match;
861 876
862 if ($text =~ /^(.*?)\s+$/) { 877 if ($text =~ /^(.*?)\s+$/) {
878 my ($cmd, $arg) = $text =~ /^\s*([^[:space:]]*)(.*)$/;
863 @match = [$cmd, "(appended whitespace suppresses completion)"]; 879 @match = ([[$cmd,'(appended whitespace suppresses completion)'],$text]);
864 } else { 880 } else {
881 # @match is [command, penalty, command with arguments] until sort
882
883 my ($cmd, $arg) = $text =~ /^\s*([^[:space:]]*)(.*)$/;
884
865 my $regexp = do { 885 my $regexp_abbrev = do {
866 my ($beg, @chr) = split //, lc $cmd; 886 my ($beg, @chr) = split //, lc $cmd;
867 887
868 # the following regex is used to match our "completion entry" 888 # the following regex is used to match our "completion entry"
869 # to an actual command - the parentheses match kind of "overhead" 889 # to an actual command - the parentheses match kind of "overhead"
870 # - the more characters the parentheses match, the less attractive 890 # - the more characters the parentheses match, the less attractive
872 my $regexp = "^\Q$beg\E" 892 my $regexp = "^\Q$beg\E"
873 . join "", map "(?:.*?[ \\\\]\Q$_\E|(.*?)\Q$_\E)", @chr; 893 . join "", map "(?:.*?[ \\\\]\Q$_\E|(.*?)\Q$_\E)", @chr;
874 qr<$regexp> 894 qr<$regexp>
875 }; 895 };
876 896
877 my @penalty; 897 my $regexp_partial = do {
898 my $regexp = "^\Q$text\E(.*)";
899 qr<$regexp>
900 };
878 901
879 for (keys %{$self->{command}}) { 902 for (keys %{$self->{command}}) {
880 if (@penalty = $_ =~ $regexp) { 903 my @scores;
881 push @match, [$_, length join "", map "::$_", grep defined, @penalty]; 904
905 # 1. Complete command [with args]
906 # command is a prefix of the text
907 # score is length of complete command matched
908 # e.g. "invoke summon pet monster bat"
909 # "invoke" "summon pet monster bat" = 6
910 # "invoke summon pet monster" "bat" = 25
911 if ($text =~ /^\Q$_\E(.*)/) {
912 push @scores, [$_, length $_, $text];
882 } 913 }
914
915 # 2. Partial command
916 # text is a prefix of the full command
917 # score is the length of the input text
918 # e.g. "invoke s"
919 # "invoke small fireball" = 8
920 # "invoke summon pet monster" = 8
921
922 if ($_ =~ $regexp_partial) {
923 push @scores, [$_, length $text, $_];
924 }
925
926 # 3. Abbreviation match
927 # attempts to use first word of text as an abbreviated command
928 # score is length of word + 1 - 3 per non-word-initial character
929
930 if (my @penalty = $_ =~ $regexp_abbrev) {
931 push @scores, [$_, (length $cmd) + 1 - (length join "", map "::$_", grep defined, @penalty), "$_$arg"];
932 }
933
934 # Pick the best option for this command
935 push @match, (sort {
936 $b->[1] <=> $a->[1]
937 } @scores)[0];
883 } 938 }
884 939
940 # @match is now [command object, command with arguments]
885 @match = map $self->{command}{$_->[0]}, 941 @match = map [$self->{command}{$_->[0]}, $_->[2]],
886 sort { 942 sort {
887 $a->[1] <=> $b->[1] 943 $b->[1] <=> $a->[1]
888 or $self->{command}{$a->[0]}[4] <=> $self->{command}{$b->[0]}[4] 944 or $self->{command}{$a->[0]}[4] <=> $self->{command}{$b->[0]}[4]
889 or (length $b->[0]) <=> (length $a->[0]) 945 or (length $b->[0]) <=> (length $a->[0])
890 } @match; 946 } @match;
891 } 947 }
892 948
911 $label->{fg} = [1, 1, 1, 1]; 967 $label->{fg} = [1, 1, 1, 1];
912 $label->{bg} = [0, 0, 0, 0]; 968 $label->{bg} = [0, 0, 0, 0];
913 } 969 }
914 970
915 if (@matches) { 971 if (@matches) {
916 $self->{select} = "$matches[0][0]$arg"; 972 $self->{select} = "$matches[0][1]";
917 973
918 $labels[0]->{fg} = [0, 0, 0, 1]; 974 $labels[0]->{fg} = [0, 0, 0, 1];
919 $labels[0]->{bg} = [1, 1, 1, 0.8]; 975 $labels[0]->{bg} = [1, 1, 1, 0.8];
920 } else { 976 } else {
921 $self->{select} = "$cmd$arg"; 977 $self->{select} = "$text";
922 } 978 }
923 979
924 for my $match (@matches) { 980 for my $match (@matches) {
925 my $label = shift @labels; 981 my $label = shift @labels;
926 982
927 if (@labels) { 983 if (@labels) {
928 $label->set_text ("$match->[0]$arg"); 984 $label->set_text ("$match->[1]");
929 $label->set_tooltip ($match->[1]); 985 $label->set_tooltip ("$match->[0][1]");
930 } else { 986 } else {
931 $label->set_text ("..."); 987 $label->set_text ("...");
932 $label->set_tooltip ("Use Cursor-Down to view more matches"); 988 $label->set_tooltip ("Use Cursor-Down to view more matches");
933 last; 989 last;
934 } 990 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines