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.6 by root, Thu Apr 20 08:11:57 2006 UTC vs.
Revision 1.15 by root, Mon Apr 24 13:01:13 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});
93 my $sh = int $::HEIGHT / 32; 87 my $sh = int $::HEIGHT / (32 * $::CFG->{map_scale});
94 88
89 glScale $::CFG->{map_scale}, $::CFG->{map_scale};
90
95 my $sx = $::CFG->{map_shift_x}; my $sx0 = $sx & 31; $sx = ($sx - $sx0) / 32; 91 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; 92 my $sy = $::CFG->{map_shift_y} / $::CFG->{map_scale}; my $sy0 = $sy & 31; $sy = ($sy - $sy0) / 32;
97 93
98 glTranslate $sx0 - 32, $sy0 - 32, 0; 94 glTranslate $sx0 - 32, $sy0 - 32, 0;
99 95
100 my ($w, $h, $data) = $::MAP->draw ($sx, $sy, 0, 0, $sw + 1, $sh + 1); 96 my ($w, $h, $data) = $::MAP->draw ($sx, $sy, 0, 0, $sw + 1, $sh + 1);
101 97
106 GL_CONVOLUTION_2D, 102 GL_CONVOLUTION_2D,
107 GL_ALPHA, 103 GL_ALPHA,
108 3, 3, 104 3, 3,
109 GL_ALPHA, GL_FLOAT, 105 GL_ALPHA, GL_FLOAT,
110 pack "f*", 106 pack "f*",
111 0.1, 0.1, 0.1, 107 0.05, 0.13, 0.05,
112 0.1, 0.2, 0.1, 108 0.13, 0.30, 0.13,
113 0.1, 0.1, 0.1, 109 0.05, 0.13, 0.05,
114 ); 110 );
115 glEnable GL_CONVOLUTION_2D; 111 glEnable GL_CONVOLUTION_2D;
116 } 112 }
117 113
118 $self->{fow_texture} = new CFClient::Texture 114 $self->{fow_texture} = new CFClient::Texture
127 glEnable GL_BLEND; 123 glEnable GL_BLEND;
128 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 124 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
129 glEnable GL_TEXTURE_2D; 125 glEnable GL_TEXTURE_2D;
130 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 126 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
131 127
132 glColor +($::CFG->{fow_intensity}) x 3, 1; 128 glColor +($::CFG->{fow_intensity}) x 3, 0.8;
133 $self->{fow_texture}->draw_quad (0, 0, $w * 32, $h * 32); 129 $self->{fow_texture}->draw_quad (0, 0, $w * 32, $h * 32);
134 130
135 glDisable GL_TEXTURE_2D; 131 glDisable GL_TEXTURE_2D;
136 glDisable GL_BLEND; 132 glDisable GL_BLEND;
137 } 133 }
219 my $mod = $ev->{mod}; 215 my $mod = $ev->{mod};
220 my $sym = $ev->{sym}; 216 my $sym = $ev->{sym};
221 217
222 if ($sym == CFClient::SDLK_KP5) { 218 if ($sym == CFClient::SDLK_KP5) {
223 $::CONN->user_send ("stay fire"); 219 $::CONN->user_send ("stay fire");
220 } elsif ($sym == ord ",") {
221 $::CONN->user_send ("take");
224 } elsif ($sym == ord "a") { 222 } elsif ($sym == ord "a") {
225 $::CONN->user_send ("apply"); 223 $::CONN->user_send ("apply");
226 } elsif ($sym == ord "'") { 224 } elsif ($sym == ord "'") {
227 $self->emit ('activate_console'); 225 $self->emit ('activate_console');
228 } elsif ($sym == ord "/") { 226 } elsif ($sym == ord "/") {
229 $self->emit ('activate_console' => '/'); 227 $self->emit (activate_console => '/');
230 } elsif (exists $DIR{$sym}) { 228 } elsif (exists $DIR{$sym}) {
231 if ($mod & CFClient::KMOD_SHIFT) { 229 if ($mod & CFClient::KMOD_SHIFT) {
232 $self->{shft}++; 230 $self->{shft}++;
233 $::CONN->user_send ("fire $DIR{$sym}[0]"); 231 $::CONN->user_send ("fire $DIR{$sym}[0]");
234 } elsif ($mod & CFClient::KMOD_CTRL) { 232 } elsif ($mod & CFClient::KMOD_CTRL) {
235 $self->{ctrl}++; 233 $self->{ctrl}++;
236 $::CONN->user_send ("run $DIR{$sym}[0]"); 234 $::CONN->user_send ("run $DIR{$sym}[0]");
237 } else { 235 } else {
238 $::CONN->user_send ("$DIR{$sym}[1]"); 236 $::CONN->user_send ("$DIR{$sym}[1]");
239 } 237 }
238 } elsif ($ev->{unicode}) {
239 $self->{command_widget} ||=
240 new CFClient::MapWidget::Command::
241 command => $self->{command},
242 can_focus => 1,
243 connect_execute => sub {
244 # todo: support callback instead of user_send
245 $::CONN->user_send ($_[1][1]);
246 },
247 connect_close => sub {
248 (delete $self->{command_widget})->hide;
249 $self->focus_in;
250 },
251 ;
252 $self->{command_widget}->key_down ($ev);
253 return unless $self->{command_widget};
254 $self->{command_widget}->show;
255 $self->{command_widget}->focus_in;
240 } 256 }
241} 257}
242 258
243sub key_up { 259sub key_up {
244 my ($self, $ev) = @_; 260 my ($self, $ev) = @_;
253 $::CONN->user_send ("run_stop"); 269 $::CONN->user_send ("run_stop");
254 } 270 }
255} 271}
256 272
257sub add_command { 273sub add_command {
258 my ($self, $command, $widget, $cb) = @_; 274 my ($self, $command, $tooltip, $widget, $cb) = @_;
259 275
260 (my $abbrev = $command) =~ s/(\S)[^[:space:]_]*[[:space:]_]+/$1/g; 276 (my $abbrev = $command) =~ s/(\S)[^[:space:]_]*[[:space:]_]+/$1/g;
261 warn "$command|$abbrev|$widget\n";#d# 277
278 push @{$self->{command}}, [$abbrev, $command, $tooltip, $widget, $cb];
279}
280
281package CFClient::MapWidget::Command;
282
283use strict;
284
285use CFClient::OpenGL;
286
287our @ISA = CFClient::UI::VBox::;
288
289sub new {
290 my $class = shift;
291
292 my $self = $class->SUPER::new (
293 @_,
294 children => [map
295 CFClient::UI::Label->new (
296 can_hover => 1,
297 can_events => 1,
298 fontsize => $_,
299 ), 1, 1, 0.8, 0.8, 0.8, 0.8, 0.8
300 ],
301 );
302
303 $self
304}
305
306sub size_allocate {
307 my ($self, $w, $h) = @_;
308
309 $self->SUPER::size_allocate ($w, $h);
310 $self->move (($::WIDTH - $w) * 0.5, ($::HEIGHT - $h) * 0.6, 10);
311}
312
313sub update_labels {
314 my ($self) = @_;
315
316 my $command = $self->{command};
317 my $search_abbrev = qr/^\Q$self->{search}/;
318 my $search_full = qr/\Q$self->{search}/;
319
320 my @found;
321
322 for (@$command) {
323 if ($_->[0] =~ $search_abbrev) {
324 push @found, [$_->[0], $_];
325 } elsif ($_->[1] =~ $search_full) {
326 push @found, [$_->[1], $_];
327 }
328 }
329
330 @found = sort { $a->[0] cmp $b->[0] } @found;
331
332 $self->{children}[0]->set_text ("$self->{search}_");
333
334 for (0..5) {
335 $self->{children}[$_ + 1]->set_text ($found[$_] ? "$found[$_][0] ($found[$_][1][1])" : "");
336 $self->{children}[$_ + 1]{tooltip} = ($found[$_] ? $found[$_][1][2] : "");
337 }
338
339 $self->{select} = $found[0][1]
340 if @found;
341
342 if (@found > 6) {
343 $self->{children}[6]->set_text ("...");
344 }
345
346 $self->check_size;
347}
348
349sub key_down {
350 my ($self, $ev) = @_;
351
352 if ($ev->{sym} == 8) {
353 substr $self->{search}, -1, 1, "";
354 $self->update_labels;
355 } elsif ($ev->{sym} == 13) {
356 if (exists $self->{select}) {
357 $self->emit (execute => $self->{select});
358 $self->emit ("close");
359 }
360 } elsif ($ev->{sym} == 27) {
361 $self->emit ("close");
362 return;
363 } elsif ((chr $ev->{unicode}) =~ /^[[:alpha:]]$/) {
364 $self->{search} .= chr $ev->{unicode};
365 $self->update_labels;
366 }
367
368 length $self->{search}
369 or $self->emit ("close");
262} 370}
263 371
2641 3721

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines