… | |
… | |
6 | use List::Util qw(min max); |
6 | use List::Util qw(min max); |
7 | |
7 | |
8 | use CFPlus; |
8 | use CFPlus; |
9 | use CFPlus::OpenGL; |
9 | use CFPlus::OpenGL; |
10 | use CFPlus::UI; |
10 | use CFPlus::UI; |
|
|
11 | use CFPlus::Macro; |
11 | |
12 | |
12 | our @ISA = CFPlus::UI::Base::; |
13 | our @ISA = CFPlus::UI::Base::; |
13 | |
14 | |
14 | my $magicmap_tex = |
15 | my $magicmap_tex = |
15 | new_from_file CFPlus::Texture CFPlus::find_rcfile "magicmap.png", |
16 | new_from_file CFPlus::Texture CFPlus::find_rcfile "magicmap.png", |
… | |
… | |
20 | |
21 | |
21 | my $self = $class->SUPER::new ( |
22 | my $self = $class->SUPER::new ( |
22 | z => -1, |
23 | z => -1, |
23 | can_focus => 1, |
24 | can_focus => 1, |
24 | list => glGenList, |
25 | list => glGenList, |
|
|
26 | tilesize => 32, |
25 | |
27 | |
26 | smooth_matrix => [ |
28 | smooth_matrix => [ |
27 | 0.05, 0.13, 0.05, |
29 | 0.30, 0.50, 0.30, |
28 | 0.13, 0.30, 0.13, |
|
|
29 | 0.05, 0.13, 0.05, |
30 | 0.50, 0.50, 0.50, |
|
|
31 | 0.30, 0.50, 0.30, |
30 | ], |
32 | ], |
31 | |
33 | |
32 | @_ |
34 | @_ |
33 | ); |
35 | ); |
34 | |
36 | |
… | |
… | |
36 | command => $self->{command}, |
38 | command => $self->{command}, |
37 | tooltip => "#completer_help", |
39 | tooltip => "#completer_help", |
38 | ; |
40 | ; |
39 | |
41 | |
40 | $self |
42 | $self |
|
|
43 | } |
|
|
44 | |
|
|
45 | sub set_tilesize { |
|
|
46 | my ($self, $tilesize) = @_; |
|
|
47 | |
|
|
48 | $self->{tilesize} = $tilesize; |
41 | } |
49 | } |
42 | |
50 | |
43 | sub add_command { |
51 | sub add_command { |
44 | my ($self, $command, $tooltip, $widget, $cb) = @_; |
52 | my ($self, $command, $tooltip, $widget, $cb) = @_; |
45 | |
53 | |
… | |
… | |
176 | |
184 | |
177 | if ($ev->{button} == 1) { |
185 | if ($ev->{button} == 1) { |
178 | $self->grab_focus; |
186 | $self->grab_focus; |
179 | return unless $::CONN; |
187 | return unless $::CONN; |
180 | |
188 | |
181 | my $x = $self->{dx} + CFPlus::floor +($ev->{x} - $self->{sx0}) / $self->{tilesize}; |
189 | my $x = $self->{dx} + CFPlus::floor +($ev->{x} - $self->{sx0}) / $self->{ctilesize}; |
182 | my $y = $self->{dy} + CFPlus::floor +($ev->{y} - $self->{sy0}) / $self->{tilesize}; |
190 | my $y = $self->{dy} + CFPlus::floor +($ev->{y} - $self->{sy0}) / $self->{ctilesize}; |
183 | |
191 | |
184 | $x -= CFPlus::floor $::MAP->w * 0.5; |
192 | $x -= CFPlus::floor $::MAP->w * 0.5; |
185 | $y -= CFPlus::floor $::MAP->h * 0.5; |
193 | $y -= CFPlus::floor $::MAP->h * 0.5; |
186 | |
194 | |
|
|
195 | if ($::CONN) { |
|
|
196 | if ($::IN_BUILD_MODE) { |
|
|
197 | $::CONN->buildat ($::IN_BUILD_MODE, $x, $y); |
|
|
198 | } else { |
187 | $::CONN->lookat ($x, $y) |
199 | $::CONN->lookat ($x, $y) |
188 | if $::CONN; |
200 | } |
|
|
201 | } |
189 | |
202 | |
190 | } elsif ($ev->{button} == 2) { |
203 | } elsif ($ev->{button} == 2) { |
191 | $self->grab_focus; |
204 | $self->grab_focus; |
192 | return unless $::CONN; |
205 | return unless $::CONN; |
193 | |
206 | |
… | |
… | |
279 | |
292 | |
280 | 1 |
293 | 1 |
281 | } |
294 | } |
282 | |
295 | |
283 | sub size_request { |
296 | sub size_request { |
|
|
297 | my ($self) = @_; |
|
|
298 | |
284 | ( |
299 | ( |
285 | 32 * CFPlus::ceil $::WIDTH / 32, |
300 | $self->{tilesize} * CFPlus::ceil $::WIDTH / $self->{tilesize}, |
286 | 32 * CFPlus::ceil $::HEIGHT / 32, |
301 | $self->{tilesize} * CFPlus::ceil $::HEIGHT / $self->{tilesize}, |
287 | ) |
302 | ) |
288 | } |
303 | } |
289 | |
304 | |
290 | sub update { |
305 | sub update { |
291 | my ($self) = @_; |
306 | my ($self) = @_; |
… | |
… | |
293 | $self->{need_update} = 1; |
308 | $self->{need_update} = 1; |
294 | $self->SUPER::update; |
309 | $self->SUPER::update; |
295 | } |
310 | } |
296 | |
311 | |
297 | my %DIR = ( |
312 | my %DIR = ( |
|
|
313 | CFPlus::SDLK_KP5, [0, "stay fire"], |
298 | CFPlus::SDLK_KP8, [1, "north"], |
314 | CFPlus::SDLK_KP8, [1, "north"], |
299 | CFPlus::SDLK_KP9, [2, "northeast"], |
315 | CFPlus::SDLK_KP9, [2, "northeast"], |
300 | CFPlus::SDLK_KP6, [3, "east"], |
316 | CFPlus::SDLK_KP6, [3, "east"], |
301 | CFPlus::SDLK_KP3, [4, "southeast"], |
317 | CFPlus::SDLK_KP3, [4, "southeast"], |
302 | CFPlus::SDLK_KP2, [5, "south"], |
318 | CFPlus::SDLK_KP2, [5, "south"], |
… | |
… | |
317 | my $sym = $ev->{sym}; |
333 | my $sym = $ev->{sym}; |
318 | my $uni = $ev->{unicode}; |
334 | my $uni = $ev->{unicode}; |
319 | |
335 | |
320 | $mod &= CFPlus::KMOD_CTRL | CFPlus::KMOD_ALT | CFPlus::KMOD_SHIFT; |
336 | $mod &= CFPlus::KMOD_CTRL | CFPlus::KMOD_ALT | CFPlus::KMOD_SHIFT; |
321 | |
337 | |
322 | if ($uni == ord "\t") { |
338 | if ($sym == 9) { |
323 | $::PL_WINDOW->toggle_visibility; |
339 | ($mod & CFPlus::KMOD_SHIFT ? $::CONSOLE->{window} : $::PL_WINDOW)->toggle_visibility; |
324 | } elsif ($sym == CFPlus::SDLK_F1 && !$mod) { |
340 | } elsif ($sym == CFPlus::SDLK_F1 && !$mod) { |
325 | $::HELP_WINDOW->toggle_visibility; |
341 | $::HELP_WINDOW->toggle_visibility; |
326 | } elsif ($sym == CFPlus::SDLK_F2 && !$mod) { |
342 | } elsif ($sym == CFPlus::SDLK_F2 && !$mod) { |
327 | ::toggle_player_page ($::STATS_PAGE); |
343 | ::toggle_player_page ($::STATS_PAGE); |
328 | } elsif ($sym == CFPlus::SDLK_F3 && !$mod) { |
344 | } elsif ($sym == CFPlus::SDLK_F3 && !$mod) { |
… | |
… | |
331 | ::toggle_player_page ($::SPELL_PAGE); |
347 | ::toggle_player_page ($::SPELL_PAGE); |
332 | } elsif ($sym == CFPlus::SDLK_F5 && !$mod) { |
348 | } elsif ($sym == CFPlus::SDLK_F5 && !$mod) { |
333 | ::toggle_player_page ($::INVENTORY_PAGE); |
349 | ::toggle_player_page ($::INVENTORY_PAGE); |
334 | } elsif ($sym == CFPlus::SDLK_F9 && !$mod) { |
350 | } elsif ($sym == CFPlus::SDLK_F9 && !$mod) { |
335 | $::SETUP_DIALOG->toggle_visibility; |
351 | $::SETUP_DIALOG->toggle_visibility; |
336 | } elsif ($sym == CFPlus::SDLK_INSERT && $mod & CFPlus::KMOD_CTRL) { |
|
|
337 | $::BIND_EDITOR->set_binding (undef, undef, [], |
|
|
338 | sub { |
|
|
339 | my ($mod, $sym, $cmds) = @_; |
|
|
340 | $::BIND_EDITOR->cfg_bind ($mod, $sym, $cmds); |
|
|
341 | }); |
|
|
342 | $::BIND_EDITOR->start; |
|
|
343 | $::BIND_EDITOR->show; |
|
|
344 | #TODO: elmex, what was this supposed to do? it currently crashes the client. |
|
|
345 | # } elsif ($sym == CFPlus::SDLK_INSERT && not ($mod & CFPlus::KMOD_CTRL)) { |
|
|
346 | # $::BIND_EDITOR->stop; |
|
|
347 | # $::BIND_EDITOR->ask_for_bind_and_commit; |
|
|
348 | # $::BIND_EDITOR->hide; |
|
|
349 | } elsif (!$::CONN) { |
352 | } elsif (!$::CONN) { |
350 | return 0; # bindings further down need a valid connection |
353 | return 0; # bindings further down need a valid connection |
351 | |
354 | |
352 | } elsif ($sym == CFPlus::SDLK_KP5 && !$mod) { |
|
|
353 | $::CONN->user_send ("stay fire"); |
|
|
354 | } elsif ($uni == ord ",") { |
355 | } elsif ($uni == ord ",") { |
355 | $::CONN->user_send ("take"); |
356 | $::CONN->user_send ("take"); |
356 | } elsif ($uni == ord " ") { |
357 | } elsif ($uni == ord " ") { |
357 | $::CONN->user_send ("apply"); |
358 | $::CONN->user_send ("apply"); |
358 | } elsif ($uni == 13) { |
359 | } elsif ($uni == 13) { |
359 | $::CONN->user_send ("examine"); |
360 | $::CONN->user_send ("examine"); |
360 | } elsif ($uni == ord ".") { |
361 | } elsif ($uni == ord ".") { |
361 | $::CONN->user_send ($self->{completer}{last_command}) |
362 | $::CONN->user_send ($self->{completer}{last_command}) |
362 | if exists $self->{completer}{last_command}; |
363 | if exists $self->{completer}{last_command}; |
363 | } elsif (my $bind_cmd = $::PROFILE->{bindings}{$mod}{$sym}) { |
364 | } elsif (my @macros = CFPlus::Macro::match_event $ev) { |
364 | $::CONN->user_send ($_) for @$bind_cmd; |
365 | $::CONN->macro_send ($_) for @macros; |
365 | } elsif (($sym == CFPlus::SDLK_KP_PLUS && !$mod) || $uni == ord "+") { |
366 | } elsif (($sym == CFPlus::SDLK_KP_PLUS && !$mod) || $uni == ord "+") { |
366 | $::CONN->user_send ("rotateshoottype +"); |
367 | $::CONN->user_send ("rotateshoottype +"); |
367 | } elsif (($sym == CFPlus::SDLK_KP_MINUS && !$mod) || $uni == ord "-") { |
368 | } elsif (($sym == CFPlus::SDLK_KP_MINUS && !$mod) || $uni == ord "-") { |
368 | $::CONN->user_send ("rotateshoottype -"); |
369 | $::CONN->user_send ("rotateshoottype -"); |
|
|
370 | } elsif ($uni == ord '!') { |
|
|
371 | $self->{completer}->set_prefix ("shout "); |
|
|
372 | $self->{completer}->show; |
369 | } elsif ($uni == ord '"') { |
373 | } elsif ($uni == ord '"') { |
370 | $self->{completer}->set_prefix ("$::CFG->{say_command} "); |
374 | $self->{completer}->set_prefix ("$::CFG->{say_command} "); |
371 | $self->{completer}->show; |
375 | $self->{completer}->show; |
372 | } elsif ($uni == ord "'") { |
376 | } elsif ($uni == ord "'") { |
373 | $self->{completer}->set_prefix (""); |
377 | $self->{completer}->set_prefix (""); |
… | |
… | |
449 | |
453 | |
450 | return |
454 | return |
451 | unless $focused || !$::FAST; |
455 | unless $focused || !$::FAST; |
452 | |
456 | |
453 | if (delete $self->{need_update}) { |
457 | if (delete $self->{need_update}) { |
454 | my $tilesize = $self->{tilesize} = int 32 * $::CFG->{map_scale}; |
458 | my $tilesize = $self->{ctilesize} = (int $self->{tilesize} * $::CFG->{map_scale}) || 1; |
455 | |
459 | |
456 | my $sw = $self->{sw} = 1 + CFPlus::ceil $self->{w} / $tilesize; |
460 | my $sw = $self->{sw} = 1 + CFPlus::ceil $self->{w} / $tilesize; |
457 | my $sh = $self->{sh} = 1 + CFPlus::ceil $self->{h} / $tilesize; |
461 | my $sh = $self->{sh} = 1 + CFPlus::ceil $self->{h} / $tilesize; |
458 | |
462 | |
459 | my $sx = CFPlus::ceil $::CFG->{map_shift_x} / $tilesize; |
463 | my $sx = CFPlus::ceil $::CFG->{map_shift_x} / $tilesize; |
… | |
… | |
464 | |
468 | |
465 | my $dx = $self->{dx} = CFPlus::ceil 0.5 * ($::MAP->w - $sw) - $sx; |
469 | my $dx = $self->{dx} = CFPlus::ceil 0.5 * ($::MAP->w - $sw) - $sx; |
466 | my $dy = $self->{dy} = CFPlus::ceil 0.5 * ($::MAP->h - $sh) - $sy; |
470 | my $dy = $self->{dy} = CFPlus::ceil 0.5 * ($::MAP->h - $sh) - $sy; |
467 | |
471 | |
468 | if ($::CFG->{fow_enable}) { |
472 | if ($::CFG->{fow_enable}) { |
469 | my ($w, $h, $data) = $::MAP->fow_texture ($dx, $dy, $sw, $sh); |
473 | my ($w, $h, $data) = $::MAP->fow_texture ( |
470 | |
474 | $dx, $dy, $sw, $sh, |
471 | if ($::CFG->{fow_smooth} && $CFPlus::OpenGL::GL_VERSION >= 1.2) { # smooth fog of war |
475 | $::CFG->{fow_smooth}, |
472 | glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER); |
|
|
473 | glConvolutionFilter2D ( |
|
|
474 | GL_CONVOLUTION_2D, |
|
|
475 | GL_ALPHA, |
|
|
476 | 3, 3, |
|
|
477 | GL_ALPHA, GL_FLOAT, |
|
|
478 | (pack "f*", @{ $self->{smooth_matrix} }), |
476 | pack "f*", @{ $self->{smooth_matrix} }, |
479 | ); |
477 | ); |
480 | glEnable GL_CONVOLUTION_2D; |
|
|
481 | } |
|
|
482 | |
478 | |
483 | $self->{fow_texture} = new CFPlus::Texture |
479 | $self->{fow_texture} = new CFPlus::Texture |
484 | w => $w, |
480 | w => $w, |
485 | h => $h, |
481 | h => $h, |
486 | data => $data, |
482 | data => $data, |
487 | internalformat => GL_ALPHA, |
483 | internalformat => GL_ALPHA, |
488 | format => GL_ALPHA; |
484 | format => GL_ALPHA; |
489 | |
|
|
490 | glDisable GL_CONVOLUTION_2D if $::CFG->{fow_smooth}; |
|
|
491 | } else { |
485 | } else { |
492 | delete $self->{fow_texture}; |
486 | delete $self->{fow_texture}; |
493 | } |
487 | } |
494 | |
488 | |
495 | glNewList $self->{list}; |
489 | glNewList $self->{list}; |
496 | |
490 | |
497 | glPushMatrix; |
491 | glPushMatrix; |
498 | glTranslate $sx0, $sy0; |
492 | glTranslate $sx0, $sy0; |
499 | glScale $::CFG->{map_scale}, $::CFG->{map_scale}; |
493 | glScale $::CFG->{map_scale}, $::CFG->{map_scale}; |
500 | |
494 | |
501 | $::MAP->draw ($dx, $dy, $sw, $sh); |
495 | $::MAP->draw ($dx, $dy, $sw, $sh, $self->{tilesize}); |
502 | |
496 | |
503 | glScale 32, 32; |
497 | glScale $self->{tilesize}, $self->{tilesize}; |
504 | |
498 | |
505 | if (my $tex = $self->{fow_texture}) { |
499 | if (my $tex = $self->{fow_texture}) { |
|
|
500 | glPushMatrix; |
|
|
501 | #glScale 1/3, 1/3 if $::CFG->{fow_smooth}; |
506 | glEnable GL_TEXTURE_2D; |
502 | glEnable GL_TEXTURE_2D; |
507 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
503 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
508 | |
504 | |
509 | glColor +($::CFG->{fow_intensity}) x 3, 0.9; |
505 | glColor +($::CFG->{fow_intensity}) x 3, 0.9; |
510 | $self->{fow_texture}->draw_quad_alpha (0, 0); |
506 | $self->{fow_texture}->draw_quad_alpha (0, 0); |
511 | |
507 | |
512 | glDisable GL_TEXTURE_2D; |
508 | glDisable GL_TEXTURE_2D; |
|
|
509 | glPopMatrix; |
513 | } |
510 | } |
514 | |
511 | |
515 | if ($self->{magicmap}) { |
512 | if ($self->{magicmap}) { |
516 | my ($x, $y, $w, $h, $data) = @{ $self->{magicmap} }; |
513 | my ($x, $y, $w, $h, $data) = @{ $self->{magicmap} }; |
517 | |
514 | |
… | |
… | |
552 | $self->SUPER::DESTROY; |
549 | $self->SUPER::DESTROY; |
553 | } |
550 | } |
554 | |
551 | |
555 | package CFPlus::MapWidget::MapMap; |
552 | package CFPlus::MapWidget::MapMap; |
556 | |
553 | |
|
|
554 | use strict; |
|
|
555 | use utf8; |
|
|
556 | |
557 | our @ISA = CFPlus::UI::Base::; |
557 | our @ISA = CFPlus::UI::Base::; |
558 | |
558 | |
559 | use Time::HiRes qw(time); |
559 | use Time::HiRes qw(time); |
560 | use CFPlus::OpenGL; |
560 | use CFPlus::OpenGL; |
561 | |
561 | |
… | |
… | |
583 | |
583 | |
584 | $::MAP or return; |
584 | $::MAP or return; |
585 | |
585 | |
586 | my ($w, $h) = @$self{qw(w h)}; |
586 | my ($w, $h) = @$self{qw(w h)}; |
587 | |
587 | |
588 | my $sw = int $::WIDTH / (32 * $::CFG->{map_scale}) + 0.99; |
588 | my $sw = int $::WIDTH / ($::MAPWIDGET->{tilesize} * $::CFG->{map_scale}) + 0.99; |
589 | my $sh = int $::HEIGHT / (32 * $::CFG->{map_scale}) + 0.99; |
589 | my $sh = int $::HEIGHT / ($::MAPWIDGET->{tilesize} * $::CFG->{map_scale}) + 0.99; |
590 | |
590 | |
591 | my $sx = int $::CFG->{map_shift_x} / 32; |
591 | my $sx = int $::CFG->{map_shift_x} / $::MAPWIDGET->{tilesize}; |
592 | my $sy = int $::CFG->{map_shift_y} / 32; |
592 | my $sy = int $::CFG->{map_shift_y} / $::MAPWIDGET->{tilesize}; |
593 | |
593 | |
594 | my $ox = 0.5 * ($w - $sw); |
594 | my $ox = 0.5 * ($w - $sw); |
595 | my $oy = 0.5 * ($h - $sh); |
595 | my $oy = 0.5 * ($h - $sh); |
596 | |
596 | |
597 | glEnable GL_BLEND; |
597 | glEnable GL_BLEND; |
… | |
… | |
670 | |
670 | |
671 | if ($ev->{button} == 3) { |
671 | if ($ev->{button} == 3) { |
672 | (new CFPlus::UI::Menu |
672 | (new CFPlus::UI::Menu |
673 | items => [ |
673 | items => [ |
674 | ["bind <i>" . (CFPlus::asxml $self->{select}) . "</i> to a key" |
674 | ["bind <i>" . (CFPlus::asxml $self->{select}) . "</i> to a key" |
675 | => sub { $::BIND_EDITOR->do_quick_binding ([$self->{select}], sub { $entry->grab_focus }) }] |
675 | => sub { CFPlus::Macro::quick_macro [$self->{select}], sub { $entry->grab_focus } }] |
676 | ], |
676 | ], |
677 | )->popup ($ev); |
677 | )->popup ($ev); |
678 | return 1; |
678 | return 1; |
679 | } |
679 | } |
680 | 0 |
680 | 0 |