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