… | |
… | |
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; |
… | |
… | |
51 | } |
52 | } |
52 | |
53 | |
53 | sub view_item { |
54 | sub view_item { |
54 | ("\t" x ($indent / 4)) |
55 | ("\t" x ($indent / 4)) |
55 | . $_[1]->title->present ($_[0]) |
56 | . $_[1]->title->present ($_[0]) |
56 | . "\n" |
57 | . "\n\n" |
57 | . $_[1]->content->present ($_[0]) |
58 | . $_[1]->content->present ($_[0]) |
58 | } |
59 | } |
59 | |
60 | |
60 | sub view_verbatim { |
61 | sub view_verbatim { |
61 | (join "", |
62 | (join "", |
… | |
… | |
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; |
… | |
… | |
291 | $cb->($last_enter_count); |
298 | $cb->($last_enter_count); |
292 | $w->hide; |
299 | $w->hide; |
293 | $w = undef; |
300 | $w = undef; |
294 | } |
301 | } |
295 | ); |
302 | ); |
296 | $entry->focus_in; |
303 | $entry->grab_focus; |
297 | $w->show; |
304 | $w->show; |
298 | |
305 | |
299 | } |
306 | } |
300 | |
307 | |
301 | sub update_widgets { |
308 | sub update_widgets { |
302 | my ($self) = @_; |
309 | my ($self) = @_; |
|
|
310 | |
|
|
311 | # necessary to avoid cyclic references |
|
|
312 | Scalar::Util::weaken $self; |
303 | |
313 | |
304 | my $button_cb = sub { |
314 | my $button_cb = sub { |
305 | my (undef, $ev, $x, $y) = @_; |
315 | my (undef, $ev, $x, $y) = @_; |
306 | |
316 | |
307 | my $targ = $::CONN->{player}{tag}; |
317 | my $targ = $::CONN->{player}{tag}; |
… | |
… | |
323 | $::CONN->send ("apply $self->{tag}"); |
333 | $::CONN->send ("apply $self->{tag}"); |
324 | } elsif ($ev->{button} == 3) { |
334 | } elsif ($ev->{button} == 3) { |
325 | my @menu_items = ( |
335 | my @menu_items = ( |
326 | ["examine", sub { $::CONN->send ("examine $self->{tag}") }], |
336 | ["examine", sub { $::CONN->send ("examine $self->{tag}") }], |
327 | ["mark", sub { $::CONN->send ("mark ". pack "N", $self->{tag}) }], |
337 | ["mark", sub { $::CONN->send ("mark ". pack "N", $self->{tag}) }], |
|
|
338 | ["ignite/thaw", # first try of an easier use of flint&steel |
|
|
339 | sub { |
|
|
340 | $::CONN->send ("mark ". pack "N", $self->{tag}); |
|
|
341 | $::CONN->send ("command apply flint and steel"); |
|
|
342 | } |
|
|
343 | ], |
328 | ["apply", sub { $::CONN->send ("apply $self->{tag}") }], |
344 | ["apply", sub { $::CONN->send ("apply $self->{tag}") }], |
329 | ( |
345 | ( |
330 | $self->{flags} & F_LOCKED |
346 | $self->{flags} & F_LOCKED |
331 | ? ( |
347 | ? ( |
332 | ["unlock", sub { $::CONN->send ("lock " . pack "CN", 0, $self->{tag}) }], |
348 | ["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. ") |
416 | . ($self->{nrof} ? "You have $self->{nrof} of it. " : "Item cannot stack with others of it's kind. ") |
401 | . "\n\n$tooltip_std" |
417 | . "\n\n$tooltip_std" |
402 | ); |
418 | ); |
403 | } |
419 | } |
404 | |
420 | |
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 | package CFClient::Pickup; |
|
|
513 | # some pickup constants |
|
|
514 | sub PU_NOTHING { 0x00000000 } |
|
|
515 | |
|
|
516 | sub PU_DEBUG { 0x10000000 } |
|
|
517 | sub PU_INHIBIT { 0x20000000 } |
|
|
518 | sub PU_STOP { 0x40000000 } |
|
|
519 | sub PU_NEWMODE { 0x80000000 } |
|
|
520 | |
|
|
521 | sub PU_RATIO { 0x0000000F } |
|
|
522 | |
|
|
523 | sub PU_FOOD { 0x00000010 } |
|
|
524 | sub PU_DRINK { 0x00000020 } |
|
|
525 | sub PU_VALUABLES { 0x00000040 } |
|
|
526 | sub PU_BOW { 0x00000080 } |
|
|
527 | |
|
|
528 | sub PU_ARROW { 0x00000100 } |
|
|
529 | sub PU_HELMET { 0x00000200 } |
|
|
530 | sub PU_SHIELD { 0x00000400 } |
|
|
531 | sub PU_ARMOUR { 0x00000800 } |
|
|
532 | |
|
|
533 | sub PU_BOOTS { 0x00001000 } |
|
|
534 | sub PU_GLOVES { 0x00002000 } |
|
|
535 | sub PU_CLOAK { 0x00004000 } |
|
|
536 | sub PU_KEY { 0x00008000 } |
|
|
537 | |
|
|
538 | sub PU_MISSILEWEAPON { 0x00010000 } |
|
|
539 | sub PU_ALLWEAPON { 0x00020000 } |
|
|
540 | sub PU_MAGICAL { 0x00040000 } |
|
|
541 | sub PU_POTION { 0x00080000 } |
|
|
542 | |
|
|
543 | sub PU_SPELLBOOK { 0x00100000 } |
|
|
544 | sub PU_SKILLSCROLL { 0x00200000 } |
|
|
545 | sub PU_READABLES { 0x00400000 } |
|
|
546 | sub PU_MAGIC_DEVICE { 0x00800000 } |
|
|
547 | |
|
|
548 | sub PU_NOT_CURSED { 0x01000000 } |
|
|
549 | |
|
|
550 | sub PU_JEWELS { 0x02000000 } |
|
|
551 | |
|
|
552 | |
|
|
553 | 1; |
421 | 1; |
554 | |
422 | |
555 | =back |
423 | =back |
556 | |
424 | |
557 | =head1 AUTHOR |
425 | =head1 AUTHOR |