… | |
… | |
636 | $self->{logview}->scroll_to_bottom; |
636 | $self->{logview}->scroll_to_bottom; |
637 | |
637 | |
638 | $self->{statusbox}->add ($text, |
638 | $self->{statusbox}->add ($text, |
639 | group => $text, |
639 | group => $text, |
640 | fg => $color[$color], |
640 | fg => $color[$color], |
641 | timeout => $color >= 2 ? 60 : 10, |
641 | timeout => $color >= 2 ? 180 : 10, |
642 | tooltip_font => $::FONT_FIXED, |
642 | tooltip_font => $::FONT_FIXED, |
643 | ); |
643 | ); |
644 | } |
644 | } |
645 | |
645 | |
646 | sub drawextinfo { |
646 | sub drawextinfo { |
… | |
… | |
894 | } |
894 | } |
895 | |
895 | |
896 | sub logged_in { |
896 | sub logged_in { |
897 | my ($self) = @_; |
897 | my ($self) = @_; |
898 | |
898 | |
899 | $self->send_ext_req (cfplus_support => "1", sub { |
899 | $self->send_ext_req (cfplus_support => version => 1, sub { |
900 | $self->{cfplus_ext} = $_[0]; |
900 | $self->{cfplus_ext} = $_[0]{version}; |
901 | $self->update_server_info; |
901 | $self->update_server_info; |
|
|
902 | |
|
|
903 | 0 |
902 | }); |
904 | }); |
903 | |
905 | |
904 | $self->update_server_info; |
906 | $self->update_server_info; |
905 | |
907 | |
906 | $self->send_command ("output-sync $::CFG->{output_sync}"); |
908 | $self->send_command ("output-sync $::CFG->{output_sync}"); |
… | |
… | |
910 | |
912 | |
911 | sub lookat { |
913 | sub lookat { |
912 | my ($self, $x, $y) = @_; |
914 | my ($self, $x, $y) = @_; |
913 | |
915 | |
914 | if ($self->{cfplus_ext}) { |
916 | if ($self->{cfplus_ext}) { |
915 | $self->send_ext_req (lookat => "$x $y", sub { |
917 | $self->send_ext_req (lookat => dx => $x, dy => $y, sub { |
916 | my %res = split /\x00/, $_[0]; |
918 | my ($msg) = @_; |
917 | |
919 | |
918 | if (exists $res{npc_dialog}) { |
920 | if (exists $msg->{npc_dialog}) { |
919 | # start npc chat dialog |
921 | # start npc chat dialog |
920 | $self->{npc_dialog} = new CFPlus::NPCDialog:: |
922 | $self->{npc_dialog} = new CFPlus::NPCDialog:: |
921 | dx => $x, |
923 | dx => $x, |
922 | dy => $y, |
924 | dy => $y, |
923 | title => "$res{npc_dialog} (NPC)", |
925 | title => "$msg->{npc_dialog} (NPC)", |
924 | conn => $self, |
926 | conn => $self, |
925 | ; |
927 | ; |
926 | } |
928 | } |
927 | }); |
929 | }); |
928 | } |
930 | } |
… | |
… | |
995 | on_activate => sub { $this->destroy; 1 }, |
997 | on_activate => sub { $this->destroy; 1 }, |
996 | ; |
998 | ; |
997 | |
999 | |
998 | $self->update_options; |
1000 | $self->update_options; |
999 | |
1001 | |
1000 | $self->{token} = $self->{conn}->ext_token; |
1002 | $self->{id} = $self->{conn}->send_ext_req ( |
1001 | $self->{conn}->connect_ext ($self->{token} => sub { $this->feed (@_) }); |
1003 | npc_dialog_begin => dx => $self->{dx}, dy => $self->{dy}, |
1002 | $self->{conn}->send ("ext npc_dialog_begin $self->{token} $self->{dx} $self->{dy}"); |
1004 | sub { $this && $this->feed (@_) } |
|
|
1005 | ); |
1003 | |
1006 | |
1004 | $self->{entry}->grab_focus; |
1007 | $self->{entry}->grab_focus; |
1005 | |
1008 | |
1006 | $self->{textview}->add_paragraph ({ |
1009 | $self->{textview}->add_paragraph ({ |
1007 | fg => [1, 1, 0, 1], |
1010 | fg => [1, 1, 0, 1], |
… | |
… | |
1030 | ); |
1033 | ); |
1031 | } |
1034 | } |
1032 | } |
1035 | } |
1033 | |
1036 | |
1034 | sub feed { |
1037 | sub feed { |
1035 | my ($self, $data) = @_; |
1038 | my ($self, $msg) = @_; |
1036 | |
1039 | |
1037 | Scalar::Util::weaken $self; |
1040 | Scalar::Util::weaken $self; |
1038 | |
1041 | |
1039 | my ($type, $msg) = split / /, $data, 2; |
1042 | if ($msg->{msgtype} eq "reply") { |
|
|
1043 | $self->{kw}{$_} = 1 for @{$msg->{add_topics} || []}; |
|
|
1044 | $self->{kw}{$_} = 0 for @{$msg->{del_topics} || []}; |
1040 | |
1045 | |
1041 | if ($type eq "msg") { |
|
|
1042 | my ($msg, @kw) = split /\x00/, $msg; |
|
|
1043 | |
|
|
1044 | utf8::decode $_ for ($msg, @kw); |
|
|
1045 | |
|
|
1046 | $self->{kw}{$_} = 1 for @kw; |
|
|
1047 | |
|
|
1048 | $msg = "\n" . CFPlus::UI::asxml $msg; |
1046 | my $text = "\n" . CFPlus::asxml $msg->{msg}; |
1049 | my $match = join "|", map "\\b\Q$_\E\\b", sort { (length $b) <=> (length $a) } keys %{ $self->{kw} }; |
1047 | my $match = join "|", map "\\b\Q$_\E\\b", sort { (length $b) <=> (length $a) } keys %{ $self->{kw} }; |
1050 | my @link; |
1048 | my @link; |
1051 | $msg =~ s{ |
1049 | $text =~ s{ |
1052 | ($match) |
1050 | ($match) |
1053 | }{ |
1051 | }{ |
1054 | my $kw = $1; |
1052 | my $kw = $1; |
1055 | |
1053 | |
1056 | push @link, new CFPlus::UI::Label |
1054 | push @link, new CFPlus::UI::Label |
… | |
… | |
1064 | }; |
1062 | }; |
1065 | |
1063 | |
1066 | chr 0xfffc |
1064 | chr 0xfffc |
1067 | }giex; |
1065 | }giex; |
1068 | |
1066 | |
1069 | $self->{textview}->add_paragraph ({ markup => $msg, widget => \@link }); |
1067 | $self->{textview}->add_paragraph ({ markup => $text, widget => \@link }); |
1070 | $self->{textview}->scroll_to_bottom; |
1068 | $self->{textview}->scroll_to_bottom; |
1071 | $self->update_options; |
1069 | $self->update_options; |
1072 | } else { |
1070 | } else { |
1073 | $self->destroy; |
1071 | $self->destroy; |
1074 | } |
1072 | } |
… | |
… | |
1080 | my ($self, $msg) = @_; |
1078 | my ($self, $msg) = @_; |
1081 | |
1079 | |
1082 | $self->{textview}->add_paragraph ({ markup => "\n" . CFPlus::asxml $msg }); |
1080 | $self->{textview}->add_paragraph ({ markup => "\n" . CFPlus::asxml $msg }); |
1083 | $self->{textview}->scroll_to_bottom; |
1081 | $self->{textview}->scroll_to_bottom; |
1084 | |
1082 | |
1085 | utf8::encode $msg; |
1083 | $self->{conn}->send_ext_msg (npc_dialog_tell => msgid => $self->{id}, msg => $msg); |
1086 | $self->{conn}->send ("ext npc_dialog_tell $self->{token} $msg"); |
|
|
1087 | } |
1084 | } |
1088 | |
1085 | |
1089 | sub destroy { |
1086 | sub destroy { |
1090 | my ($self) = @_; |
1087 | my ($self) = @_; |
1091 | |
1088 | |
1092 | #Carp::cluck "debug\n";#d# #todo# enable: destroy gets called twice because scalar keys {} is 1 |
1089 | #Carp::cluck "debug\n";#d# #todo# enable: destroy gets called twice because scalar keys {} is 1 |
1093 | |
1090 | |
|
|
1091 | if ($self->{conn}) { |
1094 | $self->{conn}->send ("ext npc_dialog_end $self->{token}") if $self->{token}; |
1092 | $self->{conn}->send_ext_msg (npc_dialog_end => msgid => $self->{id}) if $self->{id}; |
1095 | delete $self->{conn}{npc_dialog}; |
1093 | delete $self->{conn}{npc_dialog}; |
1096 | $self->{conn}->disconnect_ext ($self->{token}); |
1094 | $self->{conn}->disconnect_ext ($self->{id}); |
|
|
1095 | } |
1097 | |
1096 | |
1098 | $self->SUPER::destroy; |
1097 | $self->SUPER::destroy; |
1099 | } |
1098 | } |
1100 | |
1099 | |
1101 | 1 |
1100 | 1 |