… | |
… | |
61 | } |
61 | } |
62 | |
62 | |
63 | sub button_down { |
63 | sub button_down { |
64 | my ($self, $ev, $x, $y) = @_; |
64 | my ($self, $ev, $x, $y) = @_; |
65 | |
65 | |
|
|
66 | return unless $::CONN; |
|
|
67 | |
66 | $self->focus_in; |
68 | $self->focus_in; |
67 | |
69 | |
68 | if ($ev->{button} == 1) { |
70 | if ($ev->{button} == 1) { |
69 | my $x = int +($ev->{x} - $::CFG->{map_shift_x}) / (32 * $::CFG->{map_scale}); |
71 | my $x = CFClient::floor +($ev->{x} - $self->{sx0}) / $self->{tilesize} - $self->{sx}; |
70 | my $y = int +($ev->{y} - $::CFG->{map_shift_y}) / (32 * $::CFG->{map_scale}); |
72 | my $y = CFClient::floor +($ev->{y} - $self->{sy0}) / $self->{tilesize} - $self->{sy}; |
71 | |
|
|
72 | $x += int 0.5 * ($::MAP->w - $self->{sw} - 1); |
|
|
73 | $y += int 0.5 * ($::MAP->h - $self->{sh} - 1); |
|
|
74 | |
73 | |
75 | $x -= int 0.5 * $::MAP->w; |
74 | $x -= int 0.5 * $self->{sw}; |
76 | $y -= int 0.5 * $::MAP->h; |
75 | $y -= int 0.5 * $self->{sh}; |
77 | |
76 | |
78 | $x += 1; |
77 | $::CONN->lookat ($x, $y) |
79 | $y += 1; |
|
|
80 | |
|
|
81 | $::CONN->send (sprintf "lookat %d %d", $x, $y) |
|
|
82 | if $::CONN; |
78 | if $::CONN; |
83 | |
79 | |
84 | } elsif ($ev->{button} == 2) { |
80 | } elsif ($ev->{button} == 2) { |
85 | my ($ox, $oy) = ($ev->{x}, $ev->{y}); |
81 | my ($ox, $oy) = ($ev->{x}, $ev->{y}); |
86 | my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y}); |
82 | my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y}); |
… | |
… | |
181 | $self->{completer}->set_prefix (""); |
177 | $self->{completer}->set_prefix (""); |
182 | $self->{completer}->show; |
178 | $self->{completer}->show; |
183 | } elsif (exists $DIR{$sym}) { |
179 | } elsif (exists $DIR{$sym}) { |
184 | if ($mod & CFClient::KMOD_SHIFT) { |
180 | if ($mod & CFClient::KMOD_SHIFT) { |
185 | $self->{shft}++; |
181 | $self->{shft}++; |
|
|
182 | if ($DIR{$sym}[0] != $self->{fire_dir}) { |
186 | $::CONN->user_send ("fire $DIR{$sym}[0]"); |
183 | $::CONN->user_send ("fire $DIR{$sym}[0]"); |
|
|
184 | } |
|
|
185 | $self->{fire_dir} = $DIR{$sym}[0]; |
187 | } elsif ($mod & CFClient::KMOD_CTRL) { |
186 | } elsif ($mod & CFClient::KMOD_CTRL) { |
188 | $self->{ctrl}++; |
187 | $self->{ctrl}++; |
189 | $::CONN->user_send ("run $DIR{$sym}[0]"); |
188 | $::CONN->user_send ("run $DIR{$sym}[0]"); |
190 | } else { |
189 | } else { |
191 | $::CONN->user_send ("$DIR{$sym}[1]"); |
190 | $::CONN->user_send ("$DIR{$sym}[1]"); |
… | |
… | |
219 | |
218 | |
220 | my $res = 0; |
219 | my $res = 0; |
221 | my $mod = $ev->{mod}; |
220 | my $mod = $ev->{mod}; |
222 | my $sym = $ev->{sym}; |
221 | my $sym = $ev->{sym}; |
223 | |
222 | |
|
|
223 | if ($::CFG->{shift_fire_stop}) { |
224 | if (!($mod & CFClient::KMOD_SHIFT) && delete $self->{shft}) { |
224 | if (!($mod & CFClient::KMOD_SHIFT) && delete $self->{shft}) { |
225 | $::CONN->user_send ("fire_stop"); |
225 | $::CONN->user_send ("fire_stop"); |
|
|
226 | delete $self->{fire_dir}; |
226 | $res = 1; |
227 | $res = 1; |
|
|
228 | } |
|
|
229 | } else { |
|
|
230 | if (exists $DIR{$sym} && delete $self->{shft}) { |
|
|
231 | $::CONN->user_send ("fire_stop"); |
|
|
232 | delete $self->{fire_dir}; |
|
|
233 | $res = 1; |
|
|
234 | } elsif (($sym == CFClient::SDLK_LSHIFT || $sym == CFClient::SDLK_RSHIFT) && delete $self->{shft}) { # XXX: is RSHIFT ok? |
|
|
235 | $::CONN->user_send ("fire_stop"); |
|
|
236 | delete $self->{fire_dir}; |
|
|
237 | $res = 1; |
|
|
238 | } |
227 | } |
239 | } |
228 | |
240 | |
229 | if (!($mod & CFClient::KMOD_CTRL ) && delete $self->{ctrl}) { |
241 | if (!($mod & CFClient::KMOD_CTRL ) && delete $self->{ctrl}) { |
230 | $::CONN->user_send ("run_stop"); |
242 | $::CONN->user_send ("run_stop"); |
231 | $res = 1; |
243 | $res = 1; |
… | |
… | |
235 | } |
247 | } |
236 | |
248 | |
237 | sub draw { |
249 | sub draw { |
238 | my ($self) = @_; |
250 | my ($self) = @_; |
239 | |
251 | |
|
|
252 | return unless $::MAP; |
|
|
253 | |
240 | my $focused = $CFClient::UI::FOCUS == $self |
254 | my $focused = $CFClient::UI::FOCUS == $self |
241 | || $CFClient::UI::FOCUS == $self->{completer}{entry}; |
255 | || $CFClient::UI::FOCUS == $self->{completer}{entry}; |
242 | |
256 | |
243 | return |
257 | return |
244 | unless $focused || !$::FAST; |
258 | unless $focused || !$::FAST; |
245 | |
259 | |
246 | if (delete $self->{need_update}) { |
260 | if (delete $self->{need_update}) { |
|
|
261 | my $tilesize = $self->{tilesize} = int 32 * $::CFG->{map_scale}; |
|
|
262 | |
|
|
263 | my $sx = $self->{sx} = CFClient::ceil $::CFG->{map_shift_x} / $tilesize; |
|
|
264 | my $sy = $self->{sy} = CFClient::ceil $::CFG->{map_shift_y} / $tilesize; |
|
|
265 | |
|
|
266 | my $sx0 = $self->{sx0} = $::CFG->{map_shift_x} - $sx * $tilesize; |
|
|
267 | my $sy0 = $self->{sy0} = $::CFG->{map_shift_y} - $sy * $tilesize; |
|
|
268 | |
|
|
269 | my $sw = $self->{sw} = 1 + CFClient::ceil $::WIDTH / $tilesize; |
|
|
270 | my $sh = $self->{sh} = 1 + CFClient::ceil $::HEIGHT / $tilesize; |
|
|
271 | |
|
|
272 | if ($::CFG->{fow_enable}) { |
|
|
273 | my ($w, $h, $data) = $::MAP->fow_texture ($sx, $sy, 0, 0, $sw, $sh); |
|
|
274 | |
|
|
275 | if ($::CFG->{fow_smooth} && $CFClient::OpenGL::GL_VERSION >= 1.2) { # smooth fog of war |
|
|
276 | glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER); |
|
|
277 | glConvolutionFilter2D ( |
|
|
278 | GL_CONVOLUTION_2D, |
|
|
279 | GL_ALPHA, |
|
|
280 | 3, 3, |
|
|
281 | GL_ALPHA, GL_FLOAT, |
|
|
282 | (pack "f*", @{ $self->{smooth_matrix} }), |
|
|
283 | ); |
|
|
284 | glEnable GL_CONVOLUTION_2D; |
|
|
285 | } |
|
|
286 | |
|
|
287 | $self->{fow_texture} = new CFClient::Texture |
|
|
288 | w => $w, |
|
|
289 | h => $h, |
|
|
290 | data => $data, |
|
|
291 | internalformat => GL_ALPHA, |
|
|
292 | format => GL_ALPHA; |
|
|
293 | |
|
|
294 | glDisable GL_CONVOLUTION_2D if $::CFG->{fow_smooth}; |
|
|
295 | } else { |
|
|
296 | delete $self->{fow_texture}; |
|
|
297 | } |
|
|
298 | |
247 | glNewList $self->{list}; |
299 | glNewList $self->{list}; |
248 | |
300 | |
249 | if ($::MAP) { |
|
|
250 | my $sw = $self->{sw} = int $::WIDTH / (32 * $::CFG->{map_scale}) + 0.99; |
|
|
251 | my $sh = $self->{sh} = int $::HEIGHT / (32 * $::CFG->{map_scale}) + 0.99; |
|
|
252 | |
|
|
253 | my $sx = $::CFG->{map_shift_x} / $::CFG->{map_scale}; |
|
|
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; |
|
|
257 | |
|
|
258 | glPushMatrix; |
301 | glPushMatrix; |
|
|
302 | glTranslate $sx0, $sy0; |
259 | glScale $::CFG->{map_scale}, $::CFG->{map_scale}; |
303 | glScale $::CFG->{map_scale}, $::CFG->{map_scale}; |
260 | |
304 | |
261 | glTranslate $sx0, $sy0; |
305 | $::MAP->draw ($sx, $sy, 0, 0, $sw, $sh); |
262 | |
306 | |
263 | my ($w, $h, $data) = $::MAP->draw ($sx, $sy, 0, 0, $sw + 1, $sh + 1); |
307 | if (my $tex = $self->{fow_texture}) { |
264 | |
|
|
265 | if ($::CFG->{fow_enable}) { |
|
|
266 | if ($::CFG->{fow_smooth} && $CFClient::OpenGL::GL_VERSION >= 1.2) { # smooth fog of war |
|
|
267 | glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER); |
|
|
268 | glConvolutionFilter2D ( |
|
|
269 | GL_CONVOLUTION_2D, |
|
|
270 | GL_ALPHA, |
|
|
271 | 3, 3, |
|
|
272 | GL_ALPHA, GL_FLOAT, |
|
|
273 | (pack "f*", @{ $self->{smooth_matrix} }), |
|
|
274 | ); |
|
|
275 | glEnable GL_CONVOLUTION_2D; |
|
|
276 | } |
|
|
277 | |
|
|
278 | $self->{fow_texture_name} ||= glGenTexture; |
|
|
279 | # try to re-use the texture name: TODO improve texture class instead |
|
|
280 | |
|
|
281 | $self->{fow_texture} = new CFClient::Texture |
|
|
282 | w => $w, |
|
|
283 | h => $h, |
|
|
284 | data => $data, |
|
|
285 | name => $self->{fow_texture_name}, |
|
|
286 | internalformat => GL_ALPHA, |
|
|
287 | format => GL_ALPHA; |
|
|
288 | |
|
|
289 | glDisable GL_CONVOLUTION_2D if $::CFG->{fow_smooth}; |
|
|
290 | |
|
|
291 | glEnable GL_TEXTURE_2D; |
308 | glEnable GL_TEXTURE_2D; |
292 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
309 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
293 | |
310 | |
|
|
311 | glScale 32, 32; |
294 | glColor +($::CFG->{fow_intensity}) x 3, 0.8; |
312 | glColor +($::CFG->{fow_intensity}) x 3, 0.9; |
295 | $self->{fow_texture}->draw_quad_alpha (0, 0, $w * 32, $h * 32); |
313 | $self->{fow_texture}->draw_quad_alpha (0, 0); |
296 | |
314 | |
297 | glDisable GL_TEXTURE_2D; |
315 | glDisable GL_TEXTURE_2D; |
298 | } |
316 | } |
299 | |
317 | |
300 | glPopMatrix; |
318 | glPopMatrix; |
301 | } |
|
|
302 | |
319 | |
303 | glEndList; |
320 | glEndList; |
304 | } |
321 | } |
305 | |
322 | |
306 | glPushMatrix; |
323 | glPushMatrix; |
307 | glCallList $self->{list}; |
324 | glCallList $self->{list}; |
308 | glPopMatrix; |
325 | glPopMatrix; |
309 | |
326 | |
310 | # TNT2 emulates logops in software (or worse :) |
327 | # TNT2 emulates logops in software (or worse :) |
311 | if ($focused) { |
328 | unless ($focused) { |
312 | (delete $self->{out_of_focus})->destroy |
|
|
313 | if $self->{out_of_focus}; |
|
|
314 | } else { |
|
|
315 | glColor 0.4, 0.2, 0.2, 0.6; |
329 | glColor 0.4, 0.2, 0.2, 0.6; |
316 | glEnable GL_BLEND; |
330 | glEnable GL_BLEND; |
317 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
331 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
318 | glBegin GL_QUADS; |
332 | glBegin GL_QUADS; |
319 | glVertex 0, 0; |
333 | glVertex 0, 0; |
320 | glVertex 0, $::HEIGHT; |
334 | glVertex 0, $::HEIGHT; |
321 | glVertex $::WIDTH, $::HEIGHT; |
335 | glVertex $::WIDTH, $::HEIGHT; |
322 | glVertex $::WIDTH, 0; |
336 | glVertex $::WIDTH, 0; |
323 | glEnd; |
337 | glEnd; |
324 | glDisable GL_BLEND; |
338 | glDisable GL_BLEND; |
325 | |
|
|
326 | # $self->{out_of_focus} ||= do { |
|
|
327 | # my $label = new CFClient::UI::Label |
|
|
328 | # x => 0, |
|
|
329 | # y => 0, |
|
|
330 | # z => 1, |
|
|
331 | # ellipsise => 0, |
|
|
332 | # text => "map out of focus (click map to play)"; |
|
|
333 | # |
|
|
334 | # $label->show; |
|
|
335 | # $label->update; |
|
|
336 | # |
|
|
337 | # $CFClient::UI::ROOT->on_post_alloc ("$self$label" => sub { |
|
|
338 | # $label->move_abs ( |
|
|
339 | # ($::WIDTH - $label->{w}) * 0.5, |
|
|
340 | # ($::HEIGHT - $label->{h}) * 0.5, |
|
|
341 | # ); |
|
|
342 | # }); |
|
|
343 | # |
|
|
344 | # $label |
|
|
345 | # }; |
|
|
346 | } |
339 | } |
347 | } |
340 | } |
348 | |
341 | |
349 | sub DESTROY { |
342 | sub DESTROY { |
350 | my $self = shift; |
343 | my $self = shift; |
… | |
… | |
462 | ]; |
455 | ]; |
463 | |
456 | |
464 | $self->{entry} = new CFClient::UI::Entry |
457 | $self->{entry} = new CFClient::UI::Entry |
465 | on_changed => sub { |
458 | on_changed => sub { |
466 | $self->update_labels; |
459 | $self->update_labels; |
|
|
460 | }, |
|
|
461 | on_button_down => sub { |
|
|
462 | my ($entry, $ev, $x, $y) = @_; |
|
|
463 | |
|
|
464 | if ($ev->{button} == 3) { |
|
|
465 | (new CFClient::UI::Menu |
|
|
466 | items => [ |
|
|
467 | ["bind to a key" => sub { $::BIND_EDITOR->do_quick_binding ([$self->{select}], sub { $entry->focus_in }) }] |
|
|
468 | ], |
|
|
469 | )->popup ($ev); |
|
|
470 | return 1; |
|
|
471 | } |
|
|
472 | 0 |
467 | }, |
473 | }, |
468 | on_key_down => sub { |
474 | on_key_down => sub { |
469 | my ($entry, $ev) = @_; |
475 | my ($entry, $ev) = @_; |
470 | |
476 | |
471 | my $self = $entry->{parent}{parent}; |
477 | my $self = $entry->{parent}{parent}; |