… | |
… | |
20 | ); |
20 | ); |
21 | |
21 | |
22 | $self->{completer} = new CFClient::MapWidget::Command:: |
22 | $self->{completer} = new CFClient::MapWidget::Command:: |
23 | command => $self->{command}, |
23 | command => $self->{command}, |
24 | can_focus => 1, |
24 | can_focus => 1, |
|
|
25 | tooltip => "<b>The Command Completer</b>\n\n" |
|
|
26 | . "This is your central interface to send text commands to the server. " |
|
|
27 | . "To enter a verbatim command to send to the server, just type the command, " |
|
|
28 | . "followed by a space, and press return. " |
|
|
29 | . "Typing the initial letters of words (or just any letters) displays guesses " |
|
|
30 | . "for commands you might want to use.\n" |
|
|
31 | . "You can use the cursor-up and cursor-down keys to select between those guesses.\n" |
|
|
32 | . "<b>Right-Click</b> opens a menu where you cna select further options, sich as redefining keybindings.", |
25 | ; |
33 | ; |
26 | |
34 | |
27 | $self |
35 | $self |
28 | } |
36 | } |
29 | |
37 | |
… | |
… | |
31 | my ($self, $command, $tooltip, $widget, $cb) = @_; |
39 | my ($self, $command, $tooltip, $widget, $cb) = @_; |
32 | |
40 | |
33 | (my $data = $command) =~ s/\\//g; |
41 | (my $data = $command) =~ s/\\//g; |
34 | |
42 | |
35 | $tooltip =~ s/^\s+//; |
43 | $tooltip =~ s/^\s+//; |
36 | |
|
|
37 | $tooltip = "<big>$data</big>\n\n$tooltip"; |
44 | $tooltip = "<big>$data</big>\n\n$tooltip"; |
38 | |
|
|
39 | $tooltip =~ s/\s+$//; |
45 | $tooltip =~ s/\s+$//; |
40 | |
46 | |
41 | $self->{completer}{command}{$command} = [$data, $tooltip, $widget, $cb, ++$self->{command_id}]; |
47 | $self->{completer}{command}{$command} = [$data, $tooltip, $widget, $cb, ++$self->{command_id}]; |
42 | } |
48 | } |
43 | |
49 | |
… | |
… | |
50 | sub button_down { |
56 | sub button_down { |
51 | my ($self, $ev, $x, $y) = @_; |
57 | my ($self, $ev, $x, $y) = @_; |
52 | |
58 | |
53 | $self->focus_in; |
59 | $self->focus_in; |
54 | |
60 | |
55 | if ($ev->{button} == 2) { |
61 | if ($ev->{button} == 1) { |
|
|
62 | my $sw = int $::WIDTH / (32 * $::CFG->{map_scale}) + 0.99; |
|
|
63 | my $sh = int $::HEIGHT / (32 * $::CFG->{map_scale}) + 0.99; |
|
|
64 | |
|
|
65 | my $fx = int +($ev->{x} - $::CFG->{map_shift_x}) / (32 * $::CFG->{map_scale}) - 0.5 * $sw + 0.99; |
|
|
66 | my $fy = int +($ev->{y} - $::CFG->{map_shift_y}) / (32 * $::CFG->{map_scale}) - 0.5 * $sh + 0.99; |
|
|
67 | |
|
|
68 | $::CONN->send (sprintf "lookat %d %d", $fx, $fy); |
|
|
69 | |
|
|
70 | } elsif ($ev->{button} == 2) { |
56 | my ($ox, $oy) = ($ev->{x}, $ev->{y}); |
71 | my ($ox, $oy) = ($ev->{x}, $ev->{y}); |
57 | my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y}); |
72 | my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y}); |
58 | |
73 | |
59 | $self->{motion} = sub { |
74 | $self->{motion} = sub { |
60 | my ($ev, $x, $y) = @_; |
75 | my ($ev, $x, $y) = @_; |
… | |
… | |
65 | $::CFG->{map_shift_y} = $bh + $y - $oy; |
80 | $::CFG->{map_shift_y} = $bh + $y - $oy; |
66 | |
81 | |
67 | $self->update; |
82 | $self->update; |
68 | }; |
83 | }; |
69 | } |
84 | } |
|
|
85 | |
|
|
86 | 1 |
70 | } |
87 | } |
71 | |
88 | |
72 | sub button_up { |
89 | sub button_up { |
73 | my ($self, $ev, $x, $y) = @_; |
90 | my ($self, $ev, $x, $y) = @_; |
74 | |
91 | |
75 | delete $self->{motion}; |
92 | delete $self->{motion}; |
|
|
93 | |
|
|
94 | 1 |
76 | } |
95 | } |
77 | |
96 | |
78 | sub mouse_motion { |
97 | sub mouse_motion { |
79 | my ($self, $ev, $x, $y) = @_; |
98 | my ($self, $ev, $x, $y) = @_; |
80 | |
99 | |
|
|
100 | if ($self->{motion}) { |
81 | $self->{motion}->($ev, $x, $y) if $self->{motion}; |
101 | $self->{motion}->($ev, $x, $y); |
|
|
102 | } else { |
|
|
103 | return 0; |
|
|
104 | } |
|
|
105 | |
|
|
106 | 1 |
82 | } |
107 | } |
83 | |
108 | |
84 | sub size_request { |
109 | sub size_request { |
85 | ( |
110 | ( |
86 | 1 + 32 * int $::WIDTH / 32, |
111 | 1 + 32 * int $::WIDTH / 32, |
… | |
… | |
112 | ); |
137 | ); |
113 | |
138 | |
114 | sub key_down { |
139 | sub key_down { |
115 | my ($self, $ev) = @_; |
140 | my ($self, $ev) = @_; |
116 | |
141 | |
117 | return unless $::CONN; |
142 | return 0 unless $::CONN; |
118 | |
143 | |
119 | my $mod = $ev->{mod}; |
144 | my $mod = $ev->{mod}; |
120 | my $sym = $ev->{sym}; |
145 | my $sym = $ev->{sym}; |
121 | my $uni = $ev->{unicode}; |
146 | my $uni = $ev->{unicode}; |
122 | |
147 | |
… | |
… | |
124 | $::CONN->user_send ("stay fire"); |
149 | $::CONN->user_send ("stay fire"); |
125 | } elsif ($uni == ord ",") { |
150 | } elsif ($uni == ord ",") { |
126 | $::CONN->user_send ("take"); |
151 | $::CONN->user_send ("take"); |
127 | } elsif ($uni == ord " ") { |
152 | } elsif ($uni == ord " ") { |
128 | $::CONN->user_send ("apply"); |
153 | $::CONN->user_send ("apply"); |
|
|
154 | } elsif ($uni == ord ".") { |
|
|
155 | $::CONN->user_send ($self->{completer}{last_command}) |
|
|
156 | if exists $self->{completer}{last_command}; |
129 | } elsif ($uni == ord "\t") { |
157 | } elsif ($uni == ord "\t") { |
130 | # TODO: toggle inventory |
158 | $::INV_WINDOW->toggle_visibility; |
131 | } elsif ($sym == CFClient::SDLK_KP_PLUS || $uni == ord "+") { |
159 | } elsif ($sym == CFClient::SDLK_KP_PLUS || $uni == ord "+") { |
132 | $::CONN->user_send ("rotateshoottype +"); |
160 | $::CONN->user_send ("rotateshoottype +"); |
133 | } elsif ($sym == CFClient::SDLK_KP_MINUS || $uni == ord "-") { |
161 | } elsif ($sym == CFClient::SDLK_KP_MINUS || $uni == ord "-") { |
134 | $::CONN->user_send ("rotateshoottype -"); |
162 | $::CONN->user_send ("rotateshoottype -"); |
135 | } elsif ($uni == ord '"') { |
163 | } elsif ($uni == ord '"') { |
… | |
… | |
146 | $self->{ctrl}++; |
174 | $self->{ctrl}++; |
147 | $::CONN->user_send ("run $DIR{$sym}[0]"); |
175 | $::CONN->user_send ("run $DIR{$sym}[0]"); |
148 | } else { |
176 | } else { |
149 | $::CONN->user_send ("$DIR{$sym}[1]"); |
177 | $::CONN->user_send ("$DIR{$sym}[1]"); |
150 | } |
178 | } |
151 | } elsif ($ev->{unicode}) { |
179 | } elsif ($sym == CFClient::SDLK_INSERT && $mod & CFClient::KMOD_CTRL) { |
|
|
180 | $::BIND_EDITOR->set_binding (undef, undef, [], |
|
|
181 | sub { |
|
|
182 | my ($mod, $sym, $cmds) = @_; |
|
|
183 | $::CFG->{bindings}->{$mod}->{$sym} = $cmds; |
|
|
184 | }); |
|
|
185 | $::BIND_EDITOR->start; |
|
|
186 | $::BIND_EDITOR->show; |
|
|
187 | } elsif ($sym == CFClient::SDLK_INSERT && not ($mod & CFClient::KMOD_CTRL)) { |
|
|
188 | $::BIND_EDITOR->stop; |
|
|
189 | $::BIND_EDITOR->ask_for_bind_and_commit; |
|
|
190 | $::BIND_EDITOR->hide; |
|
|
191 | } elsif (my $bind_cmd = $::CFG->{bindings}->{$mod}->{$sym}) { |
|
|
192 | $::CONN->user_send ($_) for @$bind_cmd; |
|
|
193 | } elsif ((ord 'a') <= $uni && $uni <= (ord 'z')) { |
152 | $self->{completer}->key_down ($ev); |
194 | $self->{completer}->key_down ($ev); |
153 | $self->{completer}->show; |
195 | $self->{completer}->show; |
|
|
196 | } else { |
|
|
197 | return 0; |
|
|
198 | } |
|
|
199 | |
154 | } |
200 | 1 |
155 | } |
201 | } |
156 | |
202 | |
157 | sub key_up { |
203 | sub key_up { |
158 | my ($self, $ev) = @_; |
204 | my ($self, $ev) = @_; |
159 | |
205 | |
|
|
206 | my $res = 0; |
160 | my $mod = $ev->{mod}; |
207 | my $mod = $ev->{mod}; |
161 | my $sym = $ev->{sym}; |
208 | my $sym = $ev->{sym}; |
162 | |
209 | |
163 | if (!($mod & CFClient::KMOD_SHIFT) && delete $self->{shft}) { |
210 | if (!($mod & CFClient::KMOD_SHIFT) && delete $self->{shft}) { |
164 | $::CONN->user_send ("fire_stop"); |
211 | $::CONN->user_send ("fire_stop"); |
|
|
212 | $res = 1; |
165 | } |
213 | } |
|
|
214 | |
166 | if (!($mod & CFClient::KMOD_CTRL ) && delete $self->{ctrl}) { |
215 | if (!($mod & CFClient::KMOD_CTRL ) && delete $self->{ctrl}) { |
167 | $::CONN->user_send ("run_stop"); |
216 | $::CONN->user_send ("run_stop"); |
|
|
217 | $res = 1; |
168 | } |
218 | } |
|
|
219 | |
|
|
220 | $res |
169 | } |
221 | } |
170 | |
222 | |
171 | sub draw { |
223 | sub draw { |
172 | my ($self) = @_; |
224 | my ($self) = @_; |
173 | |
225 | |
… | |
… | |
193 | glTranslate $sx0 - 32, $sy0 - 32, 0; |
245 | glTranslate $sx0 - 32, $sy0 - 32, 0; |
194 | |
246 | |
195 | my ($w, $h, $data) = $::MAP->draw ($sx, $sy, 0, 0, $sw + 1, $sh + 1); |
247 | my ($w, $h, $data) = $::MAP->draw ($sx, $sy, 0, 0, $sw + 1, $sh + 1); |
196 | |
248 | |
197 | if ($::CFG->{fow_enable}) { |
249 | if ($::CFG->{fow_enable}) { |
198 | if ($::CFG->{fow_smooth} && $CFClient::GL_VERSION >= 1.2) { # smooth fog of war |
250 | if ($::CFG->{fow_smooth} && $CFClient::OpenGL::GL_VERSION >= 1.2) { # smooth fog of war |
199 | glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER); |
251 | glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER); |
200 | glConvolutionFilter2D ( |
252 | glConvolutionFilter2D ( |
201 | GL_CONVOLUTION_2D, |
253 | GL_CONVOLUTION_2D, |
202 | GL_ALPHA, |
254 | GL_ALPHA, |
203 | 3, 3, |
255 | 3, 3, |
… | |
… | |
256 | glVertex $::WIDTH, $::HEIGHT; |
308 | glVertex $::WIDTH, $::HEIGHT; |
257 | glVertex $::WIDTH, 0; |
309 | glVertex $::WIDTH, 0; |
258 | glEnd; |
310 | glEnd; |
259 | glDisable GL_BLEND; |
311 | glDisable GL_BLEND; |
260 | |
312 | |
261 | $self->{out_of_focus} ||= do { |
313 | # $self->{out_of_focus} ||= do { |
262 | my $label = new CFClient::UI::Label |
314 | # my $label = new CFClient::UI::Label |
263 | x => 0, |
315 | # x => 0, |
264 | y => 0, |
316 | # y => 0, |
265 | z => 1, |
317 | # z => 1, |
266 | ellipsise => 0, |
318 | # ellipsise => 0, |
267 | text => "map out of focus (click map to play)"; |
319 | # text => "map out of focus (click map to play)"; |
268 | |
320 | # |
269 | $label->show; |
321 | # $label->show; |
270 | $label->update; |
322 | # $label->update; |
271 | |
323 | # |
272 | $CFClient::UI::ROOT->on_post_alloc ("$self$label" => sub { |
324 | # $CFClient::UI::ROOT->on_post_alloc ("$self$label" => sub { |
273 | $label->move ( |
325 | # $label->move_abs ( |
274 | ($::WIDTH - $label->{w}) * 0.5, |
326 | # ($::WIDTH - $label->{w}) * 0.5, |
275 | ($::HEIGHT - $label->{h}) * 0.5, |
327 | # ($::HEIGHT - $label->{h}) * 0.5, |
276 | ); |
328 | # ); |
277 | }); |
329 | # }); |
278 | |
330 | # |
279 | $label |
331 | # $label |
280 | }; |
332 | # }; |
281 | } |
333 | } |
282 | } |
334 | } |
283 | |
335 | |
284 | sub DESTROY { |
336 | sub DESTROY { |
285 | my $self = shift; |
337 | my $self = shift; |
… | |
… | |
395 | fontsize => $_, |
447 | fontsize => $_, |
396 | ), (0.8) x 16 |
448 | ), (0.8) x 16 |
397 | ]; |
449 | ]; |
398 | |
450 | |
399 | $self->{entry} = new CFClient::UI::Entry |
451 | $self->{entry} = new CFClient::UI::Entry |
400 | connect_changed => sub { |
452 | on_changed => sub { |
401 | $self->update_labels; |
453 | $self->update_labels; |
402 | }, |
454 | }, |
403 | connect_key_down => sub { |
455 | on_key_down => sub { |
404 | my ($entry, $ev) = @_; |
456 | my ($entry, $ev) = @_; |
405 | |
457 | |
406 | my $self = $entry->{parent}{parent}; |
458 | my $self = $entry->{parent}{parent}; |
407 | |
459 | |
408 | if ($ev->{sym} == 13) { |
460 | if ($ev->{sym} == 13) { |
409 | if (exists $self->{select}) { |
461 | if (exists $self->{select}) { |
|
|
462 | $self->{last_command} = $self->{select}; |
410 | $::CONN->user_send ($self->{select}); |
463 | $::CONN->user_send ($self->{select}); |
411 | $self->hide; |
464 | $self->hide; |
412 | } |
465 | } |
413 | } elsif ($ev->{sym} == 27) { |
466 | } elsif ($ev->{sym} == 27) { |
414 | $self->hide; |
467 | $self->hide; |
… | |
… | |
446 | |
499 | |
447 | sub size_allocate { |
500 | sub size_allocate { |
448 | my ($self, $w, $h) = @_; |
501 | my ($self, $w, $h) = @_; |
449 | |
502 | |
450 | $self->SUPER::size_allocate ($w, $h); |
503 | $self->SUPER::size_allocate ($w, $h); |
451 | $self->move (($::WIDTH - $w) * 0.5, ($::HEIGHT - $h) * 0.6, 10); |
504 | $self->move_abs (($::WIDTH - $w) * 0.5, ($::HEIGHT - $h) * 0.6, 10); |
452 | } |
505 | } |
453 | |
506 | |
454 | sub show { |
507 | sub show { |
455 | my ($self) = @_; |
508 | my ($self) = @_; |
456 | |
509 | |
… | |
… | |
466 | } |
519 | } |
467 | |
520 | |
468 | sub key_down { |
521 | sub key_down { |
469 | my ($self, $ev) = @_; |
522 | my ($self, $ev) = @_; |
470 | |
523 | |
471 | $self->{entry}->key_down ($ev); |
524 | $self->{entry}->key_down ($ev) |
472 | } |
525 | } |
473 | |
526 | |
474 | sub update_labels { |
527 | sub update_labels { |
475 | my ($self) = @_; |
528 | my ($self) = @_; |
476 | |
529 | |
… | |
… | |
509 | |
562 | |
510 | @match = map $self->{command}{$_->[0]}, |
563 | @match = map $self->{command}{$_->[0]}, |
511 | sort { |
564 | sort { |
512 | $a->[1] <=> $b->[1] |
565 | $a->[1] <=> $b->[1] |
513 | or $self->{command}{$a->[0]}[4] <=> $self->{command}{$b->[0]}[4] |
566 | or $self->{command}{$a->[0]}[4] <=> $self->{command}{$b->[0]}[4] |
514 | or (length $a->[0]) <=> (length $b->[0]) |
567 | or (length $b->[0]) <=> (length $a->[0]) |
515 | } @match; |
568 | } @match; |
516 | } |
569 | } |
517 | |
570 | |
518 | $self->{last_search} = $cmd; |
571 | $self->{last_search} = $text; |
519 | $self->{last_match} = \@match; |
572 | $self->{last_match} = \@match; |
520 | |
573 | |
521 | $self->{select_offset} = 0; |
574 | $self->{select_offset} = 0; |
522 | } |
575 | } |
523 | |
576 | |