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