… | |
… | |
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 |
… | |
… | |
494 | |
499 | |
495 | $self->{fow_texture} = new DC::Texture |
500 | $self->{fow_texture} = new DC::Texture |
496 | w => $w, |
501 | w => $w, |
497 | h => $h, |
502 | h => $h, |
498 | data => $data, |
503 | data => $data, |
499 | internalformat => GL_ALPHA, |
504 | internalformat => GL_INTENSITY, |
500 | format => GL_ALPHA; |
505 | format => GL_LUMINANCE; |
501 | } else { |
506 | } else { |
502 | delete $self->{fow_texture}; |
507 | delete $self->{fow_texture}; |
503 | } |
508 | } |
504 | |
509 | |
505 | glNewList ($self->{list} ||= glGenList); |
510 | glNewList ($self->{list} ||= glGenList); |
506 | |
511 | |
507 | glPushMatrix; |
512 | glPushMatrix; |
508 | glTranslate $sx0, $sy0; |
513 | glTranslate $sx0, $sy0; |
509 | glScale $::CFG->{map_scale}, $::CFG->{map_scale}; |
514 | glScale $::CFG->{map_scale}, $::CFG->{map_scale}; |
510 | glTranslate $self->{sdx}, $self->{sdy}; |
515 | glTranslate DC::ceil $self->{sdx}, DC::ceil $self->{sdy}; |
511 | |
516 | |
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 | if (0 && $self->{last_fow_texture}) { |
|
|
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 | my $a2 = $d1 / $d2; |
|
|
532 | my $a1 = 1 - $a2; |
|
|
533 | |
|
|
534 | #$a1 *= 0.9; |
|
|
535 | #$a2 *= 0.9; |
|
|
536 | |
|
|
537 | printf "%8g %8g %8g %8g\n", $d1, $d2, $a1, $a2;#d# |
|
|
538 | |
|
|
539 | #$a1 = 1 - (1-$a1) * 0.707; |
|
|
540 | #$a2 = 1 - (1-$a2) * 0.707; |
|
|
541 | |
|
|
542 | glColor 1,0,0,1; |
|
|
543 | glBegin GL_QUADS; |
|
|
544 | glVertex 10 + $sdx_t, 10; |
|
|
545 | glVertex 11 + $sdx_t, 10; |
|
|
546 | glVertex 11 + $sdx_t, 11; |
|
|
547 | glVertex 10 + $sdx_t, 11; |
|
|
548 | glEnd; |
|
|
549 | |
|
|
550 | if(0){ |
|
|
551 | glBlendFunc GL_ZERO, GL_DST_COLOR; |
|
|
552 | glColor +($::CFG->{fow_intensity}) x 3, $a2; |
521 | glPushMatrix; |
553 | glPushMatrix; |
522 | glTranslate +(min 0, $sdx_t), (min 0, $sdy_t); |
554 | glTranslate $sdx_t, $sdy_t; # anchor at player |
|
|
555 | glTranslate $self->{ldx} / -$tilesize, $self->{ldy} / -$tilesize; |
523 | glScale 1/3, 1/3; |
556 | 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); |
557 | $self->{last_fow_texture}->draw_quad_alpha (0, 0); |
529 | |
|
|
530 | glDisable GL_TEXTURE_2D; |
|
|
531 | glPopMatrix; |
558 | glPopMatrix; |
|
|
559 | } |
|
|
560 | } else { |
|
|
561 | delete $self->{last_fow_texture}; |
|
|
562 | } |
|
|
563 | } else { |
|
|
564 | DC::Texture::draw_fow_texture |
|
|
565 | $::CFG->{fow_intensity}, |
|
|
566 | @{$self->{fow_texture}}{qw(name s t w h)}; |
|
|
567 | #d#glTranslate +(min 0, $sdx_t), (min 0, $sdy_t); # anchor at player |
|
|
568 | } |
532 | } |
569 | } |
533 | |
570 | |
534 | if ($self->{magicmap}) { |
571 | if ($self->{magicmap}) { |
535 | my ($x, $y, $w, $h, $data) = @{ $self->{magicmap} }; |
572 | my ($x, $y, $w, $h, $data) = @{ $self->{magicmap} }; |
536 | |
573 | |
… | |
… | |
846 | my $text = $self->{entry}->get_text; |
883 | my $text = $self->{entry}->get_text; |
847 | |
884 | |
848 | length $text |
885 | length $text |
849 | or return $self->hide; |
886 | or return $self->hide; |
850 | |
887 | |
851 | my ($cmd, $arg) = $text =~ /^\s*([^[:space:]]*)(.*)$/; |
|
|
852 | |
|
|
853 | if ($text ne $self->{last_search}) { |
888 | if ($text ne $self->{last_search}) { |
854 | my @match; |
889 | my @match; |
855 | |
890 | |
856 | if ($text =~ /^(.*?)\s+$/) { |
891 | if ($text =~ /^(.*?)\s+$/) { |
|
|
892 | my ($cmd, $arg) = $text =~ /^\s*([^[:space:]]*)(.*)$/; |
857 | @match = [$cmd, "(appended whitespace suppresses completion)"]; |
893 | @match = ([[$cmd,'(appended whitespace suppresses completion)'],$text]); |
858 | } else { |
894 | } else { |
|
|
895 | # @match is [command, penalty, command with arguments] until sort |
|
|
896 | |
|
|
897 | my ($cmd, $arg) = $text =~ /^\s*([^[:space:]]*)(.*)$/; |
|
|
898 | |
859 | my $regexp = do { |
899 | my $regexp_abbrev = do { |
860 | my ($beg, @chr) = split //, lc $cmd; |
900 | my ($beg, @chr) = split //, lc $cmd; |
861 | |
901 | |
862 | # the following regex is used to match our "completion entry" |
902 | # the following regex is used to match our "completion entry" |
863 | # to an actual command - the parentheses match kind of "overhead" |
903 | # to an actual command - the parentheses match kind of "overhead" |
864 | # - the more characters the parentheses match, the less attractive |
904 | # - the more characters the parentheses match, the less attractive |
… | |
… | |
866 | my $regexp = "^\Q$beg\E" |
906 | my $regexp = "^\Q$beg\E" |
867 | . join "", map "(?:.*?[ \\\\]\Q$_\E|(.*?)\Q$_\E)", @chr; |
907 | . join "", map "(?:.*?[ \\\\]\Q$_\E|(.*?)\Q$_\E)", @chr; |
868 | qr<$regexp> |
908 | qr<$regexp> |
869 | }; |
909 | }; |
870 | |
910 | |
871 | my @penalty; |
911 | my $regexp_partial = do { |
|
|
912 | my $regexp = "^\Q$text\E(.*)"; |
|
|
913 | qr<$regexp> |
|
|
914 | }; |
872 | |
915 | |
873 | for (keys %{$self->{command}}) { |
916 | for (keys %{$self->{command}}) { |
874 | if (@penalty = $_ =~ $regexp) { |
917 | my @scores; |
875 | push @match, [$_, length join "", map "::$_", grep defined, @penalty]; |
918 | |
|
|
919 | # 1. Complete command [with args] |
|
|
920 | # command is a prefix of the text |
|
|
921 | # score is length of complete command matched |
|
|
922 | # e.g. "invoke summon pet monster bat" |
|
|
923 | # "invoke" "summon pet monster bat" = 6 |
|
|
924 | # "invoke summon pet monster" "bat" = 25 |
|
|
925 | if ($text =~ /^\Q$_\E(.*)/) { |
|
|
926 | push @scores, [$_, length $_, $text]; |
876 | } |
927 | } |
|
|
928 | |
|
|
929 | # 2. Partial command |
|
|
930 | # text is a prefix of the full command |
|
|
931 | # score is the length of the input text |
|
|
932 | # e.g. "invoke s" |
|
|
933 | # "invoke small fireball" = 8 |
|
|
934 | # "invoke summon pet monster" = 8 |
|
|
935 | |
|
|
936 | if ($_ =~ $regexp_partial) { |
|
|
937 | push @scores, [$_, length $text, $_]; |
|
|
938 | } |
|
|
939 | |
|
|
940 | # 3. Abbreviation match |
|
|
941 | # attempts to use first word of text as an abbreviated command |
|
|
942 | # score is length of word + 1 - 3 per non-word-initial character |
|
|
943 | |
|
|
944 | if (my @penalty = $_ =~ $regexp_abbrev) { |
|
|
945 | push @scores, [$_, (length $cmd) + 1 - (length join "", map "::$_", grep defined, @penalty), "$_$arg"]; |
|
|
946 | } |
|
|
947 | |
|
|
948 | # Pick the best option for this command |
|
|
949 | push @match, (sort { |
|
|
950 | $b->[1] <=> $a->[1] |
|
|
951 | } @scores)[0]; |
877 | } |
952 | } |
878 | |
953 | |
|
|
954 | # @match is now [command object, command with arguments] |
879 | @match = map $self->{command}{$_->[0]}, |
955 | @match = map [$self->{command}{$_->[0]}, $_->[2]], |
880 | sort { |
956 | sort { |
881 | $a->[1] <=> $b->[1] |
957 | $b->[1] <=> $a->[1] |
882 | or $self->{command}{$a->[0]}[4] <=> $self->{command}{$b->[0]}[4] |
958 | or $self->{command}{$a->[0]}[4] <=> $self->{command}{$b->[0]}[4] |
883 | or (length $b->[0]) <=> (length $a->[0]) |
959 | or (length $b->[0]) <=> (length $a->[0]) |
884 | } @match; |
960 | } @match; |
885 | } |
961 | } |
886 | |
962 | |
… | |
… | |
905 | $label->{fg} = [1, 1, 1, 1]; |
981 | $label->{fg} = [1, 1, 1, 1]; |
906 | $label->{bg} = [0, 0, 0, 0]; |
982 | $label->{bg} = [0, 0, 0, 0]; |
907 | } |
983 | } |
908 | |
984 | |
909 | if (@matches) { |
985 | if (@matches) { |
910 | $self->{select} = "$matches[0][0]$arg"; |
986 | $self->{select} = "$matches[0][1]"; |
911 | |
987 | |
912 | $labels[0]->{fg} = [0, 0, 0, 1]; |
988 | $labels[0]->{fg} = [0, 0, 0, 1]; |
913 | $labels[0]->{bg} = [1, 1, 1, 0.8]; |
989 | $labels[0]->{bg} = [1, 1, 1, 0.8]; |
914 | } else { |
990 | } else { |
915 | $self->{select} = "$cmd$arg"; |
991 | $self->{select} = "$text"; |
916 | } |
992 | } |
917 | |
993 | |
918 | for my $match (@matches) { |
994 | for my $match (@matches) { |
919 | my $label = shift @labels; |
995 | my $label = shift @labels; |
920 | |
996 | |
921 | if (@labels) { |
997 | if (@labels) { |
922 | $label->set_text ("$match->[0]$arg"); |
998 | $label->set_text ("$match->[1]"); |
923 | $label->set_tooltip ($match->[1]); |
999 | $label->set_tooltip ("$match->[0][1]"); |
924 | } else { |
1000 | } else { |
925 | $label->set_text ("..."); |
1001 | $label->set_text ("..."); |
926 | $label->set_tooltip ("Use Cursor-Down to view more matches"); |
1002 | $label->set_tooltip ("Use Cursor-Down to view more matches"); |
927 | last; |
1003 | last; |
928 | } |
1004 | } |