--- deliantra/Deliantra-Client/DC/Protocol.pm 2006/05/26 19:34:30 1.3 +++ deliantra/Deliantra-Client/DC/Protocol.pm 2006/06/11 18:43:09 1.31 @@ -5,6 +5,7 @@ use Crossfire::Protocol::Constants; +use CFClient; use CFClient::UI; use base 'Crossfire::Protocol::Base'; @@ -16,25 +17,34 @@ $self->{map_widget}->clr_commands; - my $parser = new Pod::POM; - my $pod = $parser->parse_file (CFClient::find_rcfile "pod/command_help.pod"); + my $cmd_help = CFClient::load_pod CFClient::find_rcfile "pod/command_help.pod", command_help => 1, sub { + my ($pom) = @_; - for my $head2 ($pod->head1->[-2]->head2) { - $head2->title =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x - or next; + my @cmd_help; - my $cmd = $1; - my @args = split /\|/, $2; - @args = (".*") unless @args; + for my $head2 ($pom->head1->[-2]->head2) { + $head2->title =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x + or next; - my $text = CFClient::pod_to_pango $head2->content; + my $cmd = $1; + my @args = split /\|/, $2; + @args = (".*") unless @args; + + $_ = $_ eq ".*" ? "" : " $_" + for @args; + + my $text = CFClient::pod_to_pango $head2->content; + + push @cmd_help, ["$cmd$_", $text] + for sort { (length $a) <=> (length $b) } + @args; + } - for my $arg (@args) { - $arg = $arg eq ".*" ? "" : " $arg"; + \@cmd_help + }; - $self->{map_widget}->add_command ("$cmd$arg", $text); - } - } + $self->{map_widget}->add_command (@$_) + for @$cmd_help; $self->{noface} = new_from_file CFClient::Texture CFClient::find_rcfile "noface.png", minify => 1, mipmap => 1; @@ -54,7 +64,7 @@ sub stats_update { my ($self, $stats) = @_; - if (my $exp = $stats->{CS_STAT_EXP64}) { + if (my $exp = $stats->{+CS_STAT_EXP64}) { my $diff = $exp - $self->{prev_exp}; $self->{statusbox}->add ("$diff experience gained", group => "experience $diff", fg => [0.5, 1, 0.5, 0.8], timeout => 5) if exists $self->{prev_exp} && $diff; @@ -67,10 +77,25 @@ sub user_send { my ($self, $command) = @_; + if ($self->{record}) { + push @{$self->{record}}, $command; + } + $self->send_command ($command); ::status $command; } +sub start_record { + my ($self) = @_; + + $self->{record} = []; +} + +sub stop_record { + my ($self) = @_; + return delete $self->{record}; +} + sub map_scroll { my ($self, $dx, $dy) = @_; @@ -254,7 +279,7 @@ # I love transactions for (1..100) { my $txn = $CFClient::DB_ENV->txn_begin; - my $status = $self->{facemap}->db_get (id => $id, BerkeleyDB::DB_RMW); + my $status = $self->{facemap}->db_get (id => $id); if ($status == 0 || $status == BerkeleyDB::DB_NOTFOUND) { $id = ($id || 16) + 1; if ($self->{facemap}->put (id => $id) == 0 @@ -264,7 +289,7 @@ goto gotid; } } - $txn->abort; + $txn->txn_abort; } CFClient::fatal "maximum number of transaction retries reached - database problems?"; @@ -324,61 +349,7 @@ $prompt = $LAST_QUERY unless length $prompt; $LAST_QUERY = $prompt; - my $dialog = new CFClient::UI::FancyFrame - title => "Query", - child => my $vbox = new CFClient::UI::VBox; - - $vbox->add (new CFClient::UI::Label - max_w => $::WIDTH * 0.4, - ellipsise => 0, - text => $prompt); - - if ($flags & CS_QUERY_YESNO) { - $vbox->add (my $hbox = new CFClient::UI::HBox); - $hbox->add (new CFClient::UI::Button - text => "No", - connect_activate => sub { - $self->send ("reply n"); - $dialog->destroy; - $self->{map_widget}->focus_in; - } - ); - $hbox->add (new CFClient::UI::Button - text => "Yes", - connect_activate => sub { - $self->send ("reply y"); - $dialog->destroy; - }, - ); - - $dialog->focus_in; - - } elsif ($flags & CS_QUERY_SINGLECHAR) { - $dialog->{tooltip} = "Press a key (click on the entry to make sure it has keyboard focus)"; - $vbox->add (my $entry = new CFClient::UI::Entry - connect_changed => sub { - $self->send ("reply $_[1]"); - $dialog->destroy; - }, - ); - - $entry->focus_in; - - } else { - $dialog->{tooltip} = "Enter the reply and press return (click on the entry to make sure it has keyboard focus)"; - - $vbox->add (my $entry = new CFClient::UI::Entry - $flags & CS_QUERY_HIDEINPUT ? (hiddenchar => "*") : (), - connect_activate => sub { - $self->send ("reply $_[1]"); - $dialog->destroy; - }, - ); - - $entry->focus_in; - } - - $dialog->show_centered; + $self->{query}-> ($self, $flags, $prompt); } sub drawinfo { @@ -402,6 +373,9 @@ my $time = sprintf "%02d:%02d:%02d", (localtime time)[2,1,0]; + # try to create single paragraphs of multiple lines sent by the server + $text =~ s/(?<=\S)\n(?=\w)/ /g; + $text = CFClient::UI::Label::escape $text; $text =~ s/\[b\](.*?)\[\/b\]/\1<\/b>/g; $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/\2<\/span>/g; @@ -412,7 +386,7 @@ $self->{statusbox}->add ($text, group => $text, fg => $color[$color], - timeout => 10, + timeout => $color >= 2 ? 60 : 10, tooltip_font => $::FONT_FIXED, ); } @@ -426,38 +400,44 @@ sub spell_add { my ($self, $spell) = @_; - # TODO - # create a widget dynamically, using spell face (CF::Protocol downloads them) + # try to create single paragraphs of multiple lines sent by the server + $spell->{message} =~ s/(?<=\S)\n(?=\w)/ /g; + $spell->{message} =~ s/\n+$//; + $spell->{message} ||= "Server did not provide a description for this spell."; + + $::SETUP_SPELLS->add_spell ($spell); + $self->{map_widget}->add_command ("invoke $spell->{name}", CFClient::UI::Label::escape $spell->{message}); $self->{map_widget}->add_command ("cast $spell->{name}", CFClient::UI::Label::escape $spell->{message}); } sub spell_delete { my ($self, $spell) = @_; + $::SETUP_SPELLS->remove_spell ($spell); } sub addme_success { my ($self) = @_; - $self->send ("command output-sync $::CFG->{output_sync}"); - $self->send ("command output-count $::CFG->{output_count}"); + my $skill_help = CFClient::load_pod CFClient::find_rcfile "pod/skill_help.pod", skill_help => 1, sub { + my ($pom) = @_; - my $parser = new Pod::POM; - my $pod = $parser->parse_file (CFClient::find_rcfile "pod/skill_help.pod"); + my %skill_help; - my %skill_tooltip; + for my $head2 ($pom->head1->[3]->head2) { + $skill_help{$head2->title} = CFClient::pod_to_pango $head2->content; + } - for my $head2 ($pod->head1->[-2]->head2) { - $skill_tooltip{$head2->title} = CFClient::pod_to_pango $head2->content; - } + \%skill_help + }; for my $skill (values %{$self->{skill_info}}) { $self->{map_widget}->add_command ("ready_skill $skill", (CFClient::UI::Label::escape "Ready the skill '$skill'\n\n") - . $skill_tooltip{$skill}); + . $skill_help->{$skill}); $self->{map_widget}->add_command ("use_skill $skill", (CFClient::UI::Label::escape "Immediately use the skill '$skill'\n\n") - . $skill_tooltip{$skill}); + . $skill_help->{$skill}); } } @@ -492,14 +472,14 @@ $self->send ("requestinfo image_sums $face $face"); $self->{statusbox}->add (CFClient::UI::Label::escape "prefetching $todo", - group => "prefetch", timeout => 2, fg => [1, 1, 0, 0.5]); + group => "prefetch", timeout => 3, fg => [1, 1, 0, 0.5]); } elsif (!exists $self->{num_faces}) { $self->send ("requestinfo image_info"); $self->{num_faces} = 0; $self->{statusbox}->add (CFClient::UI::Label::escape "starting to prefetch", - group => "prefetch", timeout => 2, fg => [1, 1, 0, 0.5]); + group => "prefetch", timeout => 3, fg => [1, 1, 0, 0.5]); } } @@ -511,7 +491,7 @@ my $row; for (@{ $::CONN->{container}{0} }) { - if ($row < 7) { + if ($row < 6) { local $_->{face_widget}; # hack to force recreation of widget local $_->{desc_widget}; # hack to force recreation of widget CFClient::Item::update_widgets $_; @@ -521,7 +501,10 @@ $row++; } else { - $::FLOORBOX->add (1, $row, new CFClient::UI::Label text => "More..."); + $::FLOORBOX->add (1, $row, new CFClient::UI::Button + text => "More...", + on_activate => sub { $::INV_WINDOW->toggle_visibility }, + ); last; } } @@ -533,7 +516,22 @@ sub set_opencont { my ($conn, $tag, $name) = @_; $conn->{open_container} = $tag; - $::INVR_LBL->set_text ($name); + + $::INV_RIGHT_HB->clear (); + $::INV_RIGHT_HB->add (new CFClient::UI::Label align => 0, expand => 1, text => $name); + + if ($tag != 0) { # Floor isn't closable, is it? + $::INV_RIGHT_HB->add (new CFClient::UI::Button + text => "Close container", + tooltip => "Close the currently open container (if one is open)", + on_activate => sub { + $::CONN->send ("apply $tag") # $::CONN->{open_container}") + if $tag != 0; + #if $CONN->{open_container} != 0; + }, + ); + } + $::INVR->set_items ($conn->{container}{$tag}); } @@ -572,6 +570,8 @@ update_container (0); } elsif ($tag == $self->{player}{tag}) { $::INV->set_items ($self->{container}{$tag}) + } else { + update_container ($tag); } # use PApp::Util; warn PApp::Util::dumpval $self->{container}{0}; @@ -589,7 +589,7 @@ } elsif ($_->{container} == $self->{player}{tag}) { $::INV->set_items ($self->{container}{$self->{player}{tag}}) } else { - update_container ($_->{tag}); + update_container ($_->{container}); } } } @@ -623,7 +623,31 @@ sub player_update { my ($self, $player) = @_; + $::STATWIDS->{weight}->set_text (sprintf "Weight: %.1fkg", $player->{weight} / 1000); } +sub logged_in { + my ($self) = @_; + + $self->send_ext_req (cfplus => "version", "1", sub { + $self->{cfplus_ext} = $_[0]; + + my @yesno = ("no", "yes"); + + $::SERVER_INFO->set_markup ( + "server $self->{host}:$self->{port}\n" + . "protocol version $self->{version}\n" + . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n" + . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n" + . "cfplus support $yesno[$self->{cfplus_ext} > 0]\n" + . "map size $self->{mapw}×$self->{maph}\n" + ); + }); + + $self->send_command ("output-sync $::CFG->{output_sync}"); + $self->send_command ("output-count $::CFG->{output_count}"); + $self->send_command ("pickup $::CFG->{pickup}"); +} + 1;