--- deliantra/Deliantra-Client/DC/MapWidget.pm 2009/01/11 22:11:23 1.148 +++ deliantra/Deliantra-Client/DC/MapWidget.pm 2009/12/21 03:30:23 1.157 @@ -398,12 +398,20 @@ sub scroll { my ($self, $dx, $dy) = @_; - $::MAP->scroll ($dx, $dy); - $self->movement_update; $self->{sdx} += $dx * $self->{tilesize}; # smooth displacement $self->{sdy} += $dy * $self->{tilesize}; + + # save old fow texture, if applicable + $self->{last_fow_texture} = $self->{fow_texture} + if $::CFG->{smooth_transitions}; + $self->{lfdx} = $dx; + $self->{lfdy} = $dy; + $self->{lmdx} = $self->{dx}; + $self->{lmdy} = $self->{dy}; + + $::MAP->scroll ($dx, $dy); } sub set_magicmap { @@ -484,13 +492,7 @@ my $dy = $self->{dy} = DC::ceil 0.5 * ($::MAP->h - $sh) - $sy; if ($::CFG->{fow_enable}) { - $sdx_t = $sdy_t = 0;#d# - my ($w, $h, $data) = $::MAP->fow_texture ( - $dx + (min 0, $sdx_t), - $dy + (min 0, $sdy_t), - $sw + abs $sdx_t, - $sh + abs $sdy_t - ); + my ($w, $h, $data) = $::MAP->fow_texture ($dx, $dy, $sw, $sh); $self->{fow_texture} = new DC::Texture w => $w, @@ -507,28 +509,38 @@ glPushMatrix; glTranslate $sx0, $sy0; glScale $::CFG->{map_scale}, $::CFG->{map_scale}; - glTranslate $self->{sdx}, $self->{sdy}; + glTranslate DC::ceil $self->{sdx}, DC::ceil $self->{sdy}; $::MAP->draw ($dx, $dy, $sw, $sh, $self->{tilesize}, $::CONN->{player}{tag}, -$self->{sdx}, -$self->{sdy}); - #glTranslate -$self->{sdx}, -$self->{sdy}; # anchor fow at player glScale $self->{tilesize}, $self->{tilesize}; if (my $tex = $self->{fow_texture}) { - glPushMatrix; - glTranslate +(min 0, $sdx_t), (min 0, $sdy_t); - glScale 1/3, 1/3; - glEnable GL_TEXTURE_2D; - glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; - - glColor +($::CFG->{fow_intensity}) x 3, 0.9; - $self->{fow_texture}->draw_quad_alpha (0, 0); + if ($DC::OpenGL::GL_MULTITEX && $self->{last_fow_texture}) {#d# + my $d1 = DC::distance $self->{sdx}, $self->{sdy}; + my $d2 = (DC::distance $self->{lfdx}, $self->{lfdy}) * $tilesize; + + if ($d1 * $d2) { + DC::Texture::draw_fow_texture + $::CFG->{fow_intensity}, + @{$self->{fow_texture}}{qw(name s t w h)}, + (min 1, $d1 / $d2), + $self->{lmdx} - $dx - $self->{lfdx}, + $self->{lmdy} - $dy - $self->{lfdy}, + @{$self->{last_fow_texture}}{qw(name s t w h)}; + } else { + delete $self->{last_fow_texture}; + } + } - glDisable GL_TEXTURE_2D; - glPopMatrix; + unless ($self->{last_fow_texture}) { + DC::Texture::draw_fow_texture + $::CFG->{fow_intensity}, + @{$self->{fow_texture}}{qw(name s t w h)}; + } } if ($self->{magicmap}) { @@ -539,7 +551,7 @@ glTranslate - $x - 1, - $y - 1; glBindTexture GL_TEXTURE_2D, $magicmap_tex->{name}; - $::MAP->draw_magicmap ($x, $y, $w, $h, $data); + $::MAP->draw_magicmap ($w, $h, $data); } glPopMatrix; @@ -848,15 +860,18 @@ length $text or return $self->hide; - my ($cmd, $arg) = $text =~ /^\s*([^[:space:]]*)(.*)$/; - if ($text ne $self->{last_search}) { my @match; if ($text =~ /^(.*?)\s+$/) { - @match = [$cmd, "(appended whitespace suppresses completion)"]; + my ($cmd, $arg) = $text =~ /^\s*([^[:space:]]*)(.*)$/; + @match = ([[$cmd,'(appended whitespace suppresses completion)'],$text]); } else { - my $regexp = do { + # @match is [command, penalty, command with arguments] until sort + + my ($cmd, $arg) = $text =~ /^\s*([^[:space:]]*)(.*)$/; + + my $regexp_abbrev = do { my ($beg, @chr) = split //, lc $cmd; # the following regex is used to match our "completion entry" @@ -868,17 +883,53 @@ qr<$regexp> }; - my @penalty; + my $regexp_partial = do { + my $regexp = "^\Q$text\E(.*)"; + qr<$regexp> + }; for (keys %{$self->{command}}) { - if (@penalty = $_ =~ $regexp) { - push @match, [$_, length join "", map "::$_", grep defined, @penalty]; + my @scores; + + # 1. Complete command [with args] + # command is a prefix of the text + # score is length of complete command matched + # e.g. "invoke summon pet monster bat" + # "invoke" "summon pet monster bat" = 6 + # "invoke summon pet monster" "bat" = 25 + if ($text =~ /^\Q$_\E(.*)/) { + push @scores, [$_, length $_, $text]; } + + # 2. Partial command + # text is a prefix of the full command + # score is the length of the input text + # e.g. "invoke s" + # "invoke small fireball" = 8 + # "invoke summon pet monster" = 8 + + if ($_ =~ $regexp_partial) { + push @scores, [$_, length $text, $_]; + } + + # 3. Abbreviation match + # attempts to use first word of text as an abbreviated command + # score is length of word + 1 - 3 per non-word-initial character + + if (my @penalty = $_ =~ $regexp_abbrev) { + push @scores, [$_, (length $cmd) + 1 - (length join "", map "::$_", grep defined, @penalty), "$_$arg"]; + } + + # Pick the best option for this command + push @match, (sort { + $b->[1] <=> $a->[1] + } @scores)[0]; } - @match = map $self->{command}{$_->[0]}, + # @match is now [command object, command with arguments] + @match = map [$self->{command}{$_->[0]}, $_->[2]], sort { - $a->[1] <=> $b->[1] + $b->[1] <=> $a->[1] or $self->{command}{$a->[0]}[4] <=> $self->{command}{$b->[0]}[4] or (length $b->[0]) <=> (length $a->[0]) } @match; @@ -907,20 +958,20 @@ } if (@matches) { - $self->{select} = "$matches[0][0]$arg"; + $self->{select} = "$matches[0][1]"; $labels[0]->{fg} = [0, 0, 0, 1]; $labels[0]->{bg} = [1, 1, 1, 0.8]; } else { - $self->{select} = "$cmd$arg"; + $self->{select} = "$text"; } for my $match (@matches) { my $label = shift @labels; if (@labels) { - $label->set_text ("$match->[0]$arg"); - $label->set_tooltip ($match->[1]); + $label->set_text ("$match->[1]"); + $label->set_tooltip ("$match->[0][1]"); } else { $label->set_text ("..."); $label->set_tooltip ("Use Cursor-Down to view more matches");