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; |
10 | use DC::UI; |
9 | use DC::UI; |
11 | use DC::Macro; |
10 | use DC::Macro; |
12 | |
11 | |
13 | our @ISA = DC::UI::Base::; |
12 | our @ISA = DC::UI::Base::; |
|
|
13 | |
|
|
14 | our @TEX_HIDDEN = map { |
|
|
15 | new_from_resource DC::Texture # MUST be POT |
|
|
16 | "hidden-$_.png", mipmap => 1, wrap => 1 |
|
|
17 | } 0, 1, 2; |
14 | |
18 | |
15 | my $magicmap_tex = |
19 | my $magicmap_tex = |
16 | new_from_resource DC::Texture "magicmap.png", |
20 | new_from_resource DC::Texture "magicmap.png", |
17 | mipmap => 1, wrap => 0, internalformat => GL_ALPHA; |
21 | mipmap => 1, wrap => 0, internalformat => GL_ALPHA; |
18 | |
22 | |
… | |
… | |
209 | # push @items, [ |
213 | # push @items, [ |
210 | # "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>", |
211 | # \&editor_invoke, |
215 | # \&editor_invoke, |
212 | # ]; |
216 | # ]; |
213 | |
217 | |
214 | for my $type (qw(test name)) { |
218 | for my $type (@{ $::CONN->{editor_support}{servertypes} }) { |
215 | $::CONN->{editor_support}{type} ne $type |
219 | $::CONN->{editor_support}{servertype} ne $type |
216 | or next; |
220 | or next; |
217 | my $server = $::CONN->{editor_support}{"${type}server"} |
221 | my $server = $::CONN->{editor_support}{"${type}server"} |
218 | or next; |
222 | or next; |
219 | |
223 | |
220 | push @items, [ |
224 | push @items, [ |
… | |
… | |
396 | } |
400 | } |
397 | |
401 | |
398 | sub scroll { |
402 | sub scroll { |
399 | my ($self, $dx, $dy) = @_; |
403 | my ($self, $dx, $dy) = @_; |
400 | |
404 | |
401 | $::MAP->scroll ($dx, $dy); |
|
|
402 | |
|
|
403 | $self->movement_update; |
405 | $self->movement_update; |
404 | |
406 | |
405 | $self->{sdx} += $dx * $self->{tilesize}; # smooth displacement |
407 | $self->{sdx} += $dx * $self->{tilesize}; # smooth displacement |
406 | $self->{sdy} += $dy * $self->{tilesize}; |
408 | $self->{sdy} += $dy * $self->{tilesize}; |
|
|
409 | |
|
|
410 | # save old fow texture, if applicable |
|
|
411 | $self->{prev_fow_texture} = $::CFG->{smooth_transitions} && $self->{fow_texture}; |
|
|
412 | $self->{lfdx} = $dx; |
|
|
413 | $self->{lfdy} = $dy; |
|
|
414 | $self->{lmdx} = $self->{dx}; |
|
|
415 | $self->{lmdy} = $self->{dy}; |
|
|
416 | |
|
|
417 | $::MAP->scroll ($dx, $dy); |
407 | } |
418 | } |
408 | |
419 | |
409 | sub set_magicmap { |
420 | sub set_magicmap { |
410 | my ($self, $w, $h, $x, $y, $data) = @_; |
421 | my ($self, $w, $h, $x, $y, $data) = @_; |
411 | |
422 | |
… | |
… | |
482 | |
493 | |
483 | my $dx = $self->{dx} = DC::ceil 0.5 * ($::MAP->w - $sw) - $sx; |
494 | my $dx = $self->{dx} = DC::ceil 0.5 * ($::MAP->w - $sw) - $sx; |
484 | my $dy = $self->{dy} = DC::ceil 0.5 * ($::MAP->h - $sh) - $sy; |
495 | my $dy = $self->{dy} = DC::ceil 0.5 * ($::MAP->h - $sh) - $sy; |
485 | |
496 | |
486 | if ($::CFG->{fow_enable}) { |
497 | if ($::CFG->{fow_enable}) { |
487 | $sdx_t = $sdy_t = 0;#d# |
498 | # draw_fow_texture REQUIRES the fow texture to stay the same size. |
488 | my ($w, $h, $data) = $::MAP->fow_texture ( |
499 | my ($w, $h, $data) = $::MAP->fow_texture ($dx, $dy, $sw, $sh); |
489 | $dx + (min 0, $sdx_t), |
|
|
490 | $dy + (min 0, $sdy_t), |
|
|
491 | $sw + abs $sdx_t, |
|
|
492 | $sh + abs $sdy_t |
|
|
493 | ); |
|
|
494 | |
500 | |
495 | $self->{fow_texture} = new DC::Texture |
501 | $self->{fow_texture} = new DC::Texture |
496 | w => $w, |
502 | w => $w, |
497 | h => $h, |
503 | h => $h, |
498 | data => $data, |
504 | data => $data, |
… | |
… | |
512 | $::MAP->draw ($dx, $dy, $sw, $sh, |
518 | $::MAP->draw ($dx, $dy, $sw, $sh, |
513 | $self->{tilesize}, |
519 | $self->{tilesize}, |
514 | $::CONN->{player}{tag}, |
520 | $::CONN->{player}{tag}, |
515 | -$self->{sdx}, -$self->{sdy}); |
521 | -$self->{sdx}, -$self->{sdy}); |
516 | |
522 | |
517 | #glTranslate -$self->{sdx}, -$self->{sdy}; # anchor fow at player |
|
|
518 | glScale $self->{tilesize}, $self->{tilesize}; |
523 | glScale $self->{tilesize}, $self->{tilesize}; |
519 | |
524 | |
520 | if (my $tex = $self->{fow_texture}) { |
525 | if (my $tex = $self->{fow_texture}) { |
521 | glPushMatrix; |
526 | my @prev_fow_params; |
522 | glTranslate +(min 0, $sdx_t), (min 0, $sdy_t); |
|
|
523 | glScale 1/3, 1/3; |
|
|
524 | glEnable GL_TEXTURE_2D; |
|
|
525 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
|
|
526 | |
527 | |
|
|
528 | if ($DC::OpenGL::GL_MULTITEX && $self->{prev_fow_texture}) { |
|
|
529 | my $d1 = DC::distance $self->{sdx}, $self->{sdy}; |
|
|
530 | my $d2 = (DC::distance $self->{lfdx}, $self->{lfdy}) * $tilesize; |
|
|
531 | |
|
|
532 | if ($d1 * $d2) { |
|
|
533 | @prev_fow_params = ( |
|
|
534 | (min 1, $d1 / $d2), |
|
|
535 | $self->{lmdx} - $dx - $self->{lfdx}, |
|
|
536 | $self->{lmdy} - $dy - $self->{lfdy}, |
|
|
537 | @{$self->{prev_fow_texture}}{qw(name data)} |
|
|
538 | ); |
|
|
539 | } |
|
|
540 | } |
|
|
541 | |
|
|
542 | DC::Texture::draw_fow_texture |
527 | glColor +($::CFG->{fow_intensity}) x 3, 0.9; |
543 | $::CFG->{fow_intensity}, |
528 | $self->{fow_texture}->draw_quad_alpha (0, 0); |
544 | $TEX_HIDDEN[$::CFG->{fow_texture}]{name}, |
529 | |
545 | @{$self->{fow_texture}}{qw(name data s t w h)}, |
530 | glDisable GL_TEXTURE_2D; |
546 | @prev_fow_params; |
531 | glPopMatrix; |
|
|
532 | } |
547 | } |
533 | |
548 | |
534 | if ($self->{magicmap}) { |
549 | if ($self->{magicmap}) { |
535 | my ($x, $y, $w, $h, $data) = @{ $self->{magicmap} }; |
550 | my ($x, $y, $w, $h, $data) = @{ $self->{magicmap} }; |
536 | |
551 | |
537 | $x += $::MAP->ox + $self->{dx}; |
552 | $x += $::MAP->ox + $self->{dx}; |
538 | $y += $::MAP->oy + $self->{dy}; |
553 | $y += $::MAP->oy + $self->{dy}; |
539 | |
554 | |
540 | glTranslate - $x - 1, - $y - 1; |
555 | glTranslate - $x - 1, - $y - 1; |
541 | glBindTexture GL_TEXTURE_2D, $magicmap_tex->{name}; |
556 | glBindTexture GL_TEXTURE_2D, $magicmap_tex->{name}; |
542 | $::MAP->draw_magicmap ($x, $y, $w, $h, $data); |
557 | $::MAP->draw_magicmap ($w, $h, $data); |
543 | } |
558 | } |
544 | |
559 | |
545 | glPopMatrix; |
560 | glPopMatrix; |
546 | glEndList; |
561 | glEndList; |
547 | } |
562 | } |
548 | } else { |
563 | } else { |
|
|
564 | delete $self->{last_fow_texture}; |
|
|
565 | delete $self->{fow_texture}; |
|
|
566 | |
549 | glDeleteList delete $self->{list} |
567 | glDeleteList delete $self->{list} |
550 | if $self->{list}; |
568 | if $self->{list}; |
551 | } |
569 | } |
552 | } |
570 | } |
553 | |
571 | |
… | |
… | |
589 | $self->SUPER::DESTROY; |
607 | $self->SUPER::DESTROY; |
590 | } |
608 | } |
591 | |
609 | |
592 | package DC::MapWidget::MapMap; |
610 | package DC::MapWidget::MapMap; |
593 | |
611 | |
594 | use strict; |
612 | use common::sense; |
595 | use utf8; |
|
|
596 | |
613 | |
597 | our @ISA = DC::UI::Base::; |
614 | our @ISA = DC::UI::Base::; |
598 | |
615 | |
599 | use Time::HiRes qw(time); |
616 | use Time::HiRes qw(time); |
600 | use DC::OpenGL; |
617 | use DC::OpenGL; |
… | |
… | |
694 | glDisable GL_BLEND; |
711 | glDisable GL_BLEND; |
695 | } |
712 | } |
696 | |
713 | |
697 | package DC::MapWidget::Command; |
714 | package DC::MapWidget::Command; |
698 | |
715 | |
699 | use strict; |
716 | use common::sense; |
700 | |
717 | |
701 | use DC::OpenGL; |
718 | use DC::OpenGL; |
702 | |
719 | |
703 | our @ISA = DC::UI::Frame::; |
720 | our @ISA = DC::UI::Frame::; |
704 | |
721 | |