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.7 by root, Thu Apr 20 21:28:50 2006 UTC vs.
Revision 1.17 by root, Mon Apr 24 13:12:32 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
25 glDeleteList $self->{list}; 26 glDeleteList $self->{list};
26 27
27 $self->SUPER::DESTROY; 28 $self->SUPER::DESTROY;
28} 29}
29 30
30sub key_down {
31 print "MAPKEYDOWN\n";
32}
33
34sub key_up {
35}
36
37sub button_down { 31sub button_down {
38 my ($self, $ev, $x, $y) = @_; 32 my ($self, $ev, $x, $y) = @_;
39 33
40 $self->focus_in; 34 $self->focus_in;
41 35
87 81
88 if (delete $self->{need_update}) { 82 if (delete $self->{need_update}) {
89 glNewList $self->{list}; 83 glNewList $self->{list};
90 84
91 if ($::MAP) { 85 if ($::MAP) {
92 my $sw = int $::WIDTH / 32; 86 my $sw = int $::WIDTH / (32 * $::CFG->{map_scale}) + 0.99;
93 my $sh = int $::HEIGHT / 32; 87 my $sh = int $::HEIGHT / (32 * $::CFG->{map_scale}) + 0.99;
94 88
89 glPushMatrix;
90 glScale $::CFG->{map_scale}, $::CFG->{map_scale};
91
95 my $sx = $::CFG->{map_shift_x}; my $sx0 = $sx & 31; $sx = ($sx - $sx0) / 32; 92 my $sx = $::CFG->{map_shift_x} / $::CFG->{map_scale}; my $sx0 = $sx & 31; $sx = ($sx - $sx0) / 32;
96 my $sy = $::CFG->{map_shift_y}; my $sy0 = $sy & 31; $sy = ($sy - $sy0) / 32; 93 my $sy = $::CFG->{map_shift_y} / $::CFG->{map_scale}; my $sy0 = $sy & 31; $sy = ($sy - $sy0) / 32;
97 94
98 glTranslate $sx0 - 32, $sy0 - 32, 0; 95 glTranslate $sx0 - 32, $sy0 - 32, 0;
99 96
100 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);
101 98
148 glEnable GL_BLEND; 145 glEnable GL_BLEND;
149 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 146 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
150 glEnable GL_TEXTURE_2D; 147 glEnable GL_TEXTURE_2D;
151 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 148 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
152 149
150 glPopMatrix;
151
153 $self->{mapmap_texture} = 152 $self->{mapmap_texture} =
154 new CFClient::Texture 153 new CFClient::Texture
155 w => $w, 154 w => $w,
156 h => $h, 155 h => $h,
157 data => $::MAP->mapmap (- $w * 0.5, - $h * 0.5, $w, $h), 156 data => $::MAP->mapmap (- $w * 0.5, - $h * 0.5, $w, $h),
219 my $mod = $ev->{mod}; 218 my $mod = $ev->{mod};
220 my $sym = $ev->{sym}; 219 my $sym = $ev->{sym};
221 220
222 if ($sym == CFClient::SDLK_KP5) { 221 if ($sym == CFClient::SDLK_KP5) {
223 $::CONN->user_send ("stay fire"); 222 $::CONN->user_send ("stay fire");
223 } elsif ($sym == ord ",") {
224 $::CONN->user_send ("take");
224 } elsif ($sym == ord "a") { 225 } elsif ($sym == ord "a") {
225 $::CONN->user_send ("apply"); 226 $::CONN->user_send ("apply");
226 } elsif ($sym == ord "'") { 227 } elsif ($sym == ord "'") {
227 $self->emit ('activate_console'); 228 $self->emit ('activate_console');
228 } elsif ($sym == ord "/") { 229 } elsif ($sym == ord "/") {
229 $self->emit ('activate_console' => '/'); 230 $self->emit (activate_console => '/');
230 } elsif (exists $DIR{$sym}) { 231 } elsif (exists $DIR{$sym}) {
231 if ($mod & CFClient::KMOD_SHIFT) { 232 if ($mod & CFClient::KMOD_SHIFT) {
232 $self->{shft}++; 233 $self->{shft}++;
233 $::CONN->user_send ("fire $DIR{$sym}[0]"); 234 $::CONN->user_send ("fire $DIR{$sym}[0]");
234 } elsif ($mod & CFClient::KMOD_CTRL) { 235 } elsif ($mod & CFClient::KMOD_CTRL) {
235 $self->{ctrl}++; 236 $self->{ctrl}++;
236 $::CONN->user_send ("run $DIR{$sym}[0]"); 237 $::CONN->user_send ("run $DIR{$sym}[0]");
237 } else { 238 } else {
238 $::CONN->user_send ("$DIR{$sym}[1]"); 239 $::CONN->user_send ("$DIR{$sym}[1]");
239 } 240 }
241 } elsif ($ev->{unicode}) {
242 $self->{command_widget} ||=
243 new CFClient::MapWidget::Command::
244 command => $self->{command},
245 can_focus => 1,
246 connect_execute => sub {
247 # todo: support callback instead of user_send
248 $::CONN->user_send ($_[1][1]);
249 },
250 connect_close => sub {
251 (delete $self->{command_widget})->hide;
252 $self->focus_in;
253 },
254 ;
255 $self->{command_widget}->key_down ($ev);
256 return unless $self->{command_widget};
257 $self->{command_widget}->show;
258 $self->{command_widget}->focus_in;
240 } 259 }
241} 260}
242 261
243sub key_up { 262sub key_up {
244 my ($self, $ev) = @_; 263 my ($self, $ev) = @_;
253 $::CONN->user_send ("run_stop"); 272 $::CONN->user_send ("run_stop");
254 } 273 }
255} 274}
256 275
257sub add_command { 276sub add_command {
258 my ($self, $command, $widget, $cb) = @_; 277 my ($self, $command, $tooltip, $widget, $cb) = @_;
259 278
260 (my $abbrev = $command) =~ s/(\S)[^[:space:]_]*[[:space:]_]+/$1/g; 279 (my $abbrev = $command) =~ s/(\S)[^[:space:]_]*[[:space:]_]+/$1/g;
261 warn "$command|$abbrev|$widget\n";#d# 280
281 push @{$self->{command}}, [$abbrev, $command, $tooltip, $widget, $cb];
282}
283
284package CFClient::MapWidget::Command;
285
286use strict;
287
288use CFClient::OpenGL;
289
290our @ISA = CFClient::UI::VBox::;
291
292sub new {
293 my $class = shift;
294
295 my $self = $class->SUPER::new (
296 @_,
297 children => [map
298 CFClient::UI::Label->new (
299 can_hover => 1,
300 can_events => 1,
301 fontsize => $_,
302 ), 1, 1, 0.8, 0.8, 0.8, 0.8, 0.8
303 ],
304 );
305
306 $self
307}
308
309sub size_allocate {
310 my ($self, $w, $h) = @_;
311
312 $self->SUPER::size_allocate ($w, $h);
313 $self->move (($::WIDTH - $w) * 0.5, ($::HEIGHT - $h) * 0.6, 10);
314}
315
316sub update_labels {
317 my ($self) = @_;
318
319 my $command = $self->{command};
320 my $search_abbrev = qr/^\Q$self->{search}/;
321 my $search_full = qr/\Q$self->{search}/;
322
323 my @found;
324
325 for (@$command) {
326 if ($_->[0] =~ $search_abbrev) {
327 push @found, [$_->[0], $_];
328 } elsif ($_->[1] =~ $search_full) {
329 push @found, [$_->[1], $_];
330 }
331 }
332
333 @found = sort { $a->[0] cmp $b->[0] } @found;
334
335 $self->{children}[0]->set_text ("$self->{search}_");
336
337 for (0..5) {
338 $self->{children}[$_ + 1]->set_text ($found[$_] ? "$found[$_][0] ($found[$_][1][1])" : "");
339 $self->{children}[$_ + 1]{tooltip} = ($found[$_] ? $found[$_][1][2] : "");
340 }
341
342 $self->{select} = $found[0][1]
343 if @found;
344
345 if (@found > 6) {
346 $self->{children}[6]->set_text ("...");
347 }
348
349 $self->check_size;
350}
351
352sub key_down {
353 my ($self, $ev) = @_;
354
355 if ($ev->{sym} == 8) {
356 substr $self->{search}, -1, 1, "";
357 $self->update_labels;
358 } elsif ($ev->{sym} == 13) {
359 if (exists $self->{select}) {
360 $self->emit (execute => $self->{select});
361 $self->emit ("close");
362 }
363 } elsif ($ev->{sym} == 27) {
364 $self->emit ("close");
365 return;
366 } elsif ((chr $ev->{unicode}) =~ /^[[:alpha:]]$/) {
367 $self->{search} .= chr $ev->{unicode};
368 $self->update_labels;
369 }
370
371 length $self->{search}
372 or $self->emit ("close");
262} 373}
263 374
2641 3751

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines