… | |
… | |
39 | my ($self, $command, $tooltip, $widget, $cb) = @_; |
39 | my ($self, $command, $tooltip, $widget, $cb) = @_; |
40 | |
40 | |
41 | (my $data = $command) =~ s/\\//g; |
41 | (my $data = $command) =~ s/\\//g; |
42 | |
42 | |
43 | $tooltip =~ s/^\s+//; |
43 | $tooltip =~ s/^\s+//; |
44 | |
|
|
45 | $tooltip = "<big>$data</big>\n\n$tooltip"; |
44 | $tooltip = "<big>$data</big>\n\n$tooltip"; |
46 | |
|
|
47 | $tooltip =~ s/\s+$//; |
45 | $tooltip =~ s/\s+$//; |
48 | |
46 | |
49 | $self->{completer}{command}{$command} = [$data, $tooltip, $widget, $cb, ++$self->{command_id}]; |
47 | $self->{completer}{command}{$command} = [$data, $tooltip, $widget, $cb, ++$self->{command_id}]; |
50 | } |
48 | } |
51 | |
49 | |
… | |
… | |
73 | $::CFG->{map_shift_y} = $bh + $y - $oy; |
71 | $::CFG->{map_shift_y} = $bh + $y - $oy; |
74 | |
72 | |
75 | $self->update; |
73 | $self->update; |
76 | }; |
74 | }; |
77 | } |
75 | } |
|
|
76 | |
|
|
77 | 1 |
78 | } |
78 | } |
79 | |
79 | |
80 | sub button_up { |
80 | sub button_up { |
81 | my ($self, $ev, $x, $y) = @_; |
81 | my ($self, $ev, $x, $y) = @_; |
82 | |
82 | |
83 | delete $self->{motion}; |
83 | delete $self->{motion}; |
|
|
84 | |
|
|
85 | 1 |
84 | } |
86 | } |
85 | |
87 | |
86 | sub mouse_motion { |
88 | sub mouse_motion { |
87 | my ($self, $ev, $x, $y) = @_; |
89 | my ($self, $ev, $x, $y) = @_; |
88 | |
90 | |
|
|
91 | if ($self->{motion}) { |
89 | $self->{motion}->($ev, $x, $y) if $self->{motion}; |
92 | $self->{motion}->($ev, $x, $y); |
|
|
93 | } else { |
|
|
94 | return 0; |
|
|
95 | } |
|
|
96 | |
|
|
97 | 1 |
90 | } |
98 | } |
91 | |
99 | |
92 | sub size_request { |
100 | sub size_request { |
93 | ( |
101 | ( |
94 | 1 + 32 * int $::WIDTH / 32, |
102 | 1 + 32 * int $::WIDTH / 32, |
… | |
… | |
120 | ); |
128 | ); |
121 | |
129 | |
122 | sub key_down { |
130 | sub key_down { |
123 | my ($self, $ev) = @_; |
131 | my ($self, $ev) = @_; |
124 | |
132 | |
125 | return unless $::CONN; |
133 | return 0 unless $::CONN; |
126 | |
134 | |
127 | my $mod = $ev->{mod}; |
135 | my $mod = $ev->{mod}; |
128 | my $sym = $ev->{sym}; |
136 | my $sym = $ev->{sym}; |
129 | my $uni = $ev->{unicode}; |
137 | my $uni = $ev->{unicode}; |
130 | |
138 | |
… | |
… | |
136 | $::CONN->user_send ("apply"); |
144 | $::CONN->user_send ("apply"); |
137 | } elsif ($uni == ord ".") { |
145 | } elsif ($uni == ord ".") { |
138 | $::CONN->user_send ($self->{completer}{last_command}) |
146 | $::CONN->user_send ($self->{completer}{last_command}) |
139 | if exists $self->{completer}{last_command}; |
147 | if exists $self->{completer}{last_command}; |
140 | } elsif ($uni == ord "\t") { |
148 | } elsif ($uni == ord "\t") { |
141 | # TODO: toggle inventory |
149 | $::INV_WINDOW->toggle_visibility; |
142 | } elsif ($sym == CFClient::SDLK_KP_PLUS || $uni == ord "+") { |
150 | } elsif ($sym == CFClient::SDLK_KP_PLUS || $uni == ord "+") { |
143 | $::CONN->user_send ("rotateshoottype +"); |
151 | $::CONN->user_send ("rotateshoottype +"); |
144 | } elsif ($sym == CFClient::SDLK_KP_MINUS || $uni == ord "-") { |
152 | } elsif ($sym == CFClient::SDLK_KP_MINUS || $uni == ord "-") { |
145 | $::CONN->user_send ("rotateshoottype -"); |
153 | $::CONN->user_send ("rotateshoottype -"); |
146 | } elsif ($uni == ord '"') { |
154 | } elsif ($uni == ord '"') { |
… | |
… | |
157 | $self->{ctrl}++; |
165 | $self->{ctrl}++; |
158 | $::CONN->user_send ("run $DIR{$sym}[0]"); |
166 | $::CONN->user_send ("run $DIR{$sym}[0]"); |
159 | } else { |
167 | } else { |
160 | $::CONN->user_send ("$DIR{$sym}[1]"); |
168 | $::CONN->user_send ("$DIR{$sym}[1]"); |
161 | } |
169 | } |
162 | } elsif ($ev->{unicode}) { |
170 | } elsif ($sym == CFClient::SDLK_INSERT && $mod & CFClient::KMOD_CTRL) { |
|
|
171 | $::BIND_EDITOR->set_binding (undef, undef, [], |
|
|
172 | sub { |
|
|
173 | my ($mod, $sym, $cmds) = @_; |
|
|
174 | $::CFG->{bindings}->{$mod}->{$sym} = $cmds; |
|
|
175 | }); |
|
|
176 | $::BIND_EDITOR->start; |
|
|
177 | $::BIND_EDITOR->show; |
|
|
178 | } elsif ($sym == CFClient::SDLK_INSERT && not ($mod & CFClient::KMOD_CTRL)) { |
|
|
179 | $::BIND_EDITOR->stop; |
|
|
180 | $::BIND_EDITOR->ask_for_bind_and_commit; |
|
|
181 | $::BIND_EDITOR->hide; |
|
|
182 | } elsif (my $bind_cmd = $::CFG->{bindings}->{$mod}->{$sym}) { |
|
|
183 | $::CONN->user_send ($_) for @$bind_cmd; |
|
|
184 | } elsif ((ord 'a') <= $uni && $uni <= (ord 'z')) { |
163 | $self->{completer}->key_down ($ev); |
185 | $self->{completer}->key_down ($ev); |
164 | $self->{completer}->show; |
186 | $self->{completer}->show; |
|
|
187 | } else { |
|
|
188 | return 0; |
|
|
189 | } |
|
|
190 | |
165 | } |
191 | 1 |
166 | } |
192 | } |
167 | |
193 | |
168 | sub key_up { |
194 | sub key_up { |
169 | my ($self, $ev) = @_; |
195 | my ($self, $ev) = @_; |
170 | |
196 | |
|
|
197 | my $res = 0; |
171 | my $mod = $ev->{mod}; |
198 | my $mod = $ev->{mod}; |
172 | my $sym = $ev->{sym}; |
199 | my $sym = $ev->{sym}; |
173 | |
200 | |
174 | if (!($mod & CFClient::KMOD_SHIFT) && delete $self->{shft}) { |
201 | if (!($mod & CFClient::KMOD_SHIFT) && delete $self->{shft}) { |
175 | $::CONN->user_send ("fire_stop"); |
202 | $::CONN->user_send ("fire_stop"); |
|
|
203 | $res = 1; |
176 | } |
204 | } |
|
|
205 | |
177 | if (!($mod & CFClient::KMOD_CTRL ) && delete $self->{ctrl}) { |
206 | if (!($mod & CFClient::KMOD_CTRL ) && delete $self->{ctrl}) { |
178 | $::CONN->user_send ("run_stop"); |
207 | $::CONN->user_send ("run_stop"); |
|
|
208 | $res = 1; |
179 | } |
209 | } |
|
|
210 | |
|
|
211 | $res |
180 | } |
212 | } |
181 | |
213 | |
182 | sub draw { |
214 | sub draw { |
183 | my ($self) = @_; |
215 | my ($self) = @_; |
184 | |
216 | |
… | |
… | |
204 | glTranslate $sx0 - 32, $sy0 - 32, 0; |
236 | glTranslate $sx0 - 32, $sy0 - 32, 0; |
205 | |
237 | |
206 | my ($w, $h, $data) = $::MAP->draw ($sx, $sy, 0, 0, $sw + 1, $sh + 1); |
238 | my ($w, $h, $data) = $::MAP->draw ($sx, $sy, 0, 0, $sw + 1, $sh + 1); |
207 | |
239 | |
208 | if ($::CFG->{fow_enable}) { |
240 | if ($::CFG->{fow_enable}) { |
209 | if ($::CFG->{fow_smooth} && $CFClient::GL_VERSION >= 1.2) { # smooth fog of war |
241 | if ($::CFG->{fow_smooth} && $CFClient::OpenGL::GL_VERSION >= 1.2) { # smooth fog of war |
210 | glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER); |
242 | glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER); |
211 | glConvolutionFilter2D ( |
243 | glConvolutionFilter2D ( |
212 | GL_CONVOLUTION_2D, |
244 | GL_CONVOLUTION_2D, |
213 | GL_ALPHA, |
245 | GL_ALPHA, |
214 | 3, 3, |
246 | 3, 3, |
… | |
… | |
267 | glVertex $::WIDTH, $::HEIGHT; |
299 | glVertex $::WIDTH, $::HEIGHT; |
268 | glVertex $::WIDTH, 0; |
300 | glVertex $::WIDTH, 0; |
269 | glEnd; |
301 | glEnd; |
270 | glDisable GL_BLEND; |
302 | glDisable GL_BLEND; |
271 | |
303 | |
272 | $self->{out_of_focus} ||= do { |
304 | # $self->{out_of_focus} ||= do { |
273 | my $label = new CFClient::UI::Label |
305 | # my $label = new CFClient::UI::Label |
274 | x => 0, |
306 | # x => 0, |
275 | y => 0, |
307 | # y => 0, |
276 | z => 1, |
308 | # z => 1, |
277 | ellipsise => 0, |
309 | # ellipsise => 0, |
278 | text => "map out of focus (click map to play)"; |
310 | # text => "map out of focus (click map to play)"; |
279 | |
311 | # |
280 | $label->show; |
312 | # $label->show; |
281 | $label->update; |
313 | # $label->update; |
282 | |
314 | # |
283 | $CFClient::UI::ROOT->on_post_alloc ("$self$label" => sub { |
315 | # $CFClient::UI::ROOT->on_post_alloc ("$self$label" => sub { |
284 | $label->move ( |
316 | # $label->move_abs ( |
285 | ($::WIDTH - $label->{w}) * 0.5, |
317 | # ($::WIDTH - $label->{w}) * 0.5, |
286 | ($::HEIGHT - $label->{h}) * 0.5, |
318 | # ($::HEIGHT - $label->{h}) * 0.5, |
287 | ); |
319 | # ); |
288 | }); |
320 | # }); |
289 | |
321 | # |
290 | $label |
322 | # $label |
291 | }; |
323 | # }; |
292 | } |
324 | } |
293 | } |
325 | } |
294 | |
326 | |
295 | sub DESTROY { |
327 | sub DESTROY { |
296 | my $self = shift; |
328 | my $self = shift; |
… | |
… | |
406 | fontsize => $_, |
438 | fontsize => $_, |
407 | ), (0.8) x 16 |
439 | ), (0.8) x 16 |
408 | ]; |
440 | ]; |
409 | |
441 | |
410 | $self->{entry} = new CFClient::UI::Entry |
442 | $self->{entry} = new CFClient::UI::Entry |
411 | connect_changed => sub { |
443 | on_changed => sub { |
412 | $self->update_labels; |
444 | $self->update_labels; |
413 | }, |
445 | }, |
414 | connect_key_down => sub { |
446 | on_key_down => sub { |
415 | my ($entry, $ev) = @_; |
447 | my ($entry, $ev) = @_; |
416 | |
448 | |
417 | my $self = $entry->{parent}{parent}; |
449 | my $self = $entry->{parent}{parent}; |
418 | |
450 | |
419 | if ($ev->{sym} == 13) { |
451 | if ($ev->{sym} == 13) { |
… | |
… | |
458 | |
490 | |
459 | sub size_allocate { |
491 | sub size_allocate { |
460 | my ($self, $w, $h) = @_; |
492 | my ($self, $w, $h) = @_; |
461 | |
493 | |
462 | $self->SUPER::size_allocate ($w, $h); |
494 | $self->SUPER::size_allocate ($w, $h); |
463 | $self->move (($::WIDTH - $w) * 0.5, ($::HEIGHT - $h) * 0.6, 10); |
495 | $self->move_abs (($::WIDTH - $w) * 0.5, ($::HEIGHT - $h) * 0.6, 10); |
464 | } |
496 | } |
465 | |
497 | |
466 | sub show { |
498 | sub show { |
467 | my ($self) = @_; |
499 | my ($self) = @_; |
468 | |
500 | |
… | |
… | |
478 | } |
510 | } |
479 | |
511 | |
480 | sub key_down { |
512 | sub key_down { |
481 | my ($self, $ev) = @_; |
513 | my ($self, $ev) = @_; |
482 | |
514 | |
483 | $self->{entry}->key_down ($ev); |
515 | $self->{entry}->key_down ($ev) |
484 | } |
516 | } |
485 | |
517 | |
486 | sub update_labels { |
518 | sub update_labels { |
487 | my ($self) = @_; |
519 | my ($self) = @_; |
488 | |
520 | |
… | |
… | |
521 | |
553 | |
522 | @match = map $self->{command}{$_->[0]}, |
554 | @match = map $self->{command}{$_->[0]}, |
523 | sort { |
555 | sort { |
524 | $a->[1] <=> $b->[1] |
556 | $a->[1] <=> $b->[1] |
525 | or $self->{command}{$a->[0]}[4] <=> $self->{command}{$b->[0]}[4] |
557 | or $self->{command}{$a->[0]}[4] <=> $self->{command}{$b->[0]}[4] |
526 | or (length $a->[0]) <=> (length $b->[0]) |
558 | or (length $b->[0]) <=> (length $a->[0]) |
527 | } @match; |
559 | } @match; |
528 | } |
560 | } |
529 | |
561 | |
530 | $self->{last_search} = $cmd; |
562 | $self->{last_search} = $text; |
531 | $self->{last_match} = \@match; |
563 | $self->{last_match} = \@match; |
532 | |
564 | |
533 | $self->{select_offset} = 0; |
565 | $self->{select_offset} = 0; |
534 | } |
566 | } |
535 | |
567 | |