… | |
… | |
17 | can_focus => 1, |
17 | can_focus => 1, |
18 | list => glGenList, |
18 | list => glGenList, |
19 | @_ |
19 | @_ |
20 | ); |
20 | ); |
21 | |
21 | |
|
|
22 | $self->{completer} = new CFClient::MapWidget::Command:: |
|
|
23 | command => $self->{command}, |
|
|
24 | can_focus => 1, |
|
|
25 | ; |
|
|
26 | |
22 | $self |
27 | $self |
23 | } |
28 | } |
24 | |
29 | |
25 | 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 { |
26 | my $self = shift; |
45 | my ($self) = @_; |
27 | |
46 | |
28 | glDeleteList $self->{list}; |
47 | %{$self->{completer}{command}} = (); |
29 | |
|
|
30 | $self->SUPER::DESTROY; |
|
|
31 | } |
48 | } |
32 | |
49 | |
33 | sub button_down { |
50 | sub button_down { |
34 | my ($self, $ev, $x, $y) = @_; |
51 | my ($self, $ev, $x, $y) = @_; |
35 | |
52 | |
… | |
… | |
76 | |
93 | |
77 | $self->{need_update} = 1; |
94 | $self->{need_update} = 1; |
78 | $self->SUPER::update; |
95 | $self->SUPER::update; |
79 | } |
96 | } |
80 | |
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 | |
81 | sub draw { |
171 | sub draw { |
82 | 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; |
83 | |
179 | |
84 | if (delete $self->{need_update}) { |
180 | if (delete $self->{need_update}) { |
85 | glNewList $self->{list}; |
181 | glNewList $self->{list}; |
86 | |
182 | |
87 | if ($::MAP) { |
183 | if ($::MAP) { |
… | |
… | |
112 | 0.05, 0.13, 0.05, |
208 | 0.05, 0.13, 0.05, |
113 | ); |
209 | ); |
114 | glEnable GL_CONVOLUTION_2D; |
210 | glEnable GL_CONVOLUTION_2D; |
115 | } |
211 | } |
116 | |
212 | |
|
|
213 | $self->{fow_texture_name} ||= glGenTexture; |
|
|
214 | # try to re-use the texture name: TODO improve texture class instead |
|
|
215 | |
117 | $self->{fow_texture} = new CFClient::Texture |
216 | $self->{fow_texture} = new CFClient::Texture |
118 | w => $w, |
217 | w => $w, |
119 | h => $h, |
218 | h => $h, |
120 | data => $data, |
219 | data => $data, |
|
|
220 | name => $self->{fow_texture_name}, |
121 | internalformat => GL_ALPHA, |
221 | internalformat => GL_ALPHA, |
122 | format => GL_ALPHA; |
222 | format => GL_ALPHA; |
123 | |
223 | |
124 | glDisable GL_CONVOLUTION_2D if $::CFG->{fow_smooth}; |
224 | glDisable GL_CONVOLUTION_2D if $::CFG->{fow_smooth}; |
125 | |
225 | |
126 | glEnable GL_BLEND; |
|
|
127 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
128 | glEnable GL_TEXTURE_2D; |
226 | glEnable GL_TEXTURE_2D; |
129 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
227 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
130 | |
228 | |
131 | glColor +($::CFG->{fow_intensity}) x 3, 0.8; |
229 | glColor +($::CFG->{fow_intensity}) x 3, 0.8; |
132 | $self->{fow_texture}->draw_quad (0, 0, $w * 32, $h * 32); |
230 | $self->{fow_texture}->draw_quad_alpha (0, 0, $w * 32, $h * 32); |
133 | |
231 | |
134 | glDisable GL_TEXTURE_2D; |
232 | glDisable GL_TEXTURE_2D; |
135 | glDisable GL_BLEND; |
|
|
136 | } |
233 | } |
137 | |
234 | |
138 | glPopMatrix; |
235 | glPopMatrix; |
139 | } |
236 | } |
140 | |
237 | |
… | |
… | |
143 | |
240 | |
144 | glPushMatrix; |
241 | glPushMatrix; |
145 | glCallList $self->{list}; |
242 | glCallList $self->{list}; |
146 | glPopMatrix; |
243 | glPopMatrix; |
147 | |
244 | |
148 | if ($CFClient::UI::FOCUS != $self) { |
245 | # TNT2 emulates logops in software (or worse :) |
149 | glColor 64/255, 64/255, 64/255; |
246 | if ($focused) { |
150 | glLogicOp GL_AND; |
247 | (delete $self->{out_of_focus})->destroy |
151 | 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; |
152 | glBegin GL_QUADS; |
253 | glBegin GL_QUADS; |
153 | glVertex 0, 0; |
254 | glVertex 0, 0; |
154 | glVertex 0, $::HEIGHT; |
255 | glVertex 0, $::HEIGHT; |
155 | glVertex $::WIDTH, $::HEIGHT; |
256 | glVertex $::WIDTH, $::HEIGHT; |
156 | glVertex $::WIDTH, 0; |
257 | glVertex $::WIDTH, 0; |
157 | glEnd; |
258 | glEnd; |
158 | glDisable GL_COLOR_LOGIC_OP; |
259 | glDisable GL_BLEND; |
159 | } |
|
|
160 | } |
|
|
161 | |
260 | |
162 | my %DIR = ( |
261 | $self->{out_of_focus} ||= do { |
163 | CFClient::SDLK_KP8, [1, "north"], |
262 | my $label = new CFClient::UI::Label |
164 | CFClient::SDLK_KP9, [2, "northeast"], |
263 | x => 0, |
165 | CFClient::SDLK_KP6, [3, "east"], |
264 | y => 0, |
166 | CFClient::SDLK_KP3, [4, "southeast"], |
265 | z => 1, |
167 | CFClient::SDLK_KP2, [5, "south"], |
266 | ellipsise => 0, |
168 | CFClient::SDLK_KP1, [6, "southwest"], |
267 | text => "map out of focus (click map to play)"; |
169 | CFClient::SDLK_KP4, [7, "west"], |
|
|
170 | CFClient::SDLK_KP7, [8, "northwest"], |
|
|
171 | |
268 | |
172 | CFClient::SDLK_UP, [1, "north"], |
269 | $label->show; |
173 | CFClient::SDLK_RIGHT, [3, "east"], |
270 | $label->update; |
174 | CFClient::SDLK_DOWN, [5, "south"], |
|
|
175 | CFClient::SDLK_LEFT, [7, "west"], |
|
|
176 | ); |
|
|
177 | |
271 | |
178 | sub key_down { |
272 | $CFClient::UI::ROOT->on_post_alloc ("$self$label" => sub { |
179 | my ($self, $ev) = @_; |
273 | $label->move ( |
|
|
274 | ($::WIDTH - $label->{w}) * 0.5, |
|
|
275 | ($::HEIGHT - $label->{h}) * 0.5, |
|
|
276 | ); |
|
|
277 | }); |
180 | |
278 | |
181 | return unless $::CONN; |
279 | $label |
182 | |
|
|
183 | my $mod = $ev->{mod}; |
|
|
184 | my $sym = $ev->{sym}; |
|
|
185 | my $uni = $ev->{unicode}; |
|
|
186 | |
|
|
187 | if ($sym == CFClient::SDLK_KP5) { |
|
|
188 | $::CONN->user_send ("stay fire"); |
|
|
189 | } elsif ($uni == ord ",") { |
|
|
190 | $::CONN->user_send ("take"); |
|
|
191 | } elsif ($uni == ord "\t") { |
|
|
192 | $::CONN->user_send ("apply"); |
|
|
193 | } elsif ($uni == ord "'") { |
|
|
194 | $self->emit ('activate_console'); |
|
|
195 | } elsif ($uni == ord "/") { |
|
|
196 | $self->emit (activate_console => '/'); |
|
|
197 | } elsif (exists $DIR{$sym}) { |
|
|
198 | if ($mod & CFClient::KMOD_SHIFT) { |
|
|
199 | $self->{shft}++; |
|
|
200 | $::CONN->user_send ("fire $DIR{$sym}[0]"); |
|
|
201 | } elsif ($mod & CFClient::KMOD_CTRL) { |
|
|
202 | $self->{ctrl}++; |
|
|
203 | $::CONN->user_send ("run $DIR{$sym}[0]"); |
|
|
204 | } else { |
|
|
205 | $::CONN->user_send ("$DIR{$sym}[1]"); |
|
|
206 | } |
280 | }; |
207 | } elsif ($ev->{unicode}) { |
|
|
208 | $self->{command_widget} ||= |
|
|
209 | new CFClient::MapWidget::Command:: |
|
|
210 | command => $self->{command}, |
|
|
211 | can_focus => 1, |
|
|
212 | connect_execute => sub { |
|
|
213 | # todo: support callback instead of user_send |
|
|
214 | $::CONN->user_send ($_[1]); |
|
|
215 | }, |
|
|
216 | connect_close => sub { |
|
|
217 | (delete $self->{command_widget})->hide; |
|
|
218 | $self->focus_in; |
|
|
219 | }, |
|
|
220 | ; |
|
|
221 | $self->{command_widget}->key_down ($ev) |
|
|
222 | unless $ev->{unicode} == 20; |
|
|
223 | return unless $self->{command_widget}; |
|
|
224 | $self->{command_widget}->show; |
|
|
225 | $self->{command_widget}->focus_in; |
|
|
226 | } |
281 | } |
227 | } |
282 | } |
228 | |
283 | |
229 | sub key_up { |
284 | sub DESTROY { |
230 | my ($self, $ev) = @_; |
|
|
231 | |
|
|
232 | my $mod = $ev->{mod}; |
|
|
233 | my $sym = $ev->{sym}; |
|
|
234 | |
|
|
235 | if (!($mod & CFClient::KMOD_SHIFT) && delete $self->{shft}) { |
|
|
236 | $::CONN->user_send ("fire_stop"); |
|
|
237 | } |
|
|
238 | if (!($mod & CFClient::KMOD_CTRL ) && delete $self->{ctrl}) { |
|
|
239 | $::CONN->user_send ("run_stop"); |
|
|
240 | } |
|
|
241 | } |
|
|
242 | |
|
|
243 | sub add_command { |
|
|
244 | my ($self, $command, $tooltip, $widget, $cb) = @_; |
|
|
245 | |
|
|
246 | (my $data = $command) =~ s/\\//g; |
|
|
247 | |
|
|
248 | $tooltip =~ s/^\s+//; |
|
|
249 | |
|
|
250 | $tooltip = "<big>" . (CFClient::UI::Label::escape $data) . "</big>\n\n" |
|
|
251 | . CFClient::UI::Label::escape $tooltip; |
|
|
252 | |
|
|
253 | $tooltip =~ s/\s+$//; |
|
|
254 | |
|
|
255 | $self->{command}{$command} = [$data, $tooltip, $widget, $cb]; |
|
|
256 | } |
|
|
257 | |
|
|
258 | sub clr_commands { |
|
|
259 | my ($self) = @_; |
285 | my $self = shift; |
260 | |
286 | |
261 | %{$self->{command}} = (); |
287 | glDeleteList $self->{list}; |
|
|
288 | |
|
|
289 | $self->SUPER::DESTROY; |
262 | } |
290 | } |
263 | |
291 | |
264 | package CFClient::MapWidget::MapMap; |
292 | package CFClient::MapWidget::MapMap; |
265 | |
293 | |
266 | our @ISA = CFClient::UI::Base::; |
294 | our @ISA = CFClient::UI::Base::; |
… | |
… | |
359 | $self->add ($self->{vbox} = new CFClient::UI::VBox); |
387 | $self->add ($self->{vbox} = new CFClient::UI::VBox); |
360 | |
388 | |
361 | $self->{label} = [ |
389 | $self->{label} = [ |
362 | map |
390 | map |
363 | CFClient::UI::Label->new ( |
391 | CFClient::UI::Label->new ( |
364 | can_hover => 1, |
392 | can_hover => 1, |
365 | can_events => 1, |
393 | can_events => 1, |
|
|
394 | tooltip_width => 0.33, |
366 | fontsize => $_, |
395 | fontsize => $_, |
367 | ), (0.8) x 6 |
396 | ), (0.8) x 16 |
368 | ]; |
397 | ]; |
369 | |
398 | |
370 | $self->{entry} = new CFClient::UI::Entry |
399 | $self->{entry} = new CFClient::UI::Entry |
371 | connect_changed => sub { |
400 | connect_changed => sub { |
372 | $self->update_labels; |
401 | $self->update_labels; |
|
|
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 |
373 | }; |
429 | } |
|
|
430 | ; |
374 | |
431 | |
375 | $self->{vbox}->add ( |
432 | $self->{vbox}->add ( |
376 | $self->{entry}, |
433 | $self->{entry}, |
377 | @{$self->{label}}, |
434 | @{$self->{label}}, |
378 | ); |
435 | ); |
379 | |
436 | |
380 | $self |
437 | $self |
381 | } |
438 | } |
382 | |
439 | |
|
|
440 | sub set_prefix { |
|
|
441 | my ($self, $prefix) = @_; |
|
|
442 | |
|
|
443 | $self->{entry}->set_text ($prefix); |
|
|
444 | $self->show; |
|
|
445 | } |
|
|
446 | |
383 | sub size_allocate { |
447 | sub size_allocate { |
384 | my ($self, $w, $h) = @_; |
448 | my ($self, $w, $h) = @_; |
385 | |
449 | |
386 | $self->SUPER::size_allocate ($w, $h); |
450 | $self->SUPER::size_allocate ($w, $h); |
387 | $self->move (($::WIDTH - $w) * 0.5, ($::HEIGHT - $h) * 0.6, 10); |
451 | $self->move (($::WIDTH - $w) * 0.5, ($::HEIGHT - $h) * 0.6, 10); |
388 | } |
452 | } |
389 | |
453 | |
|
|
454 | sub show { |
|
|
455 | my ($self) = @_; |
|
|
456 | |
|
|
457 | $self->SUPER::show; |
|
|
458 | $self->{entry}->focus_in; |
|
|
459 | } |
|
|
460 | |
|
|
461 | sub hide { |
|
|
462 | my ($self) = @_; |
|
|
463 | |
|
|
464 | $self->SUPER::hide; |
|
|
465 | $self->{entry}->set_text (""); |
|
|
466 | } |
|
|
467 | |
390 | sub key_down { |
468 | sub key_down { |
391 | my ($self, $ev) = @_; |
469 | my ($self, $ev) = @_; |
392 | |
470 | |
393 | if ($ev->{sym} == 13) { |
471 | $self->{entry}->key_down ($ev); |
394 | if (exists $self->{select}) { |
472 | } |
395 | $self->emit (execute => $self->{select}); |
473 | |
396 | $self->emit ("close"); |
474 | sub update_labels { |
|
|
475 | my ($self) = @_; |
|
|
476 | |
|
|
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; |
397 | } |
516 | } |
398 | } elsif ($ev->{sym} == 27) { |
|
|
399 | $self->{entry}->set_text (""); |
|
|
400 | $self->emit ("close"); |
|
|
401 | return; |
|
|
402 | } elsif ($ev->{sym} == CFClient::SDLK_DOWN) { |
|
|
403 | ++$self->{select_offset} |
|
|
404 | if $self->{select_offset} < $#{ $self->{last_match} || [] }; |
|
|
405 | $self->update_labels; |
|
|
406 | } elsif ($ev->{sym} == CFClient::SDLK_UP) { |
|
|
407 | --$self->{select_offset} |
|
|
408 | if $self->{select_offset}; |
|
|
409 | $self->update_labels; |
|
|
410 | } else { |
|
|
411 | #$self->{entry}{force_alloc} = 1; |
|
|
412 | $self->{entry}->key_down ($ev); |
|
|
413 | } |
|
|
414 | } |
|
|
415 | |
|
|
416 | sub update_labels { |
|
|
417 | my ($self) = @_; |
|
|
418 | |
|
|
419 | my $text = $self->{entry}->get_text; |
|
|
420 | |
|
|
421 | length $text |
|
|
422 | or return $self->emit ("close"); |
|
|
423 | |
|
|
424 | my ($cmd, $arg) = $text =~ /^\s*([^[:space:]]*)(.*)$/; |
|
|
425 | |
|
|
426 | if ($cmd ne $self->{last_search}) { |
|
|
427 | my $regexp = do { |
|
|
428 | my ($beg, @chr) = split //, lc $cmd; |
|
|
429 | |
|
|
430 | # the following regex is used to match our "completion entry" |
|
|
431 | # to an actual command - the parentheses match kind of "overhead" |
|
|
432 | # - the more characters the parentheses match, the less attractive |
|
|
433 | # is the match. |
|
|
434 | my $regexp = "^\Q$beg\E" |
|
|
435 | . join "", map "(?:.*?[ \\\\]\Q$_\E|(.*?)\Q$_\E)", @chr; |
|
|
436 | qr<$regexp> |
|
|
437 | }; |
|
|
438 | |
|
|
439 | my @match; |
|
|
440 | my @penalty; |
|
|
441 | |
|
|
442 | for (keys %{$self->{command}}) { |
|
|
443 | if (@penalty = $_ =~ $regexp) { |
|
|
444 | push @match, [$_, length join "", map "::$_", grep defined, @penalty]; |
|
|
445 | } |
|
|
446 | } |
|
|
447 | |
|
|
448 | @match = map $self->{command}{$_->[0]}, |
|
|
449 | sort { |
|
|
450 | $a->[1] <=> $b->[1] |
|
|
451 | or (length $a->[0]) <=> (length $b->[0]) |
|
|
452 | } @match; |
|
|
453 | |
517 | |
454 | $self->{last_search} = $cmd; |
518 | $self->{last_search} = $cmd; |
455 | $self->{last_match} = \@match; |
519 | $self->{last_match} = \@match; |
456 | |
520 | |
457 | $self->{select_offset} = 0; |
521 | $self->{select_offset} = 0; |