1 | package CFClient::MapWidget; |
1 | package CFPlus::MapWidget; |
2 | |
2 | |
3 | use strict; |
3 | use strict; |
4 | use utf8; |
4 | use utf8; |
5 | |
5 | |
6 | use List::Util qw(min max); |
6 | use List::Util qw(min max); |
7 | |
7 | |
|
|
8 | use CFPlus; |
8 | use CFClient::OpenGL; |
9 | use CFPlus::OpenGL; |
|
|
10 | use CFPlus::UI; |
9 | |
11 | |
10 | our @ISA = CFClient::UI::Base::; |
12 | our @ISA = CFPlus::UI::Base::; |
|
|
13 | |
|
|
14 | my $magicmap_tex = |
|
|
15 | new_from_file CFPlus::Texture CFPlus::find_rcfile "magicmap.png", |
|
|
16 | mipmap => 1, wrap => 0, internalformat => GL_ALPHA; |
11 | |
17 | |
12 | sub new { |
18 | sub new { |
13 | my $class = shift; |
19 | my $class = shift; |
14 | |
20 | |
15 | my $self = $class->SUPER::new ( |
21 | my $self = $class->SUPER::new ( |
16 | z => -1, |
22 | z => -1, |
17 | can_focus => 1, |
23 | can_focus => 1, |
18 | list => glGenList, |
24 | list => glGenList, |
|
|
25 | |
|
|
26 | smooth_matrix => [ |
|
|
27 | 0.05, 0.13, 0.05, |
|
|
28 | 0.13, 0.30, 0.13, |
|
|
29 | 0.05, 0.13, 0.05, |
|
|
30 | ], |
|
|
31 | |
19 | @_ |
32 | @_ |
20 | ); |
33 | ); |
21 | |
34 | |
22 | $self->add_command ("killpets", "kills all your summoned and charmed creates"); |
35 | $self->{completer} = new CFPlus::MapWidget::Command:: |
|
|
36 | command => $self->{command}, |
|
|
37 | tooltip => "#completer_help", |
|
|
38 | ; |
23 | |
39 | |
24 | $self |
40 | $self |
25 | } |
41 | } |
26 | |
42 | |
27 | sub DESTROY { |
43 | sub add_command { |
|
|
44 | my ($self, $command, $tooltip, $widget, $cb) = @_; |
|
|
45 | |
|
|
46 | (my $data = $command) =~ s/\\//g; |
|
|
47 | |
|
|
48 | $tooltip =~ s/^\s+//; |
|
|
49 | $tooltip = "<big>$data</big>\n\n$tooltip"; |
|
|
50 | $tooltip =~ s/\s+$//; |
|
|
51 | |
|
|
52 | $self->{completer}{command}{$command} = [$data, $tooltip, $widget, $cb, ++$self->{command_id}]; |
|
|
53 | } |
|
|
54 | |
|
|
55 | sub clr_commands { |
28 | my $self = shift; |
56 | my ($self) = @_; |
29 | |
57 | |
30 | glDeleteList $self->{list}; |
58 | %{$self->{completer}{command}} = (); |
31 | |
59 | |
32 | $self->SUPER::DESTROY; |
60 | $self->{completer}->hide |
|
|
61 | if $self->{completer}; |
33 | } |
62 | } |
34 | |
63 | |
|
|
64 | sub test_server_login { |
|
|
65 | return unless |
|
|
66 | $::CONN && length $::CONN->{test_server}; |
|
|
67 | |
|
|
68 | my $server = $::CONN->{test_server}; |
|
|
69 | ::stop_game (); |
|
|
70 | local $::PROFILE->{host} = $server; |
|
|
71 | ::start_game (); |
|
|
72 | } |
|
|
73 | |
|
|
74 | sub editor_invoke { |
|
|
75 | return unless $::CONN; |
|
|
76 | |
|
|
77 | # putting the password into the env is somewhat tasteless |
|
|
78 | local $ENV{CFPLUS_LOGIN} = $::PROFILE->{user}; |
|
|
79 | local $ENV{CFPLUS_PASSWORD} = $::PROFILE->{password}; |
|
|
80 | local $ENV{CFPLUS_UPLOAD} = $::CONN->{upload}; |
|
|
81 | local $ENV{CROSSFIRE_MAPDIR} = $::CONN->{cvs_root}; |
|
|
82 | |
|
|
83 | # CFPlus::set_proxy; |
|
|
84 | |
|
|
85 | # TODO: move into editor |
|
|
86 | require LWP::Simple; |
|
|
87 | } |
|
|
88 | |
35 | sub button_down { |
89 | sub invoke_button_down { |
36 | my ($self, $ev, $x, $y) = @_; |
90 | my ($self, $ev, $x, $y) = @_; |
37 | |
91 | |
38 | $self->focus_in; |
|
|
39 | |
|
|
40 | if ($ev->{button} == 2) { |
92 | if ($ev->{button} == 1) { |
|
|
93 | $self->grab_focus; |
|
|
94 | return unless $::CONN; |
|
|
95 | |
|
|
96 | my $x = 1 + CFPlus::floor +($ev->{x} - $self->{sx0}) / $self->{tilesize} - $self->{sx}; |
|
|
97 | my $y = 1 + CFPlus::floor +($ev->{y} - $self->{sy0}) / $self->{tilesize} - $self->{sy}; |
|
|
98 | |
|
|
99 | $x -= int 0.5 * $self->{sw}; |
|
|
100 | $y -= int 0.5 * $self->{sh}; |
|
|
101 | |
|
|
102 | $::CONN->lookat ($x, $y) |
|
|
103 | if $::CONN; |
|
|
104 | |
|
|
105 | } elsif ($ev->{button} == 2) { |
|
|
106 | $self->grab_focus; |
|
|
107 | return unless $::CONN; |
|
|
108 | |
41 | my ($ox, $oy) = ($ev->{x}, $ev->{y}); |
109 | my ($ox, $oy) = ($ev->{x}, $ev->{y}); |
42 | my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y}); |
110 | my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y}); |
43 | |
111 | |
44 | $self->{motion} = sub { |
112 | $self->{motion} = sub { |
45 | my ($ev, $x, $y) = @_; |
113 | my ($ev, $x, $y) = @_; |
… | |
… | |
49 | $::CFG->{map_shift_x} = $bw + $x - $ox; |
117 | $::CFG->{map_shift_x} = $bw + $x - $ox; |
50 | $::CFG->{map_shift_y} = $bh + $y - $oy; |
118 | $::CFG->{map_shift_y} = $bh + $y - $oy; |
51 | |
119 | |
52 | $self->update; |
120 | $self->update; |
53 | }; |
121 | }; |
|
|
122 | } elsif ($ev->{button} == 3) { |
|
|
123 | (new CFPlus::UI::Menu |
|
|
124 | items => [ |
|
|
125 | ["Help Browser…\tF1", sub { $::HELP_WINDOW->toggle_visibility }], |
|
|
126 | ["Statistics\tF2", sub { ::toggle_player_page ($::STATS_PAGE) }], |
|
|
127 | ["Skills\tF3", sub { ::toggle_player_page ($::SKILL_PAGE) }], |
|
|
128 | ["Spells…\tF4", sub { ::toggle_player_page ($::SPELL_PAGE) }], |
|
|
129 | ["Inventory…\tF5", sub { ::toggle_player_page ($::INVENTORY_PAGE) }], |
|
|
130 | ["Setup… \tF9", sub { $::SETUP_DIALOG->toggle_visibility }], |
|
|
131 | ["Server Messages…", sub { $::MESSAGE_WINDOW->toggle_visibility }], |
|
|
132 | [ |
|
|
133 | $::PICKUP_ENABLE->{state} |
|
|
134 | ? "Disable automatic pickup" |
|
|
135 | : "Enable automatic pickup", |
|
|
136 | sub { $::PICKUP_ENABLE->toggle } |
|
|
137 | ], |
|
|
138 | $::CONN && length $::CONN->{cvs_root} |
|
|
139 | ? ["Edit this map <span size='xx-small'>(" . (CFPlus::asxml $::CONN->{map_info}[0]) . ")</span>", \&editor_invoke] |
|
|
140 | : (), |
|
|
141 | $::CONN && length $::CONN->{test_server} |
|
|
142 | ? ["Login on Test Server", \&test_server_login] |
|
|
143 | : (), |
|
|
144 | ["Quit", |
|
|
145 | sub { |
|
|
146 | if ($::CONN) { |
|
|
147 | &::open_quit_dialog; |
|
|
148 | } else { |
|
|
149 | exit; |
|
|
150 | } |
|
|
151 | } |
|
|
152 | ], |
|
|
153 | ], |
|
|
154 | )->popup ($ev); |
|
|
155 | } |
|
|
156 | |
54 | } |
157 | 1 |
55 | } |
158 | } |
56 | |
159 | |
57 | sub button_up { |
160 | sub invoke_button_up { |
58 | my ($self, $ev, $x, $y) = @_; |
161 | my ($self, $ev, $x, $y) = @_; |
59 | |
162 | |
60 | delete $self->{motion}; |
163 | delete $self->{motion}; |
61 | } |
|
|
62 | |
164 | |
|
|
165 | 1 |
|
|
166 | } |
|
|
167 | |
63 | sub mouse_motion { |
168 | sub invoke_mouse_motion { |
64 | my ($self, $ev, $x, $y) = @_; |
169 | my ($self, $ev, $x, $y) = @_; |
65 | |
170 | |
|
|
171 | if ($self->{motion}) { |
66 | $self->{motion}->($ev, $x, $y) if $self->{motion}; |
172 | $self->{motion}->($ev, $x, $y); |
|
|
173 | } else { |
|
|
174 | return 0; |
|
|
175 | } |
|
|
176 | |
|
|
177 | 1 |
67 | } |
178 | } |
68 | |
179 | |
69 | sub size_request { |
180 | sub size_request { |
70 | ( |
181 | ( |
71 | 1 + 32 * int $::WIDTH / 32, |
182 | 32 * CFPlus::ceil $::WIDTH / 32, |
72 | 1 + 32 * int $::HEIGHT / 32, |
183 | 32 * CFPlus::ceil $::HEIGHT / 32, |
73 | ) |
184 | ) |
74 | } |
185 | } |
75 | |
186 | |
76 | sub update { |
187 | sub update { |
77 | my ($self) = @_; |
188 | my ($self) = @_; |
78 | |
189 | |
79 | $self->{need_update} = 1; |
190 | $self->{need_update} = 1; |
80 | $self->SUPER::update; |
191 | $self->SUPER::update; |
81 | } |
192 | } |
82 | |
193 | |
|
|
194 | my %DIR = ( |
|
|
195 | CFPlus::SDLK_KP8, [1, "north"], |
|
|
196 | CFPlus::SDLK_KP9, [2, "northeast"], |
|
|
197 | CFPlus::SDLK_KP6, [3, "east"], |
|
|
198 | CFPlus::SDLK_KP3, [4, "southeast"], |
|
|
199 | CFPlus::SDLK_KP2, [5, "south"], |
|
|
200 | CFPlus::SDLK_KP1, [6, "southwest"], |
|
|
201 | CFPlus::SDLK_KP4, [7, "west"], |
|
|
202 | CFPlus::SDLK_KP7, [8, "northwest"], |
|
|
203 | |
|
|
204 | CFPlus::SDLK_UP, [1, "north"], |
|
|
205 | CFPlus::SDLK_RIGHT, [3, "east"], |
|
|
206 | CFPlus::SDLK_DOWN, [5, "south"], |
|
|
207 | CFPlus::SDLK_LEFT, [7, "west"], |
|
|
208 | ); |
|
|
209 | |
|
|
210 | sub invoke_key_down { |
|
|
211 | my ($self, $ev) = @_; |
|
|
212 | |
|
|
213 | my $mod = $ev->{mod}; |
|
|
214 | my $sym = $ev->{sym}; |
|
|
215 | my $uni = $ev->{unicode}; |
|
|
216 | |
|
|
217 | $mod &= CFPlus::KMOD_CTRL | CFPlus::KMOD_ALT | CFPlus::KMOD_SHIFT; |
|
|
218 | |
|
|
219 | if ($uni == ord "\t") { |
|
|
220 | $::PL_WINDOW->toggle_visibility; |
|
|
221 | } elsif ($sym == CFPlus::SDLK_F1 && !$mod) { |
|
|
222 | $::HELP_WINDOW->toggle_visibility; |
|
|
223 | } elsif ($sym == CFPlus::SDLK_F2 && !$mod) { |
|
|
224 | ::toggle_player_page ($::STATS_PAGE); |
|
|
225 | } elsif ($sym == CFPlus::SDLK_F3 && !$mod) { |
|
|
226 | ::toggle_player_page ($::SKILL_PAGE); |
|
|
227 | } elsif ($sym == CFPlus::SDLK_F4 && !$mod) { |
|
|
228 | ::toggle_player_page ($::SPELL_PAGE); |
|
|
229 | } elsif ($sym == CFPlus::SDLK_F5 && !$mod) { |
|
|
230 | ::toggle_player_page ($::INVENTORY_PAGE); |
|
|
231 | } elsif ($sym == CFPlus::SDLK_F9 && !$mod) { |
|
|
232 | $::SETUP_DIALOG->toggle_visibility; |
|
|
233 | } elsif ($sym == CFPlus::SDLK_INSERT && $mod & CFPlus::KMOD_CTRL) { |
|
|
234 | $::BIND_EDITOR->set_binding (undef, undef, [], |
|
|
235 | sub { |
|
|
236 | my ($mod, $sym, $cmds) = @_; |
|
|
237 | $::BIND_EDITOR->cfg_bind ($mod, $sym, $cmds); |
|
|
238 | }); |
|
|
239 | $::BIND_EDITOR->start; |
|
|
240 | $::BIND_EDITOR->show; |
|
|
241 | #TODO: elmex, what was this supposed to do? it currently crashes the client. |
|
|
242 | # } elsif ($sym == CFPlus::SDLK_INSERT && not ($mod & CFPlus::KMOD_CTRL)) { |
|
|
243 | # $::BIND_EDITOR->stop; |
|
|
244 | # $::BIND_EDITOR->ask_for_bind_and_commit; |
|
|
245 | # $::BIND_EDITOR->hide; |
|
|
246 | } elsif (!$::CONN) { |
|
|
247 | return 0; # bindings further down need a valid connection |
|
|
248 | |
|
|
249 | } elsif ($sym == CFPlus::SDLK_KP5 && !$mod) { |
|
|
250 | $::CONN->user_send ("stay fire"); |
|
|
251 | } elsif ($uni == ord ",") { |
|
|
252 | $::CONN->user_send ("take"); |
|
|
253 | } elsif ($uni == ord " ") { |
|
|
254 | $::CONN->user_send ("apply"); |
|
|
255 | } elsif ($uni == 13) { |
|
|
256 | $::CONN->user_send ("examine"); |
|
|
257 | } elsif ($uni == ord ".") { |
|
|
258 | $::CONN->user_send ($self->{completer}{last_command}) |
|
|
259 | if exists $self->{completer}{last_command}; |
|
|
260 | } elsif (my $bind_cmd = $::PROFILE->{bindings}{$mod}{$sym}) { |
|
|
261 | $::CONN->user_send ($_) for @$bind_cmd; |
|
|
262 | } elsif (($sym == CFPlus::SDLK_KP_PLUS && !$mod) || $uni == ord "+") { |
|
|
263 | $::CONN->user_send ("rotateshoottype +"); |
|
|
264 | } elsif (($sym == CFPlus::SDLK_KP_MINUS && !$mod) || $uni == ord "-") { |
|
|
265 | $::CONN->user_send ("rotateshoottype -"); |
|
|
266 | } elsif ($uni == ord '"') { |
|
|
267 | $self->{completer}->set_prefix ("$::CFG->{say_command} "); |
|
|
268 | $self->{completer}->show; |
|
|
269 | } elsif ($uni == ord "'") { |
|
|
270 | $self->{completer}->set_prefix (""); |
|
|
271 | $self->{completer}->show; |
|
|
272 | } elsif (exists $DIR{$sym}) { |
|
|
273 | if ($mod & CFPlus::KMOD_SHIFT) { |
|
|
274 | $self->{shft}++; |
|
|
275 | if ($DIR{$sym}[0] != $self->{fire_dir}) { |
|
|
276 | $::CONN->user_send ("fire $DIR{$sym}[0]"); |
|
|
277 | } |
|
|
278 | $self->{fire_dir} = $DIR{$sym}[0]; |
|
|
279 | } elsif ($mod & CFPlus::KMOD_CTRL) { |
|
|
280 | $self->{ctrl}++; |
|
|
281 | $::CONN->user_send ("run $DIR{$sym}[0]"); |
|
|
282 | } else { |
|
|
283 | $::CONN->user_send ("$DIR{$sym}[1]"); |
|
|
284 | } |
|
|
285 | } elsif ((ord 'a') <= $uni && $uni <= (ord 'z')) { |
|
|
286 | $self->{completer}->inject_key_down ($ev); |
|
|
287 | $self->{completer}->show; |
|
|
288 | } else { |
|
|
289 | return 0; |
|
|
290 | } |
|
|
291 | |
|
|
292 | 1 |
|
|
293 | } |
|
|
294 | |
|
|
295 | sub invoke_key_up { |
|
|
296 | my ($self, $ev) = @_; |
|
|
297 | |
|
|
298 | my $res = 0; |
|
|
299 | my $mod = $ev->{mod}; |
|
|
300 | my $sym = $ev->{sym}; |
|
|
301 | |
|
|
302 | if ($::CFG->{shift_fire_stop}) { |
|
|
303 | if (!($mod & CFPlus::KMOD_SHIFT) && delete $self->{shft}) { |
|
|
304 | $::CONN->user_send ("fire_stop"); |
|
|
305 | delete $self->{fire_dir}; |
|
|
306 | $res = 1; |
|
|
307 | } |
|
|
308 | } else { |
|
|
309 | if (exists $DIR{$sym} && delete $self->{shft}) { |
|
|
310 | $::CONN->user_send ("fire_stop"); |
|
|
311 | delete $self->{fire_dir}; |
|
|
312 | $res = 1; |
|
|
313 | } elsif (($sym == CFPlus::SDLK_LSHIFT || $sym == CFPlus::SDLK_RSHIFT) && delete $self->{shft}) { # XXX: is RSHIFT ok? |
|
|
314 | $::CONN->user_send ("fire_stop"); |
|
|
315 | delete $self->{fire_dir}; |
|
|
316 | $res = 1; |
|
|
317 | } |
|
|
318 | } |
|
|
319 | |
|
|
320 | if (!($mod & CFPlus::KMOD_CTRL ) && delete $self->{ctrl}) { |
|
|
321 | $::CONN->user_send ("run_stop"); |
|
|
322 | $res = 1; |
|
|
323 | } |
|
|
324 | |
|
|
325 | $res |
|
|
326 | } |
|
|
327 | |
|
|
328 | sub set_magicmap { |
|
|
329 | my ($self, $w, $h, $x, $y, $data) = @_; |
|
|
330 | |
|
|
331 | $x -= $::MAP->ox + int 0.5 * $::MAP->w; |
|
|
332 | $y -= $::MAP->oy + int 0.5 * $::MAP->h; |
|
|
333 | |
|
|
334 | $self->{magicmap} = [$x, $y, $w, $h, $data]; |
|
|
335 | |
|
|
336 | $self->update; |
|
|
337 | } |
|
|
338 | |
83 | sub draw { |
339 | sub draw { |
84 | my ($self) = @_; |
340 | my ($self) = @_; |
85 | |
341 | |
|
|
342 | return unless $::MAP; |
|
|
343 | |
|
|
344 | my $focused = $CFPlus::UI::FOCUS == $self |
|
|
345 | || $CFPlus::UI::FOCUS == $self->{completer}{entry}; |
|
|
346 | |
|
|
347 | return |
|
|
348 | unless $focused || !$::FAST; |
|
|
349 | |
86 | if (delete $self->{need_update}) { |
350 | if (delete $self->{need_update}) { |
|
|
351 | my $tilesize = $self->{tilesize} = int 32 * $::CFG->{map_scale}; |
|
|
352 | |
|
|
353 | my $sx = $self->{sx} = CFPlus::ceil $::CFG->{map_shift_x} / $tilesize; |
|
|
354 | my $sy = $self->{sy} = CFPlus::ceil $::CFG->{map_shift_y} / $tilesize; |
|
|
355 | |
|
|
356 | my $sx0 = $self->{sx0} = $::CFG->{map_shift_x} - $sx * $tilesize; |
|
|
357 | my $sy0 = $self->{sy0} = $::CFG->{map_shift_y} - $sy * $tilesize; |
|
|
358 | |
|
|
359 | my $sw = $self->{sw} = 1 + CFPlus::ceil $self->{w} / $tilesize; |
|
|
360 | my $sh = $self->{sh} = 1 + CFPlus::ceil $self->{h} / $tilesize; |
|
|
361 | |
|
|
362 | if ($::CFG->{fow_enable}) { |
|
|
363 | my ($w, $h, $data) = $::MAP->fow_texture ($sx, $sy, 0, 0, $sw, $sh); |
|
|
364 | |
|
|
365 | if ($::CFG->{fow_smooth} && $CFPlus::OpenGL::GL_VERSION >= 1.2) { # smooth fog of war |
|
|
366 | glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER); |
|
|
367 | glConvolutionFilter2D ( |
|
|
368 | GL_CONVOLUTION_2D, |
|
|
369 | GL_ALPHA, |
|
|
370 | 3, 3, |
|
|
371 | GL_ALPHA, GL_FLOAT, |
|
|
372 | (pack "f*", @{ $self->{smooth_matrix} }), |
|
|
373 | ); |
|
|
374 | glEnable GL_CONVOLUTION_2D; |
|
|
375 | } |
|
|
376 | |
|
|
377 | $self->{fow_texture} = new CFPlus::Texture |
|
|
378 | w => $w, |
|
|
379 | h => $h, |
|
|
380 | data => $data, |
|
|
381 | internalformat => GL_ALPHA, |
|
|
382 | format => GL_ALPHA; |
|
|
383 | |
|
|
384 | glDisable GL_CONVOLUTION_2D if $::CFG->{fow_smooth}; |
|
|
385 | } else { |
|
|
386 | delete $self->{fow_texture}; |
|
|
387 | } |
|
|
388 | |
87 | glNewList $self->{list}; |
389 | glNewList $self->{list}; |
88 | |
390 | |
89 | if ($::MAP) { |
|
|
90 | my $sw = int $::WIDTH / (32 * $::CFG->{map_scale}) + 0.99; |
|
|
91 | my $sh = int $::HEIGHT / (32 * $::CFG->{map_scale}) + 0.99; |
|
|
92 | |
|
|
93 | my $sx = $::CFG->{map_shift_x} / $::CFG->{map_scale}; my $sx0 = $sx & 31; $sx = ($sx - $sx0) / 32; |
|
|
94 | my $sy = $::CFG->{map_shift_y} / $::CFG->{map_scale}; my $sy0 = $sy & 31; $sy = ($sy - $sy0) / 32; |
|
|
95 | |
|
|
96 | glPushMatrix; |
391 | glPushMatrix; |
|
|
392 | glTranslate $sx0, $sy0; |
97 | glScale $::CFG->{map_scale}, $::CFG->{map_scale}; |
393 | glScale $::CFG->{map_scale}, $::CFG->{map_scale}; |
98 | |
394 | |
99 | glTranslate $sx0 - 32, $sy0 - 32, 0; |
395 | $::MAP->draw ($sx, $sy, 0, 0, $sw, $sh); |
100 | |
396 | |
101 | my ($w, $h, $data) = $::MAP->draw ($sx, $sy, 0, 0, $sw + 1, $sh + 1); |
397 | glScale 32, 32; |
102 | |
398 | |
103 | if ($::CFG->{fow_enable}) { |
399 | if (my $tex = $self->{fow_texture}) { |
104 | if ($::CFG->{fow_smooth} && $CFClient::GL_VERSION >= 1.2) { # smooth fog of war |
|
|
105 | glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER); |
|
|
106 | glConvolutionFilter2D ( |
|
|
107 | GL_CONVOLUTION_2D, |
|
|
108 | GL_ALPHA, |
|
|
109 | 3, 3, |
|
|
110 | GL_ALPHA, GL_FLOAT, |
|
|
111 | pack "f*", |
|
|
112 | 0.05, 0.13, 0.05, |
|
|
113 | 0.13, 0.30, 0.13, |
|
|
114 | 0.05, 0.13, 0.05, |
|
|
115 | ); |
|
|
116 | glEnable GL_CONVOLUTION_2D; |
|
|
117 | } |
|
|
118 | |
|
|
119 | $self->{fow_texture} = new CFClient::Texture |
|
|
120 | w => $w, |
|
|
121 | h => $h, |
|
|
122 | data => $data, |
|
|
123 | internalformat => GL_ALPHA, |
|
|
124 | format => GL_ALPHA; |
|
|
125 | |
|
|
126 | glDisable GL_CONVOLUTION_2D if $::CFG->{fow_smooth}; |
|
|
127 | |
|
|
128 | glEnable GL_BLEND; |
|
|
129 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
130 | glEnable GL_TEXTURE_2D; |
400 | glEnable GL_TEXTURE_2D; |
131 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
401 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
132 | |
402 | |
133 | glColor +($::CFG->{fow_intensity}) x 3, 0.8; |
403 | glColor +($::CFG->{fow_intensity}) x 3, 0.9; |
134 | $self->{fow_texture}->draw_quad (0, 0, $w * 32, $h * 32); |
404 | $self->{fow_texture}->draw_quad_alpha (0, 0); |
135 | |
405 | |
136 | glDisable GL_TEXTURE_2D; |
406 | glDisable GL_TEXTURE_2D; |
137 | glDisable GL_BLEND; |
|
|
138 | } |
407 | } |
139 | |
408 | |
|
|
409 | if ($self->{magicmap}) { |
|
|
410 | my ($x, $y, $w, $h, $data) = @{ $self->{magicmap} }; |
|
|
411 | |
|
|
412 | $x += $::MAP->ox - $sx + int 0.5 * ($::MAP->w - $sw + 1); |
|
|
413 | $y += $::MAP->oy - $sy + int 0.5 * ($::MAP->h - $sh + 1); |
|
|
414 | |
|
|
415 | glTranslate - $x - 1, - $y - 1; |
|
|
416 | glBindTexture GL_TEXTURE_2D, $magicmap_tex->{name}; |
|
|
417 | $::MAP->draw_magicmap ($x, $y, $w, $h, $data); |
|
|
418 | } |
|
|
419 | |
140 | glPopMatrix; |
420 | glPopMatrix; |
141 | } |
|
|
142 | |
|
|
143 | glEndList; |
421 | glEndList; |
144 | } |
422 | } |
145 | |
423 | |
146 | glPushMatrix; |
|
|
147 | glCallList $self->{list}; |
424 | glCallList $self->{list}; |
148 | glPopMatrix; |
|
|
149 | |
425 | |
150 | if ($CFClient::UI::FOCUS != $self) { |
426 | # TNT2 emulates logops in software (or worse :) |
151 | glColor 64/255, 64/255, 64/255; |
427 | unless ($focused) { |
152 | glLogicOp GL_AND; |
428 | glColor 0.4, 0.2, 0.2, 0.6; |
153 | glEnable GL_COLOR_LOGIC_OP; |
429 | glEnable GL_BLEND; |
|
|
430 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
154 | glBegin GL_QUADS; |
431 | glBegin GL_QUADS; |
155 | glVertex 0, 0; |
432 | glVertex 0, 0; |
156 | glVertex 0, $::HEIGHT; |
433 | glVertex 0, $::HEIGHT; |
157 | glVertex $::WIDTH, $::HEIGHT; |
434 | glVertex $::WIDTH, $::HEIGHT; |
158 | glVertex $::WIDTH, 0; |
435 | glVertex $::WIDTH, 0; |
159 | glEnd; |
436 | glEnd; |
160 | glDisable GL_COLOR_LOGIC_OP; |
437 | glDisable GL_BLEND; |
161 | } |
438 | } |
162 | } |
439 | } |
163 | |
440 | |
164 | my %DIR = ( |
441 | sub DESTROY { |
165 | CFClient::SDLK_KP8, [1, "north"], |
442 | my $self = shift; |
166 | CFClient::SDLK_KP9, [2, "northeast"], |
|
|
167 | CFClient::SDLK_KP6, [3, "east"], |
|
|
168 | CFClient::SDLK_KP3, [4, "southeast"], |
|
|
169 | CFClient::SDLK_KP2, [5, "south"], |
|
|
170 | CFClient::SDLK_KP1, [6, "southwest"], |
|
|
171 | CFClient::SDLK_KP4, [7, "west"], |
|
|
172 | CFClient::SDLK_KP7, [8, "northwest"], |
|
|
173 | |
443 | |
174 | CFClient::SDLK_UP, [1, "north"], |
444 | glDeleteList $self->{list}; |
175 | CFClient::SDLK_RIGHT, [3, "east"], |
|
|
176 | CFClient::SDLK_DOWN, [5, "south"], |
|
|
177 | CFClient::SDLK_LEFT, [7, "west"], |
|
|
178 | ); |
|
|
179 | |
445 | |
180 | sub key_down { |
446 | $self->SUPER::DESTROY; |
181 | my ($self, $ev) = @_; |
|
|
182 | |
|
|
183 | return unless $::CONN; |
|
|
184 | |
|
|
185 | my $mod = $ev->{mod}; |
|
|
186 | my $sym = $ev->{sym}; |
|
|
187 | my $uni = $ev->{unicode}; |
|
|
188 | |
|
|
189 | if ($sym == CFClient::SDLK_KP5) { |
|
|
190 | $::CONN->user_send ("stay fire"); |
|
|
191 | } elsif ($uni == ord ",") { |
|
|
192 | $::CONN->user_send ("take"); |
|
|
193 | } elsif ($uni == ord "a") { |
|
|
194 | $::CONN->user_send ("apply"); |
|
|
195 | } elsif ($uni == ord "'") { |
|
|
196 | $self->emit ('activate_console'); |
|
|
197 | } elsif ($uni == ord "/") { |
|
|
198 | $self->emit (activate_console => '/'); |
|
|
199 | } elsif (exists $DIR{$sym}) { |
|
|
200 | if ($mod & CFClient::KMOD_SHIFT) { |
|
|
201 | $self->{shft}++; |
|
|
202 | $::CONN->user_send ("fire $DIR{$sym}[0]"); |
|
|
203 | } elsif ($mod & CFClient::KMOD_CTRL) { |
|
|
204 | $self->{ctrl}++; |
|
|
205 | $::CONN->user_send ("run $DIR{$sym}[0]"); |
|
|
206 | } else { |
|
|
207 | $::CONN->user_send ("$DIR{$sym}[1]"); |
|
|
208 | } |
|
|
209 | } elsif ($ev->{unicode}) { |
|
|
210 | $self->{command_widget} ||= |
|
|
211 | new CFClient::MapWidget::Command:: |
|
|
212 | command => $self->{command}, |
|
|
213 | can_focus => 1, |
|
|
214 | connect_execute => sub { |
|
|
215 | # todo: support callback instead of user_send |
|
|
216 | $::CONN->user_send ($_[1][1]); |
|
|
217 | }, |
|
|
218 | connect_close => sub { |
|
|
219 | (delete $self->{command_widget})->hide; |
|
|
220 | $self->focus_in; |
|
|
221 | }, |
|
|
222 | ; |
|
|
223 | $self->{command_widget}->key_down ($ev); |
|
|
224 | return unless $self->{command_widget}; |
|
|
225 | $self->{command_widget}->show; |
|
|
226 | $self->{command_widget}->focus_in; |
|
|
227 | } |
|
|
228 | } |
447 | } |
229 | |
448 | |
230 | sub key_up { |
|
|
231 | my ($self, $ev) = @_; |
|
|
232 | |
|
|
233 | my $mod = $ev->{mod}; |
|
|
234 | my $sym = $ev->{sym}; |
|
|
235 | |
|
|
236 | if (!($mod & CFClient::KMOD_SHIFT) && delete $self->{shft}) { |
|
|
237 | $::CONN->user_send ("fire_stop"); |
|
|
238 | } |
|
|
239 | if (!($mod & CFClient::KMOD_CTRL ) && delete $self->{ctrl}) { |
|
|
240 | $::CONN->user_send ("run_stop"); |
|
|
241 | } |
|
|
242 | } |
|
|
243 | |
|
|
244 | sub add_command { |
|
|
245 | my ($self, $command, $tooltip, $widget, $cb) = @_; |
|
|
246 | |
|
|
247 | (my $abbrev = $command) =~ s/(\S)[^[:space:]_]*[[:space:]_]+/$1/g; |
|
|
248 | |
|
|
249 | $self->{command} = [ |
|
|
250 | [$abbrev, $command, $tooltip, $widget, $cb], |
|
|
251 | grep $_->[1] ne $command, @{ $self->{command} }, |
|
|
252 | ]; |
|
|
253 | } |
|
|
254 | |
|
|
255 | package CFClient::MapWidget::MapMap; |
449 | package CFPlus::MapWidget::MapMap; |
256 | |
450 | |
257 | our @ISA = CFClient::UI::Base::; |
451 | our @ISA = CFPlus::UI::Base::; |
258 | |
452 | |
259 | use Time::HiRes qw(time); |
453 | use Time::HiRes qw(time); |
260 | use CFClient::OpenGL; |
454 | use CFPlus::OpenGL; |
261 | |
455 | |
262 | sub size_request { |
456 | sub size_request { |
263 | ($::HEIGHT * 0.25, $::HEIGHT * 0.25) |
457 | ($::HEIGHT * 0.25, $::HEIGHT * 0.25) |
264 | } |
458 | } |
265 | |
459 | |
266 | sub size_allocate { |
460 | sub invoke_size_allocate { |
267 | my ($self, $w, $h) = @_; |
461 | my ($self, $w, $h) = @_; |
268 | |
462 | |
269 | $self->SUPER::size_allocate ($w, $h); |
|
|
270 | $self->update; |
463 | $self->update; |
|
|
464 | |
|
|
465 | 1 |
271 | } |
466 | } |
272 | |
467 | |
273 | sub update { |
468 | sub update { |
274 | my ($self) = @_; |
469 | my ($self) = @_; |
275 | |
470 | |
… | |
… | |
300 | |
495 | |
301 | if ($self->{texture_atime} < time) { |
496 | if ($self->{texture_atime} < time) { |
302 | $self->{texture_atime} = time + 1/3; |
497 | $self->{texture_atime} = time + 1/3; |
303 | |
498 | |
304 | $self->{texture} = |
499 | $self->{texture} = |
305 | new CFClient::Texture |
500 | new CFPlus::Texture |
306 | w => $w, |
501 | w => $w, |
307 | h => $h, |
502 | h => $h, |
308 | data => $::MAP->mapmap (-$ox, -$oy, $w, $h), |
503 | data => $::MAP->mapmap (-$ox, -$oy, $w, $h), |
309 | type => $CFClient::GL_VERSION >= 1.2 ? GL_UNSIGNED_INT_8_8_8_8_REV : GL_UNSIGNED_BYTE; |
504 | type => $CFPlus::GL_VERSION >= 1.2 ? GL_UNSIGNED_INT_8_8_8_8_REV : GL_UNSIGNED_BYTE; |
310 | } |
505 | } |
311 | |
506 | |
312 | $self->{texture}->draw_quad (0, 0); |
507 | $self->{texture}->draw_quad (0, 0); |
313 | |
508 | |
314 | glDisable GL_TEXTURE_2D; |
509 | glDisable GL_TEXTURE_2D; |
… | |
… | |
329 | glEnd; |
524 | glEnd; |
330 | |
525 | |
331 | glDisable GL_BLEND; |
526 | glDisable GL_BLEND; |
332 | } |
527 | } |
333 | |
528 | |
334 | package CFClient::MapWidget::Command; |
529 | package CFPlus::MapWidget::Command; |
335 | |
530 | |
336 | use strict; |
531 | use strict; |
337 | |
532 | |
338 | use CFClient::OpenGL; |
533 | use CFPlus::OpenGL; |
339 | |
534 | |
340 | our @ISA = CFClient::UI::VBox::; |
535 | our @ISA = CFPlus::UI::Frame::; |
341 | |
536 | |
342 | sub new { |
537 | sub new { |
343 | my $class = shift; |
538 | my $class = shift; |
344 | |
539 | |
345 | my $self = $class->SUPER::new ( |
540 | my $self = $class->SUPER::new ( |
|
|
541 | bg => [0, 0, 0, 0.8], |
346 | @_, |
542 | @_, |
347 | children => [map |
|
|
348 | CFClient::UI::Label->new ( |
|
|
349 | can_hover => 1, |
|
|
350 | can_events => 1, |
|
|
351 | fontsize => $_, |
|
|
352 | ), 1, 1, 0.8, 0.8, 0.8, 0.8, 0.8 |
|
|
353 | ], |
|
|
354 | ); |
543 | ); |
355 | |
544 | |
|
|
545 | $self->add ($self->{vbox} = new CFPlus::UI::VBox); |
|
|
546 | |
|
|
547 | $self->{label} = [ |
|
|
548 | map |
|
|
549 | CFPlus::UI::Label->new ( |
|
|
550 | can_hover => 1, |
|
|
551 | can_events => 1, |
|
|
552 | tooltip_width => 0.33, |
|
|
553 | fontsize => $_, |
|
|
554 | ), (0.8) x 16 |
|
|
555 | ]; |
|
|
556 | |
|
|
557 | $self->{entry} = new CFPlus::UI::Entry |
|
|
558 | on_changed => sub { |
|
|
559 | $self->update_labels; |
|
|
560 | 0 |
|
|
561 | }, |
|
|
562 | on_button_down => sub { |
|
|
563 | my ($entry, $ev, $x, $y) = @_; |
|
|
564 | |
|
|
565 | if ($ev->{button} == 3) { |
|
|
566 | (new CFPlus::UI::Menu |
|
|
567 | items => [ |
|
|
568 | ["bind <i>" . (CFPlus::asxml $self->{select}) . "</i> to a key" |
|
|
569 | => sub { $::BIND_EDITOR->do_quick_binding ([$self->{select}], sub { $entry->grab_focus }) }] |
|
|
570 | ], |
|
|
571 | )->popup ($ev); |
|
|
572 | return 1; |
|
|
573 | } |
|
|
574 | 0 |
|
|
575 | }, |
|
|
576 | on_key_down => sub { |
|
|
577 | my ($entry, $ev) = @_; |
|
|
578 | |
|
|
579 | my $self = $entry->{parent}{parent}; |
|
|
580 | |
|
|
581 | if ($ev->{sym} == 13) { |
|
|
582 | if (exists $self->{select}) { |
|
|
583 | $self->{last_command} = $self->{select}; |
|
|
584 | $::CONN->user_send ($self->{select}); |
|
|
585 | |
|
|
586 | unshift @{$self->{history}}, $self->{entry}->get_text; |
|
|
587 | $self->{hist_ptr} = 0; |
|
|
588 | |
|
|
589 | $self->hide; |
|
|
590 | } |
|
|
591 | } elsif ($ev->{sym} == 27) { |
|
|
592 | $self->{hist_ptr} = 0; |
|
|
593 | $self->hide; |
|
|
594 | } elsif ($ev->{sym} == CFPlus::SDLK_DOWN) { |
|
|
595 | if ($self->{hist_ptr} > 1) { |
|
|
596 | $self->{hist_ptr}--; |
|
|
597 | $self->{entry}->set_text ($self->{history}->[$self->{hist_ptr} - 1]); |
|
|
598 | } elsif ($self->{hist_ptr} > 0) { |
|
|
599 | $self->{hist_ptr}--; |
|
|
600 | $self->{entry}->set_text ($self->{hist_saveback}); |
|
|
601 | } else { |
|
|
602 | ++$self->{select_offset} |
|
|
603 | if $self->{select_offset} < $#{ $self->{last_match} || [] }; |
|
|
604 | } |
|
|
605 | $self->update_labels; |
|
|
606 | } elsif ($ev->{sym} == CFPlus::SDLK_UP) { |
|
|
607 | if ($self->{select_offset}) { |
|
|
608 | --$self->{select_offset} |
|
|
609 | } else { |
|
|
610 | unless ($self->{hist_ptr}) { |
|
|
611 | $self->{hist_saveback} = $self->{entry}->get_text; |
|
|
612 | } |
|
|
613 | if ($self->{hist_ptr} <= $#{$self->{history}}) { |
|
|
614 | $self->{hist_ptr}++; |
|
|
615 | } |
|
|
616 | $self->{entry}->set_text ($self->{history}->[$self->{hist_ptr} - 1]) |
|
|
617 | if exists $self->{history}->[$self->{hist_ptr} - 1]; |
|
|
618 | } |
|
|
619 | $self->update_labels; |
|
|
620 | } else { |
|
|
621 | return 0; |
|
|
622 | } |
|
|
623 | |
|
|
624 | 1 |
|
|
625 | } |
|
|
626 | ; |
|
|
627 | |
|
|
628 | $self->{vbox}->add ( |
|
|
629 | $self->{entry}, |
|
|
630 | @{$self->{label}}, |
|
|
631 | ); |
|
|
632 | |
356 | $self |
633 | $self |
357 | } |
634 | } |
358 | |
635 | |
|
|
636 | sub set_prefix { |
|
|
637 | my ($self, $prefix) = @_; |
|
|
638 | |
|
|
639 | $self->{entry}->set_text ($prefix); |
|
|
640 | $self->show; |
|
|
641 | } |
|
|
642 | |
359 | sub size_allocate { |
643 | sub invoke_size_allocate { |
360 | my ($self, $w, $h) = @_; |
644 | my ($self, $w, $h) = @_; |
361 | |
645 | |
362 | $self->SUPER::size_allocate ($w, $h); |
|
|
363 | $self->move (($::WIDTH - $w) * 0.5, ($::HEIGHT - $h) * 0.6, 10); |
646 | $self->move_abs (($::WIDTH - $w) * 0.5, ($::HEIGHT - $h) * 0.6, 10); |
|
|
647 | |
|
|
648 | $self->SUPER::invoke_size_allocate ($w, $h) |
|
|
649 | } |
|
|
650 | |
|
|
651 | sub show { |
|
|
652 | my ($self) = @_; |
|
|
653 | |
|
|
654 | $self->SUPER::show; |
|
|
655 | $self->{entry}->grab_focus; |
|
|
656 | } |
|
|
657 | |
|
|
658 | sub hide { |
|
|
659 | my ($self) = @_; |
|
|
660 | |
|
|
661 | $self->{hist_ptr} = 0; |
|
|
662 | |
|
|
663 | $self->SUPER::hide; |
|
|
664 | $self->{entry}->set_text (""); |
|
|
665 | } |
|
|
666 | |
|
|
667 | sub inject_key_down { |
|
|
668 | my ($self, $ev) = @_; |
|
|
669 | |
|
|
670 | $self->{entry}->grab_focus; |
|
|
671 | $self->{entry}->emit (key_down => $ev); |
364 | } |
672 | } |
365 | |
673 | |
366 | sub update_labels { |
674 | sub update_labels { |
367 | my ($self) = @_; |
675 | my ($self) = @_; |
368 | |
676 | |
369 | my $command = $self->{command}; |
677 | my $text = $self->{entry}->get_text; |
370 | my $search_abbrev = qr/^\Q$self->{search}/; |
|
|
371 | my $search_full = qr/\Q$self->{search}/; |
|
|
372 | |
678 | |
373 | my @found; |
679 | length $text |
|
|
680 | or return $self->hide; |
374 | |
681 | |
375 | for (@$command) { |
682 | my ($cmd, $arg) = $text =~ /^\s*([^[:space:]]*)(.*)$/; |
376 | if ($_->[0] =~ $search_abbrev) { |
683 | |
377 | push @found, [$_->[0], $_]; |
684 | if ($text ne $self->{last_search}) { |
378 | } elsif (2 < length $self->{search} and $_->[1] =~ $search_full) { |
685 | my @match; |
379 | push @found, [$_->[1], $_]; |
686 | |
|
|
687 | if ($text =~ /^(.*?)\s+$/) { |
|
|
688 | @match = [$cmd, "(appended whitespace suppresses completion)"]; |
|
|
689 | } else { |
|
|
690 | my $regexp = do { |
|
|
691 | my ($beg, @chr) = split //, lc $cmd; |
|
|
692 | |
|
|
693 | # the following regex is used to match our "completion entry" |
|
|
694 | # to an actual command - the parentheses match kind of "overhead" |
|
|
695 | # - the more characters the parentheses match, the less attractive |
|
|
696 | # is the match. |
|
|
697 | my $regexp = "^\Q$beg\E" |
|
|
698 | . join "", map "(?:.*?[ \\\\]\Q$_\E|(.*?)\Q$_\E)", @chr; |
|
|
699 | qr<$regexp> |
|
|
700 | }; |
|
|
701 | |
|
|
702 | my @penalty; |
|
|
703 | |
|
|
704 | for (keys %{$self->{command}}) { |
|
|
705 | if (@penalty = $_ =~ $regexp) { |
|
|
706 | push @match, [$_, length join "", map "::$_", grep defined, @penalty]; |
|
|
707 | } |
380 | } |
708 | } |
381 | } |
|
|
382 | |
709 | |
383 | @found = sort { $a->[0] cmp $b->[0] } @found; |
710 | @match = map $self->{command}{$_->[0]}, |
|
|
711 | sort { |
|
|
712 | $a->[1] <=> $b->[1] |
|
|
713 | or $self->{command}{$a->[0]}[4] <=> $self->{command}{$b->[0]}[4] |
|
|
714 | or (length $b->[0]) <=> (length $a->[0]) |
|
|
715 | } @match; |
|
|
716 | } |
384 | |
717 | |
385 | $self->{children}[0]->set_text ("$self->{search}_"); |
718 | $self->{last_search} = $text; |
|
|
719 | $self->{last_match} = \@match; |
386 | |
720 | |
387 | for (0..5) { |
721 | $self->{select_offset} = 0; |
388 | $self->{children}[$_ + 1]->set_text ($found[$_] ? "$found[$_][0] ($found[$_][1][1])" : ""); |
|
|
389 | $self->{children}[$_ + 1]{tooltip} = ($found[$_] ? $found[$_][1][2] : ""); |
|
|
390 | } |
722 | } |
391 | |
723 | |
392 | $self->{select} = $found[0][1] |
724 | my @labels = @{ $self->{label} }; |
393 | if @found; |
725 | my @matches = @{ $self->{last_match} || [] }; |
394 | |
726 | |
395 | if (@found > 6) { |
727 | if ($self->{select_offset}) { |
396 | $self->{children}[6]->set_text ("..."); |
728 | splice @matches, 0, $self->{select_offset}, (); |
397 | } |
|
|
398 | |
729 | |
399 | $self->check_size; |
730 | my $label = shift @labels; |
400 | } |
731 | $label->set_text ("..."); |
|
|
732 | $label->set_tooltip ("Use Cursor-Up to view previous matches"); |
|
|
733 | } |
401 | |
734 | |
402 | sub key_down { |
735 | for my $label (@labels) { |
|
|
736 | $label->{fg} = [1, 1, 1, 1]; |
|
|
737 | $label->{bg} = [0, 0, 0, 0]; |
|
|
738 | } |
|
|
739 | |
|
|
740 | if (@matches) { |
|
|
741 | $self->{select} = "$matches[0][0]$arg"; |
|
|
742 | |
|
|
743 | $labels[0]->{fg} = [0, 0, 0, 1]; |
|
|
744 | $labels[0]->{bg} = [1, 1, 1, 0.8]; |
|
|
745 | } else { |
|
|
746 | $self->{select} = "$cmd$arg"; |
|
|
747 | } |
|
|
748 | |
|
|
749 | for my $match (@matches) { |
|
|
750 | my $label = shift @labels; |
|
|
751 | |
|
|
752 | if (@labels) { |
|
|
753 | $label->set_text ("$match->[0]$arg"); |
|
|
754 | $label->set_tooltip ($match->[1]); |
|
|
755 | } else { |
|
|
756 | $label->set_text ("..."); |
|
|
757 | $label->set_tooltip ("Use Cursor-Down to view more matches"); |
|
|
758 | last; |
|
|
759 | } |
|
|
760 | } |
|
|
761 | |
|
|
762 | for my $label (@labels) { |
|
|
763 | $label->set_text (""); |
|
|
764 | $label->set_tooltip (""); |
|
|
765 | } |
|
|
766 | |
|
|
767 | $self->update; |
|
|
768 | } |
|
|
769 | |
|
|
770 | sub _draw { |
403 | my ($self, $ev) = @_; |
771 | my ($self) = @_; |
404 | |
772 | |
405 | if ($ev->{sym} == 8) { |
773 | # hack |
406 | substr $self->{search}, -1, 1, ""; |
774 | local $CFPlus::UI::FOCUS = $self->{entry}; |
407 | $self->update_labels; |
|
|
408 | } elsif ($ev->{sym} == 13) { |
|
|
409 | if (exists $self->{select}) { |
|
|
410 | $self->emit (execute => $self->{select}); |
|
|
411 | $self->emit ("close"); |
|
|
412 | } |
|
|
413 | } elsif ($ev->{sym} == 27) { |
|
|
414 | $self->emit ("close"); |
|
|
415 | return; |
|
|
416 | } elsif ((chr $ev->{unicode}) =~ /^[[:alpha:]]$/) { |
|
|
417 | $self->{search} .= chr $ev->{unicode}; |
|
|
418 | $self->update_labels; |
|
|
419 | } |
|
|
420 | |
775 | |
421 | length $self->{search} |
776 | $self->SUPER::_draw; |
422 | or $self->emit ("close"); |
|
|
423 | } |
777 | } |
424 | |
778 | |
425 | 1 |
779 | 1 |