… | |
… | |
30 | @_ |
30 | @_ |
31 | ); |
31 | ); |
32 | |
32 | |
33 | $self->{completer} = new CFClient::MapWidget::Command:: |
33 | $self->{completer} = new CFClient::MapWidget::Command:: |
34 | command => $self->{command}, |
34 | command => $self->{command}, |
35 | can_focus => 1, |
|
|
36 | tooltip => "<b>The Command Completer</b>\n\n" |
35 | tooltip => "<b>The Command Completer</b>\n\n" |
37 | . "This is your central interface to send text commands to the server. " |
36 | . "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, " |
37 | . "To enter a verbatim command to send to the server, just type the command, " |
39 | . "followed by a space, and press return. " |
38 | . "followed by a space, and press return. " |
40 | . "Typing the initial letters of words (or just any letters) displays guesses " |
39 | . "Typing the initial letters of words (or just any letters) displays guesses " |
41 | . "for commands you might want to use.\n" |
40 | . "for commands you might want to use.\n" |
42 | . "You can use the cursor-up and cursor-down keys to select between those guesses.\n" |
41 | . "You can use the cursor-up and cursor-down keys to select between those guesses.\n" |
43 | . "<b>Right-Click</b> opens a menu where you cna select further options, sich as redefining keybindings.", |
42 | . "<b>Right-Click</b> opens a menu where you cna select further options, sich as redefining key bindings.", |
44 | ; |
43 | ; |
45 | |
44 | |
46 | $self |
45 | $self |
47 | } |
46 | } |
48 | |
47 | |
… | |
… | |
60 | |
59 | |
61 | sub clr_commands { |
60 | sub clr_commands { |
62 | my ($self) = @_; |
61 | my ($self) = @_; |
63 | |
62 | |
64 | %{$self->{completer}{command}} = (); |
63 | %{$self->{completer}{command}} = (); |
65 | } |
|
|
66 | |
64 | |
|
|
65 | $self->{completer}->hide |
|
|
66 | if $self->{completer}; |
|
|
67 | } |
|
|
68 | |
67 | sub button_down { |
69 | sub invoke_button_down { |
68 | my ($self, $ev, $x, $y) = @_; |
70 | my ($self, $ev, $x, $y) = @_; |
69 | |
71 | |
70 | return unless $::CONN; |
|
|
71 | |
|
|
72 | $self->focus_in; |
|
|
73 | |
|
|
74 | if ($ev->{button} == 1) { |
72 | if ($ev->{button} == 1) { |
|
|
73 | $self->grab_focus; |
|
|
74 | return unless $::CONN; |
|
|
75 | |
75 | my $x = CFClient::floor +($ev->{x} - $self->{sx0}) / $self->{tilesize} - $self->{sx}; |
76 | 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}; |
77 | my $y = 1 + CFClient::floor +($ev->{y} - $self->{sy0}) / $self->{tilesize} - $self->{sy}; |
77 | |
78 | |
78 | $x -= int 0.5 * $self->{sw}; |
79 | $x -= int 0.5 * $self->{sw}; |
79 | $y -= int 0.5 * $self->{sh}; |
80 | $y -= int 0.5 * $self->{sh}; |
80 | |
81 | |
81 | $::CONN->lookat ($x, $y) |
82 | $::CONN->lookat ($x, $y) |
82 | if $::CONN; |
83 | if $::CONN; |
83 | |
84 | |
84 | } elsif ($ev->{button} == 2) { |
85 | } elsif ($ev->{button} == 2) { |
|
|
86 | $self->grab_focus; |
|
|
87 | return unless $::CONN; |
|
|
88 | |
85 | my ($ox, $oy) = ($ev->{x}, $ev->{y}); |
89 | my ($ox, $oy) = ($ev->{x}, $ev->{y}); |
86 | my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y}); |
90 | my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y}); |
87 | |
91 | |
88 | $self->{motion} = sub { |
92 | $self->{motion} = sub { |
89 | my ($ev, $x, $y) = @_; |
93 | my ($ev, $x, $y) = @_; |
… | |
… | |
93 | $::CFG->{map_shift_x} = $bw + $x - $ox; |
97 | $::CFG->{map_shift_x} = $bw + $x - $ox; |
94 | $::CFG->{map_shift_y} = $bh + $y - $oy; |
98 | $::CFG->{map_shift_y} = $bh + $y - $oy; |
95 | |
99 | |
96 | $self->update; |
100 | $self->update; |
97 | }; |
101 | }; |
|
|
102 | } elsif ($ev->{button} == 3) { |
|
|
103 | (new CFClient::UI::Menu |
|
|
104 | items => [ |
|
|
105 | ["Help Browser…\tF1", sub { $::HELP_WINDOW->toggle_visibility }], |
|
|
106 | ["Statistics\tF2", sub { ::toggle_player_page ($::STATS_PAGE) }], |
|
|
107 | ["Skills\tF3", sub { ::toggle_player_page ($::SKILL_PAGE) }], |
|
|
108 | ["Spells…\tF4", sub { ::toggle_player_page ($::SPELL_PAGE) }], |
|
|
109 | ["Inventory…\tF5", sub { ::toggle_player_page ($::INVENTORY_PAGE) }], |
|
|
110 | ["Setup… \tF9", sub { $::SETUP_DIALOG->toggle_visibility }], |
|
|
111 | ["Server Messages…", sub { $::MESSAGE_WINDOW->toggle_visibility }], |
|
|
112 | [ |
|
|
113 | $::PICKUP_ENABLE->{state} |
|
|
114 | ? "Disable automatic pickup" |
|
|
115 | : "Enable automatic pickup", |
|
|
116 | sub { $::PICKUP_ENABLE->toggle } |
|
|
117 | ], |
|
|
118 | ], |
|
|
119 | )->popup ($ev); |
98 | } |
120 | } |
99 | |
121 | |
100 | 1 |
122 | 1 |
101 | } |
123 | } |
102 | |
124 | |
103 | sub button_up { |
125 | sub invoke_button_up { |
104 | my ($self, $ev, $x, $y) = @_; |
126 | my ($self, $ev, $x, $y) = @_; |
105 | |
127 | |
106 | delete $self->{motion}; |
128 | delete $self->{motion}; |
107 | |
129 | |
108 | 1 |
130 | 1 |
109 | } |
131 | } |
110 | |
132 | |
111 | sub mouse_motion { |
133 | sub invoke_mouse_motion { |
112 | my ($self, $ev, $x, $y) = @_; |
134 | my ($self, $ev, $x, $y) = @_; |
113 | |
135 | |
114 | if ($self->{motion}) { |
136 | if ($self->{motion}) { |
115 | $self->{motion}->($ev, $x, $y); |
137 | $self->{motion}->($ev, $x, $y); |
116 | } else { |
138 | } else { |
… | |
… | |
120 | 1 |
142 | 1 |
121 | } |
143 | } |
122 | |
144 | |
123 | sub size_request { |
145 | sub size_request { |
124 | ( |
146 | ( |
125 | 1 + 32 * int $::WIDTH / 32, |
147 | 32 * CFClient::ceil $::WIDTH / 32, |
126 | 1 + 32 * int $::HEIGHT / 32, |
148 | 32 * CFClient::ceil $::HEIGHT / 32, |
127 | ) |
149 | ) |
128 | } |
150 | } |
129 | |
151 | |
130 | sub update { |
152 | sub update { |
131 | my ($self) = @_; |
153 | my ($self) = @_; |
… | |
… | |
148 | CFClient::SDLK_RIGHT, [3, "east"], |
170 | CFClient::SDLK_RIGHT, [3, "east"], |
149 | CFClient::SDLK_DOWN, [5, "south"], |
171 | CFClient::SDLK_DOWN, [5, "south"], |
150 | CFClient::SDLK_LEFT, [7, "west"], |
172 | CFClient::SDLK_LEFT, [7, "west"], |
151 | ); |
173 | ); |
152 | |
174 | |
153 | sub key_down { |
175 | sub invoke_key_down { |
154 | my ($self, $ev) = @_; |
176 | my ($self, $ev) = @_; |
155 | |
|
|
156 | return 0 unless $::CONN; |
|
|
157 | |
177 | |
158 | my $mod = $ev->{mod}; |
178 | my $mod = $ev->{mod}; |
159 | my $sym = $ev->{sym}; |
179 | my $sym = $ev->{sym}; |
160 | my $uni = $ev->{unicode}; |
180 | my $uni = $ev->{unicode}; |
161 | |
181 | |
|
|
182 | $mod &= CFClient::KMOD_CTRL | CFClient::KMOD_ALT | CFClient::KMOD_SHIFT; |
|
|
183 | |
|
|
184 | if ($uni == ord "\t") { |
|
|
185 | $::PL_WINDOW->toggle_visibility; |
|
|
186 | } elsif ($sym == CFClient::SDLK_F1 && !$mod) { |
|
|
187 | $::HELP_WINDOW->toggle_visibility; |
|
|
188 | } elsif ($sym == CFClient::SDLK_F2 && !$mod) { |
|
|
189 | ::toggle_player_page ($::STATS_PAGE); |
|
|
190 | } elsif ($sym == CFClient::SDLK_F3 && !$mod) { |
|
|
191 | ::toggle_player_page ($::SKILL_PAGE); |
|
|
192 | } elsif ($sym == CFClient::SDLK_F4 && !$mod) { |
|
|
193 | ::toggle_player_page ($::SPELL_PAGE); |
|
|
194 | } elsif ($sym == CFClient::SDLK_F5 && !$mod) { |
|
|
195 | ::toggle_player_page ($::INVENTORY_PAGE); |
|
|
196 | } elsif ($sym == CFClient::SDLK_F9 && !$mod) { |
|
|
197 | $::SETUP_DIALOG->toggle_visibility; |
|
|
198 | } elsif ($sym == CFClient::SDLK_INSERT && $mod & CFClient::KMOD_CTRL) { |
|
|
199 | $::BIND_EDITOR->set_binding (undef, undef, [], |
|
|
200 | sub { |
|
|
201 | my ($mod, $sym, $cmds) = @_; |
|
|
202 | $::BIND_EDITOR->cfg_bind ($mod, $sym, $cmds); |
|
|
203 | }); |
|
|
204 | $::BIND_EDITOR->start; |
|
|
205 | $::BIND_EDITOR->show; |
|
|
206 | } elsif ($sym == CFClient::SDLK_INSERT && not ($mod & CFClient::KMOD_CTRL)) { |
|
|
207 | $::BIND_EDITOR->stop; |
|
|
208 | $::BIND_EDITOR->ask_for_bind_and_commit; |
|
|
209 | $::BIND_EDITOR->hide; |
|
|
210 | } elsif (!$::CONN) { |
|
|
211 | return 0; # bindings further down need a valid connection |
|
|
212 | |
162 | if ($sym == CFClient::SDLK_KP5) { |
213 | } elsif ($sym == CFClient::SDLK_KP5 && !$mod) { |
163 | $::CONN->user_send ("stay fire"); |
214 | $::CONN->user_send ("stay fire"); |
164 | } elsif ($uni == ord ",") { |
215 | } elsif ($uni == ord ",") { |
165 | $::CONN->user_send ("take"); |
216 | $::CONN->user_send ("take"); |
166 | } elsif ($uni == ord " ") { |
217 | } elsif ($uni == ord " ") { |
167 | $::CONN->user_send ("apply"); |
218 | $::CONN->user_send ("apply"); |
168 | } elsif ($uni == ord ".") { |
219 | } elsif ($uni == ord ".") { |
169 | $::CONN->user_send ($self->{completer}{last_command}) |
220 | $::CONN->user_send ($self->{completer}{last_command}) |
170 | if exists $self->{completer}{last_command}; |
221 | if exists $self->{completer}{last_command}; |
171 | } elsif ($uni == ord "\t") { |
222 | } elsif (my $bind_cmd = $::CFG->{profile}{default}{bindings}{$mod}{$sym}) { |
172 | $::INV_WINDOW->toggle_visibility; |
223 | $::CONN->user_send ($_) for @$bind_cmd; |
173 | } elsif ($sym == CFClient::SDLK_KP_PLUS || $uni == ord "+") { |
224 | } elsif (($sym == CFClient::SDLK_KP_PLUS && !$mod) || $uni == ord "+") { |
174 | $::CONN->user_send ("rotateshoottype +"); |
225 | $::CONN->user_send ("rotateshoottype +"); |
175 | } elsif ($sym == CFClient::SDLK_KP_MINUS || $uni == ord "-") { |
226 | } elsif (($sym == CFClient::SDLK_KP_MINUS && !$mod) || $uni == ord "-") { |
176 | $::CONN->user_send ("rotateshoottype -"); |
227 | $::CONN->user_send ("rotateshoottype -"); |
177 | } elsif ($uni == ord '"') { |
228 | } elsif ($uni == ord '"') { |
178 | $self->{completer}->set_prefix ("$::CFG->{say_command} "); |
229 | $self->{completer}->set_prefix ("$::CFG->{say_command} "); |
179 | $self->{completer}->show; |
230 | $self->{completer}->show; |
180 | } elsif ($uni == ord "'") { |
231 | } elsif ($uni == ord "'") { |
… | |
… | |
191 | $self->{ctrl}++; |
242 | $self->{ctrl}++; |
192 | $::CONN->user_send ("run $DIR{$sym}[0]"); |
243 | $::CONN->user_send ("run $DIR{$sym}[0]"); |
193 | } else { |
244 | } else { |
194 | $::CONN->user_send ("$DIR{$sym}[1]"); |
245 | $::CONN->user_send ("$DIR{$sym}[1]"); |
195 | } |
246 | } |
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->{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->{bindings}->{$mod}->{$sym}) { |
|
|
209 | $::CONN->user_send ($_) for @$bind_cmd; |
|
|
210 | } elsif ((ord 'a') <= $uni && $uni <= (ord 'z')) { |
247 | } elsif ((ord 'a') <= $uni && $uni <= (ord 'z')) { |
211 | $self->{completer}->key_down ($ev); |
248 | $self->{completer}->inject_key_down ($ev); |
212 | $self->{completer}->show; |
249 | $self->{completer}->show; |
213 | } else { |
250 | } else { |
214 | return 0; |
251 | return 0; |
215 | } |
252 | } |
216 | |
253 | |
217 | 1 |
254 | 1 |
218 | } |
255 | } |
219 | |
256 | |
220 | sub key_up { |
257 | sub invoke_key_up { |
221 | my ($self, $ev) = @_; |
258 | my ($self, $ev) = @_; |
222 | |
259 | |
223 | my $res = 0; |
260 | my $res = 0; |
224 | my $mod = $ev->{mod}; |
261 | my $mod = $ev->{mod}; |
225 | my $sym = $ev->{sym}; |
262 | my $sym = $ev->{sym}; |
… | |
… | |
380 | |
417 | |
381 | sub size_request { |
418 | sub size_request { |
382 | ($::HEIGHT * 0.25, $::HEIGHT * 0.25) |
419 | ($::HEIGHT * 0.25, $::HEIGHT * 0.25) |
383 | } |
420 | } |
384 | |
421 | |
385 | sub size_allocate { |
422 | sub invoke_size_allocate { |
386 | my ($self, $w, $h) = @_; |
423 | my ($self, $w, $h) = @_; |
387 | |
424 | |
388 | $self->SUPER::size_allocate ($w, $h); |
|
|
389 | $self->update; |
425 | $self->update; |
|
|
426 | |
|
|
427 | 1 |
390 | } |
428 | } |
391 | |
429 | |
392 | sub update { |
430 | sub update { |
393 | my ($self) = @_; |
431 | my ($self) = @_; |
394 | |
432 | |
… | |
… | |
479 | ]; |
517 | ]; |
480 | |
518 | |
481 | $self->{entry} = new CFClient::UI::Entry |
519 | $self->{entry} = new CFClient::UI::Entry |
482 | on_changed => sub { |
520 | on_changed => sub { |
483 | $self->update_labels; |
521 | $self->update_labels; |
|
|
522 | 0 |
484 | }, |
523 | }, |
485 | on_button_down => sub { |
524 | on_button_down => sub { |
486 | my ($entry, $ev, $x, $y) = @_; |
525 | my ($entry, $ev, $x, $y) = @_; |
487 | |
526 | |
488 | if ($ev->{button} == 3) { |
527 | if ($ev->{button} == 3) { |
489 | (new CFClient::UI::Menu |
528 | (new CFClient::UI::Menu |
490 | items => [ |
529 | items => [ |
|
|
530 | ["bind <i>" . (CFClient::UI::Label::escape $self->{select}) . "</i> to a key" |
491 | ["bind to a key" => sub { $::BIND_EDITOR->do_quick_binding ([$self->{select}], sub { $entry->focus_in }) }] |
531 | => sub { $::BIND_EDITOR->do_quick_binding ([$self->{select}], sub { $entry->grab_focus }) }] |
492 | ], |
532 | ], |
493 | )->popup ($ev); |
533 | )->popup ($ev); |
494 | return 1; |
534 | return 1; |
495 | } |
535 | } |
496 | 0 |
536 | 0 |
… | |
… | |
503 | if ($ev->{sym} == 13) { |
543 | if ($ev->{sym} == 13) { |
504 | if (exists $self->{select}) { |
544 | if (exists $self->{select}) { |
505 | $self->{last_command} = $self->{select}; |
545 | $self->{last_command} = $self->{select}; |
506 | $::CONN->user_send ($self->{select}); |
546 | $::CONN->user_send ($self->{select}); |
507 | |
547 | |
508 | unshift @{$self->{history}}, $self->{select}; |
548 | unshift @{$self->{history}}, $self->{entry}->get_text; |
509 | $self->{hist_ptr} = 0; |
549 | $self->{hist_ptr} = 0; |
510 | |
550 | |
511 | $self->hide; |
551 | $self->hide; |
512 | } |
552 | } |
513 | } elsif ($ev->{sym} == 27) { |
553 | } elsif ($ev->{sym} == 27) { |
514 | $self->{hist_ptr} = 0; |
554 | $self->{hist_ptr} = 0; |
515 | $self->hide; |
555 | $self->hide; |
516 | return; |
|
|
517 | } elsif ($ev->{sym} == CFClient::SDLK_DOWN) { |
556 | } elsif ($ev->{sym} == CFClient::SDLK_DOWN) { |
518 | if ($self->{hist_ptr} > 1) { |
557 | if ($self->{hist_ptr} > 1) { |
519 | $self->{hist_ptr}--; |
558 | $self->{hist_ptr}--; |
520 | $self->{entry}->set_text ($self->{history}->[$self->{hist_ptr} - 1]); |
559 | $self->{entry}->set_text ($self->{history}->[$self->{hist_ptr} - 1]); |
521 | } elsif ($self->{hist_ptr} > 0) { |
560 | } elsif ($self->{hist_ptr} > 0) { |
… | |
… | |
561 | |
600 | |
562 | $self->{entry}->set_text ($prefix); |
601 | $self->{entry}->set_text ($prefix); |
563 | $self->show; |
602 | $self->show; |
564 | } |
603 | } |
565 | |
604 | |
566 | sub size_allocate { |
605 | sub invoke_size_allocate { |
567 | my ($self, $w, $h) = @_; |
606 | my ($self, $w, $h) = @_; |
568 | |
607 | |
569 | $self->SUPER::size_allocate ($w, $h); |
|
|
570 | $self->move_abs (($::WIDTH - $w) * 0.5, ($::HEIGHT - $h) * 0.6, 10); |
608 | $self->move_abs (($::WIDTH - $w) * 0.5, ($::HEIGHT - $h) * 0.6, 10); |
|
|
609 | |
|
|
610 | $self->SUPER::invoke_size_allocate ($w, $h) |
571 | } |
611 | } |
572 | |
612 | |
573 | sub show { |
613 | sub show { |
574 | my ($self) = @_; |
614 | my ($self) = @_; |
575 | |
615 | |
576 | $self->SUPER::show; |
616 | $self->SUPER::show; |
577 | $self->{entry}->focus_in; |
617 | $self->{entry}->grab_focus; |
578 | } |
618 | } |
579 | |
619 | |
580 | sub hide { |
620 | sub hide { |
581 | my ($self) = @_; |
621 | my ($self) = @_; |
|
|
622 | |
|
|
623 | $self->{hist_ptr} = 0; |
582 | |
624 | |
583 | $self->SUPER::hide; |
625 | $self->SUPER::hide; |
584 | $self->{entry}->set_text (""); |
626 | $self->{entry}->set_text (""); |
585 | } |
627 | } |
586 | |
628 | |
587 | sub key_down { |
629 | sub inject_key_down { |
588 | my ($self, $ev) = @_; |
630 | my ($self, $ev) = @_; |
589 | |
631 | |
|
|
632 | $self->{entry}->grab_focus; |
590 | $self->{entry}->key_down ($ev) |
633 | $self->{entry}->emit (key_down => $ev); |
591 | } |
634 | } |
592 | |
635 | |
593 | sub update_labels { |
636 | sub update_labels { |
594 | my ($self) = @_; |
637 | my ($self) = @_; |
595 | |
638 | |
… | |
… | |
682 | $label->set_text (""); |
725 | $label->set_text (""); |
683 | $label->set_tooltip (""); |
726 | $label->set_tooltip (""); |
684 | } |
727 | } |
685 | |
728 | |
686 | $self->update; |
729 | $self->update; |
687 | ### |
|
|
688 | } |
730 | } |
689 | |
731 | |
690 | sub _draw { |
732 | sub _draw { |
691 | my ($self) = @_; |
733 | my ($self) = @_; |
692 | |
734 | |