--- deliantra/Deliantra-Client/DC/Protocol.pm 2006/05/30 14:59:26 1.12 +++ deliantra/Deliantra-Client/DC/Protocol.pm 2006/06/06 03:02:15 1.23 @@ -5,6 +5,7 @@ use Crossfire::Protocol::Constants; +use CFClient; use CFClient::UI; use base 'Crossfire::Protocol::Base'; @@ -16,26 +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; - $_ = $_ eq ".*" ? "" : " $_" - for @args; + 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; + } - my $text = CFClient::pod_to_pango $head2->content; + \@cmd_help + }; - $self->{map_widget}->add_command ("$cmd$_", $text) - for sort { (length $a) <=> (length $b) } - @args; - } + $self->{map_widget}->add_command (@$_) + for @$cmd_help; $self->{noface} = new_from_file CFClient::Texture CFClient::find_rcfile "noface.png", minify => 1, mipmap => 1; @@ -270,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 @@ -280,7 +289,7 @@ goto gotid; } } - $txn->abort; + $txn->txn_abort; } CFClient::fatal "maximum number of transaction retries reached - database problems?"; @@ -340,64 +349,7 @@ $prompt = $LAST_QUERY unless length $prompt; $LAST_QUERY = $prompt; - my $dialog = new CFClient::UI::FancyFrame - x => "center", - y => "center", - 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", - on_activate => sub { - $self->send ("reply n"); - $dialog->destroy; - $self->{map_widget}->focus_in; - } - ); - $hbox->add (new CFClient::UI::Button - text => "Yes", - on_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 - on_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 => "*") : (), - on_activate => sub { - $self->send ("reply $_[1]"); - $dialog->destroy; - }, - ); - - $entry->focus_in; - } - - $dialog->show; + $self->{query}-> ($self, $flags, $prompt); } sub drawinfo { @@ -421,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(?=\S)/ /g; + $text = CFClient::UI::Label::escape $text; $text =~ s/\[b\](.*?)\[\/b\]/\1<\/b>/g; $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/\2<\/span>/g; @@ -431,7 +386,7 @@ $self->{statusbox}->add ($text, group => $text, fg => $color[$color], - timeout => 10, + timeout => $color >= 2 ? 60 : 10, tooltip_font => $::FONT_FIXED, ); } @@ -447,36 +402,39 @@ # TODO # create a widget dynamically, using spell face (CF::Protocol downloads them) + $::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}); } } @@ -511,14 +469,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]); } } @@ -660,6 +618,10 @@ sub player_update { my ($self, $player) = @_; $::STATWIDS->{weight}->set_text (sprintf "Weight: %.1fkg", $player->{weight} / 1000); + + # do it here because it is ignored earlier, and there is no "login" event + $self->send_command ("output-sync $::CFG->{output_sync}"); + $self->send_command ("output-count $::CFG->{output_count}"); } 1;