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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines