ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/Protocol.pm
(Generate patch)

Comparing deliantra/Deliantra-Client/DC/Protocol.pm (file contents):
Revision 1.38 by root, Sun Jun 18 17:13:11 2006 UTC vs.
Revision 1.43 by root, Sat Jun 24 00:24:09 2006 UTC

412 412
413 $text = CFClient::UI::Label::escape $text; 413 $text = CFClient::UI::Label::escape $text;
414 $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g; 414 $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g;
415 $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g; 415 $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g;
416 416
417 $self->{logview}->add_paragraph ($color[$color], 417 $self->{logview}->add_paragraph ($color[$color], $_)
418 join "\n", map "$time $_", split /\n/, $text); 418 for map "$time $_", split /\n/, $text;
419 $self->{logview}->scroll_to_bottom;
419 420
420 $self->{statusbox}->add ($text, 421 $self->{statusbox}->add ($text,
421 group => $text, 422 group => $text,
422 fg => $color[$color], 423 fg => $color[$color],
423 timeout => $color >= 2 ? 60 : 10, 424 timeout => $color >= 2 ? 60 : 10,
769 }, 770 },
770 ); 771 );
771 772
772 $vbox->add ($self->{options} = new CFClient::UI::VBox); 773 $vbox->add ($self->{options} = new CFClient::UI::VBox);
773 774
774 $self->{close_button} = new CFClient::UI::Button 775 $self->{bye_button} = new CFClient::UI::Button
775 text => "Bye (close)", 776 text => "Bye (close)",
776 tooltip => "Use this button to end talking to the NPC. This also closes the dialog window.", 777 tooltip => "Use this button to end talking to the NPC. This also closes the dialog window.",
777 on_activate => sub { $this->destroy; 0 }, 778 on_activate => sub { $this->destroy; 0 },
778 ; 779 ;
779 780
795 my ($self) = @_; 796 my ($self) = @_;
796 797
797 Scalar::Util::weaken $self; 798 Scalar::Util::weaken $self;
798 799
799 $self->{options}->clear; 800 $self->{options}->clear;
800 $self->{options}->add ($self->{close_button}); 801 $self->{options}->add ($self->{bye_button});
801 802
802 for my $kw (sort keys %{ $self->{kw} }) { 803 for my $kw (sort keys %{ $self->{kw} }) {
803 $self->{options}->add (new CFClient::UI::Button 804 $self->{options}->add (new CFClient::UI::Button
804 text => $kw, 805 text => $kw,
805 on_activate => sub { 806 on_activate => sub {
811} 812}
812 813
813sub feed { 814sub feed {
814 my ($self, $data) = @_; 815 my ($self, $data) = @_;
815 816
817 Scalar::Util::weaken $self;
818
816 my ($type, $msg) = split / /, $data, 2; 819 my ($type, $msg) = split / /, $data, 2;
817 820
818 if ($type eq "msg") { 821 if ($type eq "msg") {
819 my ($msg, @kw) = split /\x00/, $msg; 822 my ($msg, @kw) = split /\x00/, $msg;
820 $self->{kw}{$_} = 1 for @kw; 823 $self->{kw}{$_} = 1 for @kw;
821 824
822 $msg = CFClient::UI::Label::escape $msg; 825 $msg = "\n" . CFClient::UI::Label::escape $msg;
823 my $match = join "|", map "\\b\Q$_\E\\b", sort { (length $b) <=> (length $a) } keys %{ $self->{kw} }; 826 my $match = join "|", map "\\b\Q$_\E\\b", sort { (length $b) <=> (length $a) } keys %{ $self->{kw} };
824 $msg =~ s/($match)/<span foreground='#c0c0ff' underline='none'>$1<\/span>/gi; # underline when http-ready, huh. 827 my @link;
828 $msg =~ s{
829 ($match)
830 }{
831 my $kw = $1;
832
833 push @link, new CFClient::UI::Label
834 markup => "<span foreground='#c0c0ff' underline='single'>$kw</span>",
835 can_hover => 1,
836 can_events => 1,
837 padding_x => 0,
838 padding_y => 0,
839 on_button_up => sub {
840 $self->send ($kw);
841 };
842
843 chr 0xfffc
844 }giex;
825 845
826 $self->{textview}->add_paragraph ([1, 1, 1, 1], "\n$msg"); 846 $self->{textview}->add_paragraph ([1, 1, 1, 1], [$msg, @link]);
847 $self->{textview}->scroll_to_bottom;
827 $self->update_options; 848 $self->update_options;
828 } else { 849 } else {
829 $self->destroy; 850 $self->destroy;
830 } 851 }
831 852
835sub send { 856sub send {
836 my ($self, $msg) = @_; 857 my ($self, $msg) = @_;
837 858
838 $self->{conn}->send ("ext npc_dialog_tell $self->{token} $msg"); 859 $self->{conn}->send ("ext npc_dialog_tell $self->{token} $msg");
839 $self->{textview}->add_paragraph ([1, 1, 0, 1], "\n" . CFClient::UI::Label::escape $msg); 860 $self->{textview}->add_paragraph ([1, 1, 0, 1], "\n" . CFClient::UI::Label::escape $msg);
861 $self->{textview}->scroll_to_bottom;
840} 862}
841 863
842sub destroy { 864sub destroy {
843 my ($self) = @_; 865 my ($self) = @_;
844 866
845 #Carp::cluck "debug\n";#d# #todo# enable: destroyx gets called twice because scalar keys {} is 1 867 #Carp::cluck "debug\n";#d# #todo# enable: destroy gets called twice because scalar keys {} is 1
846 868
847 delete $self->{conn}{npc_dialog}; 869 delete $self->{conn}{npc_dialog};
848 $self->{conn}->disconnect_ext ($self->{token}); 870 $self->{conn}->disconnect_ext ($self->{token});
849 871
850 $self->SUPER::destroy; 872 $self->SUPER::destroy;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines