--- deliantra/Deliantra-Client/DC/Protocol.pm 2006/06/23 20:28:20 1.40 +++ deliantra/Deliantra-Client/DC/Protocol.pm 2006/06/28 21:43:15 1.47 @@ -107,7 +107,7 @@ $self->logprint ("send: ", $command); $self->send_command ($command); - ::status $command; + ::status ($command); } sub start_record { @@ -525,7 +525,7 @@ $::FLOORBOX->clear; my $row; - for (@{ $::CONN->{container}{0} }) { + for (sort { $a->{count} <=> $b->{count} } values %{ $::CONN->{container}{0} }) { if ($row < 6) { local $_->{face_widget}; # hack to force recreation of widget local $_->{desc_widget}; # hack to force recreation of widget @@ -581,53 +581,41 @@ sub container_add { my ($self, $tag, $items) = @_; - #d# print "container_add: container $tag ($self->{player}{tag})\n"; + $self->{update_container}{$tag}++; + $self->update_containers; +} - if ($tag == 0) { - update_floorbox; - update_container (0); - } elsif ($tag == $self->{player}{tag}) { - $::INV->set_items ($self->{container}{$self->{player}{tag}}) - } else { - update_container ($tag); - } +sub update_containers { + my ($self) = @_; - # $self-<{player}{tag} => player inv - #use PApp::Util; warn PApp::Util::dumpval $self->{container}{$self->{player}{tag}}; + $CFClient::UI::ROOT->on_refresh ("update_containers_$self" => sub { + for my $tag (keys %{ delete $self->{update_container} }) { + if ($tag == 0) { + update_floorbox; + update_container (0); + } elsif ($tag == $self->{player}{tag}) { + $::INV->set_items ($self->{container}{$tag}) + } else { + update_container ($tag); + } + } + }); } sub container_clear { my ($self, $tag) = @_; - #d# print "container_clear: container $tag ($self->{player}{tag})\n"; - - if ($tag == 0) { - update_floorbox; - 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}; + $self->{update_container}{$tag}++; + $self->update_containers; } sub item_delete { my ($self, @items) = @_; - for (@items) { - #d# print "item_delete: $_->{tag} from $_->{container} ($self->{player}{tag})\n"; - - if ($_->{container} == 0) { - update_floorbox; - update_container ($_->{tag}); - } elsif ($_->{container} == $self->{player}{tag}) { - $::INV->set_items ($self->{container}{$self->{player}{tag}}) - } else { - update_container ($_->{container}); - } - } + $self->{update_container}{$_->{tag}}++ + for @items; + + $self->update_containers; } sub item_update { @@ -647,13 +635,16 @@ } elsif ($item->{flags} & F_OPEN) { set_opencont ($::CONN, $item->{tag}, CFClient::Item::desc_string $item); + } else { - if ($item->{container} == 0) { - update_floorbox; - update_container (0); - } elsif ($item->{container} == $self->{player}{tag}) { - $::INV->set_items ($self->{container}{$item->{container}}) - } + $self->{update_container}{$item->{container}}++; + $self->update_containers; +# if ($item->{container} == 0) { +# update_floorbox; +# update_container (0); +# } elsif ($item->{container} == $self->{player}{tag}) { +# $::INV->set_items ($self->{container}{$item->{container}}) +# } } } @@ -814,17 +805,37 @@ sub feed { my ($self, $data) = @_; + Scalar::Util::weaken $self; + my ($type, $msg) = split / /, $data, 2; if ($type eq "msg") { my ($msg, @kw) = split /\x00/, $msg; $self->{kw}{$_} = 1 for @kw; - $msg = CFClient::UI::Label::escape $msg; + $msg = "\n" . CFClient::UI::Label::escape $msg; my $match = join "|", map "\\b\Q$_\E\\b", sort { (length $b) <=> (length $a) } keys %{ $self->{kw} }; - $msg =~ s/($match)/$1<\/span>/gi; # underline when http-ready, huh. + my @link; + $msg =~ s{ + ($match) + }{ + my $kw = $1; + + push @link, new CFClient::UI::Label + markup => "$kw", + can_hover => 1, + can_events => 1, + padding_x => 0, + padding_y => 0, + on_button_up => sub { + $self->send ($kw); + }; + + chr 0xfffc + }giex; - $self->{textview}->add_paragraph ([1, 1, 1, 1], "\n$msg"); + $self->{textview}->add_paragraph ([1, 1, 1, 1], [$msg, @link]); + $self->{textview}->scroll_to_bottom; $self->update_options; } else { $self->destroy; @@ -838,6 +849,7 @@ $self->{conn}->send ("ext npc_dialog_tell $self->{token} $msg"); $self->{textview}->add_paragraph ([1, 1, 0, 1], "\n" . CFClient::UI::Label::escape $msg); + $self->{textview}->scroll_to_bottom; } sub destroy {