… | |
… | |
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}, |
… | |
… | |
56 | sub button_down { |
63 | sub button_down { |
57 | my ($self, $ev, $x, $y) = @_; |
64 | my ($self, $ev, $x, $y) = @_; |
58 | |
65 | |
59 | $self->focus_in; |
66 | $self->focus_in; |
60 | |
67 | |
61 | if ($ev->{button} == 2) { |
68 | if ($ev->{button} == 1) { |
|
|
69 | my $x = int +($ev->{x} - $::CFG->{map_shift_x}) / (32 * $::CFG->{map_scale}); |
|
|
70 | my $y = int +($ev->{y} - $::CFG->{map_shift_y}) / (32 * $::CFG->{map_scale}); |
|
|
71 | |
|
|
72 | $x += int 0.5 * ($::MAP->w - $self->{sw} - 1); |
|
|
73 | $y += int 0.5 * ($::MAP->h - $self->{sh} - 1); |
|
|
74 | |
|
|
75 | $x -= int 0.5 * $::MAP->w; |
|
|
76 | $y -= int 0.5 * $::MAP->h; |
|
|
77 | |
|
|
78 | $x += 1; |
|
|
79 | $y += 1; |
|
|
80 | |
|
|
81 | $::CONN->send (sprintf "lookat %d %d", $x, $y) |
|
|
82 | if $::CONN; |
|
|
83 | |
|
|
84 | } elsif ($ev->{button} == 2) { |
62 | my ($ox, $oy) = ($ev->{x}, $ev->{y}); |
85 | my ($ox, $oy) = ($ev->{x}, $ev->{y}); |
63 | my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y}); |
86 | my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y}); |
64 | |
87 | |
65 | $self->{motion} = sub { |
88 | $self->{motion} = sub { |
66 | my ($ev, $x, $y) = @_; |
89 | my ($ev, $x, $y) = @_; |
… | |
… | |
71 | $::CFG->{map_shift_y} = $bh + $y - $oy; |
94 | $::CFG->{map_shift_y} = $bh + $y - $oy; |
72 | |
95 | |
73 | $self->update; |
96 | $self->update; |
74 | }; |
97 | }; |
75 | } |
98 | } |
|
|
99 | |
|
|
100 | 1 |
76 | } |
101 | } |
77 | |
102 | |
78 | sub button_up { |
103 | sub button_up { |
79 | my ($self, $ev, $x, $y) = @_; |
104 | my ($self, $ev, $x, $y) = @_; |
80 | |
105 | |
81 | delete $self->{motion}; |
106 | delete $self->{motion}; |
|
|
107 | |
|
|
108 | 1 |
82 | } |
109 | } |
83 | |
110 | |
84 | sub mouse_motion { |
111 | sub mouse_motion { |
85 | my ($self, $ev, $x, $y) = @_; |
112 | my ($self, $ev, $x, $y) = @_; |
86 | |
113 | |
|
|
114 | if ($self->{motion}) { |
87 | $self->{motion}->($ev, $x, $y) if $self->{motion}; |
115 | $self->{motion}->($ev, $x, $y); |
|
|
116 | } else { |
|
|
117 | return 0; |
|
|
118 | } |
|
|
119 | |
|
|
120 | 1 |
88 | } |
121 | } |
89 | |
122 | |
90 | sub size_request { |
123 | sub size_request { |
91 | ( |
124 | ( |
92 | 1 + 32 * int $::WIDTH / 32, |
125 | 1 + 32 * int $::WIDTH / 32, |
… | |
… | |
118 | ); |
151 | ); |
119 | |
152 | |
120 | sub key_down { |
153 | sub key_down { |
121 | my ($self, $ev) = @_; |
154 | my ($self, $ev) = @_; |
122 | |
155 | |
123 | return unless $::CONN; |
156 | return 0 unless $::CONN; |
124 | |
157 | |
125 | my $mod = $ev->{mod}; |
158 | my $mod = $ev->{mod}; |
126 | my $sym = $ev->{sym}; |
159 | my $sym = $ev->{sym}; |
127 | my $uni = $ev->{unicode}; |
160 | my $uni = $ev->{unicode}; |
128 | |
161 | |
… | |
… | |
165 | }); |
198 | }); |
166 | $::BIND_EDITOR->start; |
199 | $::BIND_EDITOR->start; |
167 | $::BIND_EDITOR->show; |
200 | $::BIND_EDITOR->show; |
168 | } elsif ($sym == CFClient::SDLK_INSERT && not ($mod & CFClient::KMOD_CTRL)) { |
201 | } elsif ($sym == CFClient::SDLK_INSERT && not ($mod & CFClient::KMOD_CTRL)) { |
169 | $::BIND_EDITOR->stop; |
202 | $::BIND_EDITOR->stop; |
170 | $::BIND_EDITOR->ask_for_bind (1); |
203 | $::BIND_EDITOR->ask_for_bind_and_commit; |
171 | $::BIND_EDITOR->hide; |
204 | $::BIND_EDITOR->hide; |
172 | } elsif (my $bind_cmd = $::CFG->{bindings}->{$mod}->{$sym}) { |
205 | } elsif (my $bind_cmd = $::CFG->{bindings}->{$mod}->{$sym}) { |
173 | $::CONN->user_send ($_) for @$bind_cmd; |
206 | $::CONN->user_send ($_) for @$bind_cmd; |
174 | } elsif ((ord 'a') <= $uni && $uni <= (ord 'z')) { |
207 | } elsif ((ord 'a') <= $uni && $uni <= (ord 'z')) { |
175 | $self->{completer}->key_down ($ev); |
208 | $self->{completer}->key_down ($ev); |
176 | $self->{completer}->show; |
209 | $self->{completer}->show; |
|
|
210 | } else { |
|
|
211 | return 0; |
|
|
212 | } |
|
|
213 | |
177 | } |
214 | 1 |
178 | } |
215 | } |
179 | |
216 | |
180 | sub key_up { |
217 | sub key_up { |
181 | my ($self, $ev) = @_; |
218 | my ($self, $ev) = @_; |
182 | |
219 | |
|
|
220 | my $res = 0; |
183 | my $mod = $ev->{mod}; |
221 | my $mod = $ev->{mod}; |
184 | my $sym = $ev->{sym}; |
222 | my $sym = $ev->{sym}; |
185 | |
223 | |
186 | if (!($mod & CFClient::KMOD_SHIFT) && delete $self->{shft}) { |
224 | if (!($mod & CFClient::KMOD_SHIFT) && delete $self->{shft}) { |
187 | $::CONN->user_send ("fire_stop"); |
225 | $::CONN->user_send ("fire_stop"); |
|
|
226 | $res = 1; |
188 | } |
227 | } |
|
|
228 | |
189 | if (!($mod & CFClient::KMOD_CTRL ) && delete $self->{ctrl}) { |
229 | if (!($mod & CFClient::KMOD_CTRL ) && delete $self->{ctrl}) { |
190 | $::CONN->user_send ("run_stop"); |
230 | $::CONN->user_send ("run_stop"); |
|
|
231 | $res = 1; |
191 | } |
232 | } |
|
|
233 | |
|
|
234 | $res |
192 | } |
235 | } |
193 | |
236 | |
194 | sub draw { |
237 | sub draw { |
195 | my ($self) = @_; |
238 | my ($self) = @_; |
196 | |
239 | |
… | |
… | |
202 | |
245 | |
203 | if (delete $self->{need_update}) { |
246 | if (delete $self->{need_update}) { |
204 | glNewList $self->{list}; |
247 | glNewList $self->{list}; |
205 | |
248 | |
206 | if ($::MAP) { |
249 | if ($::MAP) { |
207 | my $sw = int $::WIDTH / (32 * $::CFG->{map_scale}) + 0.99; |
250 | my $sw = $self->{sw} = int $::WIDTH / (32 * $::CFG->{map_scale}) + 0.99; |
208 | my $sh = int $::HEIGHT / (32 * $::CFG->{map_scale}) + 0.99; |
251 | my $sh = $self->{sh} = int $::HEIGHT / (32 * $::CFG->{map_scale}) + 0.99; |
209 | |
252 | |
210 | my $sx = $::CFG->{map_shift_x} / $::CFG->{map_scale}; my $sx0 = $sx & 31; $sx = ($sx - $sx0) / 32; |
253 | my $sx = $::CFG->{map_shift_x} / $::CFG->{map_scale}; |
211 | my $sy = $::CFG->{map_shift_y} / $::CFG->{map_scale}; my $sy0 = $sy & 31; $sy = ($sy - $sy0) / 32; |
254 | my $sy = $::CFG->{map_shift_y} / $::CFG->{map_scale}; |
|
|
255 | my $sx0 = $self->{sx0} = ($sx & 31) - 32; $sx = $self->{sx} = ($sx - $sx0) / 32; |
|
|
256 | my $sy0 = $self->{sy0} = ($sy & 31) - 32; $sy = $self->{sy} = ($sy - $sy0) / 32; |
212 | |
257 | |
213 | glPushMatrix; |
258 | glPushMatrix; |
214 | glScale $::CFG->{map_scale}, $::CFG->{map_scale}; |
259 | glScale $::CFG->{map_scale}, $::CFG->{map_scale}; |
215 | |
260 | |
216 | glTranslate $sx0 - 32, $sy0 - 32, 0; |
261 | glTranslate $sx0, $sy0; |
217 | |
262 | |
218 | my ($w, $h, $data) = $::MAP->draw ($sx, $sy, 0, 0, $sw + 1, $sh + 1); |
263 | my ($w, $h, $data) = $::MAP->draw ($sx, $sy, 0, 0, $sw + 1, $sh + 1); |
219 | |
264 | |
220 | if ($::CFG->{fow_enable}) { |
265 | if ($::CFG->{fow_enable}) { |
221 | if ($::CFG->{fow_smooth} && $CFClient::OpenGL::GL_VERSION >= 1.2) { # smooth fog of war |
266 | if ($::CFG->{fow_smooth} && $CFClient::OpenGL::GL_VERSION >= 1.2) { # smooth fog of war |
… | |
… | |
223 | glConvolutionFilter2D ( |
268 | glConvolutionFilter2D ( |
224 | GL_CONVOLUTION_2D, |
269 | GL_CONVOLUTION_2D, |
225 | GL_ALPHA, |
270 | GL_ALPHA, |
226 | 3, 3, |
271 | 3, 3, |
227 | GL_ALPHA, GL_FLOAT, |
272 | GL_ALPHA, GL_FLOAT, |
228 | pack "f*", |
273 | (pack "f*", @{ $self->{smooth_matrix} }), |
229 | 0.05, 0.13, 0.05, |
|
|
230 | 0.13, 0.30, 0.13, |
|
|
231 | 0.05, 0.13, 0.05, |
|
|
232 | ); |
274 | ); |
233 | glEnable GL_CONVOLUTION_2D; |
275 | glEnable GL_CONVOLUTION_2D; |
234 | } |
276 | } |
235 | |
277 | |
236 | $self->{fow_texture_name} ||= glGenTexture; |
278 | $self->{fow_texture_name} ||= glGenTexture; |
… | |
… | |
430 | |
472 | |
431 | if ($ev->{sym} == 13) { |
473 | if ($ev->{sym} == 13) { |
432 | if (exists $self->{select}) { |
474 | if (exists $self->{select}) { |
433 | $self->{last_command} = $self->{select}; |
475 | $self->{last_command} = $self->{select}; |
434 | $::CONN->user_send ($self->{select}); |
476 | $::CONN->user_send ($self->{select}); |
|
|
477 | |
|
|
478 | unshift @{$self->{history}}, $self->{select}; |
|
|
479 | $self->{hist_ptr} = 0; |
|
|
480 | |
435 | $self->hide; |
481 | $self->hide; |
436 | } |
482 | } |
437 | } elsif ($ev->{sym} == 27) { |
483 | } elsif ($ev->{sym} == 27) { |
|
|
484 | $self->{hist_ptr} = 0; |
438 | $self->hide; |
485 | $self->hide; |
439 | return; |
486 | return; |
440 | } elsif ($ev->{sym} == CFClient::SDLK_DOWN) { |
487 | } elsif ($ev->{sym} == CFClient::SDLK_DOWN) { |
|
|
488 | if ($self->{hist_ptr} > 1) { |
|
|
489 | $self->{hist_ptr}--; |
|
|
490 | $self->{entry}->set_text ($self->{history}->[$self->{hist_ptr} - 1]); |
|
|
491 | } elsif ($self->{hist_ptr} > 0) { |
|
|
492 | $self->{hist_ptr}--; |
|
|
493 | $self->{entry}->set_text ($self->{hist_saveback}); |
|
|
494 | } else { |
441 | ++$self->{select_offset} |
495 | ++$self->{select_offset} |
442 | if $self->{select_offset} < $#{ $self->{last_match} || [] }; |
496 | if $self->{select_offset} < $#{ $self->{last_match} || [] }; |
|
|
497 | } |
443 | $self->update_labels; |
498 | $self->update_labels; |
444 | } elsif ($ev->{sym} == CFClient::SDLK_UP) { |
499 | } elsif ($ev->{sym} == CFClient::SDLK_UP) { |
|
|
500 | if ($self->{select_offset}) { |
445 | --$self->{select_offset} |
501 | --$self->{select_offset} |
|
|
502 | } else { |
|
|
503 | unless ($self->{hist_ptr}) { |
|
|
504 | $self->{hist_saveback} = $self->{entry}->get_text; |
|
|
505 | } |
|
|
506 | if ($self->{hist_ptr} <= $#{$self->{history}}) { |
446 | if $self->{select_offset}; |
507 | $self->{hist_ptr}++; |
|
|
508 | } |
|
|
509 | $self->{entry}->set_text ($self->{history}->[$self->{hist_ptr} - 1]) |
|
|
510 | if exists $self->{history}->[$self->{hist_ptr} - 1]; |
|
|
511 | } |
447 | $self->update_labels; |
512 | $self->update_labels; |
448 | } else { |
513 | } else { |
449 | return 0; |
514 | return 0; |
450 | } |
515 | } |
451 | |
516 | |
… | |
… | |
490 | } |
555 | } |
491 | |
556 | |
492 | sub key_down { |
557 | sub key_down { |
493 | my ($self, $ev) = @_; |
558 | my ($self, $ev) = @_; |
494 | |
559 | |
495 | $self->{entry}->key_down ($ev); |
560 | $self->{entry}->key_down ($ev) |
496 | } |
561 | } |
497 | |
562 | |
498 | sub update_labels { |
563 | sub update_labels { |
499 | my ($self) = @_; |
564 | my ($self) = @_; |
500 | |
565 | |