--- deliantra/Deliantra-Client/DC.pm 2006/06/05 05:31:13 1.88 +++ deliantra/Deliantra-Client/DC.pm 2006/07/22 13:20:33 1.102 @@ -26,7 +26,109 @@ use Carp (); use AnyEvent (); use BerkeleyDB; -use Pod::POM; +use Pod::POM (); +use Scalar::Util (); +use Storable (); # finally + +our %STAT_TOOLTIP = ( + Str => "Physical Strength, determines damage dealt with weapons, how much you can carry, and how often you can attack", + Dex => "Dexterity, your physical agility. Determines chance of being hit and affects armor class and speed", + Con => "Constitution, physical health and toughness. Determines how many healthpoints you can have", + Int => "Intelligence, your ability to learn and use skills and incantations (both prayers and magic) and determines how much spell points you can have", + Wis => "Wisdom, the ability to learn and use divine magic (prayers). Determines how many grace points you can have", + Pow => "Power, your magical potential. Influences the strength of spell effects, and also how much your spell and grace points increase when leveling up", + Cha => "Charisma, how well you are received by NPCs. Affects buying and selling prices in shops.", + + Wc => "Weapon Class, effectiveness of melee/missile attacks. Lower is more potent. Current weapon, level and Str are some things which effect the value of Wc. The value of Wc may range between 25 and -72.", + Ac => "Armour Class, how protected you are from being hit by any attack. Lower values are better. Ac is based on your race and is modified by the Dex and current armour worn. For characters that cannot wear armour, Ac improves as their level increases.", + Dam => "Damage, how much damage your melee/missile attack inflicts. Higher values indicate a greater amount of damage will be inflicted with each attack.", + Arm => "Armour, how much damage (from physical attacks) will be subtracted from successful hits made upon you. This value ranges between 0 to 99%. Current armour worn primarily determines Arm value. This is the same as the physical resistance.", + Spd => "Speed, how fast you can move. The value of speed may range between nearly 0 (\"very slow\") to higher than 5 (\"lightning fast\"). Base speed is determined from the Dex and modified downward proportionally by the amount of weight carried which exceeds the Max Carry limit. The armour worn also sets the upper limit on speed.", + WSp => "Weapon Speed, how many attacks you may make per unit of time (0.120s). Higher values indicate faster attack speed. Current weapon and Dex effect the value of weapon speed.", +); + +package CFClient::PodToPango; + +use base Pod::POM::View::Text; + +our $VERSION = 1; # bump if resultant formatting changes + +our $indent = 0; + +*view_seq_code = +*view_seq_bold = sub { "$_[1]" }; +*view_seq_italic = sub { "$_[1]" }; +*view_seq_space = +*view_seq_link = +*view_seq_index = sub { CFClient::UI::Label::escape ($_[1]) }; + +sub view_seq_text { + my $text = $_[1]; + $text =~ s/\s+/ /g; + CFClient::UI::Label::escape ($text) +} + +sub view_item { + ("\t" x ($indent / 4)) + . $_[1]->title->present ($_[0]) + . "\n\n" + . $_[1]->content->present ($_[0]) +} + +sub view_verbatim { + (join "", + map +("\t" x ($indent / 2)) . "$_\n", + split /\n/, CFClient::UI::Label::escape ($_[1])) + . "\n" +} + +sub view_textblock { + ("\t" x ($indent / 2)) . "$_[1]\n\n" +} + +sub view_head1 { + "\n\n" . $_[1]->title->present ($_[0]) . "\n\n" + . $_[1]->content->present ($_[0]) +}; + +sub view_head2 { + "\n" . $_[1]->title->present ($_[0]) . "\n\n" + . $_[1]->content->present ($_[0]) +}; + +sub view_head3 { + "\n" . $_[1]->title->present ($_[0]) . "\n\n" + . $_[1]->content->present ($_[0]) +}; + +sub view_over { + local $indent = $indent + $_[1]->indent; + $_[1]->content->present ($_[0]) +} + +package CFClient::Database; + +our @ISA = BerkeleyDB::Btree::; + +sub get($$) { + my $data; + + $_[0]->db_get ($_[1], $data) == 0 + ? $data + : () +} + +my %DB_SYNC; + +sub put($$$) { + my ($db, $key, $data) = @_; + + $DB_SYNC{$db} = AnyEvent->timer (after => 5, cb => sub { $db->db_sync }); + + $db->db_put ($key => $data) +} + +package CFClient; sub find_rcfile($) { my $path; @@ -71,21 +173,6 @@ close CFG; } -my %POD_CACHE; - -sub load_pod($) { - $POD_CACHE{$_[0]} ||= do { - my $pod = do { - local $/; - open my $pod, "<:utf8", $_[0] - or die "$_[0]: $!"; - <$pod> - }; - - Pod::POM->new->parse_text ($pod) - } -} - our $DB_ENV; { @@ -122,99 +209,56 @@ or die "unable to create/open database table $_[0]: $BerkeleyDB::Error" } -sub pod_to_pango($) { - my ($pom) = @_; +my $pod_cache = db_table "pod_cache"; - $pom->present ("CFClient::PodToPango") -} +sub load_pod($$$$) { + my ($path, $filtertype, $filterversion, $filtercb) = @_; -sub pod_to_pango_list($) { - my ($pom) = @_; + stat $path + or die "$path: $!"; - [ - map s/^(\s*)// && [40 * length $1, length $_ ? $_ : " "], - split /\n/, $pom->present ("CFClient::PodToPango") - ] -} + my $phash = join ",", $filterversion, $CFClient::PodToPango::VERSION, (stat _)[7,9]; -package CFClient::PodToPango; + my ($chash, $pom) = eval { @{ Storable::thaw $pod_cache->get ("$path/$filtertype") } }; -use base Pod::POM::View::Text; + return $pom if $chash eq $phash; -our $indent = 0; + my $pod = do { + local $/; + open my $pod, "<:utf8", $_[0] + or die "$_[0]: $!"; + <$pod> + }; -*view_seq_code = -*view_seq_bold = sub { "$_[1]" }; -*view_seq_italic = sub { "$_[1]" }; -*view_seq_space = -*view_seq_link = -*view_seq_index = sub { CFClient::UI::Label::escape ($_[1]) }; + #utf8::downgrade $pod; -sub view_seq_text { - my $text = $_[1]; - $text =~ s/\s+/ /g; - CFClient::UI::Label::escape ($text) -} + $pom = $filtercb-> (Pod::POM->new->parse_text ($pod)); -sub view_item { - ("\t" x ($indent / 4)) - . $_[1]->title->present ($_[0]) - . "\n" - . $_[1]->content->present ($_[0]) -} + $pod_cache->put ("$path/$filtertype" => Storable::nfreeze [$phash, $pom]); -sub view_verbatim { - (join "", - map +("\t" x ($indent / 2)) . "$_\n", - split /\n/, CFClient::UI::Label::escape ($_[1])) - . "\n" + $pom } -sub view_textblock { - ("\t" x ($indent / 2)) . "$_[1]\n\n" -} - -sub view_head1 { - "\n\n" . $_[1]->title->present ($_[0]) . "\n\n" - . $_[1]->content->present ($_[0]) -}; - -sub view_head2 { - "\n" . $_[1]->title->present ($_[0]) . "\n\n" - . $_[1]->content->present ($_[0]) -}; - -sub view_head3 { - "\n" . $_[1]->title->present ($_[0]) . "\n\n" - . $_[1]->content->present ($_[0]) -}; +sub pod_to_pango($) { + my ($pom) = @_; -sub view_over { - local $indent = $indent + $_[1]->indent; - $_[1]->content->present ($_[0]) + $pom->present ("CFClient::PodToPango") } -package CFClient::Database; - -our @ISA = BerkeleyDB::Btree::; - -sub get($$) { - my $data; +sub pod_to_pango_list($) { + my ($pom) = @_; - $_[0]->db_get ($_[1], $data) == 0 - ? $data - : () + [ + map s/^(\s*)// && [40 * length $1, length $_ ? $_ : " "], + split /\n/, $pom->present ("CFClient::PodToPango") + ] } -my %DB_SYNC; - -sub put($$$) { - my ($db, $key, $data) = @_; +package CFClient::Layout; - $DB_SYNC{$db} = AnyEvent->timer (after => 5, cb => sub { $db->db_sync }); - - $db->db_put ($key => $data) -} +$CFClient::OpenGL::SHUTDOWN_HOOK{"CFClient::Layout"} = sub { + reset_glyph_cache; +}; package CFClient::Item; @@ -260,7 +304,11 @@ sub do_n_dialog { my ($cb) = @_; - my $w = new CFClient::UI::FancyFrame; + my $w = new CFClient::UI::FancyFrame + on_delete => sub { $_[0]->destroy; 1 }, + has_close_button => 1, + ; + $w->add (my $vb = new CFClient::UI::VBox x => "center", y => "center"); $vb->add (new CFClient::UI::Label text => "Enter item count:"); $vb->add (my $entry = new CFClient::UI::Entry @@ -270,17 +318,22 @@ $last_enter_count = $entry->get_text; $cb->($last_enter_count); $w->hide; - $w = undef; - } + $w->destroy; + + 0 + }, + on_escape => sub { $w->destroy; 1 }, ); - $entry->focus_in; + $entry->grab_focus; $w->show; - } sub update_widgets { my ($self) = @_; + # necessary to avoid cyclic references + Scalar::Util::weaken $self; + my $button_cb = sub { my (undef, $ev, $x, $y) = @_; @@ -302,9 +355,20 @@ } elsif ($ev->{button} == 2) { $::CONN->send ("apply $self->{tag}"); } elsif ($ev->{button} == 3) { + my $move_prefix = $::CONN->{open_container} ? 'put' : 'drop'; + if ($self->{container} == $::CONN->{open_container}) { + $move_prefix = "take"; + } + my @menu_items = ( ["examine", sub { $::CONN->send ("examine $self->{tag}") }], ["mark", sub { $::CONN->send ("mark ". pack "N", $self->{tag}) }], + ["ignite/thaw", # first try of an easier use of flint&steel + sub { + $::CONN->send ("mark ". pack "N", $self->{tag}); + $::CONN->send ("command apply flint and steel"); + } + ], ["apply", sub { $::CONN->send ("apply $self->{tag}") }], ( $self->{flags} & F_LOCKED @@ -313,8 +377,8 @@ ) : ( ["lock", sub { $::CONN->send ("lock " . pack "CN", 1, $self->{tag}) }], - ["drop", sub { $::CONN->send ("move $::CONN->{open_container} $self->{tag} 0") }], - ["move n", + ["$move_prefix all", sub { $::CONN->send ("move $targ $self->{tag} 0") }], + ["$move_prefix n", sub { do_n_dialog (sub { $::CONN->send ("move $targ $self->{tag} $_[0]") }) } @@ -382,154 +446,6 @@ ); } -package CFClient::Binder; - -my @ALLOWED_MODIFIER_KEYS = ( - CFClient::SDLK_LSHIFT, - CFClient::SDLK_LCTRL , - CFClient::SDLK_LALT , - CFClient::SDLK_LMETA , - - CFClient::SDLK_RSHIFT, - CFClient::SDLK_RCTRL , - CFClient::SDLK_RALT , - CFClient::SDLK_RMETA , -); - -my %ALLOWED_MODIFIERS = ( - CFClient::KMOD_LSHIFT => "LSHIFT", - CFClient::KMOD_LCTRL => "LCTRL", - CFClient::KMOD_LALT => "LALT", - CFClient::KMOD_LMETA => "LMETA", - - CFClient::KMOD_RSHIFT => "RSHIFT", - CFClient::KMOD_RCTRL => "RCTRL", - CFClient::KMOD_RALT => "RALT", - CFClient::KMOD_RMETA => "RMETA", -); - -my %DIRECT_BIND_CHARS = map { $_ => 1 } qw/0 1 2 3 4 5 6 7 8 9/; -my @DIRECT_BIND_KEYS = ( - CFClient::SDLK_F1, - CFClient::SDLK_F2, - CFClient::SDLK_F3, - CFClient::SDLK_F4, - CFClient::SDLK_F5, - CFClient::SDLK_F6, - CFClient::SDLK_F7, - CFClient::SDLK_F8, - CFClient::SDLK_F9, - CFClient::SDLK_F10, - CFClient::SDLK_F11, - CFClient::SDLK_F12, - CFClient::SDLK_F13, - CFClient::SDLK_F14, - CFClient::SDLK_F15, -); - -# this binding dialog asks for a key-combo to be pressed -# and if successful it calls the $cb with $mod and $sym as args. -sub open_binding_dialog { - my ($cb) = @_; - - my $w = new CFClient::UI::FancyFrame - title => "Bind Action", - x => "center", - y => "center"; - - $w->add (my $vb = new CFClient::UI::VBox); - $vb->add (new CFClient::UI::Label - text => "Press a modifier (CTRL, ALT and/or SHIFT) and a key." - ."You can only bind 0-9 and F1-F15 without modifiers." - ); - $vb->add (my $entry = new CFClient::UI::Entry - text => "", - on_key_down => sub { - my ($entry, $ev) = @_; - - my $mod = $ev->{mod}; - my $sym = $ev->{sym}; - - # XXX: This seems a little bit hackisch to me, but i have to ignore them - if (grep { $_ == $sym } @ALLOWED_MODIFIER_KEYS) { - return; - } - - if ($mod == CFClient::KMOD_NONE - and not $DIRECT_BIND_CHARS{chr ($ev->{unicode})} - and not grep { $sym == $_ } @DIRECT_BIND_KEYS) - { - $::STATUSBOX->add ( - "Can't bind key ".CFClient::SDL_GetKeyName ($sym) - ." directly without modifier! It would damage the completer handling." - ); - return; - } - - $entry->focus_out; - - $cb->($mod, $sym); - - $w->destroy - }); - - $entry->focus_in; - $w->show; -} - -sub keycombo_to_name { - my ($mod, $sym) = @_; - - my $mods = join '+', - map { $ALLOWED_MODIFIERS{$_} } - grep { ($_ + 0) & ($mod + 0) } - keys %ALLOWED_MODIFIERS; - $mods .= "+" if $mods ne ''; - - return $mods . CFClient::SDL_GetKeyName ($sym); -} - -package CFClient::Pickup; -# some pickup constants -sub PU_NOTHING { 0x00000000 } - -sub PU_DEBUG { 0x10000000 } -sub PU_INHIBIT { 0x20000000 } -sub PU_STOP { 0x40000000 } -sub PU_NEWMODE { 0x80000000 } - -sub PU_RATIO { 0x0000000F } - -sub PU_FOOD { 0x00000010 } -sub PU_DRINK { 0x00000020 } -sub PU_VALUABLES { 0x00000040 } -sub PU_BOW { 0x00000080 } - -sub PU_ARROW { 0x00000100 } -sub PU_HELMET { 0x00000200 } -sub PU_SHIELD { 0x00000400 } -sub PU_ARMOUR { 0x00000800 } - -sub PU_BOOTS { 0x00001000 } -sub PU_GLOVES { 0x00002000 } -sub PU_CLOAK { 0x00004000 } -sub PU_KEY { 0x00008000 } - -sub PU_MISSILEWEAPON { 0x00010000 } -sub PU_ALLWEAPON { 0x00020000 } -sub PU_MAGICAL { 0x00040000 } -sub PU_POTION { 0x00080000 } - -sub PU_SPELLBOOK { 0x00100000 } -sub PU_SKILLSCROLL { 0x00200000 } -sub PU_READABLES { 0x00400000 } -sub PU_MAGIC_DEVICE { 0x00800000 } - -sub PU_NOT_CURSED { 0x01000000 } - -sub PU_JEWELS { 0x02000000 } - - 1; =back