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.14 by root, Mon Apr 24 11:54:26 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});
86 my $sh = int $::HEIGHT / 32; 87 my $sh = int $::HEIGHT / (32 * $::CFG->{map_scale});
87 88
89 glScale $::CFG->{map_scale}, $::CFG->{map_scale};
90
88 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;
89 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;
90 93
91 glTranslate $sx0 - 32, $sy0 - 32, 0; 94 glTranslate $sx0 - 32, $sy0 - 32, 0;
92 95
93 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);
94 97
212 my $mod = $ev->{mod}; 215 my $mod = $ev->{mod};
213 my $sym = $ev->{sym}; 216 my $sym = $ev->{sym};
214 217
215 if ($sym == CFClient::SDLK_KP5) { 218 if ($sym == CFClient::SDLK_KP5) {
216 $::CONN->user_send ("stay fire"); 219 $::CONN->user_send ("stay fire");
220 } elsif ($sym == ord ",") {
221 $::CONN->user_send ("take");
217 } elsif ($sym == ord "a") { 222 } elsif ($sym == ord "a") {
218 $::CONN->user_send ("apply"); 223 $::CONN->user_send ("apply");
219 } elsif ($sym == ord "'") { 224 } elsif ($sym == ord "'") {
220 $self->emit ('activate_console'); 225 $self->emit ('activate_console');
221 } elsif ($sym == ord "/") { 226 } elsif ($sym == ord "/") {
234 $self->{command_widget} ||= 239 $self->{command_widget} ||=
235 new CFClient::MapWidget::Command:: 240 new CFClient::MapWidget::Command::
236 command => $self->{command}, 241 command => $self->{command},
237 can_focus => 1, 242 can_focus => 1,
238 connect_execute => sub { 243 connect_execute => sub {
244 # todo: support callback instead of user_send
239 $::CONN->user_send ($_[1]); 245 $::CONN->user_send ($_[1][1]);
240 }, 246 },
241 connect_close => sub { 247 connect_close => sub {
242 (delete $self->{command_widget})->hide; 248 (delete $self->{command_widget})->hide;
243 $self->focus_in; 249 $self->focus_in;
244 }, 250 },
245 ; 251 ;
246 $self->{command_widget}->key_down ($ev); 252 $self->{command_widget}->key_down ($ev);
253 return unless $self->{command_widget};
247 $self->{command_widget}->show; 254 $self->{command_widget}->show;
248 $self->{command_widget}->focus_in; 255 $self->{command_widget}->focus_in;
249 } 256 }
250} 257}
251 258
262 $::CONN->user_send ("run_stop"); 269 $::CONN->user_send ("run_stop");
263 } 270 }
264} 271}
265 272
266sub add_command { 273sub add_command {
267 my ($self, $command, $widget, $cb) = @_; 274 my ($self, $command, $tooltip, $widget, $cb) = @_;
268 275
269 (my $abbrev = $command) =~ s/(\S)[^[:space:]_]*[[:space:]_]+/$1/g; 276 (my $abbrev = $command) =~ s/(\S)[^[:space:]_]*[[:space:]_]+/$1/g;
270 277
271 push @{$self->{command}}, [$abbrev, $command]; 278 push @{$self->{command}}, [$abbrev, $command, $tooltip, $widget, $cb];
272 #warn "$command|$abbrev|$widget\n";#d#
273} 279}
274 280
275package CFClient::MapWidget::Command; 281package CFClient::MapWidget::Command;
276 282
277use strict; 283use strict;
285 291
286 my $self = $class->SUPER::new ( 292 my $self = $class->SUPER::new (
287 @_, 293 @_,
288 children => [map 294 children => [map
289 CFClient::UI::Label->new ( 295 CFClient::UI::Label->new (
290 can_hover => 1, 296 can_hover => 1,
297 can_events => 1,
291 fontsize => $_, 298 fontsize => $_,
292 ), 1, 1, 0.8, 0.8, 0.8, 0.8, 0.8 299 ), 1, 1, 0.8, 0.8, 0.8, 0.8, 0.8
293 ], 300 ],
294 ); 301 );
295 302
296 $self 303 $self
324 331
325 $self->{children}[0]->set_text ("$self->{search}_"); 332 $self->{children}[0]->set_text ("$self->{search}_");
326 333
327 for (0..5) { 334 for (0..5) {
328 $self->{children}[$_ + 1]->set_text ($found[$_] ? "$found[$_][0] ($found[$_][1][1])" : ""); 335 $self->{children}[$_ + 1]->set_text ($found[$_] ? "$found[$_][0] ($found[$_][1][1])" : "");
336 $self->{children}[$_ + 1]{tooltip} = ($found[$_] ? $found[$_][1][2] : "");
329 } 337 }
330 338
331 $self->{select} = $found[0][1][1] 339 $self->{select} = $found[0][1]
332 if @found; 340 if @found;
333 341
334 if (@found > 6) { 342 if (@found > 6) {
335 $self->{children}[6]->set_text ("..."); 343 $self->{children}[6]->set_text ("...");
336 } 344 }
349 $self->emit (execute => $self->{select}); 357 $self->emit (execute => $self->{select});
350 $self->emit ("close"); 358 $self->emit ("close");
351 } 359 }
352 } elsif ($ev->{sym} == 27) { 360 } elsif ($ev->{sym} == 27) {
353 $self->emit ("close"); 361 $self->emit ("close");
354 } elsif ($ev->{unicode}) { 362 return;
363 } elsif ((chr $ev->{unicode}) =~ /^[[:alpha:]]$/) {
355 $self->{search} .= chr $ev->{unicode}; 364 $self->{search} .= chr $ev->{unicode};
356 $self->update_labels; 365 $self->update_labels;
357 } 366 }
367
368 length $self->{search}
369 or $self->emit ("close");
358} 370}
359 371
3601 3721

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines