… | |
… | |
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; |
… | |
… | |
267 | glVertex $::WIDTH, $::HEIGHT; |
312 | glVertex $::WIDTH, $::HEIGHT; |
268 | glVertex $::WIDTH, 0; |
313 | glVertex $::WIDTH, 0; |
269 | glEnd; |
314 | glEnd; |
270 | glDisable GL_BLEND; |
315 | glDisable GL_BLEND; |
271 | |
316 | |
272 | $self->{out_of_focus} ||= do { |
317 | # $self->{out_of_focus} ||= do { |
273 | my $label = new CFClient::UI::Label |
318 | # my $label = new CFClient::UI::Label |
274 | x => 0, |
319 | # x => 0, |
275 | y => 0, |
320 | # y => 0, |
276 | z => 1, |
321 | # z => 1, |
277 | ellipsise => 0, |
322 | # ellipsise => 0, |
278 | text => "map out of focus (click map to play)"; |
323 | # text => "map out of focus (click map to play)"; |
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 | # |
290 | $label |
335 | # $label |
291 | }; |
336 | # }; |
292 | } |
337 | } |
293 | } |
338 | } |
294 | |
339 | |
295 | sub DESTROY { |
340 | sub DESTROY { |
296 | my $self = shift; |
341 | my $self = shift; |
… | |
… | |
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) { |
… | |
… | |
458 | |
503 | |
459 | sub size_allocate { |
504 | sub size_allocate { |
460 | my ($self, $w, $h) = @_; |
505 | my ($self, $w, $h) = @_; |
461 | |
506 | |
462 | $self->SUPER::size_allocate ($w, $h); |
507 | $self->SUPER::size_allocate ($w, $h); |
463 | $self->move (($::WIDTH - $w) * 0.5, ($::HEIGHT - $h) * 0.6, 10); |
508 | $self->move_abs (($::WIDTH - $w) * 0.5, ($::HEIGHT - $h) * 0.6, 10); |
464 | } |
509 | } |
465 | |
510 | |
466 | sub show { |
511 | sub show { |
467 | my ($self) = @_; |
512 | my ($self) = @_; |
468 | |
513 | |
… | |
… | |
478 | } |
523 | } |
479 | |
524 | |
480 | sub key_down { |
525 | sub key_down { |
481 | my ($self, $ev) = @_; |
526 | my ($self, $ev) = @_; |
482 | |
527 | |
483 | $self->{entry}->key_down ($ev); |
528 | $self->{entry}->key_down ($ev) |
484 | } |
529 | } |
485 | |
530 | |
486 | sub update_labels { |
531 | sub update_labels { |
487 | my ($self) = @_; |
532 | my ($self) = @_; |
488 | |
533 | |
… | |
… | |
521 | |
566 | |
522 | @match = map $self->{command}{$_->[0]}, |
567 | @match = map $self->{command}{$_->[0]}, |
523 | sort { |
568 | sort { |
524 | $a->[1] <=> $b->[1] |
569 | $a->[1] <=> $b->[1] |
525 | or $self->{command}{$a->[0]}[4] <=> $self->{command}{$b->[0]}[4] |
570 | or $self->{command}{$a->[0]}[4] <=> $self->{command}{$b->[0]}[4] |
526 | or (length $a->[0]) <=> (length $b->[0]) |
571 | or (length $b->[0]) <=> (length $a->[0]) |
527 | } @match; |
572 | } @match; |
528 | } |
573 | } |
529 | |
574 | |
530 | $self->{last_search} = $cmd; |
575 | $self->{last_search} = $text; |
531 | $self->{last_match} = \@match; |
576 | $self->{last_match} = \@match; |
532 | |
577 | |
533 | $self->{select_offset} = 0; |
578 | $self->{select_offset} = 0; |
534 | } |
579 | } |
535 | |
580 | |