… | |
… | |
84 | |
84 | |
85 | if ($::MAP) { |
85 | if ($::MAP) { |
86 | my $sw = int $::WIDTH / (32 * $::CFG->{map_scale}) + 0.99; |
86 | my $sw = int $::WIDTH / (32 * $::CFG->{map_scale}) + 0.99; |
87 | my $sh = int $::HEIGHT / (32 * $::CFG->{map_scale}) + 0.99; |
87 | my $sh = int $::HEIGHT / (32 * $::CFG->{map_scale}) + 0.99; |
88 | |
88 | |
|
|
89 | my $sx = $::CFG->{map_shift_x} / $::CFG->{map_scale}; my $sx0 = $sx & 31; $sx = ($sx - $sx0) / 32; |
|
|
90 | my $sy = $::CFG->{map_shift_y} / $::CFG->{map_scale}; my $sy0 = $sy & 31; $sy = ($sy - $sy0) / 32; |
|
|
91 | |
89 | glPushMatrix; |
92 | glPushMatrix; |
90 | glScale $::CFG->{map_scale}, $::CFG->{map_scale}; |
93 | glScale $::CFG->{map_scale}, $::CFG->{map_scale}; |
91 | |
|
|
92 | my $sx = $::CFG->{map_shift_x} / $::CFG->{map_scale}; my $sx0 = $sx & 31; $sx = ($sx - $sx0) / 32; |
|
|
93 | my $sy = $::CFG->{map_shift_y} / $::CFG->{map_scale}; my $sy0 = $sy & 31; $sy = ($sy - $sy0) / 32; |
|
|
94 | |
94 | |
95 | glTranslate $sx0 - 32, $sy0 - 32, 0; |
95 | glTranslate $sx0 - 32, $sy0 - 32, 0; |
96 | |
96 | |
97 | my ($w, $h, $data) = $::MAP->draw ($sx, $sy, 0, 0, $sw + 1, $sh + 1); |
97 | my ($w, $h, $data) = $::MAP->draw ($sx, $sy, 0, 0, $sw + 1, $sh + 1); |
98 | |
98 | |
… | |
… | |
131 | |
131 | |
132 | glDisable GL_TEXTURE_2D; |
132 | glDisable GL_TEXTURE_2D; |
133 | glDisable GL_BLEND; |
133 | glDisable GL_BLEND; |
134 | } |
134 | } |
135 | |
135 | |
136 | # HACK BEGIN |
|
|
137 | { |
|
|
138 | glTranslate -($sx0 - 32), -($sy0 - 32), 0;#remove |
|
|
139 | |
|
|
140 | glTranslate 0, 30; |
|
|
141 | my ($w, $h) = (250, 250); |
|
|
142 | |
|
|
143 | my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
|
|
144 | |
|
|
145 | glEnable GL_BLEND; |
|
|
146 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
147 | glEnable GL_TEXTURE_2D; |
|
|
148 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
149 | |
|
|
150 | glPopMatrix; |
136 | glPopMatrix; |
151 | |
|
|
152 | $self->{mapmap_texture} = |
|
|
153 | new CFClient::Texture |
|
|
154 | w => $w, |
|
|
155 | h => $h, |
|
|
156 | data => $::MAP->mapmap (- $w * 0.5, - $h * 0.5, $w, $h), |
|
|
157 | type => $CFClient::GL_VERSION >= 1.2 ? GL_UNSIGNED_INT_8_8_8_8_REV : GL_UNSIGNED_BYTE; |
|
|
158 | |
|
|
159 | $self->{mapmap_texture}->draw_quad (0, 0); |
|
|
160 | |
|
|
161 | glDisable GL_TEXTURE_2D; |
|
|
162 | |
|
|
163 | glTranslate 0.375, 0.375; |
|
|
164 | |
|
|
165 | glColor 1, 1, 0, 1; |
|
|
166 | glBegin GL_LINE_LOOP; |
|
|
167 | glVertex $w * 0.5 - $sx , $h * 0.5 - $sy ; |
|
|
168 | glVertex $w * 0.5 - $sx , $h * 0.5 - $sy + $sh; |
|
|
169 | glVertex $w * 0.5 - $sx + $sw, $h * 0.5 - $sy + $sh; |
|
|
170 | glVertex $w * 0.5 - $sx + $sw, $h * 0.5 - $sy ; |
|
|
171 | glEnd; |
|
|
172 | |
|
|
173 | glDisable GL_BLEND; |
|
|
174 | } |
|
|
175 | # HACK END |
|
|
176 | } |
137 | } |
177 | |
138 | |
178 | glEndList; |
139 | glEndList; |
179 | } |
140 | } |
180 | |
141 | |
… | |
… | |
279 | (my $abbrev = $command) =~ s/(\S)[^[:space:]_]*[[:space:]_]+/$1/g; |
240 | (my $abbrev = $command) =~ s/(\S)[^[:space:]_]*[[:space:]_]+/$1/g; |
280 | |
241 | |
281 | push @{$self->{command}}, [$abbrev, $command, $tooltip, $widget, $cb]; |
242 | push @{$self->{command}}, [$abbrev, $command, $tooltip, $widget, $cb]; |
282 | } |
243 | } |
283 | |
244 | |
|
|
245 | package CFClient::MapWidget::MapMap; |
|
|
246 | |
|
|
247 | use base CFClient::UI::Base::; |
|
|
248 | |
|
|
249 | use Time::HiRes qw(time); |
|
|
250 | use CFClient::OpenGL; |
|
|
251 | |
|
|
252 | sub size_request { |
|
|
253 | ($::HEIGHT * 0.25, $::HEIGHT * 0.25) |
|
|
254 | } |
|
|
255 | |
|
|
256 | sub size_allocate { |
|
|
257 | my ($self, $w, $h) = @_; |
|
|
258 | |
|
|
259 | $self->SUPER::size_allocate ($w, $h); |
|
|
260 | $self->update; |
|
|
261 | } |
|
|
262 | |
|
|
263 | sub update { |
|
|
264 | my ($self) = @_; |
|
|
265 | |
|
|
266 | delete $self->{texture_atime}; |
|
|
267 | $self->SUPER::update; |
|
|
268 | } |
|
|
269 | |
|
|
270 | sub _draw { |
|
|
271 | my ($self) = @_; |
|
|
272 | |
|
|
273 | $::MAP or return; |
|
|
274 | |
|
|
275 | my ($w, $h) = @$self{qw(w h)}; |
|
|
276 | |
|
|
277 | my $sw = int $::WIDTH / (32 * $::CFG->{map_scale}) + 0.99; |
|
|
278 | my $sh = int $::HEIGHT / (32 * $::CFG->{map_scale}) + 0.99; |
|
|
279 | |
|
|
280 | my $sx = int $::CFG->{map_shift_x} / 32; |
|
|
281 | my $sy = int $::CFG->{map_shift_y} / 32; |
|
|
282 | |
|
|
283 | my $ox = 0.5 * ($w - $sw); |
|
|
284 | my $oy = 0.5 * ($h - $sh); |
|
|
285 | |
|
|
286 | glEnable GL_BLEND; |
|
|
287 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
288 | glEnable GL_TEXTURE_2D; |
|
|
289 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
290 | |
|
|
291 | if ($self->{texture_atime} < time) { |
|
|
292 | $self->{texture_atime} = time + 1/3; |
|
|
293 | |
|
|
294 | $self->{texture} = |
|
|
295 | new CFClient::Texture |
|
|
296 | w => $w, |
|
|
297 | h => $h, |
|
|
298 | data => $::MAP->mapmap (-$ox, -$oy, $w, $h), |
|
|
299 | type => $CFClient::GL_VERSION >= 1.2 ? GL_UNSIGNED_INT_8_8_8_8_REV : GL_UNSIGNED_BYTE; |
|
|
300 | } |
|
|
301 | |
|
|
302 | $self->{texture}->draw_quad (0, 0); |
|
|
303 | |
|
|
304 | glDisable GL_TEXTURE_2D; |
|
|
305 | |
|
|
306 | glTranslate 0.375, 0.375; |
|
|
307 | |
|
|
308 | #TODO: map scale is completely borked |
|
|
309 | |
|
|
310 | my $x0 = int $ox - $sx + 0.5; |
|
|
311 | my $y0 = int $oy - $sy + 0.5; |
|
|
312 | |
|
|
313 | glColor 1, 1, 0, 1; |
|
|
314 | glBegin GL_LINE_LOOP; |
|
|
315 | glVertex $x0 , $y0 ; |
|
|
316 | glVertex $x0 , $y0 + $sh; |
|
|
317 | glVertex $x0 + $sw, $y0 + $sh; |
|
|
318 | glVertex $x0 + $sw, $y0 ; |
|
|
319 | glEnd; |
|
|
320 | |
|
|
321 | glDisable GL_BLEND; |
|
|
322 | } |
|
|
323 | |
284 | package CFClient::MapWidget::Command; |
324 | package CFClient::MapWidget::Command; |
285 | |
325 | |
286 | use strict; |
326 | use strict; |
287 | |
327 | |
288 | use CFClient::OpenGL; |
328 | use CFClient::OpenGL; |