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