… | |
… | |
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 | |
|
|
89 | |
|
|
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}) { |
94 | my $diff = $exp - $self->{prev_exp}; |
92 | my $diff = $exp - $self->{prev_exp}; |
… | |
… | |
107 | push @{$self->{record}}, $command; |
105 | push @{$self->{record}}, $command; |
108 | } |
106 | } |
109 | |
107 | |
110 | $self->logprint ("send: ", $command); |
108 | $self->logprint ("send: ", $command); |
111 | $self->send_command ($command); |
109 | $self->send_command ($command); |
112 | ::status $command; |
110 | ::status ($command); |
113 | } |
111 | } |
114 | |
112 | |
115 | sub start_record { |
113 | sub start_record { |
116 | my ($self) = @_; |
114 | my ($self) = @_; |
117 | |
115 | |
… | |
… | |
132 | sub feed_map1a { |
130 | sub feed_map1a { |
133 | my ($self, $data) = @_; |
131 | my ($self, $data) = @_; |
134 | |
132 | |
135 | $self->{map}->map1a_update ($data); |
133 | $self->{map}->map1a_update ($data); |
136 | $self->{map_widget}->update; |
134 | $self->{map_widget}->update; |
|
|
135 | } |
|
|
136 | |
|
|
137 | sub magicmap { |
|
|
138 | my ($self, $w, $h, $x, $y, $data) = @_; |
|
|
139 | |
|
|
140 | $self->{map_widget}->set_magicmap ($w, $h, $x, $y, $data); |
137 | } |
141 | } |
138 | |
142 | |
139 | sub flush_map { |
143 | sub flush_map { |
140 | my ($self) = @_; |
144 | my ($self) = @_; |
141 | |
145 | |
… | |
… | |
154 | |
158 | |
155 | $self->flush_map; |
159 | $self->flush_map; |
156 | delete $self->{neigh_map}; |
160 | delete $self->{neigh_map}; |
157 | |
161 | |
158 | $self->{map}->clear; |
162 | $self->{map}->clear; |
|
|
163 | delete $self->{map_widget}{magicmap}; |
159 | } |
164 | } |
160 | |
165 | |
161 | |
166 | |
162 | sub load_map($$$) { |
167 | sub load_map($$$) { |
163 | my ($self, $hash, $x, $y) = @_; |
168 | my ($self, $hash, $x, $y) = @_; |
… | |
… | |
407 | |
412 | |
408 | $text = CFClient::UI::Label::escape $text; |
413 | $text = CFClient::UI::Label::escape $text; |
409 | $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g; |
414 | $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g; |
410 | $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g; |
415 | $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g; |
411 | |
416 | |
412 | $self->{logview}->add_paragraph ($color[$color], |
417 | $self->{logview}->add_paragraph ($color[$color], $_) |
413 | join "\n", map "$time $_", split /\n/, $text); |
418 | for map "$time $_", split /\n/, $text; |
|
|
419 | $self->{logview}->scroll_to_bottom; |
414 | |
420 | |
415 | $self->{statusbox}->add ($text, |
421 | $self->{statusbox}->add ($text, |
416 | group => $text, |
422 | group => $text, |
417 | fg => $color[$color], |
423 | fg => $color[$color], |
418 | timeout => $color >= 2 ? 60 : 10, |
424 | timeout => $color >= 2 ? 60 : 10, |
… | |
… | |
530 | |
536 | |
531 | $row++; |
537 | $row++; |
532 | } else { |
538 | } else { |
533 | $::FLOORBOX->add (1, $row, new CFClient::UI::Button |
539 | $::FLOORBOX->add (1, $row, new CFClient::UI::Button |
534 | text => "More...", |
540 | text => "More...", |
535 | on_activate => sub { $::INV_WINDOW->toggle_visibility }, |
541 | on_activate => sub { $::INV_WINDOW->toggle_visibility; 0 }, |
536 | ); |
542 | ); |
537 | last; |
543 | last; |
538 | } |
544 | } |
539 | } |
545 | } |
540 | }); |
546 | }); |
… | |
… | |
555 | tooltip => "Close the currently open container (if one is open)", |
561 | tooltip => "Close the currently open container (if one is open)", |
556 | on_activate => sub { |
562 | on_activate => sub { |
557 | $::CONN->send ("apply $tag") # $::CONN->{open_container}") |
563 | $::CONN->send ("apply $tag") # $::CONN->{open_container}") |
558 | if $tag != 0; |
564 | if $tag != 0; |
559 | #if $CONN->{open_container} != 0; |
565 | #if $CONN->{open_container} != 0; |
|
|
566 | 0 |
560 | }, |
567 | }, |
561 | ); |
568 | ); |
562 | } |
569 | } |
563 | |
570 | |
564 | $::INVR->set_items ($conn->{container}{$tag}); |
571 | $::INVR->set_items ($conn->{container}{$tag}); |
… | |
… | |
578 | |
585 | |
579 | if ($tag == 0) { |
586 | if ($tag == 0) { |
580 | update_floorbox; |
587 | update_floorbox; |
581 | update_container (0); |
588 | update_container (0); |
582 | } elsif ($tag == $self->{player}{tag}) { |
589 | } elsif ($tag == $self->{player}{tag}) { |
|
|
590 | $::STATWIDS->{weight}->set_text (sprintf "Weight: %.1fkg", $self->{player}->{weight} / 1000); |
583 | $::INV->set_items ($self->{container}{$self->{player}{tag}}) |
591 | $::INV->set_items ($self->{container}{$self->{player}{tag}}) |
584 | } else { |
592 | } else { |
585 | update_container ($tag); |
593 | update_container ($tag); |
586 | } |
594 | } |
587 | |
595 | |
… | |
… | |
756 | |
764 | |
757 | return unless $text =~ /\S/; |
765 | return unless $text =~ /\S/; |
758 | |
766 | |
759 | $entry->set_text (""); |
767 | $entry->set_text (""); |
760 | $this->send ($text); |
768 | $this->send ($text); |
|
|
769 | |
|
|
770 | 0 |
761 | }, |
771 | }, |
762 | ); |
772 | ); |
763 | |
773 | |
764 | $vbox->add ($self->{options} = new CFClient::UI::VBox); |
774 | $vbox->add ($self->{options} = new CFClient::UI::VBox); |
765 | |
775 | |
766 | $self->{close_button} = new CFClient::UI::Button |
776 | $self->{bye_button} = new CFClient::UI::Button |
767 | text => "Bye (close)", |
777 | text => "Bye (close)", |
768 | tooltip => "Use this button to end talking to the NPC. This also closes the dialog window.", |
778 | tooltip => "Use this button to end talking to the NPC. This also closes the dialog window.", |
769 | on_activate => sub { $this->destroy }, |
779 | on_activate => sub { $this->destroy; 0 }, |
770 | ; |
780 | ; |
771 | |
781 | |
772 | $self->update_options; |
782 | $self->update_options; |
773 | |
783 | |
774 | $self->{token} = $self->{conn}->ext_token; |
784 | $self->{token} = $self->{conn}->ext_token; |
775 | $self->{conn}->connect_ext ($self->{token} => sub { $this->feed (@_) }); |
785 | $self->{conn}->connect_ext ($self->{token} => sub { $this->feed (@_) }); |
776 | $self->{conn}->send ("ext npc_dialog_begin $self->{token} $self->{dx} $self->{dy}"); |
786 | $self->{conn}->send ("ext npc_dialog_begin $self->{token} $self->{dx} $self->{dy}"); |
777 | |
787 | |
778 | $self->{entry}->focus_in; |
788 | $self->{entry}->grab_focus; |
779 | |
789 | |
780 | $self->{textview}->add_paragraph ([1, 1, 0, 1], "<small>[starting conversation with <b>$self->{title}</b>]</small>\n\n"); |
790 | $self->{textview}->add_paragraph ([1, 1, 0, 1], "<small>[starting conversation with <b>$self->{title}</b>]</small>\n\n"); |
781 | |
791 | |
782 | $self->show; |
792 | $self->show; |
783 | $self |
793 | $self |
… | |
… | |
787 | my ($self) = @_; |
797 | my ($self) = @_; |
788 | |
798 | |
789 | Scalar::Util::weaken $self; |
799 | Scalar::Util::weaken $self; |
790 | |
800 | |
791 | $self->{options}->clear; |
801 | $self->{options}->clear; |
792 | $self->{options}->add ($self->{close_button}); |
802 | $self->{options}->add ($self->{bye_button}); |
793 | |
803 | |
794 | for my $kw (sort keys %{ $self->{kw} }) { |
804 | for my $kw (sort keys %{ $self->{kw} }) { |
795 | $self->{options}->add (new CFClient::UI::Button |
805 | $self->{options}->add (new CFClient::UI::Button |
796 | text => $kw, |
806 | text => $kw, |
797 | on_activate => sub { |
807 | on_activate => sub { |
798 | $self->send ($kw); |
808 | $self->send ($kw); |
|
|
809 | 0 |
799 | }, |
810 | }, |
800 | ); |
811 | ); |
801 | } |
812 | } |
802 | } |
813 | } |
803 | |
814 | |
804 | sub feed { |
815 | sub feed { |
805 | my ($self, $data) = @_; |
816 | my ($self, $data) = @_; |
|
|
817 | |
|
|
818 | Scalar::Util::weaken $self; |
806 | |
819 | |
807 | my ($type, $msg) = split / /, $data, 2; |
820 | my ($type, $msg) = split / /, $data, 2; |
808 | |
821 | |
809 | if ($type eq "msg") { |
822 | if ($type eq "msg") { |
810 | my ($msg, @kw) = split /\x00/, $msg; |
823 | my ($msg, @kw) = split /\x00/, $msg; |
811 | $self->{kw}{$_} = 1 for @kw; |
824 | $self->{kw}{$_} = 1 for @kw; |
812 | |
825 | |
813 | $msg = CFClient::UI::Label::escape $msg; |
826 | $msg = "\n" . CFClient::UI::Label::escape $msg; |
814 | my $match = join "|", map "\\b\Q$_\E\\b", sort { (length $b) <=> (length $a) } keys %{ $self->{kw} }; |
827 | 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. |
828 | my @link; |
|
|
829 | $msg =~ s{ |
|
|
830 | ($match) |
|
|
831 | }{ |
|
|
832 | my $kw = $1; |
|
|
833 | |
|
|
834 | push @link, new CFClient::UI::Label |
|
|
835 | markup => "<span foreground='#c0c0ff' underline='single'>$kw</span>", |
|
|
836 | can_hover => 1, |
|
|
837 | can_events => 1, |
|
|
838 | padding_x => 0, |
|
|
839 | padding_y => 0, |
|
|
840 | on_button_up => sub { |
|
|
841 | $self->send ($kw); |
|
|
842 | }; |
|
|
843 | |
|
|
844 | chr 0xfffc |
|
|
845 | }giex; |
816 | |
846 | |
817 | $self->{textview}->add_paragraph ([1, 1, 1, 1], "\n$msg"); |
847 | $self->{textview}->add_paragraph ([1, 1, 1, 1], [$msg, @link]); |
|
|
848 | $self->{textview}->scroll_to_bottom; |
818 | $self->update_options; |
849 | $self->update_options; |
819 | } else { |
850 | } else { |
820 | $self->destroy; |
851 | $self->destroy; |
821 | } |
852 | } |
822 | |
853 | |
… | |
… | |
826 | sub send { |
857 | sub send { |
827 | my ($self, $msg) = @_; |
858 | my ($self, $msg) = @_; |
828 | |
859 | |
829 | $self->{conn}->send ("ext npc_dialog_tell $self->{token} $msg"); |
860 | $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); |
861 | $self->{textview}->add_paragraph ([1, 1, 0, 1], "\n" . CFClient::UI::Label::escape $msg); |
|
|
862 | $self->{textview}->scroll_to_bottom; |
831 | } |
863 | } |
832 | |
864 | |
833 | sub destroy { |
865 | sub destroy { |
834 | my ($self) = @_; |
866 | my ($self) = @_; |
835 | |
867 | |
836 | #Carp::cluck "debug\n";#d# #todo# enable: destroyx gets called twice because scalar keys {} is 1 |
868 | #Carp::cluck "debug\n";#d# #todo# enable: destroy gets called twice because scalar keys {} is 1 |
837 | |
869 | |
838 | delete $self->{conn}{npc_dialog}; |
870 | delete $self->{conn}{npc_dialog}; |
839 | $self->{conn}->disconnect_ext ($self->{token}); |
871 | $self->{conn}->disconnect_ext ($self->{token}); |
840 | |
872 | |
841 | $self->SUPER::destroy; |
873 | $self->SUPER::destroy; |