… | |
… | |
82 | $year + 1900, $mon + 1, $mday, $hour, $min, $sec; |
82 | $year + 1900, $mon + 1, $mday, $hour, $min, $sec; |
83 | |
83 | |
84 | print $fh "$ts ", @a, "\n"; |
84 | print $fh "$ts ", @a, "\n"; |
85 | $fh->flush; |
85 | $fh->flush; |
86 | } |
86 | } |
87 | |
|
|
88 | |
|
|
89 | |
87 | |
90 | sub stats_update { |
88 | sub stats_update { |
91 | my ($self, $stats) = @_; |
89 | my ($self, $stats) = @_; |
92 | |
90 | |
93 | if (my $exp = $stats->{+CS_STAT_EXP64}) { |
91 | if (my $exp = $stats->{+CS_STAT_EXP64}) { |
… | |
… | |
414 | |
412 | |
415 | $text = CFClient::UI::Label::escape $text; |
413 | $text = CFClient::UI::Label::escape $text; |
416 | $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g; |
414 | $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g; |
417 | $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g; |
415 | $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g; |
418 | |
416 | |
419 | $self->{logview}->add_paragraph ($color[$color], |
417 | $self->{logview}->add_paragraph ($color[$color], $_) |
420 | join "\n", map "$time $_", split /\n/, $text); |
418 | for map "$time $_", split /\n/, $text; |
|
|
419 | $self->{logview}->scroll_to_bottom; |
421 | |
420 | |
422 | $self->{statusbox}->add ($text, |
421 | $self->{statusbox}->add ($text, |
423 | group => $text, |
422 | group => $text, |
424 | fg => $color[$color], |
423 | fg => $color[$color], |
425 | timeout => $color >= 2 ? 60 : 10, |
424 | timeout => $color >= 2 ? 60 : 10, |
… | |
… | |
537 | |
536 | |
538 | $row++; |
537 | $row++; |
539 | } else { |
538 | } else { |
540 | $::FLOORBOX->add (1, $row, new CFClient::UI::Button |
539 | $::FLOORBOX->add (1, $row, new CFClient::UI::Button |
541 | text => "More...", |
540 | text => "More...", |
542 | on_activate => sub { $::INV_WINDOW->toggle_visibility }, |
541 | on_activate => sub { $::INV_WINDOW->toggle_visibility; 0 }, |
543 | ); |
542 | ); |
544 | last; |
543 | last; |
545 | } |
544 | } |
546 | } |
545 | } |
547 | }); |
546 | }); |
… | |
… | |
562 | tooltip => "Close the currently open container (if one is open)", |
561 | tooltip => "Close the currently open container (if one is open)", |
563 | on_activate => sub { |
562 | on_activate => sub { |
564 | $::CONN->send ("apply $tag") # $::CONN->{open_container}") |
563 | $::CONN->send ("apply $tag") # $::CONN->{open_container}") |
565 | if $tag != 0; |
564 | if $tag != 0; |
566 | #if $CONN->{open_container} != 0; |
565 | #if $CONN->{open_container} != 0; |
|
|
566 | 0 |
567 | }, |
567 | }, |
568 | ); |
568 | ); |
569 | } |
569 | } |
570 | |
570 | |
571 | $::INVR->set_items ($conn->{container}{$tag}); |
571 | $::INVR->set_items ($conn->{container}{$tag}); |
… | |
… | |
763 | |
763 | |
764 | return unless $text =~ /\S/; |
764 | return unless $text =~ /\S/; |
765 | |
765 | |
766 | $entry->set_text (""); |
766 | $entry->set_text (""); |
767 | $this->send ($text); |
767 | $this->send ($text); |
|
|
768 | |
|
|
769 | 0 |
768 | }, |
770 | }, |
769 | ); |
771 | ); |
770 | |
772 | |
771 | $vbox->add ($self->{options} = new CFClient::UI::VBox); |
773 | $vbox->add ($self->{options} = new CFClient::UI::VBox); |
772 | |
774 | |
773 | $self->{close_button} = new CFClient::UI::Button |
775 | $self->{bye_button} = new CFClient::UI::Button |
774 | text => "Bye (close)", |
776 | text => "Bye (close)", |
775 | 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.", |
776 | on_activate => sub { $this->destroy }, |
778 | on_activate => sub { $this->destroy; 0 }, |
777 | ; |
779 | ; |
778 | |
780 | |
779 | $self->update_options; |
781 | $self->update_options; |
780 | |
782 | |
781 | $self->{token} = $self->{conn}->ext_token; |
783 | $self->{token} = $self->{conn}->ext_token; |
782 | $self->{conn}->connect_ext ($self->{token} => sub { $this->feed (@_) }); |
784 | $self->{conn}->connect_ext ($self->{token} => sub { $this->feed (@_) }); |
783 | $self->{conn}->send ("ext npc_dialog_begin $self->{token} $self->{dx} $self->{dy}"); |
785 | $self->{conn}->send ("ext npc_dialog_begin $self->{token} $self->{dx} $self->{dy}"); |
784 | |
786 | |
785 | $self->{entry}->focus_in; |
787 | $self->{entry}->grab_focus; |
786 | |
788 | |
787 | $self->{textview}->add_paragraph ([1, 1, 0, 1], "<small>[starting conversation with <b>$self->{title}</b>]</small>\n\n"); |
789 | $self->{textview}->add_paragraph ([1, 1, 0, 1], "<small>[starting conversation with <b>$self->{title}</b>]</small>\n\n"); |
788 | |
790 | |
789 | $self->show; |
791 | $self->show; |
790 | $self |
792 | $self |
… | |
… | |
794 | my ($self) = @_; |
796 | my ($self) = @_; |
795 | |
797 | |
796 | Scalar::Util::weaken $self; |
798 | Scalar::Util::weaken $self; |
797 | |
799 | |
798 | $self->{options}->clear; |
800 | $self->{options}->clear; |
799 | $self->{options}->add ($self->{close_button}); |
801 | $self->{options}->add ($self->{bye_button}); |
800 | |
802 | |
801 | for my $kw (sort keys %{ $self->{kw} }) { |
803 | for my $kw (sort keys %{ $self->{kw} }) { |
802 | $self->{options}->add (new CFClient::UI::Button |
804 | $self->{options}->add (new CFClient::UI::Button |
803 | text => $kw, |
805 | text => $kw, |
804 | on_activate => sub { |
806 | on_activate => sub { |
805 | $self->send ($kw); |
807 | $self->send ($kw); |
|
|
808 | 0 |
806 | }, |
809 | }, |
807 | ); |
810 | ); |
808 | } |
811 | } |
809 | } |
812 | } |
810 | |
813 | |
811 | sub feed { |
814 | sub feed { |
812 | my ($self, $data) = @_; |
815 | my ($self, $data) = @_; |
|
|
816 | |
|
|
817 | Scalar::Util::weaken $self; |
813 | |
818 | |
814 | my ($type, $msg) = split / /, $data, 2; |
819 | my ($type, $msg) = split / /, $data, 2; |
815 | |
820 | |
816 | if ($type eq "msg") { |
821 | if ($type eq "msg") { |
817 | my ($msg, @kw) = split /\x00/, $msg; |
822 | my ($msg, @kw) = split /\x00/, $msg; |
818 | $self->{kw}{$_} = 1 for @kw; |
823 | $self->{kw}{$_} = 1 for @kw; |
819 | |
824 | |
820 | $msg = CFClient::UI::Label::escape $msg; |
825 | $msg = "\n" . CFClient::UI::Label::escape $msg; |
821 | 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} }; |
822 | $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; |
823 | |
845 | |
824 | $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; |
825 | $self->update_options; |
848 | $self->update_options; |
826 | } else { |
849 | } else { |
827 | $self->destroy; |
850 | $self->destroy; |
828 | } |
851 | } |
829 | |
852 | |
… | |
… | |
833 | sub send { |
856 | sub send { |
834 | my ($self, $msg) = @_; |
857 | my ($self, $msg) = @_; |
835 | |
858 | |
836 | $self->{conn}->send ("ext npc_dialog_tell $self->{token} $msg"); |
859 | $self->{conn}->send ("ext npc_dialog_tell $self->{token} $msg"); |
837 | $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; |
838 | } |
862 | } |
839 | |
863 | |
840 | sub destroy { |
864 | sub destroy { |
841 | my ($self) = @_; |
865 | my ($self) = @_; |
842 | |
866 | |
843 | #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 |
844 | |
868 | |
845 | delete $self->{conn}{npc_dialog}; |
869 | delete $self->{conn}{npc_dialog}; |
846 | $self->{conn}->disconnect_ext ($self->{token}); |
870 | $self->{conn}->disconnect_ext ($self->{token}); |
847 | |
871 | |
848 | $self->SUPER::destroy; |
872 | $self->SUPER::destroy; |