… | |
… | |
25 | |
25 | |
26 | use Carp (); |
26 | use Carp (); |
27 | use AnyEvent (); |
27 | use AnyEvent (); |
28 | use BerkeleyDB; |
28 | use BerkeleyDB; |
29 | use Pod::POM (); |
29 | use Pod::POM (); |
|
|
30 | use Scalar::Util (); |
30 | use Storable (); # finally |
31 | use Storable (); # finally |
31 | |
32 | |
32 | package CFClient::PodToPango; |
33 | package CFClient::PodToPango; |
33 | |
34 | |
34 | use base Pod::POM::View::Text; |
35 | use base Pod::POM::View::Text; |
… | |
… | |
233 | [ |
234 | [ |
234 | map s/^(\s*)// && [40 * length $1, length $_ ? $_ : " "], |
235 | map s/^(\s*)// && [40 * length $1, length $_ ? $_ : " "], |
235 | split /\n/, $pom->present ("CFClient::PodToPango") |
236 | split /\n/, $pom->present ("CFClient::PodToPango") |
236 | ] |
237 | ] |
237 | } |
238 | } |
|
|
239 | |
|
|
240 | package CFClient::Layout; |
|
|
241 | |
|
|
242 | $CFClient::OpenGL::SHUTDOWN_HOOK{"CFClient::Layout"} = sub { |
|
|
243 | reset_glyph_cache; |
|
|
244 | }; |
238 | |
245 | |
239 | package CFClient::Item; |
246 | package CFClient::Item; |
240 | |
247 | |
241 | use strict; |
248 | use strict; |
242 | use Crossfire::Protocol::Constants; |
249 | use Crossfire::Protocol::Constants; |
… | |
… | |
278 | } |
285 | } |
279 | |
286 | |
280 | sub do_n_dialog { |
287 | sub do_n_dialog { |
281 | my ($cb) = @_; |
288 | my ($cb) = @_; |
282 | |
289 | |
283 | my $w = new CFClient::UI::FancyFrame; |
290 | my $w = new CFClient::UI::FancyFrame |
|
|
291 | on_delete => sub { $_[0]->destroy; 1 }, |
|
|
292 | has_close_button => 1, |
|
|
293 | ; |
|
|
294 | |
284 | $w->add (my $vb = new CFClient::UI::VBox x => "center", y => "center"); |
295 | $w->add (my $vb = new CFClient::UI::VBox x => "center", y => "center"); |
285 | $vb->add (new CFClient::UI::Label text => "Enter item count:"); |
296 | $vb->add (new CFClient::UI::Label text => "Enter item count:"); |
286 | $vb->add (my $entry = new CFClient::UI::Entry |
297 | $vb->add (my $entry = new CFClient::UI::Entry |
287 | text => $last_enter_count, |
298 | text => $last_enter_count, |
288 | on_activate => sub { |
299 | on_activate => sub { |
289 | my ($entry) = @_; |
300 | my ($entry) = @_; |
290 | $last_enter_count = $entry->get_text; |
301 | $last_enter_count = $entry->get_text; |
291 | $cb->($last_enter_count); |
302 | $cb->($last_enter_count); |
292 | $w->hide; |
303 | $w->hide; |
293 | $w = undef; |
304 | $w->destroy; |
|
|
305 | |
|
|
306 | 0 |
294 | } |
307 | }, |
|
|
308 | on_escape => sub { $w->destroy; 1 }, |
295 | ); |
309 | ); |
296 | $entry->focus_in; |
310 | $entry->grab_focus; |
297 | $w->show; |
311 | $w->show; |
298 | |
|
|
299 | } |
312 | } |
300 | |
313 | |
301 | sub update_widgets { |
314 | sub update_widgets { |
302 | my ($self) = @_; |
315 | my ($self) = @_; |
|
|
316 | |
|
|
317 | # necessary to avoid cyclic references |
|
|
318 | Scalar::Util::weaken $self; |
303 | |
319 | |
304 | my $button_cb = sub { |
320 | my $button_cb = sub { |
305 | my (undef, $ev, $x, $y) = @_; |
321 | my (undef, $ev, $x, $y) = @_; |
306 | |
322 | |
307 | my $targ = $::CONN->{player}{tag}; |
323 | my $targ = $::CONN->{player}{tag}; |
… | |
… | |
323 | $::CONN->send ("apply $self->{tag}"); |
339 | $::CONN->send ("apply $self->{tag}"); |
324 | } elsif ($ev->{button} == 3) { |
340 | } elsif ($ev->{button} == 3) { |
325 | my @menu_items = ( |
341 | my @menu_items = ( |
326 | ["examine", sub { $::CONN->send ("examine $self->{tag}") }], |
342 | ["examine", sub { $::CONN->send ("examine $self->{tag}") }], |
327 | ["mark", sub { $::CONN->send ("mark ". pack "N", $self->{tag}) }], |
343 | ["mark", sub { $::CONN->send ("mark ". pack "N", $self->{tag}) }], |
|
|
344 | ["ignite/thaw", # first try of an easier use of flint&steel |
|
|
345 | sub { |
|
|
346 | $::CONN->send ("mark ". pack "N", $self->{tag}); |
|
|
347 | $::CONN->send ("command apply flint and steel"); |
|
|
348 | } |
|
|
349 | ], |
328 | ["apply", sub { $::CONN->send ("apply $self->{tag}") }], |
350 | ["apply", sub { $::CONN->send ("apply $self->{tag}") }], |
329 | ( |
351 | ( |
330 | $self->{flags} & F_LOCKED |
352 | $self->{flags} & F_LOCKED |
331 | ? ( |
353 | ? ( |
332 | ["unlock", sub { $::CONN->send ("lock " . pack "CN", 0, $self->{tag}) }], |
354 | ["unlock", sub { $::CONN->send ("lock " . pack "CN", 0, $self->{tag}) }], |
… | |
… | |
400 | . ($self->{nrof} ? "You have $self->{nrof} of it. " : "Item cannot stack with others of it's kind. ") |
422 | . ($self->{nrof} ? "You have $self->{nrof} of it. " : "Item cannot stack with others of it's kind. ") |
401 | . "\n\n$tooltip_std" |
423 | . "\n\n$tooltip_std" |
402 | ); |
424 | ); |
403 | } |
425 | } |
404 | |
426 | |
405 | package CFClient::Binder; |
|
|
406 | |
|
|
407 | my @ALLOWED_MODIFIER_KEYS = ( |
|
|
408 | CFClient::SDLK_LSHIFT, |
|
|
409 | CFClient::SDLK_LCTRL , |
|
|
410 | CFClient::SDLK_LALT , |
|
|
411 | CFClient::SDLK_LMETA , |
|
|
412 | |
|
|
413 | CFClient::SDLK_RSHIFT, |
|
|
414 | CFClient::SDLK_RCTRL , |
|
|
415 | CFClient::SDLK_RALT , |
|
|
416 | CFClient::SDLK_RMETA , |
|
|
417 | ); |
|
|
418 | |
|
|
419 | my %ALLOWED_MODIFIERS = ( |
|
|
420 | CFClient::KMOD_LSHIFT => "LSHIFT", |
|
|
421 | CFClient::KMOD_LCTRL => "LCTRL", |
|
|
422 | CFClient::KMOD_LALT => "LALT", |
|
|
423 | CFClient::KMOD_LMETA => "LMETA", |
|
|
424 | |
|
|
425 | CFClient::KMOD_RSHIFT => "RSHIFT", |
|
|
426 | CFClient::KMOD_RCTRL => "RCTRL", |
|
|
427 | CFClient::KMOD_RALT => "RALT", |
|
|
428 | CFClient::KMOD_RMETA => "RMETA", |
|
|
429 | ); |
|
|
430 | |
|
|
431 | my %DIRECT_BIND_CHARS = map { $_ => 1 } qw/0 1 2 3 4 5 6 7 8 9/; |
|
|
432 | my @DIRECT_BIND_KEYS = ( |
|
|
433 | CFClient::SDLK_F1, |
|
|
434 | CFClient::SDLK_F2, |
|
|
435 | CFClient::SDLK_F3, |
|
|
436 | CFClient::SDLK_F4, |
|
|
437 | CFClient::SDLK_F5, |
|
|
438 | CFClient::SDLK_F6, |
|
|
439 | CFClient::SDLK_F7, |
|
|
440 | CFClient::SDLK_F8, |
|
|
441 | CFClient::SDLK_F9, |
|
|
442 | CFClient::SDLK_F10, |
|
|
443 | CFClient::SDLK_F11, |
|
|
444 | CFClient::SDLK_F12, |
|
|
445 | CFClient::SDLK_F13, |
|
|
446 | CFClient::SDLK_F14, |
|
|
447 | CFClient::SDLK_F15, |
|
|
448 | ); |
|
|
449 | |
|
|
450 | # this binding dialog asks for a key-combo to be pressed |
|
|
451 | # and if successful it calls the $cb with $mod and $sym as args. |
|
|
452 | sub open_binding_dialog { |
|
|
453 | my ($cb) = @_; |
|
|
454 | |
|
|
455 | my $w = new CFClient::UI::FancyFrame |
|
|
456 | title => "Bind Action", |
|
|
457 | x => "center", |
|
|
458 | y => "center"; |
|
|
459 | |
|
|
460 | $w->add (my $vb = new CFClient::UI::VBox); |
|
|
461 | $vb->add (new CFClient::UI::Label |
|
|
462 | text => "Press a modifier (CTRL, ALT and/or SHIFT) and a key." |
|
|
463 | ."You can only bind 0-9 and F1-F15 without modifiers." |
|
|
464 | ); |
|
|
465 | $vb->add (my $entry = new CFClient::UI::Entry |
|
|
466 | text => "", |
|
|
467 | on_key_down => sub { |
|
|
468 | my ($entry, $ev) = @_; |
|
|
469 | |
|
|
470 | my $mod = $ev->{mod}; |
|
|
471 | my $sym = $ev->{sym}; |
|
|
472 | |
|
|
473 | # XXX: This seems a little bit hackisch to me, but i have to ignore them |
|
|
474 | if (grep { $_ == $sym } @ALLOWED_MODIFIER_KEYS) { |
|
|
475 | return; |
|
|
476 | } |
|
|
477 | |
|
|
478 | if ($mod == CFClient::KMOD_NONE |
|
|
479 | and not $DIRECT_BIND_CHARS{chr ($ev->{unicode})} |
|
|
480 | and not grep { $sym == $_ } @DIRECT_BIND_KEYS) |
|
|
481 | { |
|
|
482 | $::STATUSBOX->add ( |
|
|
483 | "Can't bind key ".CFClient::SDL_GetKeyName ($sym) |
|
|
484 | ." directly without modifier! It would damage the completer handling." |
|
|
485 | ); |
|
|
486 | return; |
|
|
487 | } |
|
|
488 | |
|
|
489 | $entry->focus_out; |
|
|
490 | |
|
|
491 | $cb->($mod, $sym); |
|
|
492 | |
|
|
493 | $w->destroy |
|
|
494 | }); |
|
|
495 | |
|
|
496 | $entry->focus_in; |
|
|
497 | $w->show; |
|
|
498 | } |
|
|
499 | |
|
|
500 | sub keycombo_to_name { |
|
|
501 | my ($mod, $sym) = @_; |
|
|
502 | |
|
|
503 | my $mods = join '+', |
|
|
504 | map { $ALLOWED_MODIFIERS{$_} } |
|
|
505 | grep { ($_ + 0) & ($mod + 0) } |
|
|
506 | keys %ALLOWED_MODIFIERS; |
|
|
507 | $mods .= "+" if $mods ne ''; |
|
|
508 | |
|
|
509 | return $mods . CFClient::SDL_GetKeyName ($sym); |
|
|
510 | } |
|
|
511 | |
|
|
512 | 1; |
427 | 1; |
513 | |
428 | |
514 | =back |
429 | =back |
515 | |
430 | |
516 | =head1 AUTHOR |
431 | =head1 AUTHOR |