--- deliantra/Deliantra-Client/DC/MapWidget.pm 2006/06/15 08:29:18 1.60 +++ deliantra/Deliantra-Client/DC/MapWidget.pm 2006/07/22 12:36:17 1.76 @@ -9,6 +9,10 @@ our @ISA = CFClient::UI::Base::; +my $magicmap_tex = + new_from_file CFClient::Texture CFClient::find_rcfile "magicmap.png", + mipmap => 1, wrap => 0, internalformat => GL_ALPHA; + sub new { my $class = shift; @@ -36,7 +40,7 @@ . "Typing the initial letters of words (or just any letters) displays guesses " . "for commands you might want to use.\n" . "You can use the cursor-up and cursor-down keys to select between those guesses.\n" - . "Right-Click opens a menu where you cna select further options, sich as redefining keybindings.", + . "Right-Click opens a menu where you cna select further options, sich as redefining key bindings.", ; $self @@ -58,18 +62,20 @@ my ($self) = @_; %{$self->{completer}{command}} = (); + + $self->{completer}->hide + if $self->{completer}; } -sub button_down { +sub invoke_button_down { my ($self, $ev, $x, $y) = @_; - return unless $::CONN; - - $self->focus_in; - if ($ev->{button} == 1) { - my $x = CFClient::floor +($ev->{x} - $self->{sx0}) / $self->{tilesize} - $self->{sx}; - my $y = CFClient::floor +($ev->{y} - $self->{sy0}) / $self->{tilesize} - $self->{sy}; + $self->grab_focus; + return unless $::CONN; + + my $x = 1 + CFClient::floor +($ev->{x} - $self->{sx0}) / $self->{tilesize} - $self->{sx}; + my $y = 1 + CFClient::floor +($ev->{y} - $self->{sy0}) / $self->{tilesize} - $self->{sy}; $x -= int 0.5 * $self->{sw}; $y -= int 0.5 * $self->{sh}; @@ -78,6 +84,9 @@ if $::CONN; } elsif ($ev->{button} == 2) { + $self->grab_focus; + return unless $::CONN; + my ($ox, $oy) = ($ev->{x}, $ev->{y}); my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y}); @@ -91,12 +100,30 @@ $self->update; }; + } elsif ($ev->{button} == 3) { + (new CFClient::UI::Menu + items => [ + ["Help Browser…\tF1", sub { $::HELP_WINDOW->toggle_visibility }], + ["Statistics\tF2", sub { ::toggle_player_page ($::STATS_PAGE) }], + ["Skills\tF3", sub { ::toggle_player_page ($::SKILL_PAGE) }], + ["Spells…\tF4", sub { ::toggle_player_page ($::SPELL_PAGE) }], + ["Inventory…\tF5", sub { ::toggle_player_page ($::INVENTORY_PAGE) }], + ["Setup… \tF9", sub { $::SETUP_DIALOG->toggle_visibility }], + ["Server Messages…", sub { $::MESSAGE_WINDOW->toggle_visibility }], + [ + $::PICKUP_ENABLE->{state} + ? "Disable automatic pickup" + : "Enable automatic pickup", + sub { $::PICKUP_ENABLE->toggle } + ], + ], + )->popup ($ev); } 1 } -sub button_up { +sub invoke_button_up { my ($self, $ev, $x, $y) = @_; delete $self->{motion}; @@ -104,7 +131,7 @@ 1 } -sub mouse_motion { +sub invoke_mouse_motion { my ($self, $ev, $x, $y) = @_; if ($self->{motion}) { @@ -118,8 +145,8 @@ sub size_request { ( - 1 + 32 * int $::WIDTH / 32, - 1 + 32 * int $::HEIGHT / 32, + 32 * CFClient::ceil $::WIDTH / 32, + 32 * CFClient::ceil $::HEIGHT / 32, ) } @@ -146,16 +173,45 @@ CFClient::SDLK_LEFT, [7, "west"], ); -sub key_down { +sub invoke_key_down { my ($self, $ev) = @_; - return 0 unless $::CONN; - my $mod = $ev->{mod}; my $sym = $ev->{sym}; my $uni = $ev->{unicode}; - if ($sym == CFClient::SDLK_KP5) { + $mod &= CFClient::KMOD_CTRL | CFClient::KMOD_ALT | CFClient::KMOD_SHIFT; + + if ($uni == ord "\t") { + $::PL_WINDOW->toggle_visibility; + } elsif ($sym == CFClient::SDLK_F1 && !$mod) { + $::HELP_WINDOW->toggle_visibility; + } elsif ($sym == CFClient::SDLK_F2 && !$mod) { + ::toggle_player_page ($::STATS_PAGE); + } elsif ($sym == CFClient::SDLK_F3 && !$mod) { + ::toggle_player_page ($::SKILL_PAGE); + } elsif ($sym == CFClient::SDLK_F4 && !$mod) { + ::toggle_player_page ($::SPELL_PAGE); + } elsif ($sym == CFClient::SDLK_F5 && !$mod) { + ::toggle_player_page ($::INVENTORY_PAGE); + } elsif ($sym == CFClient::SDLK_F9 && !$mod) { + $::SETUP_DIALOG->toggle_visibility; + } elsif ($sym == CFClient::SDLK_INSERT && $mod & CFClient::KMOD_CTRL) { + $::BIND_EDITOR->set_binding (undef, undef, [], + sub { + my ($mod, $sym, $cmds) = @_; + $::BIND_EDITOR->cfg_bind ($mod, $sym, $cmds); + }); + $::BIND_EDITOR->start; + $::BIND_EDITOR->show; + } elsif ($sym == CFClient::SDLK_INSERT && not ($mod & CFClient::KMOD_CTRL)) { + $::BIND_EDITOR->stop; + $::BIND_EDITOR->ask_for_bind_and_commit; + $::BIND_EDITOR->hide; + } elsif (!$::CONN) { + return 0; # bindings further down need a valid connection + + } elsif ($sym == CFClient::SDLK_KP5 && !$mod) { $::CONN->user_send ("stay fire"); } elsif ($uni == ord ",") { $::CONN->user_send ("take"); @@ -164,11 +220,11 @@ } elsif ($uni == ord ".") { $::CONN->user_send ($self->{completer}{last_command}) if exists $self->{completer}{last_command}; - } elsif ($uni == ord "\t") { - $::INV_WINDOW->toggle_visibility; - } elsif ($sym == CFClient::SDLK_KP_PLUS || $uni == ord "+") { + } elsif (my $bind_cmd = $::CFG->{profile}{default}{bindings}{$mod}{$sym}) { + $::CONN->user_send ($_) for @$bind_cmd; + } elsif (($sym == CFClient::SDLK_KP_PLUS && !$mod) || $uni == ord "+") { $::CONN->user_send ("rotateshoottype +"); - } elsif ($sym == CFClient::SDLK_KP_MINUS || $uni == ord "-") { + } elsif (($sym == CFClient::SDLK_KP_MINUS && !$mod) || $uni == ord "-") { $::CONN->user_send ("rotateshoottype -"); } elsif ($uni == ord '"') { $self->{completer}->set_prefix ("$::CFG->{say_command} "); @@ -189,22 +245,8 @@ } else { $::CONN->user_send ("$DIR{$sym}[1]"); } - } elsif ($sym == CFClient::SDLK_INSERT && $mod & CFClient::KMOD_CTRL) { - $::BIND_EDITOR->set_binding (undef, undef, [], - sub { - my ($mod, $sym, $cmds) = @_; - $::CFG->{bindings}->{$mod}->{$sym} = $cmds; - }); - $::BIND_EDITOR->start; - $::BIND_EDITOR->show; - } elsif ($sym == CFClient::SDLK_INSERT && not ($mod & CFClient::KMOD_CTRL)) { - $::BIND_EDITOR->stop; - $::BIND_EDITOR->ask_for_bind_and_commit; - $::BIND_EDITOR->hide; - } elsif (my $bind_cmd = $::CFG->{bindings}->{$mod}->{$sym}) { - $::CONN->user_send ($_) for @$bind_cmd; } elsif ((ord 'a') <= $uni && $uni <= (ord 'z')) { - $self->{completer}->key_down ($ev); + $self->{completer}->invoke_key_down ($ev); $self->{completer}->show; } else { return 0; @@ -213,7 +255,7 @@ 1 } -sub key_up { +sub invoke_key_up { my ($self, $ev) = @_; my $res = 0; @@ -246,6 +288,17 @@ $res } +sub set_magicmap { + my ($self, $w, $h, $x, $y, $data) = @_; + + $x -= $::MAP->ox + int 0.5 * $::MAP->w; + $y -= $::MAP->oy + int 0.5 * $::MAP->h; + + $self->{magicmap} = [$x, $y, $w, $h, $data]; + + $self->update; +} + sub draw { my ($self) = @_; @@ -266,8 +319,8 @@ my $sx0 = $self->{sx0} = $::CFG->{map_shift_x} - $sx * $tilesize; my $sy0 = $self->{sy0} = $::CFG->{map_shift_y} - $sy * $tilesize; - my $sw = $self->{sw} = 1 + CFClient::ceil $::WIDTH / $tilesize; - my $sh = $self->{sh} = 1 + CFClient::ceil $::HEIGHT / $tilesize; + my $sw = $self->{sw} = 1 + CFClient::ceil $self->{w} / $tilesize; + my $sh = $self->{sh} = 1 + CFClient::ceil $self->{h} / $tilesize; if ($::CFG->{fow_enable}) { my ($w, $h, $data) = $::MAP->fow_texture ($sx, $sy, 0, 0, $sw, $sh); @@ -304,25 +357,34 @@ $::MAP->draw ($sx, $sy, 0, 0, $sw, $sh); + glScale 32, 32; + if (my $tex = $self->{fow_texture}) { glEnable GL_TEXTURE_2D; glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; - glScale 32, 32; glColor +($::CFG->{fow_intensity}) x 3, 0.9; $self->{fow_texture}->draw_quad_alpha (0, 0); glDisable GL_TEXTURE_2D; } - glPopMatrix; + if ($self->{magicmap}) { + my ($x, $y, $w, $h, $data) = @{ $self->{magicmap} }; + + $x += $::MAP->ox - $sx + int 0.5 * ($::MAP->w - $sw + 1); + $y += $::MAP->oy - $sy + int 0.5 * ($::MAP->h - $sh + 1); + + glTranslate - $x - 1, - $y - 1; + glBindTexture GL_TEXTURE_2D, $magicmap_tex->{name}; + $::MAP->draw_magicmap ($x, $y, $w, $h, $data); + } + glPopMatrix; glEndList; } - glPushMatrix; glCallList $self->{list}; - glPopMatrix; # TNT2 emulates logops in software (or worse :) unless ($focused) { @@ -358,11 +420,12 @@ ($::HEIGHT * 0.25, $::HEIGHT * 0.25) } -sub size_allocate { +sub invoke_size_allocate { my ($self, $w, $h) = @_; - $self->SUPER::size_allocate ($w, $h); $self->update; + + 1 } sub update { @@ -457,6 +520,7 @@ $self->{entry} = new CFClient::UI::Entry on_changed => sub { $self->update_labels; + 0 }, on_button_down => sub { my ($entry, $ev, $x, $y) = @_; @@ -464,7 +528,8 @@ if ($ev->{button} == 3) { (new CFClient::UI::Menu items => [ - ["bind to a key" => sub { $::BIND_EDITOR->do_quick_binding ([$self->{select}], sub { $entry->focus_in }) }] + ["bind " . (CFClient::UI::Label::escape $self->{select}) . " to a key" + => sub { $::BIND_EDITOR->do_quick_binding ([$self->{select}], sub { $entry->grab_focus }) }] ], )->popup ($ev); return 1; @@ -481,7 +546,7 @@ $self->{last_command} = $self->{select}; $::CONN->user_send ($self->{select}); - unshift @{$self->{history}}, $self->{select}; + unshift @{$self->{history}}, $self->{entry}->get_text; $self->{hist_ptr} = 0; $self->hide; @@ -489,7 +554,6 @@ } elsif ($ev->{sym} == 27) { $self->{hist_ptr} = 0; $self->hide; - return; } elsif ($ev->{sym} == CFClient::SDLK_DOWN) { if ($self->{hist_ptr} > 1) { $self->{hist_ptr}--; @@ -539,31 +603,34 @@ $self->show; } -sub size_allocate { +sub invoke_size_allocate { my ($self, $w, $h) = @_; - $self->SUPER::size_allocate ($w, $h); $self->move_abs (($::WIDTH - $w) * 0.5, ($::HEIGHT - $h) * 0.6, 10); + + $self->SUPER::invoke_size_allocate ($w, $h) } sub show { my ($self) = @_; $self->SUPER::show; - $self->{entry}->focus_in; + $self->{entry}->grab_focus; } sub hide { my ($self) = @_; + $self->{hist_ptr} = 0; + $self->SUPER::hide; $self->{entry}->set_text (""); } -sub key_down { +sub invoke_key_down { my ($self, $ev) = @_; - $self->{entry}->key_down ($ev) + $self->{entry}->emit (key_down => $ev) } sub update_labels { @@ -660,7 +727,6 @@ } $self->update; - ### } sub _draw {