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