--- deliantra/Deliantra-Client/DC/MapWidget.pm 2006/07/02 19:32:55 1.70 +++ deliantra/Deliantra-Client/DC/MapWidget.pm 2006/07/23 16:11:12 1.78 @@ -5,7 +5,9 @@ use List::Util qw(min max); +use CFClient; use CFClient::OpenGL; +use CFClient::UI; our @ISA = CFClient::UI::Base::; @@ -32,7 +34,6 @@ $self->{completer} = new CFClient::MapWidget::Command:: command => $self->{command}, - can_focus => 1, tooltip => "The Command Completer\n\n" . "This is your central interface to send text commands to the server. " . "To enter a verbatim command to send to the server, just type the command, " @@ -62,16 +63,18 @@ my ($self) = @_; %{$self->{completer}{command}} = (); + + $self->{completer}->hide + if $self->{completer}; } sub invoke_button_down { my ($self, $ev, $x, $y) = @_; - return unless $::CONN; - - $self->grab_focus; - if ($ev->{button} == 1) { + $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}; @@ -82,6 +85,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}); @@ -95,6 +101,24 @@ $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 @@ -153,13 +177,42 @@ 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"); @@ -168,12 +221,11 @@ } elsif ($uni == ord ".") { $::CONN->user_send ($self->{completer}{last_command}) if exists $self->{completer}{last_command}; - } elsif ($uni == ord "\t") { - $::PL_WINDOW->toggle_visibility; - $::PL_NOTEBOOK->set_current_page ("Inventory"); - } 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} "); @@ -194,22 +246,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) = @_; - $::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 (my $bind_cmd = $::CFG->{profile}{default}{bindings}{$mod}{$sym}) { - $::CONN->user_send ($_) for @$bind_cmd; } elsif ((ord 'a') <= $uni && $uni <= (ord 'z')) { - $self->{completer}->invoke_key_down ($ev); + $self->{completer}->inject_key_down ($ev); $self->{completer}->show; } else { return 0; @@ -491,7 +529,7 @@ if ($ev->{button} == 3) { (new CFClient::UI::Menu items => [ - ["bind " . (CFClient::UI::Label::escape $self->{select}) . " to a key" + ["bind " . (CFClient::asxml $self->{select}) . " to a key" => sub { $::BIND_EDITOR->do_quick_binding ([$self->{select}], sub { $entry->grab_focus }) }] ], )->popup ($ev); @@ -584,14 +622,17 @@ sub hide { my ($self) = @_; + $self->{hist_ptr} = 0; + $self->SUPER::hide; $self->{entry}->set_text (""); } -sub invoke_key_down { +sub inject_key_down { my ($self, $ev) = @_; - $self->{entry}->emit (key_down => $ev) + $self->{entry}->grab_focus; + $self->{entry}->emit (key_down => $ev); } sub update_labels {