ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/MapWidget.pm
Revision: 1.6
Committed: Thu Apr 20 08:11:57 2006 UTC (18 years, 1 month ago) by root
Branch: MAIN
Changes since 1.5: +17 -2 lines
Log Message:
map overview rectangle

File Contents

# User Rev Content
1 root 1.1 package CFClient::MapWidget;
2    
3     use strict;
4    
5     use List::Util qw(min max);
6    
7 root 1.4 use CFClient::OpenGL;
8 root 1.1
9     our @ISA = CFClient::UI::Base::;
10    
11     sub new {
12     my $class = shift;
13    
14     $class->SUPER::new (
15     z => -1,
16     can_focus => 1,
17 root 1.4 list => glGenList,
18 root 1.1 @_
19     )
20     }
21    
22 root 1.4 sub DESTROY {
23     my $self = shift;
24    
25     glDeleteList $self->{list};
26    
27     $self->SUPER::DESTROY;
28     }
29    
30 root 1.1 sub key_down {
31     print "MAPKEYDOWN\n";
32     }
33    
34     sub key_up {
35     }
36    
37     sub button_down {
38     my ($self, $ev, $x, $y) = @_;
39    
40     $self->focus_in;
41    
42 root 1.5 if ($ev->{button} == 2) {
43     my ($ox, $oy) = ($ev->{x}, $ev->{y});
44 root 1.1 my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y});
45    
46     $self->{motion} = sub {
47     my ($ev, $x, $y) = @_;
48    
49 root 1.5 ($x, $y) = ($ev->{x}, $ev->{y});
50 root 1.1
51     $::CFG->{map_shift_x} = $bw + $x - $ox;
52     $::CFG->{map_shift_y} = $bh + $y - $oy;
53    
54     $self->update;
55     };
56     }
57     }
58    
59     sub button_up {
60     my ($self, $ev, $x, $y) = @_;
61    
62     delete $self->{motion};
63     }
64    
65     sub mouse_motion {
66     my ($self, $ev, $x, $y) = @_;
67    
68     $self->{motion}->($ev, $x, $y) if $self->{motion};
69     }
70    
71     sub size_request {
72     (
73     1 + 32 * int $::WIDTH / 32,
74     1 + 32 * int $::HEIGHT / 32,
75     )
76     }
77    
78     sub update {
79     my ($self) = @_;
80    
81     $self->{need_update} = 1;
82     $self->SUPER::update;
83     }
84    
85     sub draw {
86     my ($self) = @_;
87    
88     if (delete $self->{need_update}) {
89 root 1.4 glNewList $self->{list};
90 root 1.1
91     if ($::MAP) {
92     my $sw = int $::WIDTH / 32;
93     my $sh = int $::HEIGHT / 32;
94    
95     my $sx = $::CFG->{map_shift_x}; my $sx0 = $sx & 31; $sx = ($sx - $sx0) / 32;
96     my $sy = $::CFG->{map_shift_y}; my $sy0 = $sy & 31; $sy = ($sy - $sy0) / 32;
97    
98     glTranslate $sx0 - 32, $sy0 - 32, 0;
99    
100     my ($w, $h, $data) = $::MAP->draw ($sx, $sy, 0, 0, $sw + 1, $sh + 1);
101    
102     if ($::CFG->{fow_enable}) {
103     if ($::CFG->{fow_smooth} && $CFClient::GL_VERSION >= 1.2) { # smooth fog of war
104     glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER);
105     glConvolutionFilter2D (
106     GL_CONVOLUTION_2D,
107     GL_ALPHA,
108     3, 3,
109     GL_ALPHA, GL_FLOAT,
110     pack "f*",
111     0.1, 0.1, 0.1,
112     0.1, 0.2, 0.1,
113     0.1, 0.1, 0.1,
114     );
115     glEnable GL_CONVOLUTION_2D;
116     }
117    
118     $self->{fow_texture} = new CFClient::Texture
119     w => $w,
120     h => $h,
121     data => $data,
122     internalformat => GL_ALPHA,
123     format => GL_ALPHA;
124    
125     glDisable GL_CONVOLUTION_2D if $::CFG->{fow_smooth};
126    
127     glEnable GL_BLEND;
128     glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
129     glEnable GL_TEXTURE_2D;
130     glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
131    
132     glColor +($::CFG->{fow_intensity}) x 3, 1;
133     $self->{fow_texture}->draw_quad (0, 0, $w * 32, $h * 32);
134    
135     glDisable GL_TEXTURE_2D;
136     glDisable GL_BLEND;
137     }
138    
139     # HACK BEGIN
140     {
141     glTranslate -($sx0 - 32), -($sy0 - 32), 0;#remove
142 root 1.6
143     glTranslate 0, 30;
144 root 1.1 my ($w, $h) = (250, 250);
145    
146 root 1.6 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy);
147    
148 root 1.1 glEnable GL_BLEND;
149     glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
150     glEnable GL_TEXTURE_2D;
151     glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
152    
153     $self->{mapmap_texture} =
154     new CFClient::Texture
155     w => $w,
156     h => $h,
157 root 1.6 data => $::MAP->mapmap (- $w * 0.5, - $h * 0.5, $w, $h),
158 root 1.1 type => $CFClient::GL_VERSION >= 1.2 ? GL_UNSIGNED_INT_8_8_8_8_REV : GL_UNSIGNED_BYTE;
159    
160 root 1.6 $self->{mapmap_texture}->draw_quad (0, 0);
161 root 1.1
162     glDisable GL_TEXTURE_2D;
163 root 1.6
164     glTranslate 0.375, 0.375;
165    
166     glColor 1, 1, 0, 1;
167     glBegin GL_LINE_LOOP;
168     glVertex $w * 0.5 - $sx , $h * 0.5 - $sy ;
169     glVertex $w * 0.5 - $sx , $h * 0.5 - $sy + $sh;
170     glVertex $w * 0.5 - $sx + $sw, $h * 0.5 - $sy + $sh;
171     glVertex $w * 0.5 - $sx + $sw, $h * 0.5 - $sy ;
172     glEnd;
173    
174 root 1.1 glDisable GL_BLEND;
175     }
176     # HACK END
177     }
178    
179     glEndList;
180     }
181    
182     glPushMatrix;
183     glCallList $self->{list};
184     glPopMatrix;
185    
186     if ($CFClient::UI::FOCUS != $self) {
187     glColor 64/255, 64/255, 64/255;
188     glLogicOp GL_AND;
189     glEnable GL_COLOR_LOGIC_OP;
190     glBegin GL_QUADS;
191     glVertex 0, 0;
192     glVertex 0, $::HEIGHT;
193     glVertex $::WIDTH, $::HEIGHT;
194     glVertex $::WIDTH, 0;
195     glEnd;
196     glDisable GL_COLOR_LOGIC_OP;
197     }
198     }
199    
200     my %DIR = (
201 root 1.3 CFClient::SDLK_KP8, [1, "north"],
202     CFClient::SDLK_KP9, [2, "northeast"],
203     CFClient::SDLK_KP6, [3, "east"],
204     CFClient::SDLK_KP3, [4, "southeast"],
205     CFClient::SDLK_KP2, [5, "south"],
206     CFClient::SDLK_KP1, [6, "southwest"],
207     CFClient::SDLK_KP4, [7, "west"],
208     CFClient::SDLK_KP7, [8, "northwest"],
209    
210     CFClient::SDLK_UP, [1, "north"],
211     CFClient::SDLK_RIGHT, [3, "east"],
212     CFClient::SDLK_DOWN, [5, "south"],
213     CFClient::SDLK_LEFT, [7, "west"],
214 root 1.1 );
215    
216     sub key_down {
217     my ($self, $ev) = @_;
218    
219 root 1.5 my $mod = $ev->{mod};
220     my $sym = $ev->{sym};
221 root 1.1
222 root 1.3 if ($sym == CFClient::SDLK_KP5) {
223 root 1.1 $::CONN->user_send ("stay fire");
224 root 1.3 } elsif ($sym == ord "a") {
225 root 1.1 $::CONN->user_send ("apply");
226 root 1.3 } elsif ($sym == ord "'") {
227 root 1.1 $self->emit ('activate_console');
228 root 1.3 } elsif ($sym == ord "/") {
229 root 1.1 $self->emit ('activate_console' => '/');
230     } elsif (exists $DIR{$sym}) {
231 root 1.3 if ($mod & CFClient::KMOD_SHIFT) {
232 root 1.1 $self->{shft}++;
233     $::CONN->user_send ("fire $DIR{$sym}[0]");
234 root 1.3 } elsif ($mod & CFClient::KMOD_CTRL) {
235 root 1.1 $self->{ctrl}++;
236     $::CONN->user_send ("run $DIR{$sym}[0]");
237     } else {
238     $::CONN->user_send ("$DIR{$sym}[1]");
239     }
240     }
241     }
242    
243     sub key_up {
244     my ($self, $ev) = @_;
245    
246 root 1.5 my $mod = $ev->{mod};
247     my $sym = $ev->{sym};
248 root 1.1
249 root 1.3 if (!($mod & CFClient::KMOD_SHIFT) && delete $self->{shft}) {
250 root 1.1 $::CONN->user_send ("fire_stop");
251     }
252 root 1.3 if (!($mod & CFClient::KMOD_CTRL ) && delete $self->{ctrl}) {
253 root 1.1 $::CONN->user_send ("run_stop");
254     }
255     }
256    
257 root 1.2 sub add_command {
258     my ($self, $command, $widget, $cb) = @_;
259    
260 root 1.3 (my $abbrev = $command) =~ s/(\S)[^[:space:]_]*[[:space:]_]+/$1/g;
261 root 1.2 warn "$command|$abbrev|$widget\n";#d#
262     }
263    
264 root 1.1 1