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