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.8 by root, Sat Apr 22 21:47:45 2006 UTC vs.
Revision 1.19 by root, Tue Apr 25 13:51:48 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; 86 my $sw = int $::WIDTH / (32 * $::CFG->{map_scale}) + 0.99;
86 my $sh = int $::HEIGHT / 32; 87 my $sh = int $::HEIGHT / (32 * $::CFG->{map_scale}) + 0.99;
87 88
88 my $sx = $::CFG->{map_shift_x}; 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;
89 my $sy = $::CFG->{map_shift_y}; 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};
90 94
91 glTranslate $sx0 - 32, $sy0 - 32, 0; 95 glTranslate $sx0 - 32, $sy0 - 32, 0;
92 96
93 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);
94 98
127 131
128 glDisable GL_TEXTURE_2D; 132 glDisable GL_TEXTURE_2D;
129 glDisable GL_BLEND; 133 glDisable GL_BLEND;
130 } 134 }
131 135
132 # HACK BEGIN 136 glPopMatrix;
133 {
134 glTranslate -($sx0 - 32), -($sy0 - 32), 0;#remove
135
136 glTranslate 0, 30;
137 my ($w, $h) = (250, 250);
138
139 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy);
140
141 glEnable GL_BLEND;
142 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
143 glEnable GL_TEXTURE_2D;
144 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
145
146 $self->{mapmap_texture} =
147 new CFClient::Texture
148 w => $w,
149 h => $h,
150 data => $::MAP->mapmap (- $w * 0.5, - $h * 0.5, $w, $h),
151 type => $CFClient::GL_VERSION >= 1.2 ? GL_UNSIGNED_INT_8_8_8_8_REV : GL_UNSIGNED_BYTE;
152
153 $self->{mapmap_texture}->draw_quad (0, 0);
154
155 glDisable GL_TEXTURE_2D;
156
157 glTranslate 0.375, 0.375;
158
159 glColor 1, 1, 0, 1;
160 glBegin GL_LINE_LOOP;
161 glVertex $w * 0.5 - $sx , $h * 0.5 - $sy ;
162 glVertex $w * 0.5 - $sx , $h * 0.5 - $sy + $sh;
163 glVertex $w * 0.5 - $sx + $sw, $h * 0.5 - $sy + $sh;
164 glVertex $w * 0.5 - $sx + $sw, $h * 0.5 - $sy ;
165 glEnd;
166
167 glDisable GL_BLEND;
168 }
169 # HACK END
170 } 137 }
171 138
172 glEndList; 139 glEndList;
173 } 140 }
174 141
212 my $mod = $ev->{mod}; 179 my $mod = $ev->{mod};
213 my $sym = $ev->{sym}; 180 my $sym = $ev->{sym};
214 181
215 if ($sym == CFClient::SDLK_KP5) { 182 if ($sym == CFClient::SDLK_KP5) {
216 $::CONN->user_send ("stay fire"); 183 $::CONN->user_send ("stay fire");
184 } elsif ($sym == ord ",") {
185 $::CONN->user_send ("take");
217 } elsif ($sym == ord "a") { 186 } elsif ($sym == ord "a") {
218 $::CONN->user_send ("apply"); 187 $::CONN->user_send ("apply");
219 } elsif ($sym == ord "'") { 188 } elsif ($sym == ord "'") {
220 $self->emit ('activate_console'); 189 $self->emit ('activate_console');
221 } elsif ($sym == ord "/") { 190 } elsif ($sym == ord "/") {
234 $self->{command_widget} ||= 203 $self->{command_widget} ||=
235 new CFClient::MapWidget::Command:: 204 new CFClient::MapWidget::Command::
236 command => $self->{command}, 205 command => $self->{command},
237 can_focus => 1, 206 can_focus => 1,
238 connect_execute => sub { 207 connect_execute => sub {
208 # todo: support callback instead of user_send
239 $::CONN->user_send ($_[1]); 209 $::CONN->user_send ($_[1][1]);
240 }, 210 },
241 connect_close => sub { 211 connect_close => sub {
242 (delete $self->{command_widget})->hide; 212 (delete $self->{command_widget})->hide;
243 $self->focus_in; 213 $self->focus_in;
244 }, 214 },
245 ; 215 ;
246 $self->{command_widget}->key_down ($ev); 216 $self->{command_widget}->key_down ($ev);
217 return unless $self->{command_widget};
247 $self->{command_widget}->show; 218 $self->{command_widget}->show;
248 $self->{command_widget}->focus_in; 219 $self->{command_widget}->focus_in;
249 } 220 }
250} 221}
251 222
262 $::CONN->user_send ("run_stop"); 233 $::CONN->user_send ("run_stop");
263 } 234 }
264} 235}
265 236
266sub add_command { 237sub add_command {
267 my ($self, $command, $widget, $cb) = @_; 238 my ($self, $command, $tooltip, $widget, $cb) = @_;
268 239
269 (my $abbrev = $command) =~ s/(\S)[^[:space:]_]*[[:space:]_]+/$1/g; 240 (my $abbrev = $command) =~ s/(\S)[^[:space:]_]*[[:space:]_]+/$1/g;
270 241
271 push @{$self->{command}}, [$abbrev, $command]; 242 push @{$self->{command}}, [$abbrev, $command, $tooltip, $widget, $cb];
272 #warn "$command|$abbrev|$widget\n";#d# 243}
244
245package CFClient::MapWidget::MapMap;
246
247our @ISA = 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;
273} 322}
274 323
275package CFClient::MapWidget::Command; 324package CFClient::MapWidget::Command;
276 325
277use strict; 326use strict;
285 334
286 my $self = $class->SUPER::new ( 335 my $self = $class->SUPER::new (
287 @_, 336 @_,
288 children => [map 337 children => [map
289 CFClient::UI::Label->new ( 338 CFClient::UI::Label->new (
290 can_hover => 1, 339 can_hover => 1,
340 can_events => 1,
291 fontsize => $_, 341 fontsize => $_,
292 ), 1, 1, 0.8, 0.8, 0.8, 0.8, 0.8 342 ), 1, 1, 0.8, 0.8, 0.8, 0.8, 0.8
293 ], 343 ],
294 ); 344 );
295 345
296 $self 346 $self
313 my @found; 363 my @found;
314 364
315 for (@$command) { 365 for (@$command) {
316 if ($_->[0] =~ $search_abbrev) { 366 if ($_->[0] =~ $search_abbrev) {
317 push @found, [$_->[0], $_]; 367 push @found, [$_->[0], $_];
318 } elsif ($_[1] =~ $search_full) { 368 } elsif ($_->[1] =~ $search_full) {
319 push @found, [$_->[1], $_]; 369 push @found, [$_->[1], $_];
320 } 370 }
321 } 371 }
322 372
323 @found = sort { $a->[0] cmp $b->[0] } @found; 373 @found = sort { $a->[0] cmp $b->[0] } @found;
324 374
325 $self->{children}[0]->set_text ("$self->{search}_"); 375 $self->{children}[0]->set_text ("$self->{search}_");
326 376
327 for (0..5) { 377 for (0..5) {
328 $self->{children}[$_ + 1]->set_text ($found[$_] ? "$found[$_][0] ($found[$_][1][1])" : ""); 378 $self->{children}[$_ + 1]->set_text ($found[$_] ? "$found[$_][0] ($found[$_][1][1])" : "");
379 $self->{children}[$_ + 1]{tooltip} = ($found[$_] ? $found[$_][1][2] : "");
329 } 380 }
330 381
331 $self->{select} = $found[0][1][1] 382 $self->{select} = $found[0][1]
332 if @found; 383 if @found;
333 384
334 if (@found > 6) { 385 if (@found > 6) {
335 $self->{children}[6]->set_text ("..."); 386 $self->{children}[6]->set_text ("...");
336 } 387 }
349 $self->emit (execute => $self->{select}); 400 $self->emit (execute => $self->{select});
350 $self->emit ("close"); 401 $self->emit ("close");
351 } 402 }
352 } elsif ($ev->{sym} == 27) { 403 } elsif ($ev->{sym} == 27) {
353 $self->emit ("close"); 404 $self->emit ("close");
354 } elsif ($ev->{unicode}) { 405 return;
406 } elsif ((chr $ev->{unicode}) =~ /^[[:alpha:]]$/) {
355 $self->{search} .= chr $ev->{unicode}; 407 $self->{search} .= chr $ev->{unicode};
356 $self->update_labels; 408 $self->update_labels;
357 } 409 }
410
411 length $self->{search}
412 or $self->emit ("close");
358} 413}
359 414
3601 4151

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines