… | |
… | |
17 | can_focus => 1, |
17 | can_focus => 1, |
18 | list => glGenList, |
18 | list => glGenList, |
19 | @_ |
19 | @_ |
20 | ); |
20 | ); |
21 | |
21 | |
22 | $self->add_command ("killpets", "kills all your summoned and charmed creates"); |
22 | $self->{completer} = new CFClient::MapWidget::Command:: |
|
|
23 | command => $self->{command}, |
|
|
24 | can_focus => 1, |
|
|
25 | ; |
23 | |
26 | |
24 | $self |
27 | $self |
25 | } |
28 | } |
26 | |
29 | |
27 | sub DESTROY { |
30 | sub add_command { |
|
|
31 | my ($self, $command, $tooltip, $widget, $cb) = @_; |
|
|
32 | |
|
|
33 | (my $data = $command) =~ s/\\//g; |
|
|
34 | |
|
|
35 | $tooltip =~ s/^\s+//; |
|
|
36 | |
|
|
37 | $tooltip = "<big>$data</big>\n\n$tooltip"; |
|
|
38 | |
|
|
39 | $tooltip =~ s/\s+$//; |
|
|
40 | |
|
|
41 | $self->{completer}{command}{$command} = [$data, $tooltip, $widget, $cb, ++$self->{command_id}]; |
|
|
42 | } |
|
|
43 | |
|
|
44 | sub clr_commands { |
28 | my $self = shift; |
45 | my ($self) = @_; |
29 | |
46 | |
30 | glDeleteList $self->{list}; |
47 | %{$self->{completer}{command}} = (); |
31 | |
|
|
32 | $self->SUPER::DESTROY; |
|
|
33 | } |
48 | } |
34 | |
49 | |
35 | sub button_down { |
50 | sub button_down { |
36 | my ($self, $ev, $x, $y) = @_; |
51 | my ($self, $ev, $x, $y) = @_; |
37 | |
52 | |
… | |
… | |
78 | |
93 | |
79 | $self->{need_update} = 1; |
94 | $self->{need_update} = 1; |
80 | $self->SUPER::update; |
95 | $self->SUPER::update; |
81 | } |
96 | } |
82 | |
97 | |
|
|
98 | my %DIR = ( |
|
|
99 | CFClient::SDLK_KP8, [1, "north"], |
|
|
100 | CFClient::SDLK_KP9, [2, "northeast"], |
|
|
101 | CFClient::SDLK_KP6, [3, "east"], |
|
|
102 | CFClient::SDLK_KP3, [4, "southeast"], |
|
|
103 | CFClient::SDLK_KP2, [5, "south"], |
|
|
104 | CFClient::SDLK_KP1, [6, "southwest"], |
|
|
105 | CFClient::SDLK_KP4, [7, "west"], |
|
|
106 | CFClient::SDLK_KP7, [8, "northwest"], |
|
|
107 | |
|
|
108 | CFClient::SDLK_UP, [1, "north"], |
|
|
109 | CFClient::SDLK_RIGHT, [3, "east"], |
|
|
110 | CFClient::SDLK_DOWN, [5, "south"], |
|
|
111 | CFClient::SDLK_LEFT, [7, "west"], |
|
|
112 | ); |
|
|
113 | |
|
|
114 | sub key_down { |
|
|
115 | my ($self, $ev) = @_; |
|
|
116 | |
|
|
117 | return unless $::CONN; |
|
|
118 | |
|
|
119 | my $mod = $ev->{mod}; |
|
|
120 | my $sym = $ev->{sym}; |
|
|
121 | my $uni = $ev->{unicode}; |
|
|
122 | |
|
|
123 | if ($sym == CFClient::SDLK_KP5) { |
|
|
124 | $::CONN->user_send ("stay fire"); |
|
|
125 | } elsif ($uni == ord ",") { |
|
|
126 | $::CONN->user_send ("take"); |
|
|
127 | } elsif ($uni == ord " ") { |
|
|
128 | $::CONN->user_send ("apply"); |
|
|
129 | } elsif ($uni == ord "\t") { |
|
|
130 | # TODO: toggle inventory |
|
|
131 | } elsif ($sym == CFClient::SDLK_KP_PLUS || $uni == ord "+") { |
|
|
132 | $::CONN->user_send ("rotateshoottype +"); |
|
|
133 | } elsif ($sym == CFClient::SDLK_KP_MINUS || $uni == ord "-") { |
|
|
134 | $::CONN->user_send ("rotateshoottype -"); |
|
|
135 | } elsif ($uni == ord '"') { |
|
|
136 | $self->{completer}->set_prefix ("$::CFG->{say_command} "); |
|
|
137 | $self->{completer}->show; |
|
|
138 | } elsif ($uni == ord "'") { |
|
|
139 | $self->{completer}->set_prefix (""); |
|
|
140 | $self->{completer}->show; |
|
|
141 | } elsif (exists $DIR{$sym}) { |
|
|
142 | if ($mod & CFClient::KMOD_SHIFT) { |
|
|
143 | $self->{shft}++; |
|
|
144 | $::CONN->user_send ("fire $DIR{$sym}[0]"); |
|
|
145 | } elsif ($mod & CFClient::KMOD_CTRL) { |
|
|
146 | $self->{ctrl}++; |
|
|
147 | $::CONN->user_send ("run $DIR{$sym}[0]"); |
|
|
148 | } else { |
|
|
149 | $::CONN->user_send ("$DIR{$sym}[1]"); |
|
|
150 | } |
|
|
151 | } elsif ($ev->{unicode}) { |
|
|
152 | $self->{completer}->key_down ($ev); |
|
|
153 | $self->{completer}->show; |
|
|
154 | } |
|
|
155 | } |
|
|
156 | |
|
|
157 | sub key_up { |
|
|
158 | my ($self, $ev) = @_; |
|
|
159 | |
|
|
160 | my $mod = $ev->{mod}; |
|
|
161 | my $sym = $ev->{sym}; |
|
|
162 | |
|
|
163 | if (!($mod & CFClient::KMOD_SHIFT) && delete $self->{shft}) { |
|
|
164 | $::CONN->user_send ("fire_stop"); |
|
|
165 | } |
|
|
166 | if (!($mod & CFClient::KMOD_CTRL ) && delete $self->{ctrl}) { |
|
|
167 | $::CONN->user_send ("run_stop"); |
|
|
168 | } |
|
|
169 | } |
|
|
170 | |
83 | sub draw { |
171 | sub draw { |
84 | my ($self) = @_; |
172 | my ($self) = @_; |
|
|
173 | |
|
|
174 | my $focused = $CFClient::UI::FOCUS == $self |
|
|
175 | || $CFClient::UI::FOCUS == $self->{completer}{entry}; |
|
|
176 | |
|
|
177 | return |
|
|
178 | unless $focused || !$::FAST; |
85 | |
179 | |
86 | if (delete $self->{need_update}) { |
180 | if (delete $self->{need_update}) { |
87 | glNewList $self->{list}; |
181 | glNewList $self->{list}; |
88 | |
182 | |
89 | if ($::MAP) { |
183 | if ($::MAP) { |
… | |
… | |
114 | 0.05, 0.13, 0.05, |
208 | 0.05, 0.13, 0.05, |
115 | ); |
209 | ); |
116 | glEnable GL_CONVOLUTION_2D; |
210 | glEnable GL_CONVOLUTION_2D; |
117 | } |
211 | } |
118 | |
212 | |
|
|
213 | $self->{fow_texture_name} ||= glGenTexture; |
|
|
214 | # try to re-use the texture name: TODO improve texture class instead |
|
|
215 | |
119 | $self->{fow_texture} = new CFClient::Texture |
216 | $self->{fow_texture} = new CFClient::Texture |
120 | w => $w, |
217 | w => $w, |
121 | h => $h, |
218 | h => $h, |
122 | data => $data, |
219 | data => $data, |
|
|
220 | name => $self->{fow_texture_name}, |
123 | internalformat => GL_ALPHA, |
221 | internalformat => GL_ALPHA, |
124 | format => GL_ALPHA; |
222 | format => GL_ALPHA; |
125 | |
223 | |
126 | glDisable GL_CONVOLUTION_2D if $::CFG->{fow_smooth}; |
224 | glDisable GL_CONVOLUTION_2D if $::CFG->{fow_smooth}; |
127 | |
225 | |
128 | glEnable GL_BLEND; |
|
|
129 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
130 | glEnable GL_TEXTURE_2D; |
226 | glEnable GL_TEXTURE_2D; |
131 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
227 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
132 | |
228 | |
133 | glColor +($::CFG->{fow_intensity}) x 3, 0.8; |
229 | glColor +($::CFG->{fow_intensity}) x 3, 0.8; |
134 | $self->{fow_texture}->draw_quad (0, 0, $w * 32, $h * 32); |
230 | $self->{fow_texture}->draw_quad_alpha (0, 0, $w * 32, $h * 32); |
135 | |
231 | |
136 | glDisable GL_TEXTURE_2D; |
232 | glDisable GL_TEXTURE_2D; |
137 | glDisable GL_BLEND; |
|
|
138 | } |
233 | } |
139 | |
234 | |
140 | glPopMatrix; |
235 | glPopMatrix; |
141 | } |
236 | } |
142 | |
237 | |
… | |
… | |
145 | |
240 | |
146 | glPushMatrix; |
241 | glPushMatrix; |
147 | glCallList $self->{list}; |
242 | glCallList $self->{list}; |
148 | glPopMatrix; |
243 | glPopMatrix; |
149 | |
244 | |
150 | if ($CFClient::UI::FOCUS != $self) { |
245 | # TNT2 emulates logops in software (or worse :) |
151 | glColor 64/255, 64/255, 64/255; |
246 | if ($focused) { |
152 | glLogicOp GL_AND; |
247 | (delete $self->{out_of_focus})->destroy |
153 | glEnable GL_COLOR_LOGIC_OP; |
248 | if $self->{out_of_focus}; |
|
|
249 | } else { |
|
|
250 | glColor 0.4, 0.2, 0.2, 0.6; |
|
|
251 | glEnable GL_BLEND; |
|
|
252 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
154 | glBegin GL_QUADS; |
253 | glBegin GL_QUADS; |
155 | glVertex 0, 0; |
254 | glVertex 0, 0; |
156 | glVertex 0, $::HEIGHT; |
255 | glVertex 0, $::HEIGHT; |
157 | glVertex $::WIDTH, $::HEIGHT; |
256 | glVertex $::WIDTH, $::HEIGHT; |
158 | glVertex $::WIDTH, 0; |
257 | glVertex $::WIDTH, 0; |
159 | glEnd; |
258 | glEnd; |
160 | glDisable GL_COLOR_LOGIC_OP; |
259 | glDisable GL_BLEND; |
161 | } |
|
|
162 | } |
|
|
163 | |
260 | |
164 | my %DIR = ( |
261 | $self->{out_of_focus} ||= do { |
165 | CFClient::SDLK_KP8, [1, "north"], |
262 | my $label = new CFClient::UI::Label |
166 | CFClient::SDLK_KP9, [2, "northeast"], |
263 | x => 0, |
167 | CFClient::SDLK_KP6, [3, "east"], |
264 | y => 0, |
168 | CFClient::SDLK_KP3, [4, "southeast"], |
265 | z => 1, |
169 | CFClient::SDLK_KP2, [5, "south"], |
266 | ellipsise => 0, |
170 | CFClient::SDLK_KP1, [6, "southwest"], |
267 | text => "map out of focus (click map to play)"; |
171 | CFClient::SDLK_KP4, [7, "west"], |
|
|
172 | CFClient::SDLK_KP7, [8, "northwest"], |
|
|
173 | |
268 | |
174 | CFClient::SDLK_UP, [1, "north"], |
269 | $label->show; |
175 | CFClient::SDLK_RIGHT, [3, "east"], |
270 | $label->update; |
176 | CFClient::SDLK_DOWN, [5, "south"], |
|
|
177 | CFClient::SDLK_LEFT, [7, "west"], |
|
|
178 | ); |
|
|
179 | |
271 | |
180 | sub key_down { |
272 | $CFClient::UI::ROOT->on_post_alloc ("$self$label" => sub { |
181 | my ($self, $ev) = @_; |
273 | $label->move ( |
|
|
274 | ($::WIDTH - $label->{w}) * 0.5, |
|
|
275 | ($::HEIGHT - $label->{h}) * 0.5, |
|
|
276 | ); |
|
|
277 | }); |
182 | |
278 | |
183 | my $mod = $ev->{mod}; |
279 | $label |
184 | my $sym = $ev->{sym}; |
|
|
185 | |
|
|
186 | if ($sym == CFClient::SDLK_KP5) { |
|
|
187 | $::CONN->user_send ("stay fire"); |
|
|
188 | } elsif ($sym == ord ",") { |
|
|
189 | $::CONN->user_send ("take"); |
|
|
190 | } elsif ($sym == ord "a") { |
|
|
191 | $::CONN->user_send ("apply"); |
|
|
192 | } elsif ($sym == ord "'") { |
|
|
193 | $self->emit ('activate_console'); |
|
|
194 | } elsif ($sym == ord "/") { |
|
|
195 | $self->emit (activate_console => '/'); |
|
|
196 | } elsif (exists $DIR{$sym}) { |
|
|
197 | if ($mod & CFClient::KMOD_SHIFT) { |
|
|
198 | $self->{shft}++; |
|
|
199 | $::CONN->user_send ("fire $DIR{$sym}[0]"); |
|
|
200 | } elsif ($mod & CFClient::KMOD_CTRL) { |
|
|
201 | $self->{ctrl}++; |
|
|
202 | $::CONN->user_send ("run $DIR{$sym}[0]"); |
|
|
203 | } else { |
|
|
204 | $::CONN->user_send ("$DIR{$sym}[1]"); |
|
|
205 | } |
280 | }; |
206 | } elsif ($ev->{unicode}) { |
|
|
207 | $self->{command_widget} ||= |
|
|
208 | new CFClient::MapWidget::Command:: |
|
|
209 | command => $self->{command}, |
|
|
210 | can_focus => 1, |
|
|
211 | connect_execute => sub { |
|
|
212 | # todo: support callback instead of user_send |
|
|
213 | $::CONN->user_send ($_[1][1]); |
|
|
214 | }, |
|
|
215 | connect_close => sub { |
|
|
216 | (delete $self->{command_widget})->hide; |
|
|
217 | $self->focus_in; |
|
|
218 | }, |
|
|
219 | ; |
|
|
220 | $self->{command_widget}->key_down ($ev); |
|
|
221 | return unless $self->{command_widget}; |
|
|
222 | $self->{command_widget}->show; |
|
|
223 | $self->{command_widget}->focus_in; |
|
|
224 | } |
281 | } |
225 | } |
282 | } |
226 | |
283 | |
227 | sub key_up { |
284 | sub DESTROY { |
228 | my ($self, $ev) = @_; |
285 | my $self = shift; |
229 | |
286 | |
230 | my $mod = $ev->{mod}; |
287 | glDeleteList $self->{list}; |
231 | my $sym = $ev->{sym}; |
|
|
232 | |
288 | |
233 | if (!($mod & CFClient::KMOD_SHIFT) && delete $self->{shft}) { |
289 | $self->SUPER::DESTROY; |
234 | $::CONN->user_send ("fire_stop"); |
|
|
235 | } |
|
|
236 | if (!($mod & CFClient::KMOD_CTRL ) && delete $self->{ctrl}) { |
|
|
237 | $::CONN->user_send ("run_stop"); |
|
|
238 | } |
|
|
239 | } |
|
|
240 | |
|
|
241 | sub add_command { |
|
|
242 | my ($self, $command, $tooltip, $widget, $cb) = @_; |
|
|
243 | |
|
|
244 | (my $abbrev = $command) =~ s/(\S)[^[:space:]_]*[[:space:]_]+/$1/g; |
|
|
245 | |
|
|
246 | $self->{command} = [ |
|
|
247 | [$abbrev, $command, $tooltip, $widget, $cb], |
|
|
248 | grep $_->[1] ne $command, @{ $self->{command} }, |
|
|
249 | ]; |
|
|
250 | } |
290 | } |
251 | |
291 | |
252 | package CFClient::MapWidget::MapMap; |
292 | package CFClient::MapWidget::MapMap; |
253 | |
293 | |
254 | our @ISA = CFClient::UI::Base::; |
294 | our @ISA = CFClient::UI::Base::; |
… | |
… | |
332 | |
372 | |
333 | use strict; |
373 | use strict; |
334 | |
374 | |
335 | use CFClient::OpenGL; |
375 | use CFClient::OpenGL; |
336 | |
376 | |
337 | our @ISA = CFClient::UI::VBox::; |
377 | our @ISA = CFClient::UI::Frame::; |
338 | |
378 | |
339 | sub new { |
379 | sub new { |
340 | my $class = shift; |
380 | my $class = shift; |
341 | |
381 | |
342 | my $self = $class->SUPER::new ( |
382 | my $self = $class->SUPER::new ( |
|
|
383 | bg => [0, 0, 0, 0.8], |
343 | @_, |
384 | @_, |
344 | children => [map |
385 | ); |
|
|
386 | |
|
|
387 | $self->add ($self->{vbox} = new CFClient::UI::VBox); |
|
|
388 | |
|
|
389 | $self->{label} = [ |
|
|
390 | map |
345 | CFClient::UI::Label->new ( |
391 | CFClient::UI::Label->new ( |
346 | can_hover => 1, |
392 | can_hover => 1, |
347 | can_events => 1, |
393 | can_events => 1, |
|
|
394 | tooltip_width => 0.33, |
348 | fontsize => $_, |
395 | fontsize => $_, |
349 | ), 1, 1, 0.8, 0.8, 0.8, 0.8, 0.8 |
396 | ), (0.8) x 16 |
|
|
397 | ]; |
|
|
398 | |
|
|
399 | $self->{entry} = new CFClient::UI::Entry |
|
|
400 | connect_changed => sub { |
|
|
401 | $self->update_labels; |
350 | ], |
402 | }, |
|
|
403 | connect_key_down => sub { |
|
|
404 | my ($entry, $ev) = @_; |
|
|
405 | |
|
|
406 | my $self = $entry->{parent}{parent}; |
|
|
407 | |
|
|
408 | if ($ev->{sym} == 13) { |
|
|
409 | if (exists $self->{select}) { |
|
|
410 | $::CONN->user_send ($self->{select}); |
|
|
411 | $self->hide; |
|
|
412 | } |
|
|
413 | } elsif ($ev->{sym} == 27) { |
|
|
414 | $self->hide; |
|
|
415 | return; |
|
|
416 | } elsif ($ev->{sym} == CFClient::SDLK_DOWN) { |
|
|
417 | ++$self->{select_offset} |
|
|
418 | if $self->{select_offset} < $#{ $self->{last_match} || [] }; |
|
|
419 | $self->update_labels; |
|
|
420 | } elsif ($ev->{sym} == CFClient::SDLK_UP) { |
|
|
421 | --$self->{select_offset} |
|
|
422 | if $self->{select_offset}; |
|
|
423 | $self->update_labels; |
|
|
424 | } else { |
|
|
425 | return 0; |
|
|
426 | } |
|
|
427 | |
|
|
428 | 1 |
|
|
429 | } |
|
|
430 | ; |
|
|
431 | |
|
|
432 | $self->{vbox}->add ( |
|
|
433 | $self->{entry}, |
|
|
434 | @{$self->{label}}, |
351 | ); |
435 | ); |
352 | |
436 | |
353 | $self |
437 | $self |
|
|
438 | } |
|
|
439 | |
|
|
440 | sub set_prefix { |
|
|
441 | my ($self, $prefix) = @_; |
|
|
442 | |
|
|
443 | $self->{entry}->set_text ($prefix); |
|
|
444 | $self->show; |
354 | } |
445 | } |
355 | |
446 | |
356 | sub size_allocate { |
447 | sub size_allocate { |
357 | my ($self, $w, $h) = @_; |
448 | my ($self, $w, $h) = @_; |
358 | |
449 | |
359 | $self->SUPER::size_allocate ($w, $h); |
450 | $self->SUPER::size_allocate ($w, $h); |
360 | $self->move (($::WIDTH - $w) * 0.5, ($::HEIGHT - $h) * 0.6, 10); |
451 | $self->move (($::WIDTH - $w) * 0.5, ($::HEIGHT - $h) * 0.6, 10); |
361 | } |
452 | } |
362 | |
453 | |
363 | sub update_labels { |
454 | sub show { |
364 | my ($self) = @_; |
455 | my ($self) = @_; |
365 | |
456 | |
366 | my $command = $self->{command}; |
457 | $self->SUPER::show; |
367 | my $search_abbrev = qr/^\Q$self->{search}/; |
458 | $self->{entry}->focus_in; |
368 | my $search_full = qr/\Q$self->{search}/; |
459 | } |
369 | |
460 | |
370 | my @found; |
461 | sub hide { |
|
|
462 | my ($self) = @_; |
371 | |
463 | |
372 | for (@$command) { |
464 | $self->SUPER::hide; |
373 | if ($_->[0] =~ $search_abbrev) { |
|
|
374 | push @found, [$_->[0], $_]; |
|
|
375 | } elsif (2 < length $self->{search} and $_->[1] =~ $search_full) { |
|
|
376 | push @found, [$_->[1], $_]; |
|
|
377 | } |
|
|
378 | } |
|
|
379 | |
|
|
380 | @found = sort { $a->[0] cmp $b->[0] } @found; |
|
|
381 | |
|
|
382 | $self->{children}[0]->set_text ("$self->{search}_"); |
|
|
383 | |
|
|
384 | for (0..5) { |
|
|
385 | $self->{children}[$_ + 1]->set_text ($found[$_] ? "$found[$_][0] ($found[$_][1][1])" : ""); |
|
|
386 | $self->{children}[$_ + 1]{tooltip} = ($found[$_] ? $found[$_][1][2] : ""); |
|
|
387 | } |
|
|
388 | |
|
|
389 | $self->{select} = $found[0][1] |
|
|
390 | if @found; |
|
|
391 | |
|
|
392 | if (@found > 6) { |
|
|
393 | $self->{children}[6]->set_text ("..."); |
465 | $self->{entry}->set_text (""); |
394 | } |
|
|
395 | |
|
|
396 | $self->check_size; |
|
|
397 | } |
466 | } |
398 | |
467 | |
399 | sub key_down { |
468 | sub key_down { |
400 | my ($self, $ev) = @_; |
469 | my ($self, $ev) = @_; |
401 | |
470 | |
402 | if ($ev->{sym} == 8) { |
471 | $self->{entry}->key_down ($ev); |
403 | substr $self->{search}, -1, 1, ""; |
472 | } |
404 | $self->update_labels; |
473 | |
405 | } elsif ($ev->{sym} == 13) { |
474 | sub update_labels { |
406 | if (exists $self->{select}) { |
475 | my ($self) = @_; |
407 | $self->emit (execute => $self->{select}); |
476 | |
408 | $self->emit ("close"); |
477 | my $text = $self->{entry}->get_text; |
|
|
478 | |
|
|
479 | length $text |
|
|
480 | or return $self->hide; |
|
|
481 | |
|
|
482 | my ($cmd, $arg) = $text =~ /^\s*([^[:space:]]*)(.*)$/; |
|
|
483 | |
|
|
484 | if ($text ne $self->{last_search}) { |
|
|
485 | my @match; |
|
|
486 | |
|
|
487 | if ($text =~ /^(.*?)\s+$/) { |
|
|
488 | @match = [$cmd, "(appended whitespace suppresses completion)"]; |
|
|
489 | } else { |
|
|
490 | my $regexp = do { |
|
|
491 | my ($beg, @chr) = split //, lc $cmd; |
|
|
492 | |
|
|
493 | # the following regex is used to match our "completion entry" |
|
|
494 | # to an actual command - the parentheses match kind of "overhead" |
|
|
495 | # - the more characters the parentheses match, the less attractive |
|
|
496 | # is the match. |
|
|
497 | my $regexp = "^\Q$beg\E" |
|
|
498 | . join "", map "(?:.*?[ \\\\]\Q$_\E|(.*?)\Q$_\E)", @chr; |
|
|
499 | qr<$regexp> |
|
|
500 | }; |
|
|
501 | |
|
|
502 | my @penalty; |
|
|
503 | |
|
|
504 | for (keys %{$self->{command}}) { |
|
|
505 | if (@penalty = $_ =~ $regexp) { |
|
|
506 | push @match, [$_, length join "", map "::$_", grep defined, @penalty]; |
|
|
507 | } |
|
|
508 | } |
|
|
509 | |
|
|
510 | @match = map $self->{command}{$_->[0]}, |
|
|
511 | sort { |
|
|
512 | $a->[1] <=> $b->[1] |
|
|
513 | or $self->{command}{$a->[0]}[4] <=> $self->{command}{$b->[0]}[4] |
|
|
514 | or (length $a->[0]) <=> (length $b->[0]) |
|
|
515 | } @match; |
409 | } |
516 | } |
410 | } elsif ($ev->{sym} == 27) { |
517 | |
411 | $self->emit ("close"); |
518 | $self->{last_search} = $cmd; |
412 | return; |
519 | $self->{last_match} = \@match; |
413 | } elsif ((chr $ev->{unicode}) =~ /^[[:alpha:]]$/) { |
520 | |
414 | $self->{search} .= chr $ev->{unicode}; |
521 | $self->{select_offset} = 0; |
|
|
522 | } |
|
|
523 | |
|
|
524 | my @labels = @{ $self->{label} }; |
|
|
525 | my @matches = @{ $self->{last_match} || [] }; |
|
|
526 | |
|
|
527 | if ($self->{select_offset}) { |
|
|
528 | splice @matches, 0, $self->{select_offset}, (); |
|
|
529 | |
|
|
530 | my $label = shift @labels; |
|
|
531 | $label->set_text ("..."); |
|
|
532 | $label->set_tooltip ("Use Cursor-Up to view previous matches"); |
|
|
533 | } |
|
|
534 | |
|
|
535 | for my $label (@labels) { |
|
|
536 | $label->{fg} = [1, 1, 1, 1]; |
|
|
537 | $label->{bg} = [0, 0, 0, 0]; |
|
|
538 | } |
|
|
539 | |
|
|
540 | if (@matches) { |
|
|
541 | $self->{select} = "$matches[0][0]$arg"; |
|
|
542 | |
|
|
543 | $labels[0]->{fg} = [0, 0, 0, 1]; |
|
|
544 | $labels[0]->{bg} = [1, 1, 1, 0.8]; |
|
|
545 | } else { |
|
|
546 | $self->{select} = "$cmd$arg"; |
|
|
547 | } |
|
|
548 | |
|
|
549 | for my $match (@matches) { |
|
|
550 | my $label = shift @labels; |
|
|
551 | |
|
|
552 | if (@labels) { |
|
|
553 | $label->set_text ("$match->[0]$arg"); |
|
|
554 | $label->set_tooltip ($match->[1]); |
|
|
555 | } else { |
|
|
556 | $label->set_text ("..."); |
|
|
557 | $label->set_tooltip ("Use Cursor-Down to view more matches"); |
|
|
558 | last; |
|
|
559 | } |
|
|
560 | } |
|
|
561 | |
|
|
562 | for my $label (@labels) { |
|
|
563 | $label->set_text (""); |
|
|
564 | $label->set_tooltip (""); |
|
|
565 | } |
|
|
566 | |
415 | $self->update_labels; |
567 | $self->update; |
416 | } |
568 | ### |
|
|
569 | } |
417 | |
570 | |
418 | length $self->{search} |
571 | sub _draw { |
419 | or $self->emit ("close"); |
572 | my ($self) = @_; |
|
|
573 | |
|
|
574 | # hack |
|
|
575 | local $CFClient::UI::FOCUS = $self->{entry}; |
|
|
576 | |
|
|
577 | $self->SUPER::_draw; |
420 | } |
578 | } |
421 | |
579 | |
422 | 1 |
580 | 1 |