ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/MapWidget.pm
(Generate patch)

Comparing deliantra/Deliantra-Client/DC/MapWidget.pm (file contents):
Revision 1.12 by root, Mon Apr 24 06:05:35 2006 UTC vs.
Revision 1.18 by root, Tue Apr 25 12:56:34 2006 UTC

1package CFClient::MapWidget; 1package CFClient::MapWidget;
2 2
3use strict; 3use strict;
4use utf8;
4 5
5use List::Util qw(min max); 6use List::Util qw(min max);
6 7
7use CFClient::OpenGL; 8use CFClient::OpenGL;
8 9
80 81
81 if (delete $self->{need_update}) { 82 if (delete $self->{need_update}) {
82 glNewList $self->{list}; 83 glNewList $self->{list};
83 84
84 if ($::MAP) { 85 if ($::MAP) {
85 my $sw = int $::WIDTH / (32 * $::CFG->{map_scale}); 86 my $sw = int $::WIDTH / (32 * $::CFG->{map_scale}) + 0.99;
86 my $sh = int $::HEIGHT / (32 * $::CFG->{map_scale}); 87 my $sh = int $::HEIGHT / (32 * $::CFG->{map_scale}) + 0.99;
87
88 glScale $::CFG->{map_scale}, $::CFG->{map_scale};
89 88
90 my $sx = $::CFG->{map_shift_x} / $::CFG->{map_scale}; my $sx0 = $sx & 31; $sx = ($sx - $sx0) / 32; 89 my $sx = $::CFG->{map_shift_x} / $::CFG->{map_scale}; my $sx0 = $sx & 31; $sx = ($sx - $sx0) / 32;
91 my $sy = $::CFG->{map_shift_y} / $::CFG->{map_scale}; my $sy0 = $sy & 31; $sy = ($sy - $sy0) / 32; 90 my $sy = $::CFG->{map_shift_y} / $::CFG->{map_scale}; my $sy0 = $sy & 31; $sy = ($sy - $sy0) / 32;
91
92 glPushMatrix;
93 glScale $::CFG->{map_scale}, $::CFG->{map_scale};
92 94
93 glTranslate $sx0 - 32, $sy0 - 32, 0; 95 glTranslate $sx0 - 32, $sy0 - 32, 0;
94 96
95 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);
96 98
129 131
130 glDisable GL_TEXTURE_2D; 132 glDisable GL_TEXTURE_2D;
131 glDisable GL_BLEND; 133 glDisable GL_BLEND;
132 } 134 }
133 135
134 # HACK BEGIN 136 glPopMatrix;
135 {
136 glTranslate -($sx0 - 32), -($sy0 - 32), 0;#remove
137
138 glTranslate 0, 30;
139 my ($w, $h) = (250, 250);
140
141 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy);
142
143 glEnable GL_BLEND;
144 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
145 glEnable GL_TEXTURE_2D;
146 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
147
148 $self->{mapmap_texture} =
149 new CFClient::Texture
150 w => $w,
151 h => $h,
152 data => $::MAP->mapmap (- $w * 0.5, - $h * 0.5, $w, $h),
153 type => $CFClient::GL_VERSION >= 1.2 ? GL_UNSIGNED_INT_8_8_8_8_REV : GL_UNSIGNED_BYTE;
154
155 $self->{mapmap_texture}->draw_quad (0, 0);
156
157 glDisable GL_TEXTURE_2D;
158
159 glTranslate 0.375, 0.375;
160
161 glColor 1, 1, 0, 1;
162 glBegin GL_LINE_LOOP;
163 glVertex $w * 0.5 - $sx , $h * 0.5 - $sy ;
164 glVertex $w * 0.5 - $sx , $h * 0.5 - $sy + $sh;
165 glVertex $w * 0.5 - $sx + $sw, $h * 0.5 - $sy + $sh;
166 glVertex $w * 0.5 - $sx + $sw, $h * 0.5 - $sy ;
167 glEnd;
168
169 glDisable GL_BLEND;
170 }
171 # HACK END
172 } 137 }
173 138
174 glEndList; 139 glEndList;
175 } 140 }
176 141
214 my $mod = $ev->{mod}; 179 my $mod = $ev->{mod};
215 my $sym = $ev->{sym}; 180 my $sym = $ev->{sym};
216 181
217 if ($sym == CFClient::SDLK_KP5) { 182 if ($sym == CFClient::SDLK_KP5) {
218 $::CONN->user_send ("stay fire"); 183 $::CONN->user_send ("stay fire");
184 } elsif ($sym == ord ",") {
185 $::CONN->user_send ("take");
219 } elsif ($sym == ord "a") { 186 } elsif ($sym == ord "a") {
220 $::CONN->user_send ("apply"); 187 $::CONN->user_send ("apply");
221 } elsif ($sym == ord "'") { 188 } elsif ($sym == ord "'") {
222 $self->emit ('activate_console'); 189 $self->emit ('activate_console');
223 } elsif ($sym == ord "/") { 190 } elsif ($sym == ord "/") {
273 (my $abbrev = $command) =~ s/(\S)[^[:space:]_]*[[:space:]_]+/$1/g; 240 (my $abbrev = $command) =~ s/(\S)[^[:space:]_]*[[:space:]_]+/$1/g;
274 241
275 push @{$self->{command}}, [$abbrev, $command, $tooltip, $widget, $cb]; 242 push @{$self->{command}}, [$abbrev, $command, $tooltip, $widget, $cb];
276} 243}
277 244
245package CFClient::MapWidget::MapMap;
246
247use base CFClient::UI::Base::;
248
249use Time::HiRes qw(time);
250use CFClient::OpenGL;
251
252sub size_request {
253 ($::HEIGHT * 0.25, $::HEIGHT * 0.25)
254}
255
256sub size_allocate {
257 my ($self, $w, $h) = @_;
258
259 $self->SUPER::size_allocate ($w, $h);
260 $self->update;
261}
262
263sub update {
264 my ($self) = @_;
265
266 delete $self->{texture_atime};
267 $self->SUPER::update;
268}
269
270sub _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
278package CFClient::MapWidget::Command; 324package CFClient::MapWidget::Command;
279 325
280use strict; 326use strict;
281 327
282use CFClient::OpenGL; 328use CFClient::OpenGL;
317 my @found; 363 my @found;
318 364
319 for (@$command) { 365 for (@$command) {
320 if ($_->[0] =~ $search_abbrev) { 366 if ($_->[0] =~ $search_abbrev) {
321 push @found, [$_->[0], $_]; 367 push @found, [$_->[0], $_];
322 } elsif ($_[1] =~ $search_full) { 368 } elsif ($_->[1] =~ $search_full) {
323 push @found, [$_->[1], $_]; 369 push @found, [$_->[1], $_];
324 } 370 }
325 } 371 }
326 372
327 @found = sort { $a->[0] cmp $b->[0] } @found; 373 @found = sort { $a->[0] cmp $b->[0] } @found;
354 $self->emit (execute => $self->{select}); 400 $self->emit (execute => $self->{select});
355 $self->emit ("close"); 401 $self->emit ("close");
356 } 402 }
357 } elsif ($ev->{sym} == 27) { 403 } elsif ($ev->{sym} == 27) {
358 $self->emit ("close"); 404 $self->emit ("close");
405 return;
359 } elsif ((chr $ev->{unicode}) =~ /^[[:alpha:]]$/) { 406 } elsif ((chr $ev->{unicode}) =~ /^[[:alpha:]]$/) {
360 $self->{search} .= chr $ev->{unicode}; 407 $self->{search} .= chr $ev->{unicode};
361 $self->update_labels; 408 $self->update_labels;
362 } 409 }
363 410

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines