… | |
… | |
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 { |
… | |
… | |
817 | |
818 | |
818 | if ($type eq "msg") { |
819 | if ($type eq "msg") { |
819 | my ($msg, @kw) = split /\x00/, $msg; |
820 | my ($msg, @kw) = split /\x00/, $msg; |
820 | $self->{kw}{$_} = 1 for @kw; |
821 | $self->{kw}{$_} = 1 for @kw; |
821 | |
822 | |
822 | $msg = CFClient::UI::Label::escape $msg; |
823 | $msg = "\n" . CFClient::UI::Label::escape $msg; |
823 | my $match = join "|", map "\\b\Q$_\E\\b", sort { (length $b) <=> (length $a) } keys %{ $self->{kw} }; |
824 | 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. |
825 | my @link; |
|
|
826 | $msg =~ s{ |
|
|
827 | ($match) |
|
|
828 | }{ |
|
|
829 | push @link, new CFClient::UI::Label |
|
|
830 | markup => "<span foreground='#c0c0ff' underline='single'>$1</span>", |
|
|
831 | can_hover => 1, |
|
|
832 | can_events => 1; |
|
|
833 | |
|
|
834 | chr 0xfffc |
|
|
835 | }giex; |
825 | |
836 | |
826 | $self->{textview}->add_paragraph ([1, 1, 1, 1], "\n$msg"); |
837 | $self->{textview}->add_paragraph ([1, 1, 1, 1], [$msg, @link]); |
827 | $self->update_options; |
838 | $self->update_options; |
828 | } else { |
839 | } else { |
829 | $self->destroy; |
840 | $self->destroy; |
830 | } |
841 | } |
831 | |
842 | |
… | |
… | |
840 | } |
851 | } |
841 | |
852 | |
842 | sub destroy { |
853 | sub destroy { |
843 | my ($self) = @_; |
854 | my ($self) = @_; |
844 | |
855 | |
845 | #Carp::cluck "debug\n";#d# #todo# enable: destroyx gets called twice because scalar keys {} is 1 |
856 | #Carp::cluck "debug\n";#d# #todo# enable: destroy gets called twice because scalar keys {} is 1 |
846 | |
857 | |
847 | delete $self->{conn}{npc_dialog}; |
858 | delete $self->{conn}{npc_dialog}; |
848 | $self->{conn}->disconnect_ext ($self->{token}); |
859 | $self->{conn}->disconnect_ext ($self->{token}); |
849 | |
860 | |
850 | $self->SUPER::destroy; |
861 | $self->SUPER::destroy; |