1 | package DC::MapWidget; |
1 | package DC::MapWidget; |
2 | |
2 | |
3 | use strict; |
3 | use common::sense; |
4 | use utf8; |
|
|
5 | |
4 | |
6 | use List::Util qw(min max); |
5 | use List::Util qw(min max); |
7 | |
6 | |
8 | use DC; |
7 | use DC; |
9 | use DC::OpenGL; |
8 | use DC::OpenGL; |
… | |
… | |
214 | # push @items, [ |
213 | # push @items, [ |
215 | # "Edit this map <span size='xx-small'>(" . (DC::asxml $::CONN->{map_info}[0]) . ")</span>", |
214 | # "Edit this map <span size='xx-small'>(" . (DC::asxml $::CONN->{map_info}[0]) . ")</span>", |
216 | # \&editor_invoke, |
215 | # \&editor_invoke, |
217 | # ]; |
216 | # ]; |
218 | |
217 | |
219 | for my $type (qw(test name)) { |
218 | for my $type (@{ $::CONN->{editor_support}{servertypes} }) { |
220 | $::CONN->{editor_support}{type} ne $type |
219 | $::CONN->{editor_support}{servertype} ne $type |
221 | or next; |
220 | or next; |
222 | my $server = $::CONN->{editor_support}{"${type}server"} |
221 | my $server = $::CONN->{editor_support}{"${type}server"} |
223 | or next; |
222 | or next; |
224 | |
223 | |
225 | push @items, [ |
224 | push @items, [ |
… | |
… | |
407 | |
406 | |
408 | $self->{sdx} += $dx * $self->{tilesize}; # smooth displacement |
407 | $self->{sdx} += $dx * $self->{tilesize}; # smooth displacement |
409 | $self->{sdy} += $dy * $self->{tilesize}; |
408 | $self->{sdy} += $dy * $self->{tilesize}; |
410 | |
409 | |
411 | # save old fow texture, if applicable |
410 | # save old fow texture, if applicable |
412 | $self->{last_fow_texture} = $self->{fow_texture} |
411 | $self->{prev_fow_texture} = $::CFG->{smooth_transitions} && $self->{fow_texture}; |
413 | if $::CFG->{smooth_transitions}; |
|
|
414 | $self->{lfdx} = $dx; |
412 | $self->{lfdx} = $dx; |
415 | $self->{lfdy} = $dy; |
413 | $self->{lfdy} = $dy; |
416 | $self->{lmdx} = $self->{dx}; |
414 | $self->{lmdx} = $self->{dx}; |
417 | $self->{lmdy} = $self->{dy}; |
415 | $self->{lmdy} = $self->{dy}; |
418 | |
416 | |
… | |
… | |
516 | glTranslate $sx0, $sy0; |
514 | glTranslate $sx0, $sy0; |
517 | glScale $::CFG->{map_scale}, $::CFG->{map_scale}; |
515 | glScale $::CFG->{map_scale}, $::CFG->{map_scale}; |
518 | glTranslate DC::ceil $self->{sdx}, DC::ceil $self->{sdy}; |
516 | glTranslate DC::ceil $self->{sdx}, DC::ceil $self->{sdy}; |
519 | |
517 | |
520 | $::MAP->draw ($dx, $dy, $sw, $sh, |
518 | $::MAP->draw ($dx, $dy, $sw, $sh, |
521 | $self->{tilesize}, |
519 | ($self->{tilesize}) x 2, |
522 | $::CONN->{player}{tag}, |
520 | $::CONN->{player}{tag}, |
523 | -$self->{sdx}, -$self->{sdy}); |
521 | -$self->{sdx}, -$self->{sdy}); |
524 | |
522 | |
525 | glScale $self->{tilesize}, $self->{tilesize}; |
523 | glScale $self->{tilesize}, $self->{tilesize}; |
526 | |
524 | |
527 | if (my $tex = $self->{fow_texture}) { |
525 | if (my $tex = $self->{fow_texture}) { |
|
|
526 | my @prev_fow_params; |
|
|
527 | |
528 | if ($DC::OpenGL::GL_MULTITEX && $self->{last_fow_texture}) { |
528 | if ($DC::OpenGL::GL_MULTITEX && $self->{prev_fow_texture}) { |
529 | my $d1 = DC::distance $self->{sdx}, $self->{sdy}; |
529 | my $d1 = DC::distance $self->{sdx}, $self->{sdy}; |
530 | my $d2 = (DC::distance $self->{lfdx}, $self->{lfdy}) * $tilesize; |
530 | my $d2 = (DC::distance $self->{lfdx}, $self->{lfdy}) * $tilesize; |
531 | |
531 | |
532 | if ($d1 * $d2) { |
532 | if ($d1 * $d2) { |
533 | DC::Texture::draw_fow_texture |
533 | @prev_fow_params = ( |
534 | $::CFG->{fow_intensity}, |
|
|
535 | $TEX_HIDDEN[$::CFG->{fow_texture}]{name}, |
|
|
536 | @{$self->{fow_texture}}{qw(name data s t w h)}, |
|
|
537 | (min 1, $d1 / $d2), |
534 | (min 1, $d1 / $d2), |
538 | $self->{lmdx} - $dx - $self->{lfdx}, |
535 | $self->{lmdx} - $dx - $self->{lfdx}, |
539 | $self->{lmdy} - $dy - $self->{lfdy}, |
536 | $self->{lmdy} - $dy - $self->{lfdy}, |
540 | @{$self->{last_fow_texture}}{qw(name data)}; |
537 | @{$self->{prev_fow_texture}}{qw(name data)} |
541 | } else { |
538 | ); |
542 | delete $self->{last_fow_texture}; |
|
|
543 | } |
539 | } |
544 | } |
540 | } |
545 | |
541 | |
546 | unless ($self->{last_fow_texture}) { |
|
|
547 | DC::Texture::draw_fow_texture |
542 | DC::Texture::draw_fow_texture |
548 | $::CFG->{fow_intensity}, |
543 | $::CFG->{fow_intensity}, |
549 | $TEX_HIDDEN[$::CFG->{fow_texture}]{name}, |
544 | $TEX_HIDDEN[$::CFG->{fow_texture}]{name}, |
550 | @{$self->{fow_texture}}{qw(name data s t w h)}; |
545 | @{$self->{fow_texture}}{qw(name data s t w h)}, |
551 | } |
546 | @prev_fow_params; |
552 | } |
547 | } |
553 | |
548 | |
554 | if ($self->{magicmap}) { |
549 | if ($self->{magicmap}) { |
555 | my ($x, $y, $w, $h, $data) = @{ $self->{magicmap} }; |
550 | my ($x, $y, $w, $h, $data) = @{ $self->{magicmap} }; |
556 | |
551 | |
… | |
… | |
612 | $self->SUPER::DESTROY; |
607 | $self->SUPER::DESTROY; |
613 | } |
608 | } |
614 | |
609 | |
615 | package DC::MapWidget::MapMap; |
610 | package DC::MapWidget::MapMap; |
616 | |
611 | |
617 | use strict; |
612 | use common::sense; |
618 | use utf8; |
|
|
619 | |
613 | |
620 | our @ISA = DC::UI::Base::; |
614 | our @ISA = DC::UI::Base::; |
621 | |
615 | |
622 | use Time::HiRes qw(time); |
|
|
623 | use DC::OpenGL; |
616 | use DC::OpenGL; |
624 | |
617 | |
625 | sub size_request { |
618 | sub size_request { |
626 | ($::HEIGHT * 0.2, $::HEIGHT * 0.2) |
619 | ($::HEIGHT * 0.2, $::HEIGHT * 0.2) |
627 | } |
620 | } |
628 | |
621 | |
629 | sub refresh_hook { |
622 | sub refresh_hook { |
630 | my ($self) = @_; |
623 | my ($self) = @_; |
631 | |
624 | |
632 | if ($::MAP && $self->{texture_atime} < time) { |
625 | if ($::MAP && $self->{texture_atime} < EV::now) { |
633 | my ($w, $h) = @$self{qw(w h)}; |
626 | my ($w, $h) = @$self{qw(w h)}; |
634 | |
627 | |
635 | return unless $w && $h; |
628 | return unless $w && $h; |
636 | |
629 | |
637 | my $sw = int $::WIDTH / ($::MAPWIDGET->{tilesize} * $::CFG->{map_scale}) + 0.99; |
630 | my $sw = int $::WIDTH / ($::MAPWIDGET->{tilesize} * $::CFG->{map_scale}) + 0.99; |
… | |
… | |
652 | $self->{sh} = $sh; |
645 | $self->{sh} = $sh; |
653 | |
646 | |
654 | $self->{x0} = $x0; |
647 | $self->{x0} = $x0; |
655 | $self->{y0} = $y0; |
648 | $self->{y0} = $y0; |
656 | |
649 | |
657 | $self->{texture_atime} = time + 1/3; |
650 | $self->{texture_atime} = EV::now + 1/2; |
658 | |
651 | |
659 | $self->{texture} = |
652 | $self->{texture} = |
660 | new DC::Texture |
653 | new DC::Texture |
661 | w => $w, |
654 | w => $w, |
662 | h => $h, |
655 | h => $h, |
… | |
… | |
717 | glDisable GL_BLEND; |
710 | glDisable GL_BLEND; |
718 | } |
711 | } |
719 | |
712 | |
720 | package DC::MapWidget::Command; |
713 | package DC::MapWidget::Command; |
721 | |
714 | |
722 | use strict; |
715 | use common::sense; |
723 | |
716 | |
724 | use DC::OpenGL; |
717 | use DC::OpenGL; |
725 | |
718 | |
726 | our @ISA = DC::UI::Frame::; |
719 | our @ISA = DC::UI::Frame::; |
727 | |
720 | |