… | |
… | |
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 | |
70 | return unless $::CONN; |
|
|
71 | |
|
|
72 | $self->grab_focus; |
|
|
73 | |
|
|
74 | if ($ev->{button} == 1) { |
74 | if ($ev->{button} == 1) { |
|
|
75 | $self->grab_focus; |
|
|
76 | return unless $::CONN; |
|
|
77 | |
75 | my $x = CFClient::floor +($ev->{x} - $self->{sx0}) / $self->{tilesize} - $self->{sx}; |
78 | my $x = 1 + CFClient::floor +($ev->{x} - $self->{sx0}) / $self->{tilesize} - $self->{sx}; |
76 | my $y = CFClient::floor +($ev->{y} - $self->{sy0}) / $self->{tilesize} - $self->{sy}; |
79 | my $y = 1 + CFClient::floor +($ev->{y} - $self->{sy0}) / $self->{tilesize} - $self->{sy}; |
77 | |
80 | |
78 | $x -= int 0.5 * $self->{sw}; |
81 | $x -= int 0.5 * $self->{sw}; |
79 | $y -= int 0.5 * $self->{sh}; |
82 | $y -= int 0.5 * $self->{sh}; |
80 | |
83 | |
81 | $::CONN->lookat ($x, $y) |
84 | $::CONN->lookat ($x, $y) |
82 | if $::CONN; |
85 | if $::CONN; |
83 | |
86 | |
84 | } elsif ($ev->{button} == 2) { |
87 | } elsif ($ev->{button} == 2) { |
|
|
88 | $self->grab_focus; |
|
|
89 | return unless $::CONN; |
|
|
90 | |
85 | my ($ox, $oy) = ($ev->{x}, $ev->{y}); |
91 | my ($ox, $oy) = ($ev->{x}, $ev->{y}); |
86 | my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y}); |
92 | my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y}); |
87 | |
93 | |
88 | $self->{motion} = sub { |
94 | $self->{motion} = sub { |
89 | my ($ev, $x, $y) = @_; |
95 | my ($ev, $x, $y) = @_; |
… | |
… | |
93 | $::CFG->{map_shift_x} = $bw + $x - $ox; |
99 | $::CFG->{map_shift_x} = $bw + $x - $ox; |
94 | $::CFG->{map_shift_y} = $bh + $y - $oy; |
100 | $::CFG->{map_shift_y} = $bh + $y - $oy; |
95 | |
101 | |
96 | $self->update; |
102 | $self->update; |
97 | }; |
103 | }; |
|
|
104 | } elsif ($ev->{button} == 3) { |
|
|
105 | (new CFClient::UI::Menu |
|
|
106 | items => [ |
|
|
107 | ["Help Browser…\tF1", sub { $::HELP_WINDOW->toggle_visibility }], |
|
|
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) }], |
|
|
111 | ["Inventory…\tF5", sub { ::toggle_player_page ($::INVENTORY_PAGE) }], |
|
|
112 | ["Setup… \tF9", sub { $::SETUP_DIALOG->toggle_visibility }], |
|
|
113 | ["Server Messages…", sub { $::MESSAGE_WINDOW->toggle_visibility }], |
|
|
114 | [ |
|
|
115 | $::PICKUP_ENABLE->{state} |
|
|
116 | ? "Disable automatic pickup" |
|
|
117 | : "Enable automatic pickup", |
|
|
118 | sub { $::PICKUP_ENABLE->toggle } |
|
|
119 | ], |
|
|
120 | ], |
|
|
121 | )->popup ($ev); |
98 | } |
122 | } |
99 | |
123 | |
100 | 1 |
124 | 1 |
101 | } |
125 | } |
102 | |
126 | |
… | |
… | |
120 | 1 |
144 | 1 |
121 | } |
145 | } |
122 | |
146 | |
123 | sub size_request { |
147 | sub size_request { |
124 | ( |
148 | ( |
125 | 1 + 32 * int $::WIDTH / 32, |
149 | 32 * CFClient::ceil $::WIDTH / 32, |
126 | 1 + 32 * int $::HEIGHT / 32, |
150 | 32 * CFClient::ceil $::HEIGHT / 32, |
127 | ) |
151 | ) |
128 | } |
152 | } |
129 | |
153 | |
130 | sub update { |
154 | sub update { |
131 | my ($self) = @_; |
155 | my ($self) = @_; |
… | |
… | |
151 | ); |
175 | ); |
152 | |
176 | |
153 | sub invoke_key_down { |
177 | sub invoke_key_down { |
154 | my ($self, $ev) = @_; |
178 | my ($self, $ev) = @_; |
155 | |
179 | |
156 | return 0 unless $::CONN; |
|
|
157 | |
|
|
158 | my $mod = $ev->{mod}; |
180 | my $mod = $ev->{mod}; |
159 | my $sym = $ev->{sym}; |
181 | my $sym = $ev->{sym}; |
160 | my $uni = $ev->{unicode}; |
182 | my $uni = $ev->{unicode}; |
161 | |
183 | |
|
|
184 | $mod &= CFClient::KMOD_CTRL | CFClient::KMOD_ALT | CFClient::KMOD_SHIFT; |
|
|
185 | |
|
|
186 | if ($uni == ord "\t") { |
|
|
187 | $::PL_WINDOW->toggle_visibility; |
|
|
188 | } elsif ($sym == CFClient::SDLK_F1 && !$mod) { |
|
|
189 | $::HELP_WINDOW->toggle_visibility; |
|
|
190 | } elsif ($sym == CFClient::SDLK_F2 && !$mod) { |
|
|
191 | ::toggle_player_page ($::STATS_PAGE); |
|
|
192 | } elsif ($sym == CFClient::SDLK_F3 && !$mod) { |
|
|
193 | ::toggle_player_page ($::SKILL_PAGE); |
|
|
194 | } elsif ($sym == CFClient::SDLK_F4 && !$mod) { |
|
|
195 | ::toggle_player_page ($::SPELL_PAGE); |
|
|
196 | } elsif ($sym == CFClient::SDLK_F5 && !$mod) { |
|
|
197 | ::toggle_player_page ($::INVENTORY_PAGE); |
|
|
198 | } elsif ($sym == CFClient::SDLK_F9 && !$mod) { |
|
|
199 | $::SETUP_DIALOG->toggle_visibility; |
|
|
200 | } elsif ($sym == CFClient::SDLK_INSERT && $mod & CFClient::KMOD_CTRL) { |
|
|
201 | $::BIND_EDITOR->set_binding (undef, undef, [], |
|
|
202 | sub { |
|
|
203 | my ($mod, $sym, $cmds) = @_; |
|
|
204 | $::BIND_EDITOR->cfg_bind ($mod, $sym, $cmds); |
|
|
205 | }); |
|
|
206 | $::BIND_EDITOR->start; |
|
|
207 | $::BIND_EDITOR->show; |
|
|
208 | } elsif ($sym == CFClient::SDLK_INSERT && not ($mod & CFClient::KMOD_CTRL)) { |
|
|
209 | $::BIND_EDITOR->stop; |
|
|
210 | $::BIND_EDITOR->ask_for_bind_and_commit; |
|
|
211 | $::BIND_EDITOR->hide; |
|
|
212 | } elsif (!$::CONN) { |
|
|
213 | return 0; # bindings further down need a valid connection |
|
|
214 | |
162 | if ($sym == CFClient::SDLK_KP5) { |
215 | } elsif ($sym == CFClient::SDLK_KP5 && !$mod) { |
163 | $::CONN->user_send ("stay fire"); |
216 | $::CONN->user_send ("stay fire"); |
164 | } elsif ($uni == ord ",") { |
217 | } elsif ($uni == ord ",") { |
165 | $::CONN->user_send ("take"); |
218 | $::CONN->user_send ("take"); |
166 | } elsif ($uni == ord " ") { |
219 | } elsif ($uni == ord " ") { |
167 | $::CONN->user_send ("apply"); |
220 | $::CONN->user_send ("apply"); |
168 | } elsif ($uni == ord ".") { |
221 | } elsif ($uni == ord ".") { |
169 | $::CONN->user_send ($self->{completer}{last_command}) |
222 | $::CONN->user_send ($self->{completer}{last_command}) |
170 | if exists $self->{completer}{last_command}; |
223 | if exists $self->{completer}{last_command}; |
171 | } elsif ($uni == ord "\t") { |
224 | } elsif (my $bind_cmd = $::CFG->{profile}{default}{bindings}{$mod}{$sym}) { |
172 | $::INV_WINDOW->toggle_visibility; |
225 | $::CONN->user_send ($_) for @$bind_cmd; |
173 | } elsif ($sym == CFClient::SDLK_KP_PLUS || $uni == ord "+") { |
226 | } elsif (($sym == CFClient::SDLK_KP_PLUS && !$mod) || $uni == ord "+") { |
174 | $::CONN->user_send ("rotateshoottype +"); |
227 | $::CONN->user_send ("rotateshoottype +"); |
175 | } elsif ($sym == CFClient::SDLK_KP_MINUS || $uni == ord "-") { |
228 | } elsif (($sym == CFClient::SDLK_KP_MINUS && !$mod) || $uni == ord "-") { |
176 | $::CONN->user_send ("rotateshoottype -"); |
229 | $::CONN->user_send ("rotateshoottype -"); |
177 | } elsif ($uni == ord '"') { |
230 | } elsif ($uni == ord '"') { |
178 | $self->{completer}->set_prefix ("$::CFG->{say_command} "); |
231 | $self->{completer}->set_prefix ("$::CFG->{say_command} "); |
179 | $self->{completer}->show; |
232 | $self->{completer}->show; |
180 | } elsif ($uni == ord "'") { |
233 | } elsif ($uni == ord "'") { |
… | |
… | |
191 | $self->{ctrl}++; |
244 | $self->{ctrl}++; |
192 | $::CONN->user_send ("run $DIR{$sym}[0]"); |
245 | $::CONN->user_send ("run $DIR{$sym}[0]"); |
193 | } else { |
246 | } else { |
194 | $::CONN->user_send ("$DIR{$sym}[1]"); |
247 | $::CONN->user_send ("$DIR{$sym}[1]"); |
195 | } |
248 | } |
196 | } elsif ($sym == CFClient::SDLK_INSERT && $mod & CFClient::KMOD_CTRL) { |
|
|
197 | $::BIND_EDITOR->set_binding (undef, undef, [], |
|
|
198 | sub { |
|
|
199 | my ($mod, $sym, $cmds) = @_; |
|
|
200 | $::CFG->{profile}{default}{bindings}{$mod}{$sym} = $cmds; |
|
|
201 | }); |
|
|
202 | $::BIND_EDITOR->start; |
|
|
203 | $::BIND_EDITOR->show; |
|
|
204 | } elsif ($sym == CFClient::SDLK_INSERT && not ($mod & CFClient::KMOD_CTRL)) { |
|
|
205 | $::BIND_EDITOR->stop; |
|
|
206 | $::BIND_EDITOR->ask_for_bind_and_commit; |
|
|
207 | $::BIND_EDITOR->hide; |
|
|
208 | } elsif (my $bind_cmd = $::CFG->{profile}{default}{bindings}{$mod}{$sym}) { |
|
|
209 | $::CONN->user_send ($_) for @$bind_cmd; |
|
|
210 | } elsif ((ord 'a') <= $uni && $uni <= (ord 'z')) { |
249 | } elsif ((ord 'a') <= $uni && $uni <= (ord 'z')) { |
211 | $self->{completer}->key_down ($ev); |
250 | $self->{completer}->inject_key_down ($ev); |
212 | $self->{completer}->show; |
251 | $self->{completer}->show; |
213 | } else { |
252 | } else { |
214 | return 0; |
253 | return 0; |
215 | } |
254 | } |
216 | |
255 | |
… | |
… | |
488 | my ($entry, $ev, $x, $y) = @_; |
527 | my ($entry, $ev, $x, $y) = @_; |
489 | |
528 | |
490 | if ($ev->{button} == 3) { |
529 | if ($ev->{button} == 3) { |
491 | (new CFClient::UI::Menu |
530 | (new CFClient::UI::Menu |
492 | items => [ |
531 | items => [ |
|
|
532 | ["bind <i>" . (CFClient::asxml $self->{select}) . "</i> to a key" |
493 | ["bind to a key" => sub { $::BIND_EDITOR->do_quick_binding ([$self->{select}], sub { $entry->grab_focus }) }] |
533 | => sub { $::BIND_EDITOR->do_quick_binding ([$self->{select}], sub { $entry->grab_focus }) }] |
494 | ], |
534 | ], |
495 | )->popup ($ev); |
535 | )->popup ($ev); |
496 | return 1; |
536 | return 1; |
497 | } |
537 | } |
498 | 0 |
538 | 0 |
… | |
… | |
505 | if ($ev->{sym} == 13) { |
545 | if ($ev->{sym} == 13) { |
506 | if (exists $self->{select}) { |
546 | if (exists $self->{select}) { |
507 | $self->{last_command} = $self->{select}; |
547 | $self->{last_command} = $self->{select}; |
508 | $::CONN->user_send ($self->{select}); |
548 | $::CONN->user_send ($self->{select}); |
509 | |
549 | |
510 | unshift @{$self->{history}}, $self->{select}; |
550 | unshift @{$self->{history}}, $self->{entry}->get_text; |
511 | $self->{hist_ptr} = 0; |
551 | $self->{hist_ptr} = 0; |
512 | |
552 | |
513 | $self->hide; |
553 | $self->hide; |
514 | } |
554 | } |
515 | } elsif ($ev->{sym} == 27) { |
555 | } elsif ($ev->{sym} == 27) { |
516 | $self->{hist_ptr} = 0; |
556 | $self->{hist_ptr} = 0; |
517 | $self->hide; |
557 | $self->hide; |
518 | return; |
|
|
519 | } elsif ($ev->{sym} == CFClient::SDLK_DOWN) { |
558 | } elsif ($ev->{sym} == CFClient::SDLK_DOWN) { |
520 | if ($self->{hist_ptr} > 1) { |
559 | if ($self->{hist_ptr} > 1) { |
521 | $self->{hist_ptr}--; |
560 | $self->{hist_ptr}--; |
522 | $self->{entry}->set_text ($self->{history}->[$self->{hist_ptr} - 1]); |
561 | $self->{entry}->set_text ($self->{history}->[$self->{hist_ptr} - 1]); |
523 | } elsif ($self->{hist_ptr} > 0) { |
562 | } elsif ($self->{hist_ptr} > 0) { |
… | |
… | |
581 | } |
620 | } |
582 | |
621 | |
583 | sub hide { |
622 | sub hide { |
584 | my ($self) = @_; |
623 | my ($self) = @_; |
585 | |
624 | |
|
|
625 | $self->{hist_ptr} = 0; |
|
|
626 | |
586 | $self->SUPER::hide; |
627 | $self->SUPER::hide; |
587 | $self->{entry}->set_text (""); |
628 | $self->{entry}->set_text (""); |
588 | } |
629 | } |
589 | |
630 | |
590 | sub invoke_key_down { |
631 | sub inject_key_down { |
591 | my ($self, $ev) = @_; |
632 | my ($self, $ev) = @_; |
592 | |
633 | |
|
|
634 | $self->{entry}->grab_focus; |
593 | $self->{entry}->key_down ($ev) |
635 | $self->{entry}->emit (key_down => $ev); |
594 | } |
636 | } |
595 | |
637 | |
596 | sub update_labels { |
638 | sub update_labels { |
597 | my ($self) = @_; |
639 | my ($self) = @_; |
598 | |
640 | |
… | |
… | |
685 | $label->set_text (""); |
727 | $label->set_text (""); |
686 | $label->set_tooltip (""); |
728 | $label->set_tooltip (""); |
687 | } |
729 | } |
688 | |
730 | |
689 | $self->update; |
731 | $self->update; |
690 | ### |
|
|
691 | } |
732 | } |
692 | |
733 | |
693 | sub _draw { |
734 | sub _draw { |
694 | my ($self) = @_; |
735 | my ($self) = @_; |
695 | |
736 | |