… | |
… | |
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 | |
… | |
… | |
160 | |
158 | |
161 | $self->flush_map; |
159 | $self->flush_map; |
162 | delete $self->{neigh_map}; |
160 | delete $self->{neigh_map}; |
163 | |
161 | |
164 | $self->{map}->clear; |
162 | $self->{map}->clear; |
|
|
163 | delete $self->{map_widget}{magicmap}; |
165 | } |
164 | } |
166 | |
165 | |
167 | |
166 | |
168 | sub load_map($$$) { |
167 | sub load_map($$$) { |
169 | my ($self, $hash, $x, $y) = @_; |
168 | my ($self, $hash, $x, $y) = @_; |
… | |
… | |
413 | |
412 | |
414 | $text = CFClient::UI::Label::escape $text; |
413 | $text = CFClient::UI::Label::escape $text; |
415 | $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g; |
414 | $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g; |
416 | $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g; |
415 | $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g; |
417 | |
416 | |
418 | $self->{logview}->add_paragraph ($color[$color], |
417 | $self->{logview}->add_paragraph ($color[$color], $_) |
419 | join "\n", map "$time $_", split /\n/, $text); |
418 | for map "$time $_", split /\n/, $text; |
|
|
419 | $self->{logview}->scroll_to_bottom; |
420 | |
420 | |
421 | $self->{statusbox}->add ($text, |
421 | $self->{statusbox}->add ($text, |
422 | group => $text, |
422 | group => $text, |
423 | fg => $color[$color], |
423 | fg => $color[$color], |
424 | timeout => $color >= 2 ? 60 : 10, |
424 | timeout => $color >= 2 ? 60 : 10, |
… | |
… | |
536 | |
536 | |
537 | $row++; |
537 | $row++; |
538 | } else { |
538 | } else { |
539 | $::FLOORBOX->add (1, $row, new CFClient::UI::Button |
539 | $::FLOORBOX->add (1, $row, new CFClient::UI::Button |
540 | text => "More...", |
540 | text => "More...", |
541 | on_activate => sub { $::INV_WINDOW->toggle_visibility }, |
541 | on_activate => sub { $::INV_WINDOW->toggle_visibility; 0 }, |
542 | ); |
542 | ); |
543 | last; |
543 | last; |
544 | } |
544 | } |
545 | } |
545 | } |
546 | }); |
546 | }); |
… | |
… | |
561 | tooltip => "Close the currently open container (if one is open)", |
561 | tooltip => "Close the currently open container (if one is open)", |
562 | on_activate => sub { |
562 | on_activate => sub { |
563 | $::CONN->send ("apply $tag") # $::CONN->{open_container}") |
563 | $::CONN->send ("apply $tag") # $::CONN->{open_container}") |
564 | if $tag != 0; |
564 | if $tag != 0; |
565 | #if $CONN->{open_container} != 0; |
565 | #if $CONN->{open_container} != 0; |
|
|
566 | 0 |
566 | }, |
567 | }, |
567 | ); |
568 | ); |
568 | } |
569 | } |
569 | |
570 | |
570 | $::INVR->set_items ($conn->{container}{$tag}); |
571 | $::INVR->set_items ($conn->{container}{$tag}); |
… | |
… | |
584 | |
585 | |
585 | if ($tag == 0) { |
586 | if ($tag == 0) { |
586 | update_floorbox; |
587 | update_floorbox; |
587 | update_container (0); |
588 | update_container (0); |
588 | } elsif ($tag == $self->{player}{tag}) { |
589 | } elsif ($tag == $self->{player}{tag}) { |
|
|
590 | $::STATWIDS->{weight}->set_text (sprintf "Weight: %.1fkg", $self->{player}->{weight} / 1000); |
589 | $::INV->set_items ($self->{container}{$self->{player}{tag}}) |
591 | $::INV->set_items ($self->{container}{$self->{player}{tag}}) |
590 | } else { |
592 | } else { |
591 | update_container ($tag); |
593 | update_container ($tag); |
592 | } |
594 | } |
593 | |
595 | |
… | |
… | |
762 | |
764 | |
763 | return unless $text =~ /\S/; |
765 | return unless $text =~ /\S/; |
764 | |
766 | |
765 | $entry->set_text (""); |
767 | $entry->set_text (""); |
766 | $this->send ($text); |
768 | $this->send ($text); |
|
|
769 | |
|
|
770 | 0 |
767 | }, |
771 | }, |
768 | ); |
772 | ); |
769 | |
773 | |
770 | $vbox->add ($self->{options} = new CFClient::UI::VBox); |
774 | $vbox->add ($self->{options} = new CFClient::UI::VBox); |
771 | |
775 | |
772 | $self->{close_button} = new CFClient::UI::Button |
776 | $self->{bye_button} = new CFClient::UI::Button |
773 | text => "Bye (close)", |
777 | text => "Bye (close)", |
774 | 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.", |
775 | on_activate => sub { $this->destroy }, |
779 | on_activate => sub { $this->destroy; 0 }, |
776 | ; |
780 | ; |
777 | |
781 | |
778 | $self->update_options; |
782 | $self->update_options; |
779 | |
783 | |
780 | $self->{token} = $self->{conn}->ext_token; |
784 | $self->{token} = $self->{conn}->ext_token; |
781 | $self->{conn}->connect_ext ($self->{token} => sub { $this->feed (@_) }); |
785 | $self->{conn}->connect_ext ($self->{token} => sub { $this->feed (@_) }); |
782 | $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}"); |
783 | |
787 | |
784 | $self->{entry}->focus_in; |
788 | $self->{entry}->grab_focus; |
785 | |
789 | |
786 | $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"); |
787 | |
791 | |
788 | $self->show; |
792 | $self->show; |
789 | $self |
793 | $self |
… | |
… | |
793 | my ($self) = @_; |
797 | my ($self) = @_; |
794 | |
798 | |
795 | Scalar::Util::weaken $self; |
799 | Scalar::Util::weaken $self; |
796 | |
800 | |
797 | $self->{options}->clear; |
801 | $self->{options}->clear; |
798 | $self->{options}->add ($self->{close_button}); |
802 | $self->{options}->add ($self->{bye_button}); |
799 | |
803 | |
800 | for my $kw (sort keys %{ $self->{kw} }) { |
804 | for my $kw (sort keys %{ $self->{kw} }) { |
801 | $self->{options}->add (new CFClient::UI::Button |
805 | $self->{options}->add (new CFClient::UI::Button |
802 | text => $kw, |
806 | text => $kw, |
803 | on_activate => sub { |
807 | on_activate => sub { |
804 | $self->send ($kw); |
808 | $self->send ($kw); |
|
|
809 | 0 |
805 | }, |
810 | }, |
806 | ); |
811 | ); |
807 | } |
812 | } |
808 | } |
813 | } |
809 | |
814 | |
810 | sub feed { |
815 | sub feed { |
811 | my ($self, $data) = @_; |
816 | my ($self, $data) = @_; |
|
|
817 | |
|
|
818 | Scalar::Util::weaken $self; |
812 | |
819 | |
813 | my ($type, $msg) = split / /, $data, 2; |
820 | my ($type, $msg) = split / /, $data, 2; |
814 | |
821 | |
815 | if ($type eq "msg") { |
822 | if ($type eq "msg") { |
816 | my ($msg, @kw) = split /\x00/, $msg; |
823 | my ($msg, @kw) = split /\x00/, $msg; |
817 | $self->{kw}{$_} = 1 for @kw; |
824 | $self->{kw}{$_} = 1 for @kw; |
818 | |
825 | |
819 | $msg = CFClient::UI::Label::escape $msg; |
826 | $msg = "\n" . CFClient::UI::Label::escape $msg; |
820 | 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} }; |
821 | $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; |
822 | |
846 | |
823 | $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; |
824 | $self->update_options; |
849 | $self->update_options; |
825 | } else { |
850 | } else { |
826 | $self->destroy; |
851 | $self->destroy; |
827 | } |
852 | } |
828 | |
853 | |
… | |
… | |
832 | sub send { |
857 | sub send { |
833 | my ($self, $msg) = @_; |
858 | my ($self, $msg) = @_; |
834 | |
859 | |
835 | $self->{conn}->send ("ext npc_dialog_tell $self->{token} $msg"); |
860 | $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); |
861 | $self->{textview}->add_paragraph ([1, 1, 0, 1], "\n" . CFClient::UI::Label::escape $msg); |
|
|
862 | $self->{textview}->scroll_to_bottom; |
837 | } |
863 | } |
838 | |
864 | |
839 | sub destroy { |
865 | sub destroy { |
840 | my ($self) = @_; |
866 | my ($self) = @_; |
841 | |
867 | |
842 | #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 |
843 | |
869 | |
844 | delete $self->{conn}{npc_dialog}; |
870 | delete $self->{conn}{npc_dialog}; |
845 | $self->{conn}->disconnect_ext ($self->{token}); |
871 | $self->{conn}->disconnect_ext ($self->{token}); |
846 | |
872 | |
847 | $self->SUPER::destroy; |
873 | $self->SUPER::destroy; |