… | |
… | |
23 | my $self = shift; |
23 | my $self = shift; |
24 | |
24 | |
25 | glDeleteList $self->{list}; |
25 | glDeleteList $self->{list}; |
26 | |
26 | |
27 | $self->SUPER::DESTROY; |
27 | $self->SUPER::DESTROY; |
28 | } |
|
|
29 | |
|
|
30 | sub key_down { |
|
|
31 | print "MAPKEYDOWN\n"; |
|
|
32 | } |
|
|
33 | |
|
|
34 | sub key_up { |
|
|
35 | } |
28 | } |
36 | |
29 | |
37 | sub button_down { |
30 | sub button_down { |
38 | my ($self, $ev, $x, $y) = @_; |
31 | my ($self, $ev, $x, $y) = @_; |
39 | |
32 | |
… | |
… | |
224 | } elsif ($sym == ord "a") { |
217 | } elsif ($sym == ord "a") { |
225 | $::CONN->user_send ("apply"); |
218 | $::CONN->user_send ("apply"); |
226 | } elsif ($sym == ord "'") { |
219 | } elsif ($sym == ord "'") { |
227 | $self->emit ('activate_console'); |
220 | $self->emit ('activate_console'); |
228 | } elsif ($sym == ord "/") { |
221 | } elsif ($sym == ord "/") { |
229 | $self->emit ('activate_console' => '/'); |
222 | $self->emit (activate_console => '/'); |
230 | } elsif (exists $DIR{$sym}) { |
223 | } elsif (exists $DIR{$sym}) { |
231 | if ($mod & CFClient::KMOD_SHIFT) { |
224 | if ($mod & CFClient::KMOD_SHIFT) { |
232 | $self->{shft}++; |
225 | $self->{shft}++; |
233 | $::CONN->user_send ("fire $DIR{$sym}[0]"); |
226 | $::CONN->user_send ("fire $DIR{$sym}[0]"); |
234 | } elsif ($mod & CFClient::KMOD_CTRL) { |
227 | } elsif ($mod & CFClient::KMOD_CTRL) { |
235 | $self->{ctrl}++; |
228 | $self->{ctrl}++; |
236 | $::CONN->user_send ("run $DIR{$sym}[0]"); |
229 | $::CONN->user_send ("run $DIR{$sym}[0]"); |
237 | } else { |
230 | } else { |
238 | $::CONN->user_send ("$DIR{$sym}[1]"); |
231 | $::CONN->user_send ("$DIR{$sym}[1]"); |
239 | } |
232 | } |
|
|
233 | } elsif ($ev->{unicode}) { |
|
|
234 | $self->{command_widget} ||= |
|
|
235 | new CFClient::MapWidget::Command:: |
|
|
236 | command => $self->{command}, |
|
|
237 | can_focus => 1, |
|
|
238 | connect_execute => sub { |
|
|
239 | $::CONN->user_send ($_[1]); |
|
|
240 | }, |
|
|
241 | connect_close => sub { |
|
|
242 | (delete $self->{command_widget})->hide; |
|
|
243 | $self->focus_in; |
|
|
244 | }, |
|
|
245 | ; |
|
|
246 | $self->{command_widget}->key_down ($ev); |
|
|
247 | $self->{command_widget}->show; |
|
|
248 | $self->{command_widget}->focus_in; |
240 | } |
249 | } |
241 | } |
250 | } |
242 | |
251 | |
243 | sub key_up { |
252 | sub key_up { |
244 | my ($self, $ev) = @_; |
253 | my ($self, $ev) = @_; |
… | |
… | |
256 | |
265 | |
257 | sub add_command { |
266 | sub add_command { |
258 | my ($self, $command, $widget, $cb) = @_; |
267 | my ($self, $command, $widget, $cb) = @_; |
259 | |
268 | |
260 | (my $abbrev = $command) =~ s/(\S)[^[:space:]_]*[[:space:]_]+/$1/g; |
269 | (my $abbrev = $command) =~ s/(\S)[^[:space:]_]*[[:space:]_]+/$1/g; |
|
|
270 | |
|
|
271 | push @{$self->{command}}, [$abbrev, $command]; |
261 | warn "$command|$abbrev|$widget\n";#d# |
272 | #warn "$command|$abbrev|$widget\n";#d# |
|
|
273 | } |
|
|
274 | |
|
|
275 | package CFClient::MapWidget::Command; |
|
|
276 | |
|
|
277 | use strict; |
|
|
278 | |
|
|
279 | use CFClient::OpenGL; |
|
|
280 | |
|
|
281 | our @ISA = CFClient::UI::VBox::; |
|
|
282 | |
|
|
283 | sub new { |
|
|
284 | my $class = shift; |
|
|
285 | |
|
|
286 | my $self = $class->SUPER::new ( |
|
|
287 | @_, |
|
|
288 | children => [map |
|
|
289 | CFClient::UI::Label->new ( |
|
|
290 | can_hover => 1, |
|
|
291 | fontsize => $_, |
|
|
292 | ), 1, 1, 0.8, 0.8, 0.8, 0.8, 0.8 |
|
|
293 | ], |
|
|
294 | ); |
|
|
295 | |
|
|
296 | $self |
|
|
297 | } |
|
|
298 | |
|
|
299 | sub size_allocate { |
|
|
300 | my ($self, $w, $h) = @_; |
|
|
301 | |
|
|
302 | $self->SUPER::size_allocate ($w, $h); |
|
|
303 | $self->move (($::WIDTH - $w) * 0.5, ($::HEIGHT - $h) * 0.6, 10); |
|
|
304 | } |
|
|
305 | |
|
|
306 | sub update_labels { |
|
|
307 | my ($self) = @_; |
|
|
308 | |
|
|
309 | my $command = $self->{command}; |
|
|
310 | my $search_abbrev = qr/^\Q$self->{search}/; |
|
|
311 | my $search_full = qr/\Q$self->{search}/; |
|
|
312 | |
|
|
313 | my @found; |
|
|
314 | |
|
|
315 | for (@$command) { |
|
|
316 | if ($_->[0] =~ $search_abbrev) { |
|
|
317 | push @found, [$_->[0], $_]; |
|
|
318 | } elsif ($_[1] =~ $search_full) { |
|
|
319 | push @found, [$_->[1], $_]; |
|
|
320 | } |
|
|
321 | } |
|
|
322 | |
|
|
323 | @found = sort { $a->[0] cmp $b->[0] } @found; |
|
|
324 | |
|
|
325 | $self->{children}[0]->set_text ("$self->{search}_"); |
|
|
326 | |
|
|
327 | for (0..5) { |
|
|
328 | $self->{children}[$_ + 1]->set_text ($found[$_] ? "$found[$_][0] ($found[$_][1][1])" : ""); |
|
|
329 | } |
|
|
330 | |
|
|
331 | $self->{select} = $found[0][1][1] |
|
|
332 | if @found; |
|
|
333 | |
|
|
334 | if (@found > 6) { |
|
|
335 | $self->{children}[6]->set_text ("..."); |
|
|
336 | } |
|
|
337 | |
|
|
338 | $self->check_size; |
|
|
339 | } |
|
|
340 | |
|
|
341 | sub key_down { |
|
|
342 | my ($self, $ev) = @_; |
|
|
343 | |
|
|
344 | if ($ev->{sym} == 8) { |
|
|
345 | substr $self->{search}, -1, 1, ""; |
|
|
346 | $self->update_labels; |
|
|
347 | } elsif ($ev->{sym} == 13) { |
|
|
348 | if (exists $self->{select}) { |
|
|
349 | $self->emit (execute => $self->{select}); |
|
|
350 | $self->emit ("close"); |
|
|
351 | } |
|
|
352 | } elsif ($ev->{sym} == 27) { |
|
|
353 | $self->emit ("close"); |
|
|
354 | } elsif ($ev->{unicode}) { |
|
|
355 | $self->{search} .= chr $ev->{unicode}; |
|
|
356 | $self->update_labels; |
|
|
357 | } |
262 | } |
358 | } |
263 | |
359 | |
264 | 1 |
360 | 1 |