… | |
… | |
83 | |
83 | |
84 | print $fh "$ts ", @a, "\n"; |
84 | print $fh "$ts ", @a, "\n"; |
85 | $fh->flush; |
85 | $fh->flush; |
86 | } |
86 | } |
87 | |
87 | |
|
|
88 | sub _stat_numdiff { |
|
|
89 | my ($self, $old, $new) = @_; |
88 | |
90 | |
|
|
91 | my $diff = $new - $old; |
|
|
92 | $diff > 0 ? "+$diff" : $diff |
|
|
93 | } |
|
|
94 | |
|
|
95 | sub _stat_skillmaskdiff { |
|
|
96 | my ($self, $old, $new) = @_; |
|
|
97 | |
|
|
98 | my $diff = $old ^ $new; |
|
|
99 | |
|
|
100 | my @diff = map |
|
|
101 | { |
|
|
102 | $diff & $_ |
|
|
103 | ? (($new & $_ ? "+" : "-") . $self->{spell_paths}{$_}) |
|
|
104 | : () |
|
|
105 | } |
|
|
106 | sort { $a <=> $b } keys %{$self->{spell_paths}}; |
|
|
107 | |
|
|
108 | join "", @diff |
|
|
109 | } |
|
|
110 | |
|
|
111 | # all stats that are chacked against changes |
|
|
112 | my @statchange = ( |
|
|
113 | [&CS_STAT_STR => \&_stat_numdiff, "Str"], |
|
|
114 | [&CS_STAT_INT => \&_stat_numdiff, "Int"], |
|
|
115 | [&CS_STAT_WIS => \&_stat_numdiff, "Wis"], |
|
|
116 | [&CS_STAT_DEX => \&_stat_numdiff, "Dex"], |
|
|
117 | [&CS_STAT_CON => \&_stat_numdiff, "Con"], |
|
|
118 | [&CS_STAT_CHA => \&_stat_numdiff, "Cha"], |
|
|
119 | [&CS_STAT_POW => \&_stat_numdiff, "Pow"], |
|
|
120 | [&CS_STAT_WC => \&_stat_numdiff, "Wc"], |
|
|
121 | [&CS_STAT_AC => \&_stat_numdiff, "Ac"], |
|
|
122 | [&CS_STAT_DAM => \&_stat_numdiff, "Dam"], |
|
|
123 | [&CS_STAT_SPEED => \&_stat_numdiff, "Speed"], |
|
|
124 | [&CS_STAT_WEAP_SP => \&_stat_numdiff, "WSp"], |
|
|
125 | [&CS_STAT_MAXHP => \&_stat_numdiff, "HP"], |
|
|
126 | [&CS_STAT_MAXSP => \&_stat_numdiff, "Mana"], |
|
|
127 | [&CS_STAT_MAXGRACE => \&_stat_numdiff, "Grace"], |
|
|
128 | [&CS_STAT_WEIGHT_LIM => \&_stat_numdiff, "Weight"], |
|
|
129 | [&CS_STAT_SPELL_ATTUNE => \&_stat_skillmaskdiff, "attuned"], |
|
|
130 | [&CS_STAT_SPELL_REPEL => \&_stat_skillmaskdiff, "repelled"], |
|
|
131 | [&CS_STAT_SPELL_DENY => \&_stat_skillmaskdiff, "denied"], |
|
|
132 | [&CS_STAT_RES_PHYS => \&_stat_numdiff, "phys"], |
|
|
133 | [&CS_STAT_RES_MAG => \&_stat_numdiff, "magic"], |
|
|
134 | [&CS_STAT_RES_FIRE => \&_stat_numdiff, "fire"], |
|
|
135 | [&CS_STAT_RES_ELEC => \&_stat_numdiff, "electricity"], |
|
|
136 | [&CS_STAT_RES_COLD => \&_stat_numdiff, "cold"], |
|
|
137 | [&CS_STAT_RES_CONF => \&_stat_numdiff, "confusion"], |
|
|
138 | [&CS_STAT_RES_ACID => \&_stat_numdiff, "acid"], |
|
|
139 | [&CS_STAT_RES_DRAIN => \&_stat_numdiff, "drain"], |
|
|
140 | [&CS_STAT_RES_GHOSTHIT => \&_stat_numdiff, "ghosthit"], |
|
|
141 | [&CS_STAT_RES_POISON => \&_stat_numdiff, "poison"], |
|
|
142 | [&CS_STAT_RES_SLOW => \&_stat_numdiff, "slow"], |
|
|
143 | [&CS_STAT_RES_PARA => \&_stat_numdiff, "paralyse"], |
|
|
144 | [&CS_STAT_TURN_UNDEAD => \&_stat_numdiff, "turnundead"], |
|
|
145 | [&CS_STAT_RES_FEAR => \&_stat_numdiff, "fear"], |
|
|
146 | [&CS_STAT_RES_DEPLETE => \&_stat_numdiff, "depletion"], |
|
|
147 | [&CS_STAT_RES_DEATH => \&_stat_numdiff, "death"], |
|
|
148 | [&CS_STAT_RES_HOLYWORD => \&_stat_numdiff, "godpower"], |
|
|
149 | [&CS_STAT_RES_BLIND => \&_stat_numdiff, "blind"], |
|
|
150 | ); |
89 | |
151 | |
90 | sub stats_update { |
152 | sub stats_update { |
91 | my ($self, $stats) = @_; |
153 | my ($self, $stats) = @_; |
92 | |
154 | |
93 | if (my $exp = $stats->{+CS_STAT_EXP64}) { |
155 | if (my $prev = $self->{prev_stats}) { |
94 | my $diff = $exp - $self->{prev_exp}; |
156 | if (my $diff = $stats->{+CS_STAT_EXP64} - $prev->{+CS_STAT_EXP64}) { |
95 | $self->{statusbox}->add ("$diff experience gained", group => "experience $diff", fg => [0.5, 1, 0.5, 0.8], timeout => 5) |
157 | $self->{statusbox}->add ("$diff experience gained", group => "experience $diff", fg => [0.5, 1, 0.5, 0.8], timeout => 5); |
96 | if exists $self->{prev_exp} && $diff; |
158 | } |
97 | $self->{prev_exp} = $exp; |
159 | |
|
|
160 | if ( |
|
|
161 | my @diffs = map { |
|
|
162 | $stats->{$_->[0]} != $prev->{$_->[0]} |
|
|
163 | ? $_->[2] . $_->[1]->($self, $prev->{$_->[0]}, $stats->{$_->[0]}) : (); |
|
|
164 | } |
|
|
165 | @statchange |
|
|
166 | ) { |
|
|
167 | my $msg = "<b>stat change</b>: " . (join " ", @diffs); |
|
|
168 | $self->{statusbox}->add ($msg, group => $msg, fg => [0.8, 1, 0.2, 1], timeout => 10); |
|
|
169 | } |
98 | } |
170 | } |
|
|
171 | |
|
|
172 | $self->{prev_stats} = { %$stats }; |
99 | |
173 | |
100 | ::update_stats_window ($stats); |
174 | ::update_stats_window ($stats); |
101 | } |
175 | } |
102 | |
176 | |
103 | sub user_send { |
177 | sub user_send { |
… | |
… | |
107 | push @{$self->{record}}, $command; |
181 | push @{$self->{record}}, $command; |
108 | } |
182 | } |
109 | |
183 | |
110 | $self->logprint ("send: ", $command); |
184 | $self->logprint ("send: ", $command); |
111 | $self->send_command ($command); |
185 | $self->send_command ($command); |
112 | ::status $command; |
186 | ::status ($command); |
113 | } |
187 | } |
114 | |
188 | |
115 | sub start_record { |
189 | sub start_record { |
116 | my ($self) = @_; |
190 | my ($self) = @_; |
117 | |
191 | |
… | |
… | |
132 | sub feed_map1a { |
206 | sub feed_map1a { |
133 | my ($self, $data) = @_; |
207 | my ($self, $data) = @_; |
134 | |
208 | |
135 | $self->{map}->map1a_update ($data); |
209 | $self->{map}->map1a_update ($data); |
136 | $self->{map_widget}->update; |
210 | $self->{map_widget}->update; |
|
|
211 | } |
|
|
212 | |
|
|
213 | sub magicmap { |
|
|
214 | my ($self, $w, $h, $x, $y, $data) = @_; |
|
|
215 | |
|
|
216 | $self->{map_widget}->set_magicmap ($w, $h, $x, $y, $data); |
137 | } |
217 | } |
138 | |
218 | |
139 | sub flush_map { |
219 | sub flush_map { |
140 | my ($self) = @_; |
220 | my ($self) = @_; |
141 | |
221 | |
… | |
… | |
154 | |
234 | |
155 | $self->flush_map; |
235 | $self->flush_map; |
156 | delete $self->{neigh_map}; |
236 | delete $self->{neigh_map}; |
157 | |
237 | |
158 | $self->{map}->clear; |
238 | $self->{map}->clear; |
|
|
239 | delete $self->{map_widget}{magicmap}; |
159 | } |
240 | } |
160 | |
241 | |
161 | |
242 | |
162 | sub load_map($$$) { |
243 | sub load_map($$$) { |
163 | my ($self, $hash, $x, $y) = @_; |
244 | my ($self, $hash, $x, $y) = @_; |
… | |
… | |
407 | |
488 | |
408 | $text = CFClient::UI::Label::escape $text; |
489 | $text = CFClient::UI::Label::escape $text; |
409 | $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g; |
490 | $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g; |
410 | $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g; |
491 | $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g; |
411 | |
492 | |
412 | $self->{logview}->add_paragraph ($color[$color], |
493 | $self->{logview}->add_paragraph ($color[$color], $_) |
413 | join "\n", map "$time $_", split /\n/, $text); |
494 | for map "$time $_", split /\n/, $text; |
|
|
495 | $self->{logview}->scroll_to_bottom; |
414 | |
496 | |
415 | $self->{statusbox}->add ($text, |
497 | $self->{statusbox}->add ($text, |
416 | group => $text, |
498 | group => $text, |
417 | fg => $color[$color], |
499 | fg => $color[$color], |
418 | timeout => $color >= 2 ? 60 : 10, |
500 | timeout => $color >= 2 ? 60 : 10, |
… | |
… | |
432 | # try to create single paragraphs of multiple lines sent by the server |
514 | # try to create single paragraphs of multiple lines sent by the server |
433 | $spell->{message} =~ s/(?<=\S)\n(?=\w)/ /g; |
515 | $spell->{message} =~ s/(?<=\S)\n(?=\w)/ /g; |
434 | $spell->{message} =~ s/\n+$//; |
516 | $spell->{message} =~ s/\n+$//; |
435 | $spell->{message} ||= "Server did not provide a description for this spell."; |
517 | $spell->{message} ||= "Server did not provide a description for this spell."; |
436 | |
518 | |
437 | $::SETUP_SPELLS->add_spell ($spell); |
519 | $::SPELL_PAGE->add_spell ($spell); |
438 | |
520 | |
439 | $self->{map_widget}->add_command ("invoke $spell->{name}", CFClient::UI::Label::escape $spell->{message}); |
521 | $self->{map_widget}->add_command ("invoke $spell->{name}", CFClient::UI::Label::escape $spell->{message}); |
440 | $self->{map_widget}->add_command ("cast $spell->{name}", CFClient::UI::Label::escape $spell->{message}); |
522 | $self->{map_widget}->add_command ("cast $spell->{name}", CFClient::UI::Label::escape $spell->{message}); |
441 | } |
523 | } |
442 | |
524 | |
443 | sub spell_delete { |
525 | sub spell_delete { |
444 | my ($self, $spell) = @_; |
526 | my ($self, $spell) = @_; |
|
|
527 | |
445 | $::SETUP_SPELLS->remove_spell ($spell); |
528 | $::SPELL_PAGE->remove_spell ($spell); |
446 | } |
529 | } |
447 | |
530 | |
448 | sub addme_success { |
531 | sub addme_success { |
449 | my ($self) = @_; |
532 | my ($self) = @_; |
450 | |
533 | |
… | |
… | |
517 | return unless $::CONN; |
600 | return unless $::CONN; |
518 | |
601 | |
519 | $::FLOORBOX->clear; |
602 | $::FLOORBOX->clear; |
520 | |
603 | |
521 | my $row; |
604 | my $row; |
522 | for (@{ $::CONN->{container}{0} }) { |
605 | for (sort { $a->{count} <=> $b->{count} } values %{ $::CONN->{container}{0} }) { |
523 | if ($row < 6) { |
606 | if ($row < 6) { |
524 | local $_->{face_widget}; # hack to force recreation of widget |
607 | local $_->{face_widget}; # hack to force recreation of widget |
525 | local $_->{desc_widget}; # hack to force recreation of widget |
608 | local $_->{desc_widget}; # hack to force recreation of widget |
526 | CFClient::Item::update_widgets $_; |
609 | CFClient::Item::update_widgets $_; |
527 | |
610 | |
… | |
… | |
530 | |
613 | |
531 | $row++; |
614 | $row++; |
532 | } else { |
615 | } else { |
533 | $::FLOORBOX->add (1, $row, new CFClient::UI::Button |
616 | $::FLOORBOX->add (1, $row, new CFClient::UI::Button |
534 | text => "More...", |
617 | text => "More...", |
535 | on_activate => sub { $::INV_WINDOW->toggle_visibility }, |
618 | on_activate => sub { ::toggle_player_page ($::INVENTORY_PAGE); 0 }, |
536 | ); |
619 | ); |
537 | last; |
620 | last; |
538 | } |
621 | } |
539 | } |
622 | } |
540 | }); |
623 | }); |
… | |
… | |
555 | tooltip => "Close the currently open container (if one is open)", |
638 | tooltip => "Close the currently open container (if one is open)", |
556 | on_activate => sub { |
639 | on_activate => sub { |
557 | $::CONN->send ("apply $tag") # $::CONN->{open_container}") |
640 | $::CONN->send ("apply $tag") # $::CONN->{open_container}") |
558 | if $tag != 0; |
641 | if $tag != 0; |
559 | #if $CONN->{open_container} != 0; |
642 | #if $CONN->{open_container} != 0; |
|
|
643 | 0 |
560 | }, |
644 | }, |
561 | ); |
645 | ); |
562 | } |
646 | } |
563 | |
647 | |
564 | $::INVR->set_items ($conn->{container}{$tag}); |
648 | $::INVR->set_items ($conn->{container}{$tag}); |
565 | } |
649 | } |
566 | |
650 | |
567 | sub update_container { |
651 | sub update_containers { |
568 | my ($tag) = @_; |
652 | my ($self) = @_; |
569 | |
653 | |
570 | $::INVR->set_items ($::CONN->{container}{$::CONN->{open_container}}) |
654 | $CFClient::UI::ROOT->on_refresh ("update_containers_$self" => sub { |
|
|
655 | for my $tag (keys %{ delete $self->{update_container} }) { |
|
|
656 | if ($tag == 0) { |
|
|
657 | update_floorbox; |
|
|
658 | $::INVR->set_items ($self->{container}{0}) |
571 | if $tag == $::CONN->{open_container}; |
659 | if $tag == $self->{open_container}; |
|
|
660 | } elsif ($tag == $self->{player}{tag}) { |
|
|
661 | $::INV->set_items ($self->{container}{$tag}) |
|
|
662 | } else { |
|
|
663 | $::INVR->set_items ($self->{container}{$tag}) |
|
|
664 | if $tag == $self->{open_container}; |
|
|
665 | } |
|
|
666 | } |
|
|
667 | }); |
572 | } |
668 | } |
573 | |
669 | |
574 | sub container_add { |
670 | sub container_add { |
575 | my ($self, $tag, $items) = @_; |
671 | my ($self, $tag, $items) = @_; |
576 | |
672 | |
577 | #d# print "container_add: container $tag ($self->{player}{tag})\n"; |
673 | $self->{update_container}{$tag}++; |
578 | |
674 | $self->update_containers; |
579 | if ($tag == 0) { |
|
|
580 | update_floorbox; |
|
|
581 | update_container (0); |
|
|
582 | } elsif ($tag == $self->{player}{tag}) { |
|
|
583 | $::INV->set_items ($self->{container}{$self->{player}{tag}}) |
|
|
584 | } else { |
|
|
585 | update_container ($tag); |
|
|
586 | } |
|
|
587 | |
|
|
588 | # $self-<{player}{tag} => player inv |
|
|
589 | #use PApp::Util; warn PApp::Util::dumpval $self->{container}{$self->{player}{tag}}; |
|
|
590 | } |
675 | } |
591 | |
676 | |
592 | sub container_clear { |
677 | sub container_clear { |
593 | my ($self, $tag) = @_; |
678 | my ($self, $tag) = @_; |
594 | |
679 | |
595 | #d# print "container_clear: container $tag ($self->{player}{tag})\n"; |
680 | $self->{update_container}{$tag}++; |
596 | |
681 | $self->update_containers; |
597 | if ($tag == 0) { |
|
|
598 | update_floorbox; |
|
|
599 | update_container (0); |
|
|
600 | } elsif ($tag == $self->{player}{tag}) { |
|
|
601 | $::INV->set_items ($self->{container}{$tag}) |
|
|
602 | } else { |
|
|
603 | update_container ($tag); |
|
|
604 | } |
|
|
605 | |
|
|
606 | # use PApp::Util; warn PApp::Util::dumpval $self->{container}{0}; |
|
|
607 | } |
682 | } |
608 | |
683 | |
609 | sub item_delete { |
684 | sub item_delete { |
610 | my ($self, @items) = @_; |
685 | my ($self, @items) = @_; |
611 | |
686 | |
|
|
687 | $self->{update_container}{$_->{container}}++ |
612 | for (@items) { |
688 | for @items; |
613 | #d# print "item_delete: $_->{tag} from $_->{container} ($self->{player}{tag})\n"; |
|
|
614 | |
|
|
615 | if ($_->{container} == 0) { |
|
|
616 | update_floorbox; |
|
|
617 | update_container ($_->{tag}); |
|
|
618 | } elsif ($_->{container} == $self->{player}{tag}) { |
|
|
619 | $::INV->set_items ($self->{container}{$self->{player}{tag}}) |
|
|
620 | } else { |
|
|
621 | update_container ($_->{container}); |
|
|
622 | } |
|
|
623 | } |
689 | |
|
|
690 | $self->update_containers; |
624 | } |
691 | } |
625 | |
692 | |
626 | sub item_update { |
693 | sub item_update { |
627 | my ($self, $item) = @_; |
694 | my ($self, $item) = @_; |
628 | |
695 | |
629 | #d# print "item_update: $item->{tag} in $item->{container} ($self->{player}{tag}) ($::CONN->{open_container})\n"; |
696 | #d# print "item_update: $item->{tag} in $item->{container} ($self->{player}{tag}) ($::CONN->{open_container})\n"; |
630 | |
697 | |
631 | if ($item->{tag} == $self->{player}{tag}) { |
|
|
632 | $::STATWIDS->{weight}->set_text (sprintf "Weight: %.1fkg", $item->{weight} / 1000); |
|
|
633 | return; |
|
|
634 | } |
|
|
635 | |
|
|
636 | CFClient::Item::update_widgets $item; |
698 | CFClient::Item::update_widgets $item; |
637 | |
699 | |
638 | if ($item->{tag} == $::CONN->{open_container} && not ($item->{flags} & F_OPEN)) { |
700 | if ($item->{tag} == $::CONN->{open_container} && not ($item->{flags} & F_OPEN)) { |
639 | set_opencont ($::CONN, 0, "Floor"); |
701 | set_opencont ($::CONN, 0, "Floor"); |
640 | |
702 | |
641 | } elsif ($item->{flags} & F_OPEN) { |
703 | } elsif ($item->{flags} & F_OPEN) { |
642 | set_opencont ($::CONN, $item->{tag}, CFClient::Item::desc_string $item); |
704 | set_opencont ($::CONN, $item->{tag}, CFClient::Item::desc_string $item); |
|
|
705 | |
643 | } else { |
706 | } else { |
|
|
707 | $self->{update_container}{$item->{container}}++; |
|
|
708 | $self->update_containers; |
644 | if ($item->{container} == 0) { |
709 | # if ($item->{container} == 0) { |
645 | update_floorbox; |
710 | # update_floorbox; |
646 | update_container (0); |
711 | # update_container (0); |
647 | } elsif ($item->{container} == $self->{player}{tag}) { |
712 | # } elsif ($item->{container} == $self->{player}{tag}) { |
648 | $::INV->set_items ($self->{container}{$item->{container}}) |
713 | # $::INV->set_items ($self->{container}{$item->{container}}) |
649 | } |
714 | # } |
650 | } |
715 | } |
651 | } |
716 | } |
652 | |
717 | |
653 | sub player_update { |
718 | sub player_update { |
654 | my ($self, $player) = @_; |
719 | my ($self, $player) = @_; |
655 | |
|
|
656 | $::STATWIDS->{weight}->set_text (sprintf "Weight: %.1fkg", $player->{weight} / 1000); |
720 | $::STATWIDS->{weight}->set_text (sprintf "Weight: %.1fkg", $player->{weight} / 1000); |
657 | } |
721 | } |
658 | |
722 | |
659 | sub update_server_info { |
723 | sub update_server_info { |
660 | my ($self) = @_; |
724 | my ($self) = @_; |
… | |
… | |
756 | |
820 | |
757 | return unless $text =~ /\S/; |
821 | return unless $text =~ /\S/; |
758 | |
822 | |
759 | $entry->set_text (""); |
823 | $entry->set_text (""); |
760 | $this->send ($text); |
824 | $this->send ($text); |
|
|
825 | |
|
|
826 | 0 |
761 | }, |
827 | }, |
762 | ); |
828 | ); |
763 | |
829 | |
764 | $vbox->add ($self->{options} = new CFClient::UI::VBox); |
830 | $vbox->add ($self->{options} = new CFClient::UI::VBox); |
765 | |
831 | |
766 | $self->{close_button} = new CFClient::UI::Button |
832 | $self->{bye_button} = new CFClient::UI::Button |
767 | text => "Bye (close)", |
833 | text => "Bye (close)", |
768 | tooltip => "Use this button to end talking to the NPC. This also closes the dialog window.", |
834 | tooltip => "Use this button to end talking to the NPC. This also closes the dialog window.", |
769 | on_activate => sub { $this->destroy }, |
835 | on_activate => sub { $this->destroy; 0 }, |
770 | ; |
836 | ; |
771 | |
837 | |
772 | $self->update_options; |
838 | $self->update_options; |
773 | |
839 | |
774 | $self->{token} = $self->{conn}->ext_token; |
840 | $self->{token} = $self->{conn}->ext_token; |
775 | $self->{conn}->connect_ext ($self->{token} => sub { $this->feed (@_) }); |
841 | $self->{conn}->connect_ext ($self->{token} => sub { $this->feed (@_) }); |
776 | $self->{conn}->send ("ext npc_dialog_begin $self->{token} $self->{dx} $self->{dy}"); |
842 | $self->{conn}->send ("ext npc_dialog_begin $self->{token} $self->{dx} $self->{dy}"); |
777 | |
843 | |
778 | $self->{entry}->focus_in; |
844 | $self->{entry}->grab_focus; |
779 | |
845 | |
780 | $self->{textview}->add_paragraph ([1, 1, 0, 1], "<small>[starting conversation with <b>$self->{title}</b>]</small>\n\n"); |
846 | $self->{textview}->add_paragraph ([1, 1, 0, 1], "<small>[starting conversation with <b>$self->{title}</b>]</small>\n\n"); |
781 | |
847 | |
782 | $self->show; |
848 | $self->show; |
783 | $self |
849 | $self |
… | |
… | |
787 | my ($self) = @_; |
853 | my ($self) = @_; |
788 | |
854 | |
789 | Scalar::Util::weaken $self; |
855 | Scalar::Util::weaken $self; |
790 | |
856 | |
791 | $self->{options}->clear; |
857 | $self->{options}->clear; |
792 | $self->{options}->add ($self->{close_button}); |
858 | $self->{options}->add ($self->{bye_button}); |
793 | |
859 | |
794 | for my $kw (sort keys %{ $self->{kw} }) { |
860 | for my $kw (sort keys %{ $self->{kw} }) { |
795 | $self->{options}->add (new CFClient::UI::Button |
861 | $self->{options}->add (new CFClient::UI::Button |
796 | text => $kw, |
862 | text => $kw, |
797 | on_activate => sub { |
863 | on_activate => sub { |
798 | $self->send ($kw); |
864 | $self->send ($kw); |
|
|
865 | 0 |
799 | }, |
866 | }, |
800 | ); |
867 | ); |
801 | } |
868 | } |
802 | } |
869 | } |
803 | |
870 | |
804 | sub feed { |
871 | sub feed { |
805 | my ($self, $data) = @_; |
872 | my ($self, $data) = @_; |
|
|
873 | |
|
|
874 | Scalar::Util::weaken $self; |
806 | |
875 | |
807 | my ($type, $msg) = split / /, $data, 2; |
876 | my ($type, $msg) = split / /, $data, 2; |
808 | |
877 | |
809 | if ($type eq "msg") { |
878 | if ($type eq "msg") { |
810 | my ($msg, @kw) = split /\x00/, $msg; |
879 | my ($msg, @kw) = split /\x00/, $msg; |
811 | $self->{kw}{$_} = 1 for @kw; |
880 | $self->{kw}{$_} = 1 for @kw; |
812 | |
881 | |
813 | $msg = CFClient::UI::Label::escape $msg; |
882 | $msg = "\n" . CFClient::UI::Label::escape $msg; |
814 | my $match = join "|", map "\\b\Q$_\E\\b", sort { (length $b) <=> (length $a) } keys %{ $self->{kw} }; |
883 | my $match = join "|", map "\\b\Q$_\E\\b", sort { (length $b) <=> (length $a) } keys %{ $self->{kw} }; |
815 | $msg =~ s/($match)/<span foreground='#c0c0ff' underline='none'>$1<\/span>/gi; # underline when http-ready, huh. |
884 | my @link; |
|
|
885 | $msg =~ s{ |
|
|
886 | ($match) |
|
|
887 | }{ |
|
|
888 | my $kw = $1; |
|
|
889 | |
|
|
890 | push @link, new CFClient::UI::Label |
|
|
891 | markup => "<span foreground='#c0c0ff' underline='single'>$kw</span>", |
|
|
892 | can_hover => 1, |
|
|
893 | can_events => 1, |
|
|
894 | padding_x => 0, |
|
|
895 | padding_y => 0, |
|
|
896 | on_button_up => sub { |
|
|
897 | $self->send ($kw); |
|
|
898 | }; |
|
|
899 | |
|
|
900 | chr 0xfffc |
|
|
901 | }giex; |
816 | |
902 | |
817 | $self->{textview}->add_paragraph ([1, 1, 1, 1], "\n$msg"); |
903 | $self->{textview}->add_paragraph ([1, 1, 1, 1], [$msg, @link]); |
|
|
904 | $self->{textview}->scroll_to_bottom; |
818 | $self->update_options; |
905 | $self->update_options; |
819 | } else { |
906 | } else { |
820 | $self->destroy; |
907 | $self->destroy; |
821 | } |
908 | } |
822 | |
909 | |
… | |
… | |
826 | sub send { |
913 | sub send { |
827 | my ($self, $msg) = @_; |
914 | my ($self, $msg) = @_; |
828 | |
915 | |
829 | $self->{conn}->send ("ext npc_dialog_tell $self->{token} $msg"); |
916 | $self->{conn}->send ("ext npc_dialog_tell $self->{token} $msg"); |
830 | $self->{textview}->add_paragraph ([1, 1, 0, 1], "\n" . CFClient::UI::Label::escape $msg); |
917 | $self->{textview}->add_paragraph ([1, 1, 0, 1], "\n" . CFClient::UI::Label::escape $msg); |
|
|
918 | $self->{textview}->scroll_to_bottom; |
831 | } |
919 | } |
832 | |
920 | |
833 | sub destroy { |
921 | sub destroy { |
834 | my ($self) = @_; |
922 | my ($self) = @_; |
835 | |
923 | |
836 | #Carp::cluck "debug\n";#d# #todo# enable: destroyx gets called twice because scalar keys {} is 1 |
924 | #Carp::cluck "debug\n";#d# #todo# enable: destroy gets called twice because scalar keys {} is 1 |
837 | |
925 | |
838 | delete $self->{conn}{npc_dialog}; |
926 | delete $self->{conn}{npc_dialog}; |
839 | $self->{conn}->disconnect_ext ($self->{token}); |
927 | $self->{conn}->disconnect_ext ($self->{token}); |
840 | |
928 | |
841 | $self->SUPER::destroy; |
929 | $self->SUPER::destroy; |