… | |
… | |
3 | use strict; |
3 | use strict; |
4 | use utf8; |
4 | use utf8; |
5 | |
5 | |
6 | use List::Util qw(min max); |
6 | use List::Util qw(min max); |
7 | |
7 | |
|
|
8 | use CFClient; |
8 | use CFClient::OpenGL; |
9 | use CFClient::OpenGL; |
|
|
10 | use CFClient::UI; |
9 | |
11 | |
10 | our @ISA = CFClient::UI::Base::; |
12 | our @ISA = CFClient::UI::Base::; |
11 | |
13 | |
12 | my $magicmap_tex = |
14 | my $magicmap_tex = |
13 | new_from_file CFClient::Texture CFClient::find_rcfile "magicmap.png", |
15 | new_from_file CFClient::Texture CFClient::find_rcfile "magicmap.png", |
… | |
… | |
30 | @_ |
32 | @_ |
31 | ); |
33 | ); |
32 | |
34 | |
33 | $self->{completer} = new CFClient::MapWidget::Command:: |
35 | $self->{completer} = new CFClient::MapWidget::Command:: |
34 | command => $self->{command}, |
36 | command => $self->{command}, |
35 | can_focus => 1, |
|
|
36 | tooltip => "<b>The Command Completer</b>\n\n" |
37 | tooltip => "<b>The Command Completer</b>\n\n" |
37 | . "This is your central interface to send text commands to the server. " |
38 | . "This is your central interface to send text commands to the server. " |
38 | . "To enter a verbatim command to send to the server, just type the command, " |
39 | . "To enter a verbatim command to send to the server, just type the command, " |
39 | . "followed by a space, and press return. " |
40 | . "followed by a space, and press return. " |
40 | . "Typing the initial letters of words (or just any letters) displays guesses " |
41 | . "Typing the initial letters of words (or just any letters) displays guesses " |
… | |
… | |
60 | |
61 | |
61 | sub clr_commands { |
62 | sub clr_commands { |
62 | my ($self) = @_; |
63 | my ($self) = @_; |
63 | |
64 | |
64 | %{$self->{completer}{command}} = (); |
65 | %{$self->{completer}{command}} = (); |
|
|
66 | |
|
|
67 | $self->{completer}->hide |
|
|
68 | if $self->{completer}; |
65 | } |
69 | } |
66 | |
70 | |
67 | sub invoke_button_down { |
71 | sub invoke_button_down { |
68 | my ($self, $ev, $x, $y) = @_; |
72 | my ($self, $ev, $x, $y) = @_; |
69 | |
73 | |
… | |
… | |
98 | $self->update; |
102 | $self->update; |
99 | }; |
103 | }; |
100 | } elsif ($ev->{button} == 3) { |
104 | } elsif ($ev->{button} == 3) { |
101 | (new CFClient::UI::Menu |
105 | (new CFClient::UI::Menu |
102 | items => [ |
106 | items => [ |
103 | ["Help Browser…\t(F1)", sub { $::HELP_WINDOW->toggle_visibility }], |
107 | ["Help Browser…\tF1", sub { $::HELP_WINDOW->toggle_visibility }], |
104 | ["Stats & Skills…\t(F2)", sub { ::toggle_player_page ($::STATS_PAGE) }], |
108 | ["Statistics\tF2", sub { ::toggle_player_page ($::STATS_PAGE) }], |
|
|
109 | ["Skills\tF3", sub { ::toggle_player_page ($::SKILL_PAGE) }], |
|
|
110 | ["Spells…\tF4", sub { ::toggle_player_page ($::SPELL_PAGE) }], |
105 | ["Inventory…\t(F3)", sub { ::toggle_player_page ($::INVENTORY_PAGE) }], |
111 | ["Inventory…\tF5", sub { ::toggle_player_page ($::INVENTORY_PAGE) }], |
106 | ["Spells…\t(F4)", sub { ::toggle_player_page ($::SPELL_PAGE) }], |
|
|
107 | ["Setup… \t(F5)", sub { $::SETUP_DIALOG->toggle_visibility }], |
112 | ["Setup… \tF9", sub { $::SETUP_DIALOG->toggle_visibility }], |
108 | ["Server Messages…", sub { $::MESSAGE_WINDOW->toggle_visibility }], |
113 | ["Server Messages…", sub { $::MESSAGE_WINDOW->toggle_visibility }], |
109 | [ |
114 | [ |
110 | $::PICKUP_ENABLE->{state} |
115 | $::PICKUP_ENABLE->{state} |
111 | ? "Disable automatic pickup" |
116 | ? "Disable automatic pickup" |
112 | : "Enable automatic pickup", |
117 | : "Enable automatic pickup", |
113 | sub { $::PICKUP_ENABLE->toggle } |
118 | sub { $::PICKUP_ENABLE->toggle } |
|
|
119 | ], |
|
|
120 | ["Quit", |
|
|
121 | sub { |
|
|
122 | if ($::CONN) { |
|
|
123 | &::open_quit_dialog; |
|
|
124 | } else { |
|
|
125 | exit; |
|
|
126 | } |
|
|
127 | } |
114 | ], |
128 | ], |
115 | ], |
129 | ], |
116 | )->popup ($ev); |
130 | )->popup ($ev); |
117 | } |
131 | } |
118 | |
132 | |
… | |
… | |
183 | } elsif ($sym == CFClient::SDLK_F1 && !$mod) { |
197 | } elsif ($sym == CFClient::SDLK_F1 && !$mod) { |
184 | $::HELP_WINDOW->toggle_visibility; |
198 | $::HELP_WINDOW->toggle_visibility; |
185 | } elsif ($sym == CFClient::SDLK_F2 && !$mod) { |
199 | } elsif ($sym == CFClient::SDLK_F2 && !$mod) { |
186 | ::toggle_player_page ($::STATS_PAGE); |
200 | ::toggle_player_page ($::STATS_PAGE); |
187 | } elsif ($sym == CFClient::SDLK_F3 && !$mod) { |
201 | } elsif ($sym == CFClient::SDLK_F3 && !$mod) { |
188 | ::toggle_player_page ($::INVENTORY_PAGE); |
202 | ::toggle_player_page ($::SKILL_PAGE); |
189 | } elsif ($sym == CFClient::SDLK_F4 && !$mod) { |
203 | } elsif ($sym == CFClient::SDLK_F4 && !$mod) { |
190 | ::toggle_player_page ($::SPELL_PAGE); |
204 | ::toggle_player_page ($::SPELL_PAGE); |
191 | } elsif ($sym == CFClient::SDLK_F5 && !$mod) { |
205 | } elsif ($sym == CFClient::SDLK_F5 && !$mod) { |
|
|
206 | ::toggle_player_page ($::INVENTORY_PAGE); |
|
|
207 | } elsif ($sym == CFClient::SDLK_F9 && !$mod) { |
192 | $::SETUP_DIALOG->toggle_visibility; |
208 | $::SETUP_DIALOG->toggle_visibility; |
193 | } elsif ($sym == CFClient::SDLK_INSERT && $mod & CFClient::KMOD_CTRL) { |
209 | } elsif ($sym == CFClient::SDLK_INSERT && $mod & CFClient::KMOD_CTRL) { |
194 | $::BIND_EDITOR->set_binding (undef, undef, [], |
210 | $::BIND_EDITOR->set_binding (undef, undef, [], |
195 | sub { |
211 | sub { |
196 | my ($mod, $sym, $cmds) = @_; |
212 | my ($mod, $sym, $cmds) = @_; |
… | |
… | |
238 | $::CONN->user_send ("run $DIR{$sym}[0]"); |
254 | $::CONN->user_send ("run $DIR{$sym}[0]"); |
239 | } else { |
255 | } else { |
240 | $::CONN->user_send ("$DIR{$sym}[1]"); |
256 | $::CONN->user_send ("$DIR{$sym}[1]"); |
241 | } |
257 | } |
242 | } elsif ((ord 'a') <= $uni && $uni <= (ord 'z')) { |
258 | } elsif ((ord 'a') <= $uni && $uni <= (ord 'z')) { |
243 | $self->{completer}->invoke_key_down ($ev); |
259 | $self->{completer}->inject_key_down ($ev); |
244 | $self->{completer}->show; |
260 | $self->{completer}->show; |
245 | } else { |
261 | } else { |
246 | return 0; |
262 | return 0; |
247 | } |
263 | } |
248 | |
264 | |
… | |
… | |
520 | my ($entry, $ev, $x, $y) = @_; |
536 | my ($entry, $ev, $x, $y) = @_; |
521 | |
537 | |
522 | if ($ev->{button} == 3) { |
538 | if ($ev->{button} == 3) { |
523 | (new CFClient::UI::Menu |
539 | (new CFClient::UI::Menu |
524 | items => [ |
540 | items => [ |
525 | ["bind <i>" . (CFClient::UI::Label::escape $self->{select}) . "</i> to a key" |
541 | ["bind <i>" . (CFClient::asxml $self->{select}) . "</i> to a key" |
526 | => sub { $::BIND_EDITOR->do_quick_binding ([$self->{select}], sub { $entry->grab_focus }) }] |
542 | => sub { $::BIND_EDITOR->do_quick_binding ([$self->{select}], sub { $entry->grab_focus }) }] |
527 | ], |
543 | ], |
528 | )->popup ($ev); |
544 | )->popup ($ev); |
529 | return 1; |
545 | return 1; |
530 | } |
546 | } |
… | |
… | |
613 | } |
629 | } |
614 | |
630 | |
615 | sub hide { |
631 | sub hide { |
616 | my ($self) = @_; |
632 | my ($self) = @_; |
617 | |
633 | |
|
|
634 | $self->{hist_ptr} = 0; |
|
|
635 | |
618 | $self->SUPER::hide; |
636 | $self->SUPER::hide; |
619 | $self->{entry}->set_text (""); |
637 | $self->{entry}->set_text (""); |
620 | } |
638 | } |
621 | |
639 | |
622 | sub invoke_key_down { |
640 | sub inject_key_down { |
623 | my ($self, $ev) = @_; |
641 | my ($self, $ev) = @_; |
624 | |
642 | |
|
|
643 | $self->{entry}->grab_focus; |
625 | $self->{entry}->emit (key_down => $ev) |
644 | $self->{entry}->emit (key_down => $ev); |
626 | } |
645 | } |
627 | |
646 | |
628 | sub update_labels { |
647 | sub update_labels { |
629 | my ($self) = @_; |
648 | my ($self) = @_; |
630 | |
649 | |