package CFClient::MapWidget; use strict; use List::Util qw(min max); use SDL::OpenGL; our @ISA = CFClient::UI::Base::; sub new { my $class = shift; $class->SUPER::new ( z => -1, can_focus => 1, list => (glGenLists 1), @_ ) } sub key_down { print "MAPKEYDOWN\n"; } sub key_up { } sub button_down { my ($self, $ev, $x, $y) = @_; $self->focus_in; if ($ev->button == 2) { my ($ox, $oy) = ($ev->button_x, $ev->button_y); my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y}); $self->{motion} = sub { my ($ev, $x, $y) = @_; ($x, $y) = ($ev->motion_x, $ev->motion_y); $::CFG->{map_shift_x} = $bw + $x - $ox; $::CFG->{map_shift_y} = $bh + $y - $oy; $self->update; }; } } sub button_up { my ($self, $ev, $x, $y) = @_; delete $self->{motion}; } sub mouse_motion { my ($self, $ev, $x, $y) = @_; $self->{motion}->($ev, $x, $y) if $self->{motion}; } sub size_request { ( 1 + 32 * int $::WIDTH / 32, 1 + 32 * int $::HEIGHT / 32, ) } sub update { my ($self) = @_; $self->{need_update} = 1; $self->SUPER::update; } sub draw { my ($self) = @_; if (delete $self->{need_update}) { glNewList $self->{list}, GL_COMPILE; if ($::MAP) { my $sw = int $::WIDTH / 32; my $sh = int $::HEIGHT / 32; my $sx = $::CFG->{map_shift_x}; my $sx0 = $sx & 31; $sx = ($sx - $sx0) / 32; my $sy = $::CFG->{map_shift_y}; my $sy0 = $sy & 31; $sy = ($sy - $sy0) / 32; glTranslate $sx0 - 32, $sy0 - 32, 0; my ($w, $h, $data) = $::MAP->draw ($sx, $sy, 0, 0, $sw + 1, $sh + 1); if ($::CFG->{fow_enable}) { if ($::CFG->{fow_smooth} && $CFClient::GL_VERSION >= 1.2) { # smooth fog of war glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER); glConvolutionFilter2D ( GL_CONVOLUTION_2D, GL_ALPHA, 3, 3, GL_ALPHA, GL_FLOAT, pack "f*", 0.1, 0.1, 0.1, 0.1, 0.2, 0.1, 0.1, 0.1, 0.1, ); glEnable GL_CONVOLUTION_2D; } $self->{fow_texture} = new CFClient::Texture w => $w, h => $h, data => $data, internalformat => GL_ALPHA, format => GL_ALPHA; glDisable GL_CONVOLUTION_2D if $::CFG->{fow_smooth}; glEnable GL_BLEND; glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; glEnable GL_TEXTURE_2D; glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; glColor +($::CFG->{fow_intensity}) x 3, 1; $self->{fow_texture}->draw_quad (0, 0, $w * 32, $h * 32); glDisable GL_TEXTURE_2D; glDisable GL_BLEND; } # HACK BEGIN { glTranslate -($sx0 - 32), -($sy0 - 32), 0;#remove my ($w, $h) = (250, 250); glEnable GL_BLEND; glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; glEnable GL_TEXTURE_2D; glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; $self->{mapmap_texture} = new CFClient::Texture w => $w, h => $h, data => $::MAP->mapmap ($w, $h), type => $CFClient::GL_VERSION >= 1.2 ? GL_UNSIGNED_INT_8_8_8_8_REV : GL_UNSIGNED_BYTE; $self->{mapmap_texture}->draw_quad (100, 100); glDisable GL_TEXTURE_2D; glDisable GL_BLEND; } # HACK END } glEndList; } glPushMatrix; glCallList $self->{list}; glPopMatrix; if ($CFClient::UI::FOCUS != $self) { glColor 64/255, 64/255, 64/255; glLogicOp GL_AND; glEnable GL_COLOR_LOGIC_OP; glBegin GL_QUADS; glVertex 0, 0; glVertex 0, $::HEIGHT; glVertex $::WIDTH, $::HEIGHT; glVertex $::WIDTH, 0; glEnd; glDisable GL_COLOR_LOGIC_OP; } } my %DIR = ( CFClient::SDLK_KP8, [1, "north"], CFClient::SDLK_KP9, [2, "northeast"], CFClient::SDLK_KP6, [3, "east"], CFClient::SDLK_KP3, [4, "southeast"], CFClient::SDLK_KP2, [5, "south"], CFClient::SDLK_KP1, [6, "southwest"], CFClient::SDLK_KP4, [7, "west"], CFClient::SDLK_KP7, [8, "northwest"], CFClient::SDLK_UP, [1, "north"], CFClient::SDLK_RIGHT, [3, "east"], CFClient::SDLK_DOWN, [5, "south"], CFClient::SDLK_LEFT, [7, "west"], ); sub key_down { my ($self, $ev) = @_; my $mod = $ev->key_mod; my $sym = $ev->key_sym; if ($sym == CFClient::SDLK_KP5) { $::CONN->user_send ("stay fire"); } elsif ($sym == ord "a") { $::CONN->user_send ("apply"); } elsif ($sym == ord "'") { $self->emit ('activate_console'); } elsif ($sym == ord "/") { $self->emit ('activate_console' => '/'); } elsif (exists $DIR{$sym}) { if ($mod & CFClient::KMOD_SHIFT) { $self->{shft}++; $::CONN->user_send ("fire $DIR{$sym}[0]"); } elsif ($mod & CFClient::KMOD_CTRL) { $self->{ctrl}++; $::CONN->user_send ("run $DIR{$sym}[0]"); } else { $::CONN->user_send ("$DIR{$sym}[1]"); } } } sub key_up { my ($self, $ev) = @_; my $mod = $ev->key_mod; my $sym = $ev->key_sym; if (!($mod & CFClient::KMOD_SHIFT) && delete $self->{shft}) { $::CONN->user_send ("fire_stop"); } if (!($mod & CFClient::KMOD_CTRL ) && delete $self->{ctrl}) { $::CONN->user_send ("run_stop"); } } sub add_command { my ($self, $command, $widget, $cb) = @_; (my $abbrev = $command) =~ s/(\S)[^[:space:]_]*[[:space:]_]+/$1/g; warn "$command|$abbrev|$widget\n";#d# } 1