… | |
… | |
7 | |
7 | |
8 | use CFClient; |
8 | use CFClient; |
9 | use CFClient::UI; |
9 | use CFClient::UI; |
10 | |
10 | |
11 | use base 'Crossfire::Protocol::Base'; |
11 | use base 'Crossfire::Protocol::Base'; |
12 | |
|
|
13 | our %open_logs; |
|
|
14 | |
12 | |
15 | sub new { |
13 | sub new { |
16 | my $class = shift; |
14 | my $class = shift; |
17 | |
15 | |
18 | my $self = $class->SUPER::new (@_); |
16 | my $self = $class->SUPER::new (@_); |
… | |
… | |
63 | $self |
61 | $self |
64 | } |
62 | } |
65 | |
63 | |
66 | sub logprint { |
64 | sub logprint { |
67 | my ($self, @a) = @_; |
65 | my ($self, @a) = @_; |
|
|
66 | |
|
|
67 | $self->{log_fh} ||= do { |
68 | my $filename = "$Crossfire::VARDIR/log.$self->{host}"; |
68 | my $path = "$Crossfire::VARDIR/log.$self->{host}"; |
69 | |
69 | |
70 | my $fh = $open_logs{$filename}; |
70 | open my $fh, ">>:utf8", $path |
71 | unless ($fh) { |
|
|
72 | # FIXME: handle this more gracefully? |
|
|
73 | open $fh, ">>", $filename |
|
|
74 | or die "Couldn't open logfile: log.$self->{host}: $!"; |
71 | or die "Couldn't open logfile $path: $!"; |
75 | |
72 | |
76 | $open_logs{$filename} = $fh; |
73 | $fh->autoflush (1); |
|
|
74 | |
|
|
75 | $fh; |
77 | } |
76 | }; |
78 | |
77 | |
79 | my ($sec, $min, $hour, $mday, $mon, $year) = localtime (time); |
78 | my ($sec, $min, $hour, $mday, $mon, $year) = localtime time; |
80 | |
79 | |
81 | my $ts = sprintf "%04d-%02d-%02d %02d:%02d:%02d", |
80 | my $ts = sprintf "%04d-%02d-%02d %02d:%02d:%02d", |
82 | $year + 1900, $mon + 1, $mday, $hour, $min, $sec; |
81 | $year + 1900, $mon + 1, $mday, $hour, $min, $sec; |
83 | |
82 | |
84 | print $fh "$ts ", @a, "\n"; |
83 | print {$self->{log_fh}} "$ts ", @a, "\n"; |
85 | $fh->flush; |
|
|
86 | } |
84 | } |
87 | |
85 | |
88 | sub _stat_numdiff { |
86 | sub _stat_numdiff { |
89 | my ($self, $name, $old, $new) = @_; |
87 | my ($self, $name, $old, $new) = @_; |
90 | |
88 | |
… | |
… | |
155 | ); |
153 | ); |
156 | |
154 | |
157 | sub stats_update { |
155 | sub stats_update { |
158 | my ($self, $stats) = @_; |
156 | my ($self, $stats) = @_; |
159 | |
157 | |
160 | if (my $prev = $self->{prev_stats}) { |
158 | my $prev = $self->{prev_stats} || { }; |
161 | if (my $diff = $stats->{+CS_STAT_EXP64} - $prev->{+CS_STAT_EXP64}) { |
159 | |
|
|
160 | if (my @diffs = |
|
|
161 | ( |
|
|
162 | ($stats->{+CS_STAT_EXP64} > $prev->{+CS_STAT_EXP64} ? ($stats->{+CS_STAT_EXP64} - $prev->{+CS_STAT_EXP64}) . " experience gained" : ()), |
|
|
163 | map { |
|
|
164 | $stats->{$_} && $prev->{$_} |
|
|
165 | && $stats->{$_}[1] > $prev->{$_}[1] ? "($self->{skill_info}{$_}+" . ($stats->{$_}[1] - $prev->{$_}[1]) . ")" : () |
|
|
166 | } sort { $a <=> $b } keys %{$self->{skill_info}} |
|
|
167 | ) |
|
|
168 | ) { |
|
|
169 | my $msg = join " ", @diffs; |
162 | $self->{statusbox}->add ("$diff experience gained", group => "experience $diff", fg => [0.5, 1, 0.5, 0.8], timeout => 5); |
170 | $self->{statusbox}->add ($msg, group => "experience $msg", fg => [0.5, 1, 0.5, 0.8], timeout => 5); |
|
|
171 | } |
|
|
172 | |
|
|
173 | if ( |
|
|
174 | my @diffs = map $_->[1]->($self, $_->[2], $prev->{$_->[0]}, $stats->{$_->[0]}), @statchange |
|
|
175 | ) { |
|
|
176 | my $msg = "<b>stat change</b>: " . (join " ", @diffs); |
|
|
177 | $self->{statusbox}->add ($msg, group => "stat $msg", fg => [0.8, 1, 0.2, 1], timeout => 10); |
|
|
178 | } |
|
|
179 | |
|
|
180 | $self->update_stats_window ($stats, $prev); |
|
|
181 | |
|
|
182 | $self->{prev_stats} = { %$stats }; |
|
|
183 | } |
|
|
184 | |
|
|
185 | my %RES_TBL = ( |
|
|
186 | phys => CS_STAT_RES_PHYS, |
|
|
187 | magic => CS_STAT_RES_MAG, |
|
|
188 | fire => CS_STAT_RES_FIRE, |
|
|
189 | elec => CS_STAT_RES_ELEC, |
|
|
190 | cold => CS_STAT_RES_COLD, |
|
|
191 | conf => CS_STAT_RES_CONF, |
|
|
192 | acid => CS_STAT_RES_ACID, |
|
|
193 | drain => CS_STAT_RES_DRAIN, |
|
|
194 | ghit => CS_STAT_RES_GHOSTHIT, |
|
|
195 | pois => CS_STAT_RES_POISON, |
|
|
196 | slow => CS_STAT_RES_SLOW, |
|
|
197 | para => CS_STAT_RES_PARA, |
|
|
198 | tund => CS_STAT_TURN_UNDEAD, |
|
|
199 | fear => CS_STAT_RES_FEAR, |
|
|
200 | depl => CS_STAT_RES_DEPLETE, |
|
|
201 | deat => CS_STAT_RES_DEATH, |
|
|
202 | holyw => CS_STAT_RES_HOLYWORD, |
|
|
203 | blind => CS_STAT_RES_BLIND, |
|
|
204 | ); |
|
|
205 | |
|
|
206 | sub update_stats_window { |
|
|
207 | my ($self, $stats, $prev) = @_; |
|
|
208 | |
|
|
209 | # I love text protocols... |
|
|
210 | |
|
|
211 | my $hp = $stats->{+CS_STAT_HP} * 1; |
|
|
212 | my $hp_m = $stats->{+CS_STAT_MAXHP} * 1; |
|
|
213 | my $sp = $stats->{+CS_STAT_SP} * 1; |
|
|
214 | my $sp_m = $stats->{+CS_STAT_MAXSP} * 1; |
|
|
215 | my $fo = $stats->{+CS_STAT_FOOD} * 1; |
|
|
216 | my $fo_m = 999; |
|
|
217 | my $gr = $stats->{+CS_STAT_GRACE} * 1; |
|
|
218 | my $gr_m = $stats->{+CS_STAT_MAXGRACE} * 1; |
|
|
219 | |
|
|
220 | $::GAUGES->{hp} ->set_value ($hp, $hp_m); |
|
|
221 | $::GAUGES->{mana} ->set_value ($sp, $sp_m); |
|
|
222 | $::GAUGES->{food} ->set_value ($fo, $fo_m); |
|
|
223 | $::GAUGES->{grace} ->set_value ($gr, $gr_m); |
|
|
224 | $::GAUGES->{exp} ->set_text ("Exp: " . (::formsep ($stats->{+CS_STAT_EXP64})) |
|
|
225 | . " (lvl " . ($stats->{+CS_STAT_LEVEL} * 1) . ")"); |
|
|
226 | my $rng = $stats->{+CS_STAT_RANGE}; |
|
|
227 | $rng =~ s/^Range: //; # thank you so much dear server |
|
|
228 | $::GAUGES->{range} ->set_text ("Rng: " . $rng); |
|
|
229 | my $title = $stats->{+CS_STAT_TITLE}; |
|
|
230 | $title =~ s/^Player: //; |
|
|
231 | $::STATWIDS->{title} ->set_text ("Title: " . $title); |
|
|
232 | |
|
|
233 | $::STATWIDS->{st_str} ->set_text (sprintf "%d" , $stats->{+CS_STAT_STR}); |
|
|
234 | $::STATWIDS->{st_dex} ->set_text (sprintf "%d" , $stats->{+CS_STAT_DEX}); |
|
|
235 | $::STATWIDS->{st_con} ->set_text (sprintf "%d" , $stats->{+CS_STAT_CON}); |
|
|
236 | $::STATWIDS->{st_int} ->set_text (sprintf "%d" , $stats->{+CS_STAT_INT}); |
|
|
237 | $::STATWIDS->{st_wis} ->set_text (sprintf "%d" , $stats->{+CS_STAT_WIS}); |
|
|
238 | $::STATWIDS->{st_pow} ->set_text (sprintf "%d" , $stats->{+CS_STAT_POW}); |
|
|
239 | $::STATWIDS->{st_cha} ->set_text (sprintf "%d" , $stats->{+CS_STAT_CHA}); |
|
|
240 | $::STATWIDS->{st_wc} ->set_text (sprintf "%d" , $stats->{+CS_STAT_WC}); |
|
|
241 | $::STATWIDS->{st_ac} ->set_text (sprintf "%d" , $stats->{+CS_STAT_AC}); |
|
|
242 | $::STATWIDS->{st_dam} ->set_text (sprintf "%d" , $stats->{+CS_STAT_DAM}); |
|
|
243 | $::STATWIDS->{st_arm} ->set_text (sprintf "%d" , $stats->{+CS_STAT_RES_PHYS}); |
|
|
244 | $::STATWIDS->{st_spd} ->set_text (sprintf "%.1f", $stats->{+CS_STAT_SPEED}); |
|
|
245 | $::STATWIDS->{st_wspd}->set_text (sprintf "%.1f", $stats->{+CS_STAT_WEAP_SP}); |
|
|
246 | |
|
|
247 | $self->update_weight; |
|
|
248 | |
|
|
249 | $::STATWIDS->{"res_$_"}->set_text (sprintf "%d%", $stats->{$RES_TBL{$_}}) |
|
|
250 | for keys %RES_TBL; |
|
|
251 | |
|
|
252 | my $sktbl = $::STATWIDS->{skill_tbl}; |
|
|
253 | my @skills = keys %{ $self->{skill_info} }; |
|
|
254 | |
|
|
255 | if (grep +(exists $stats->{$_}) != (exists $prev->{$_}), @skills) { |
|
|
256 | $sktbl->clear; |
|
|
257 | |
|
|
258 | $sktbl->add (0, 0, new CFClient::UI::Label text => "Experience", align => 1); |
|
|
259 | $sktbl->add (1, 0, new CFClient::UI::Label text => "Lvl.", align => 1); |
|
|
260 | $sktbl->add (2, 0, new CFClient::UI::Label text => "Skill", expand => 1); |
|
|
261 | $sktbl->add (3, 0, new CFClient::UI::Label text => "Experience", align => 1); |
|
|
262 | $sktbl->add (4, 0, new CFClient::UI::Label text => "Lvl.", align => 1); |
|
|
263 | $sktbl->add (5, 0, new CFClient::UI::Label text => "Skill", expand => 1); |
|
|
264 | |
|
|
265 | my ($x, $y) = (1, 0); |
|
|
266 | for ( |
|
|
267 | sort { $stats->{$b->[0]}[1] <=> $stats->{$a->[0]}[1] or $a->[1] cmp $b->[1] } |
|
|
268 | map [$_, $self->{skill_info}{$_}], |
|
|
269 | grep exists $stats->{$_}, |
|
|
270 | @skills |
|
|
271 | ) { |
|
|
272 | my ($idx, $name) = @$_; |
|
|
273 | |
|
|
274 | $sktbl->add ($x * 3 + 0, $y, $self->{stat_widget_exp}{$idx} = new CFClient::UI::Label |
|
|
275 | text => "0", align => 1, font => $::FONT_FIXED, fg => [1, 1, 0]); |
|
|
276 | $sktbl->add ($x * 3 + 1, $y, $self->{stat_widget_lvl}{$idx} = new CFClient::UI::Label |
|
|
277 | text => "0", align => 1, font => $::FONT_FIXED, fg => [0, 1, 0], padding_x => 4); |
|
|
278 | $sktbl->add ($x * 3 + 2, $y, new CFClient::UI::Label text => $name); |
|
|
279 | |
|
|
280 | $x++ and ($x, $y) = (0, $y + 1); |
163 | } |
281 | } |
164 | |
|
|
165 | if ( |
|
|
166 | my @diffs = map $_->[1]->($self, $_->[2], $prev->{$_->[0]}, $stats->{$_->[0]}), @statchange |
|
|
167 | ) { |
|
|
168 | my $msg = "<b>stat change</b>: " . (join " ", @diffs); |
|
|
169 | $self->{statusbox}->add ($msg, group => $msg, fg => [0.8, 1, 0.2, 1], timeout => 10); |
|
|
170 | } |
|
|
171 | } |
282 | } |
172 | |
283 | |
173 | $self->{prev_stats} = { %$stats }; |
284 | for (grep exists $stats->{$_}, @skills) { |
174 | |
285 | $self->{stat_widget_exp}{$_}->set_text (::formsep ($stats->{$_}[1])); |
175 | ::update_stats_window ($stats); |
286 | $self->{stat_widget_lvl}{$_}->set_text ($stats->{$_}[0] * 1); |
|
|
287 | } |
176 | } |
288 | } |
177 | |
289 | |
178 | sub user_send { |
290 | sub user_send { |
179 | my ($self, $command) = @_; |
291 | my ($self, $command) = @_; |
180 | |
292 | |
… | |
… | |
420 | undef |
532 | undef |
421 | }; |
533 | }; |
422 | } |
534 | } |
423 | |
535 | |
424 | sub face_update { |
536 | sub face_update { |
425 | my ($self, $facenum, $face) = @_; |
537 | my ($self, $facenum, $face, $changed) = @_; |
426 | |
538 | |
427 | $self->{tilecache}->put ($face->{id} => $face->{image}) |
539 | $self->{tilecache}->put ($face->{id} => $face->{image}) if $changed; |
428 | if $self->{tilecache}->get ($face->{id}) ne $face->{image}; |
|
|
429 | |
540 | |
430 | $self->set_texture ($face->{id} => delete $face->{image}); |
541 | $self->set_texture ($face->{id} => delete $face->{image}); |
431 | } |
542 | } |
432 | |
543 | |
433 | sub set_texture { |
544 | sub set_texture { |
… | |
… | |
474 | [0.11, 0.56, 1.00], |
585 | [0.11, 0.56, 1.00], |
475 | [0.93, 0.46, 0.00], |
586 | [0.93, 0.46, 0.00], |
476 | [0.18, 0.54, 0.34], |
587 | [0.18, 0.54, 0.34], |
477 | [0.56, 0.73, 0.56], |
588 | [0.56, 0.73, 0.56], |
478 | [0.80, 0.80, 0.80], |
589 | [0.80, 0.80, 0.80], |
479 | [0.55, 0.41, 0.13], |
590 | [0.75, 0.61, 0.20], |
480 | [0.99, 0.77, 0.26], |
591 | [0.99, 0.77, 0.26], |
481 | [0.74, 0.65, 0.41], |
592 | [0.74, 0.65, 0.41], |
482 | ); |
593 | ); |
483 | |
594 | |
484 | $self->logprint ("info: ", $text); |
595 | $self->logprint ("info: ", $text); |
… | |
… | |
491 | $text = CFClient::UI::Label::escape $text; |
602 | $text = CFClient::UI::Label::escape $text; |
492 | $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g; |
603 | $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g; |
493 | $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g; |
604 | $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g; |
494 | |
605 | |
495 | $self->{logview}->add_paragraph ($color[$color], $_) |
606 | $self->{logview}->add_paragraph ($color[$color], $_) |
496 | for map "$time $_", split /\n/, $text; |
607 | for map "<span foreground='#ffffff'>$time</span> $_", split /\n/, $text; |
497 | $self->{logview}->scroll_to_bottom; |
608 | $self->{logview}->scroll_to_bottom; |
498 | |
609 | |
499 | $self->{statusbox}->add ($text, |
610 | $self->{statusbox}->add ($text, |
500 | group => $text, |
611 | group => $text, |
501 | fg => $color[$color], |
612 | fg => $color[$color], |
… | |
… | |
598 | } |
709 | } |
599 | |
710 | |
600 | sub update_floorbox { |
711 | sub update_floorbox { |
601 | $CFClient::UI::ROOT->on_refresh ($::FLOORBOX => sub { |
712 | $CFClient::UI::ROOT->on_refresh ($::FLOORBOX => sub { |
602 | return unless $::CONN; |
713 | return unless $::CONN; |
603 | |
714 | |
604 | $::FLOORBOX->clear; |
715 | $::FLOORBOX->clear; |
605 | |
716 | |
606 | my $row; |
717 | my $row; |
607 | for (sort { $a->{count} <=> $b->{count} } values %{ $::CONN->{container}{0} }) { |
718 | for (sort { $a->{count} <=> $b->{count} } values %{ $::CONN->{container}{$::CONN->{open_container} || 0} }) { |
608 | if ($row < 6) { |
719 | if ($row < 6) { |
609 | local $_->{face_widget}; # hack to force recreation of widget |
720 | local $_->{face_widget}; # hack to force recreation of widget |
610 | local $_->{desc_widget}; # hack to force recreation of widget |
721 | local $_->{desc_widget}; # hack to force recreation of widget |
611 | CFClient::Item::update_widgets $_; |
722 | CFClient::Item::update_widgets $_; |
612 | |
723 | |
… | |
… | |
620 | on_activate => sub { ::toggle_player_page ($::INVENTORY_PAGE); 0 }, |
731 | on_activate => sub { ::toggle_player_page ($::INVENTORY_PAGE); 0 }, |
621 | ); |
732 | ); |
622 | last; |
733 | last; |
623 | } |
734 | } |
624 | } |
735 | } |
|
|
736 | if ($::CONN->{open_container}) { |
|
|
737 | $::FLOORBOX->add (1, $row++, new CFClient::UI::Button |
|
|
738 | text => "Close container", |
|
|
739 | on_activate => sub { $::CONN->send ("apply $::CONN->{open_container}") } |
|
|
740 | ); |
|
|
741 | } |
625 | }); |
742 | }); |
626 | |
743 | |
627 | $::WANT_REFRESH++; |
744 | $::WANT_REFRESH++; |
628 | } |
745 | } |
629 | |
746 | |
630 | sub set_opencont { |
747 | sub set_opencont { |
631 | my ($conn, $tag, $name) = @_; |
748 | my ($conn, $tag, $name) = @_; |
632 | $conn->{open_container} = $tag; |
749 | $conn->{open_container} = $tag; |
|
|
750 | update_floorbox; |
633 | |
751 | |
634 | $::INV_RIGHT_HB->clear (); |
752 | $::INV_RIGHT_HB->clear (); |
635 | $::INV_RIGHT_HB->add (new CFClient::UI::Label align => 0, expand => 1, text => $name); |
753 | $::INV_RIGHT_HB->add (new CFClient::UI::Label align => 0, expand => 1, text => $name); |
636 | |
754 | |
637 | if ($tag != 0) { # Floor isn't closable, is it? |
755 | if ($tag != 0) { # Floor isn't closable, is it? |
… | |
… | |
656 | $CFClient::UI::ROOT->on_refresh ("update_containers_$self" => sub { |
774 | $CFClient::UI::ROOT->on_refresh ("update_containers_$self" => sub { |
657 | my $todo = delete $self->{update_container} |
775 | my $todo = delete $self->{update_container} |
658 | or return; |
776 | or return; |
659 | |
777 | |
660 | for my $tag (keys %$todo) { |
778 | for my $tag (keys %$todo) { |
|
|
779 | update_floorbox if $tag == 0 or $tag == $self->{open_container}; |
661 | if ($tag == 0) { |
780 | if ($tag == 0) { |
662 | update_floorbox; |
|
|
663 | $::INVR->set_items ($self->{container}{0}) |
781 | $::INVR->set_items ($self->{container}{0}) |
664 | if $tag == $self->{open_container}; |
782 | if $tag == $self->{open_container}; |
665 | } elsif ($tag == $self->{player}{tag}) { |
783 | } elsif ($tag == $self->{player}{tag}) { |
666 | $::INV->set_items ($self->{container}{$tag}) |
784 | $::INV->set_items ($self->{container}{$tag}) |
667 | } else { |
785 | } else { |
… | |
… | |
714 | } |
832 | } |
715 | } |
833 | } |
716 | |
834 | |
717 | sub player_update { |
835 | sub player_update { |
718 | my ($self, $player) = @_; |
836 | my ($self, $player) = @_; |
|
|
837 | |
|
|
838 | $self->update_weight; |
|
|
839 | } |
|
|
840 | |
|
|
841 | sub update_weight { |
|
|
842 | my ($self) = @_; |
|
|
843 | |
|
|
844 | my $weight = .001 * $self->{player}{weight}; |
|
|
845 | my $limit = .001 * $self->{stat}{+CS_STAT_WEIGHT_LIM}; |
|
|
846 | |
719 | $::STATWIDS->{weight}->set_text (sprintf "Weight: %.1fkg", $player->{weight} / 1000); |
847 | $::STATWIDS->{weight}->set_text (sprintf "Weight: %.1fkg", $weight); |
|
|
848 | $::STATWIDS->{m_weight}->set_text (sprintf "%.1fkg", $limit); |
|
|
849 | $::STATWIDS->{i_weight}->set_text (sprintf "%.1f/%.1fkg", $weight, $limit); |
720 | } |
850 | } |
721 | |
851 | |
722 | sub update_server_info { |
852 | sub update_server_info { |
723 | my ($self) = @_; |
853 | my ($self) = @_; |
724 | |
854 | |
… | |
… | |
794 | name => "npc_dialog", |
924 | name => "npc_dialog", |
795 | force_w => $::WIDTH * 0.7, |
925 | force_w => $::WIDTH * 0.7, |
796 | force_h => $::HEIGHT * 0.7, |
926 | force_h => $::HEIGHT * 0.7, |
797 | title => "NPC Dialog", |
927 | title => "NPC Dialog", |
798 | kw => { hi => 0, yes => 0, no => 0 }, |
928 | kw => { hi => 0, yes => 0, no => 0 }, |
|
|
929 | has_close_button => 1, |
799 | @_, |
930 | @_, |
800 | ); |
931 | ); |
801 | |
932 | |
802 | Scalar::Util::weaken (my $this = $self); |
933 | Scalar::Util::weaken (my $this = $self); |
|
|
934 | |
|
|
935 | $self->connect (delete => sub { $this->destroy; 1 }); |
803 | |
936 | |
804 | # better use a pane... |
937 | # better use a pane... |
805 | $self->add (my $hbox = new CFClient::UI::HBox); |
938 | $self->add (my $hbox = new CFClient::UI::HBox); |
806 | $hbox->add ($self->{textview} = new CFClient::UI::TextScroller expand => 1); |
939 | $hbox->add ($self->{textview} = new CFClient::UI::TextScroller expand => 1); |
807 | |
940 | |
… | |
… | |
829 | $vbox->add ($self->{options} = new CFClient::UI::VBox); |
962 | $vbox->add ($self->{options} = new CFClient::UI::VBox); |
830 | |
963 | |
831 | $self->{bye_button} = new CFClient::UI::Button |
964 | $self->{bye_button} = new CFClient::UI::Button |
832 | text => "Bye (close)", |
965 | text => "Bye (close)", |
833 | tooltip => "Use this button to end talking to the NPC. This also closes the dialog window.", |
966 | tooltip => "Use this button to end talking to the NPC. This also closes the dialog window.", |
834 | on_activate => sub { $this->destroy; 0 }, |
967 | on_activate => sub { $this->destroy; 1 }, |
835 | ; |
968 | ; |
836 | |
969 | |
837 | $self->update_options; |
970 | $self->update_options; |
838 | |
971 | |
839 | $self->{token} = $self->{conn}->ext_token; |
972 | $self->{token} = $self->{conn}->ext_token; |
… | |
… | |
874 | |
1007 | |
875 | my ($type, $msg) = split / /, $data, 2; |
1008 | my ($type, $msg) = split / /, $data, 2; |
876 | |
1009 | |
877 | if ($type eq "msg") { |
1010 | if ($type eq "msg") { |
878 | my ($msg, @kw) = split /\x00/, $msg; |
1011 | my ($msg, @kw) = split /\x00/, $msg; |
|
|
1012 | |
|
|
1013 | utf8::decode $_ for ($msg, @kw); |
|
|
1014 | |
879 | $self->{kw}{$_} = 1 for @kw; |
1015 | $self->{kw}{$_} = 1 for @kw; |
880 | |
1016 | |
881 | $msg = "\n" . CFClient::UI::Label::escape $msg; |
1017 | $msg = "\n" . CFClient::UI::Label::escape $msg; |
882 | my $match = join "|", map "\\b\Q$_\E\\b", sort { (length $b) <=> (length $a) } keys %{ $self->{kw} }; |
1018 | my $match = join "|", map "\\b\Q$_\E\\b", sort { (length $b) <=> (length $a) } keys %{ $self->{kw} }; |
883 | my @link; |
1019 | my @link; |
… | |
… | |
910 | } |
1046 | } |
911 | |
1047 | |
912 | sub send { |
1048 | sub send { |
913 | my ($self, $msg) = @_; |
1049 | my ($self, $msg) = @_; |
914 | |
1050 | |
915 | $self->{conn}->send ("ext npc_dialog_tell $self->{token} $msg"); |
|
|
916 | $self->{textview}->add_paragraph ([1, 1, 0, 1], "\n" . CFClient::UI::Label::escape $msg); |
1051 | $self->{textview}->add_paragraph ([1, 1, 0, 1], "\n" . CFClient::UI::Label::escape $msg); |
917 | $self->{textview}->scroll_to_bottom; |
1052 | $self->{textview}->scroll_to_bottom; |
|
|
1053 | |
|
|
1054 | utf8::encode $msg; |
|
|
1055 | $self->{conn}->send ("ext npc_dialog_tell $self->{token} $msg"); |
918 | } |
1056 | } |
919 | |
1057 | |
920 | sub destroy { |
1058 | sub destroy { |
921 | my ($self) = @_; |
1059 | my ($self) = @_; |
922 | |
1060 | |