… | |
… | |
625 | my ($self, $player) = @_; |
625 | my ($self, $player) = @_; |
626 | |
626 | |
627 | $::STATWIDS->{weight}->set_text (sprintf "Weight: %.1fkg", $player->{weight} / 1000); |
627 | $::STATWIDS->{weight}->set_text (sprintf "Weight: %.1fkg", $player->{weight} / 1000); |
628 | } |
628 | } |
629 | |
629 | |
|
|
630 | sub update_server_info { |
|
|
631 | my ($self) = @_; |
|
|
632 | |
|
|
633 | my @yesno = ("<span foreground='red'>no</span>", "<span foreground='green'>yes</span>"); |
|
|
634 | |
|
|
635 | $::SERVER_INFO->set_markup ( |
|
|
636 | "server <tt>$self->{host}:$self->{port}</tt>\n" |
|
|
637 | . "protocol version <tt>$self->{version}</tt>\n" |
|
|
638 | . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n" |
|
|
639 | . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n" |
|
|
640 | . "cfplus support $yesno[$self->{cfplus_ext} > 0]" |
|
|
641 | . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" |
|
|
642 | . "map size $self->{mapw}×$self->{maph}\n" |
|
|
643 | ); |
|
|
644 | } |
|
|
645 | |
630 | sub logged_in { |
646 | sub logged_in { |
631 | my ($self) = @_; |
647 | my ($self) = @_; |
632 | |
648 | |
633 | $self->send_ext_req (cfplus => "version", "1", sub { |
649 | $self->send_ext_req (cfplus_support => "1", sub { |
634 | $self->{cfplus_ext} = $_[0]; |
650 | $self->{cfplus_ext} = $_[0]; |
635 | |
651 | $self->update_server_info; |
636 | my @yesno = ("<span foreground='red'>no</span>", "<span foreground='green'>yes</span>"); |
|
|
637 | |
|
|
638 | $::SERVER_INFO->set_markup ( |
|
|
639 | "server <tt>$self->{host}:$self->{port}</tt>\n" |
|
|
640 | . "protocol version <tt>$self->{version}</tt>\n" |
|
|
641 | . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n" |
|
|
642 | . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n" |
|
|
643 | . "cfplus support $yesno[$self->{cfplus_ext} > 0]\n" |
|
|
644 | . "map size $self->{mapw}×$self->{maph}\n" |
|
|
645 | ); |
|
|
646 | }); |
652 | }); |
|
|
653 | |
|
|
654 | $self->update_server_info; |
647 | |
655 | |
648 | $self->send_command ("output-sync $::CFG->{output_sync}"); |
656 | $self->send_command ("output-sync $::CFG->{output_sync}"); |
649 | $self->send_command ("output-count $::CFG->{output_count}"); |
657 | $self->send_command ("output-count $::CFG->{output_count}"); |
650 | $self->send_command ("pickup $::CFG->{pickup}"); |
658 | $self->send_command ("pickup $::CFG->{pickup}"); |
651 | } |
659 | } |
652 | |
660 | |
|
|
661 | sub lookat { |
|
|
662 | my ($self, $x, $y) = @_; |
|
|
663 | |
|
|
664 | if ($self->{cfplus_ext}) { |
|
|
665 | $self->send_ext_req (lookat => "$x $y", sub { |
|
|
666 | my %res = split /\x00/, $_[0]; |
|
|
667 | |
|
|
668 | if (exists $res{npc_dialog}) { |
|
|
669 | # start npc chat dialog |
|
|
670 | $self->{npc_dialog} = new CFClient::NPCDialog:: |
|
|
671 | dx => $x, |
|
|
672 | dy => $y, |
|
|
673 | title => "$res{npc_dialog} (NPC)", |
|
|
674 | conn => $self, |
|
|
675 | ; |
|
|
676 | } |
|
|
677 | }); |
|
|
678 | } |
|
|
679 | |
|
|
680 | $self->send ("lookat $x $y"); |
|
|
681 | } |
|
|
682 | |
|
|
683 | sub destroy { |
|
|
684 | my ($self) = @_; |
|
|
685 | |
|
|
686 | $self->{npc_dialog}->destroy |
|
|
687 | if $self->{npc_dialog}; |
|
|
688 | |
|
|
689 | $self->SUPER::destroy; |
|
|
690 | } |
|
|
691 | |
|
|
692 | package CFClient::NPCDialog; |
|
|
693 | |
|
|
694 | our @ISA = 'CFClient::UI::FancyFrame'; |
|
|
695 | |
|
|
696 | sub new { |
|
|
697 | my $class = shift; |
|
|
698 | |
|
|
699 | my $self = $class->SUPER::new ( |
|
|
700 | x => 'center', |
|
|
701 | y => 'center', |
|
|
702 | name => "npc_dialog", |
|
|
703 | force_w => $::WIDTH * 0.7, |
|
|
704 | force_h => $::HEIGHT * 0.7, |
|
|
705 | title => "NPC Dialog", |
|
|
706 | kw => { hi => 0, yes => 0, no => 0 }, |
|
|
707 | @_, |
|
|
708 | ); |
|
|
709 | |
|
|
710 | Scalar::Util::weaken (my $this = $self); |
|
|
711 | |
|
|
712 | # better use a pane... |
|
|
713 | $self->add (my $hbox = new CFClient::UI::HBox); |
|
|
714 | $hbox->add ($self->{textview} = new CFClient::UI::TextScroller expand => 1); |
|
|
715 | |
|
|
716 | $hbox->add (my $vbox = new CFClient::UI::VBox); |
|
|
717 | |
|
|
718 | $vbox->add (new CFClient::UI::Label text => "Message Entry:"); |
|
|
719 | $vbox->add ($self->{entry} = new CFClient::UI::Entry |
|
|
720 | tooltip => "Enter a message you want to tell the NPC and press <b>return</b>.\n\n" |
|
|
721 | . "Sometimes you have to tell an NPC something you cannot find out during " |
|
|
722 | . "a normal conversation (such as a password). In those cases you have to use " |
|
|
723 | . "this text entry. You can also enter responses manually instead of using the response " |
|
|
724 | . "buttons below.", |
|
|
725 | on_activate => sub { |
|
|
726 | my ($entry, $text) = @_; |
|
|
727 | |
|
|
728 | return unless $text =~ /\S/; |
|
|
729 | |
|
|
730 | $entry->set_text (""); |
|
|
731 | $this->send ($text); |
|
|
732 | }, |
|
|
733 | ); |
|
|
734 | |
|
|
735 | $vbox->add ($self->{options} = new CFClient::UI::VBox); |
|
|
736 | |
|
|
737 | $self->{close_button} = new CFClient::UI::Button |
|
|
738 | text => "Bye (close)", |
|
|
739 | tooltip => "Use this button to end talking to the NPC. This also closes the dialog window.", |
|
|
740 | on_activate => sub { $this->destroy }, |
|
|
741 | ; |
|
|
742 | |
|
|
743 | $self->update_options; |
|
|
744 | |
|
|
745 | $self->{token} = $self->{conn}->ext_token; |
|
|
746 | $self->{conn}->connect_ext ($self->{token} => sub { $this->feed (@_) }); |
|
|
747 | $self->{conn}->send ("ext npc_dialog_begin $self->{token} $self->{dx} $self->{dy}"); |
|
|
748 | |
|
|
749 | $self->{entry}->focus_in; |
|
|
750 | |
|
|
751 | $self->{textview}->add_paragraph ([1, 1, 0, 1], "<small>[starting conversation with <b>$self->{title}</b>]</small>\n\n"); |
|
|
752 | |
|
|
753 | $self->show; |
|
|
754 | $self |
|
|
755 | }; |
|
|
756 | |
|
|
757 | sub update_options { |
|
|
758 | my ($self) = @_; |
|
|
759 | |
|
|
760 | Scalar::Util::weaken $self; |
|
|
761 | |
|
|
762 | $self->{options}->clear; |
|
|
763 | $self->{options}->add ($self->{close_button}); |
|
|
764 | |
|
|
765 | for my $kw (sort keys %{ $self->{kw} }) { |
|
|
766 | $self->{options}->add (new CFClient::UI::Button |
|
|
767 | text => $kw, |
|
|
768 | on_activate => sub { |
|
|
769 | $self->send ($kw); |
|
|
770 | }, |
|
|
771 | ); |
|
|
772 | } |
|
|
773 | } |
|
|
774 | |
|
|
775 | sub feed { |
|
|
776 | my ($self, $data) = @_; |
|
|
777 | |
|
|
778 | my ($type, $msg) = split / /, $data, 2; |
|
|
779 | |
|
|
780 | if ($type eq "msg") { |
|
|
781 | my ($msg, @kw) = split /\x00/, $msg; |
|
|
782 | $self->{kw}{$_} = 1 for @kw; |
|
|
783 | |
|
|
784 | warn "<<<<@kw>>>>\n";#d# |
|
|
785 | |
|
|
786 | $msg = CFClient::UI::Label::escape $msg; |
|
|
787 | my $match = join "|", map "\\b\Q$_\E\\b", sort { (length $b) <=> (length $a) } keys %{ $self->{kw} }; |
|
|
788 | $msg =~ s/($match)/<span foreground='#c0c0ff' underline='none'>$1<\/span>/gi; # underline when http-ready, huh. |
|
|
789 | |
|
|
790 | $self->{textview}->add_paragraph ([1, 1, 1, 1], "\n$msg"); |
|
|
791 | $self->update_options; |
|
|
792 | } else { |
|
|
793 | $self->destroy; |
|
|
794 | } |
|
|
795 | |
|
|
796 | 1 |
|
|
797 | } |
|
|
798 | |
|
|
799 | sub send { |
|
|
800 | my ($self, $msg) = @_; |
|
|
801 | |
|
|
802 | $self->{conn}->send ("ext npc_dialog_tell $self->{token} $msg"); |
|
|
803 | $self->{textview}->add_paragraph ([1, 1, 0, 1], "\n" . CFClient::UI::Label::escape $msg); |
|
|
804 | } |
|
|
805 | |
|
|
806 | sub destroy { |
|
|
807 | my ($self) = @_; |
|
|
808 | |
|
|
809 | #Carp::cluck "debug\n";#d# #todo# enable: destroyx gets called twice because scalar keys {} is 1 |
|
|
810 | |
|
|
811 | delete $self->{conn}{npc_dialog}; |
|
|
812 | $self->{conn}->disconnect_ext ($self->{token}); |
|
|
813 | |
|
|
814 | $self->SUPER::destroy; |
|
|
815 | } |
|
|
816 | |
653 | 1; |
817 | 1; |