… | |
… | |
14 | |
14 | |
15 | my $self = $class->SUPER::new ( |
15 | my $self = $class->SUPER::new ( |
16 | z => -1, |
16 | z => -1, |
17 | can_focus => 1, |
17 | can_focus => 1, |
18 | list => glGenList, |
18 | list => glGenList, |
|
|
19 | |
|
|
20 | smooth_matrix => [ |
|
|
21 | 0.05, 0.13, 0.05, |
|
|
22 | 0.13, 0.30, 0.13, |
|
|
23 | 0.05, 0.13, 0.05, |
|
|
24 | ], |
|
|
25 | |
19 | @_ |
26 | @_ |
20 | ); |
27 | ); |
21 | |
28 | |
22 | $self->{completer} = new CFClient::MapWidget::Command:: |
29 | $self->{completer} = new CFClient::MapWidget::Command:: |
23 | command => $self->{command}, |
30 | command => $self->{command}, |
… | |
… | |
39 | my ($self, $command, $tooltip, $widget, $cb) = @_; |
46 | my ($self, $command, $tooltip, $widget, $cb) = @_; |
40 | |
47 | |
41 | (my $data = $command) =~ s/\\//g; |
48 | (my $data = $command) =~ s/\\//g; |
42 | |
49 | |
43 | $tooltip =~ s/^\s+//; |
50 | $tooltip =~ s/^\s+//; |
44 | |
|
|
45 | $tooltip = "<big>$data</big>\n\n$tooltip"; |
51 | $tooltip = "<big>$data</big>\n\n$tooltip"; |
46 | |
|
|
47 | $tooltip =~ s/\s+$//; |
52 | $tooltip =~ s/\s+$//; |
48 | |
53 | |
49 | $self->{completer}{command}{$command} = [$data, $tooltip, $widget, $cb, ++$self->{command_id}]; |
54 | $self->{completer}{command}{$command} = [$data, $tooltip, $widget, $cb, ++$self->{command_id}]; |
50 | } |
55 | } |
51 | |
56 | |
… | |
… | |
58 | sub button_down { |
63 | sub button_down { |
59 | my ($self, $ev, $x, $y) = @_; |
64 | my ($self, $ev, $x, $y) = @_; |
60 | |
65 | |
61 | $self->focus_in; |
66 | $self->focus_in; |
62 | |
67 | |
63 | if ($ev->{button} == 2) { |
68 | if ($ev->{button} == 1) { |
|
|
69 | my $sw = int $::WIDTH / (32 * $::CFG->{map_scale}) + 0.99; |
|
|
70 | my $sh = int $::HEIGHT / (32 * $::CFG->{map_scale}) + 0.99; |
|
|
71 | |
|
|
72 | my $fx = int +($ev->{x} - $::CFG->{map_shift_x}) / (32 * $::CFG->{map_scale}) - 0.5 * $sw + 0.99; |
|
|
73 | my $fy = int +($ev->{y} - $::CFG->{map_shift_y}) / (32 * $::CFG->{map_scale}) - 0.5 * $sh + 0.99; |
|
|
74 | |
|
|
75 | $::CONN->send (sprintf "lookat %d %d", $fx, $fy); |
|
|
76 | |
|
|
77 | } elsif ($ev->{button} == 2) { |
64 | my ($ox, $oy) = ($ev->{x}, $ev->{y}); |
78 | my ($ox, $oy) = ($ev->{x}, $ev->{y}); |
65 | my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y}); |
79 | my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y}); |
66 | |
80 | |
67 | $self->{motion} = sub { |
81 | $self->{motion} = sub { |
68 | my ($ev, $x, $y) = @_; |
82 | my ($ev, $x, $y) = @_; |
… | |
… | |
73 | $::CFG->{map_shift_y} = $bh + $y - $oy; |
87 | $::CFG->{map_shift_y} = $bh + $y - $oy; |
74 | |
88 | |
75 | $self->update; |
89 | $self->update; |
76 | }; |
90 | }; |
77 | } |
91 | } |
|
|
92 | |
|
|
93 | 1 |
78 | } |
94 | } |
79 | |
95 | |
80 | sub button_up { |
96 | sub button_up { |
81 | my ($self, $ev, $x, $y) = @_; |
97 | my ($self, $ev, $x, $y) = @_; |
82 | |
98 | |
83 | delete $self->{motion}; |
99 | delete $self->{motion}; |
|
|
100 | |
|
|
101 | 1 |
84 | } |
102 | } |
85 | |
103 | |
86 | sub mouse_motion { |
104 | sub mouse_motion { |
87 | my ($self, $ev, $x, $y) = @_; |
105 | my ($self, $ev, $x, $y) = @_; |
88 | |
106 | |
|
|
107 | if ($self->{motion}) { |
89 | $self->{motion}->($ev, $x, $y) if $self->{motion}; |
108 | $self->{motion}->($ev, $x, $y); |
|
|
109 | } else { |
|
|
110 | return 0; |
|
|
111 | } |
|
|
112 | |
|
|
113 | 1 |
90 | } |
114 | } |
91 | |
115 | |
92 | sub size_request { |
116 | sub size_request { |
93 | ( |
117 | ( |
94 | 1 + 32 * int $::WIDTH / 32, |
118 | 1 + 32 * int $::WIDTH / 32, |
… | |
… | |
120 | ); |
144 | ); |
121 | |
145 | |
122 | sub key_down { |
146 | sub key_down { |
123 | my ($self, $ev) = @_; |
147 | my ($self, $ev) = @_; |
124 | |
148 | |
125 | return unless $::CONN; |
149 | return 0 unless $::CONN; |
126 | |
150 | |
127 | my $mod = $ev->{mod}; |
151 | my $mod = $ev->{mod}; |
128 | my $sym = $ev->{sym}; |
152 | my $sym = $ev->{sym}; |
129 | my $uni = $ev->{unicode}; |
153 | my $uni = $ev->{unicode}; |
130 | |
154 | |
… | |
… | |
136 | $::CONN->user_send ("apply"); |
160 | $::CONN->user_send ("apply"); |
137 | } elsif ($uni == ord ".") { |
161 | } elsif ($uni == ord ".") { |
138 | $::CONN->user_send ($self->{completer}{last_command}) |
162 | $::CONN->user_send ($self->{completer}{last_command}) |
139 | if exists $self->{completer}{last_command}; |
163 | if exists $self->{completer}{last_command}; |
140 | } elsif ($uni == ord "\t") { |
164 | } elsif ($uni == ord "\t") { |
141 | # TODO: toggle inventory |
165 | $::INV_WINDOW->toggle_visibility; |
142 | } elsif ($sym == CFClient::SDLK_KP_PLUS || $uni == ord "+") { |
166 | } elsif ($sym == CFClient::SDLK_KP_PLUS || $uni == ord "+") { |
143 | $::CONN->user_send ("rotateshoottype +"); |
167 | $::CONN->user_send ("rotateshoottype +"); |
144 | } elsif ($sym == CFClient::SDLK_KP_MINUS || $uni == ord "-") { |
168 | } elsif ($sym == CFClient::SDLK_KP_MINUS || $uni == ord "-") { |
145 | $::CONN->user_send ("rotateshoottype -"); |
169 | $::CONN->user_send ("rotateshoottype -"); |
146 | } elsif ($uni == ord '"') { |
170 | } elsif ($uni == ord '"') { |
… | |
… | |
157 | $self->{ctrl}++; |
181 | $self->{ctrl}++; |
158 | $::CONN->user_send ("run $DIR{$sym}[0]"); |
182 | $::CONN->user_send ("run $DIR{$sym}[0]"); |
159 | } else { |
183 | } else { |
160 | $::CONN->user_send ("$DIR{$sym}[1]"); |
184 | $::CONN->user_send ("$DIR{$sym}[1]"); |
161 | } |
185 | } |
162 | } elsif ($ev->{unicode}) { |
186 | } elsif ($sym == CFClient::SDLK_INSERT && $mod & CFClient::KMOD_CTRL) { |
|
|
187 | $::BIND_EDITOR->set_binding (undef, undef, [], |
|
|
188 | sub { |
|
|
189 | my ($mod, $sym, $cmds) = @_; |
|
|
190 | $::CFG->{bindings}->{$mod}->{$sym} = $cmds; |
|
|
191 | }); |
|
|
192 | $::BIND_EDITOR->start; |
|
|
193 | $::BIND_EDITOR->show; |
|
|
194 | } elsif ($sym == CFClient::SDLK_INSERT && not ($mod & CFClient::KMOD_CTRL)) { |
|
|
195 | $::BIND_EDITOR->stop; |
|
|
196 | $::BIND_EDITOR->ask_for_bind_and_commit; |
|
|
197 | $::BIND_EDITOR->hide; |
|
|
198 | } elsif (my $bind_cmd = $::CFG->{bindings}->{$mod}->{$sym}) { |
|
|
199 | $::CONN->user_send ($_) for @$bind_cmd; |
|
|
200 | } elsif ((ord 'a') <= $uni && $uni <= (ord 'z')) { |
163 | $self->{completer}->key_down ($ev); |
201 | $self->{completer}->key_down ($ev); |
164 | $self->{completer}->show; |
202 | $self->{completer}->show; |
|
|
203 | } else { |
|
|
204 | return 0; |
|
|
205 | } |
|
|
206 | |
165 | } |
207 | 1 |
166 | } |
208 | } |
167 | |
209 | |
168 | sub key_up { |
210 | sub key_up { |
169 | my ($self, $ev) = @_; |
211 | my ($self, $ev) = @_; |
170 | |
212 | |
|
|
213 | my $res = 0; |
171 | my $mod = $ev->{mod}; |
214 | my $mod = $ev->{mod}; |
172 | my $sym = $ev->{sym}; |
215 | my $sym = $ev->{sym}; |
173 | |
216 | |
174 | if (!($mod & CFClient::KMOD_SHIFT) && delete $self->{shft}) { |
217 | if (!($mod & CFClient::KMOD_SHIFT) && delete $self->{shft}) { |
175 | $::CONN->user_send ("fire_stop"); |
218 | $::CONN->user_send ("fire_stop"); |
|
|
219 | $res = 1; |
176 | } |
220 | } |
|
|
221 | |
177 | if (!($mod & CFClient::KMOD_CTRL ) && delete $self->{ctrl}) { |
222 | if (!($mod & CFClient::KMOD_CTRL ) && delete $self->{ctrl}) { |
178 | $::CONN->user_send ("run_stop"); |
223 | $::CONN->user_send ("run_stop"); |
|
|
224 | $res = 1; |
179 | } |
225 | } |
|
|
226 | |
|
|
227 | $res |
180 | } |
228 | } |
181 | |
229 | |
182 | sub draw { |
230 | sub draw { |
183 | my ($self) = @_; |
231 | my ($self) = @_; |
184 | |
232 | |
… | |
… | |
204 | glTranslate $sx0 - 32, $sy0 - 32, 0; |
252 | glTranslate $sx0 - 32, $sy0 - 32, 0; |
205 | |
253 | |
206 | my ($w, $h, $data) = $::MAP->draw ($sx, $sy, 0, 0, $sw + 1, $sh + 1); |
254 | my ($w, $h, $data) = $::MAP->draw ($sx, $sy, 0, 0, $sw + 1, $sh + 1); |
207 | |
255 | |
208 | if ($::CFG->{fow_enable}) { |
256 | if ($::CFG->{fow_enable}) { |
209 | if ($::CFG->{fow_smooth} && $CFClient::GL_VERSION >= 1.2) { # smooth fog of war |
257 | 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); |
258 | glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER); |
211 | glConvolutionFilter2D ( |
259 | glConvolutionFilter2D ( |
212 | GL_CONVOLUTION_2D, |
260 | GL_CONVOLUTION_2D, |
213 | GL_ALPHA, |
261 | GL_ALPHA, |
214 | 3, 3, |
262 | 3, 3, |
215 | GL_ALPHA, GL_FLOAT, |
263 | GL_ALPHA, GL_FLOAT, |
216 | pack "f*", |
264 | (pack "f*", @{ $self->{smooth_matrix} }), |
217 | 0.05, 0.13, 0.05, |
|
|
218 | 0.13, 0.30, 0.13, |
|
|
219 | 0.05, 0.13, 0.05, |
|
|
220 | ); |
265 | ); |
221 | glEnable GL_CONVOLUTION_2D; |
266 | glEnable GL_CONVOLUTION_2D; |
222 | } |
267 | } |
223 | |
268 | |
224 | $self->{fow_texture_name} ||= glGenTexture; |
269 | $self->{fow_texture_name} ||= glGenTexture; |
… | |
… | |
279 | # |
324 | # |
280 | # $label->show; |
325 | # $label->show; |
281 | # $label->update; |
326 | # $label->update; |
282 | # |
327 | # |
283 | # $CFClient::UI::ROOT->on_post_alloc ("$self$label" => sub { |
328 | # $CFClient::UI::ROOT->on_post_alloc ("$self$label" => sub { |
284 | # $label->move ( |
329 | # $label->move_abs ( |
285 | # ($::WIDTH - $label->{w}) * 0.5, |
330 | # ($::WIDTH - $label->{w}) * 0.5, |
286 | # ($::HEIGHT - $label->{h}) * 0.5, |
331 | # ($::HEIGHT - $label->{h}) * 0.5, |
287 | # ); |
332 | # ); |
288 | # }); |
333 | # }); |
289 | # |
334 | # |
… | |
… | |
406 | fontsize => $_, |
451 | fontsize => $_, |
407 | ), (0.8) x 16 |
452 | ), (0.8) x 16 |
408 | ]; |
453 | ]; |
409 | |
454 | |
410 | $self->{entry} = new CFClient::UI::Entry |
455 | $self->{entry} = new CFClient::UI::Entry |
411 | connect_changed => sub { |
456 | on_changed => sub { |
412 | $self->update_labels; |
457 | $self->update_labels; |
413 | }, |
458 | }, |
414 | connect_key_down => sub { |
459 | on_key_down => sub { |
415 | my ($entry, $ev) = @_; |
460 | my ($entry, $ev) = @_; |
416 | |
461 | |
417 | my $self = $entry->{parent}{parent}; |
462 | my $self = $entry->{parent}{parent}; |
418 | |
463 | |
419 | if ($ev->{sym} == 13) { |
464 | if ($ev->{sym} == 13) { |
420 | if (exists $self->{select}) { |
465 | if (exists $self->{select}) { |
421 | $self->{last_command} = $self->{select}; |
466 | $self->{last_command} = $self->{select}; |
422 | $::CONN->user_send ($self->{select}); |
467 | $::CONN->user_send ($self->{select}); |
|
|
468 | |
|
|
469 | unshift @{$self->{history}}, $self->{select}; |
|
|
470 | $self->{hist_ptr} = 0; |
|
|
471 | |
423 | $self->hide; |
472 | $self->hide; |
424 | } |
473 | } |
425 | } elsif ($ev->{sym} == 27) { |
474 | } elsif ($ev->{sym} == 27) { |
|
|
475 | $self->{hist_ptr} = 0; |
426 | $self->hide; |
476 | $self->hide; |
427 | return; |
477 | return; |
428 | } elsif ($ev->{sym} == CFClient::SDLK_DOWN) { |
478 | } elsif ($ev->{sym} == CFClient::SDLK_DOWN) { |
|
|
479 | if ($self->{hist_ptr} > 1) { |
|
|
480 | $self->{hist_ptr}--; |
|
|
481 | $self->{entry}->set_text ($self->{history}->[$self->{hist_ptr} - 1]); |
|
|
482 | } elsif ($self->{hist_ptr} > 0) { |
|
|
483 | $self->{hist_ptr}--; |
|
|
484 | $self->{entry}->set_text ($self->{hist_saveback}); |
|
|
485 | } else { |
429 | ++$self->{select_offset} |
486 | ++$self->{select_offset} |
430 | if $self->{select_offset} < $#{ $self->{last_match} || [] }; |
487 | if $self->{select_offset} < $#{ $self->{last_match} || [] }; |
|
|
488 | } |
431 | $self->update_labels; |
489 | $self->update_labels; |
432 | } elsif ($ev->{sym} == CFClient::SDLK_UP) { |
490 | } elsif ($ev->{sym} == CFClient::SDLK_UP) { |
|
|
491 | if ($self->{select_offset}) { |
433 | --$self->{select_offset} |
492 | --$self->{select_offset} |
|
|
493 | } else { |
|
|
494 | unless ($self->{hist_ptr}) { |
|
|
495 | $self->{hist_saveback} = $self->{entry}->get_text; |
|
|
496 | } |
|
|
497 | if ($self->{hist_ptr} <= $#{$self->{history}}) { |
434 | if $self->{select_offset}; |
498 | $self->{hist_ptr}++; |
|
|
499 | } |
|
|
500 | $self->{entry}->set_text ($self->{history}->[$self->{hist_ptr} - 1]) |
|
|
501 | if exists $self->{history}->[$self->{hist_ptr} - 1]; |
|
|
502 | } |
435 | $self->update_labels; |
503 | $self->update_labels; |
436 | } else { |
504 | } else { |
437 | return 0; |
505 | return 0; |
438 | } |
506 | } |
439 | |
507 | |
… | |
… | |
458 | |
526 | |
459 | sub size_allocate { |
527 | sub size_allocate { |
460 | my ($self, $w, $h) = @_; |
528 | my ($self, $w, $h) = @_; |
461 | |
529 | |
462 | $self->SUPER::size_allocate ($w, $h); |
530 | $self->SUPER::size_allocate ($w, $h); |
463 | $self->move (($::WIDTH - $w) * 0.5, ($::HEIGHT - $h) * 0.6, 10); |
531 | $self->move_abs (($::WIDTH - $w) * 0.5, ($::HEIGHT - $h) * 0.6, 10); |
464 | } |
532 | } |
465 | |
533 | |
466 | sub show { |
534 | sub show { |
467 | my ($self) = @_; |
535 | my ($self) = @_; |
468 | |
536 | |
… | |
… | |
478 | } |
546 | } |
479 | |
547 | |
480 | sub key_down { |
548 | sub key_down { |
481 | my ($self, $ev) = @_; |
549 | my ($self, $ev) = @_; |
482 | |
550 | |
483 | $self->{entry}->key_down ($ev); |
551 | $self->{entry}->key_down ($ev) |
484 | } |
552 | } |
485 | |
553 | |
486 | sub update_labels { |
554 | sub update_labels { |
487 | my ($self) = @_; |
555 | my ($self) = @_; |
488 | |
556 | |
… | |
… | |
521 | |
589 | |
522 | @match = map $self->{command}{$_->[0]}, |
590 | @match = map $self->{command}{$_->[0]}, |
523 | sort { |
591 | sort { |
524 | $a->[1] <=> $b->[1] |
592 | $a->[1] <=> $b->[1] |
525 | or $self->{command}{$a->[0]}[4] <=> $self->{command}{$b->[0]}[4] |
593 | or $self->{command}{$a->[0]}[4] <=> $self->{command}{$b->[0]}[4] |
526 | or (length $a->[0]) <=> (length $b->[0]) |
594 | or (length $b->[0]) <=> (length $a->[0]) |
527 | } @match; |
595 | } @match; |
528 | } |
596 | } |
529 | |
597 | |
530 | $self->{last_search} = $cmd; |
598 | $self->{last_search} = $text; |
531 | $self->{last_match} = \@match; |
599 | $self->{last_match} = \@match; |
532 | |
600 | |
533 | $self->{select_offset} = 0; |
601 | $self->{select_offset} = 0; |
534 | } |
602 | } |
535 | |
603 | |