… | |
… | |
5 | |
5 | |
6 | use Crossfire::Protocol::Constants; |
6 | use Crossfire::Protocol::Constants; |
7 | |
7 | |
8 | use CFClient; |
8 | use CFClient; |
9 | use CFClient::UI; |
9 | use CFClient::UI; |
|
|
10 | use CFClient::Pod; |
10 | |
11 | |
11 | use base 'Crossfire::Protocol::Base'; |
12 | use base 'Crossfire::Protocol::Base'; |
12 | |
13 | |
13 | sub new { |
14 | sub new { |
14 | my $class = shift; |
15 | my $class = shift; |
15 | |
16 | |
16 | my $self = $class->SUPER::new (@_); |
17 | my $self = $class->SUPER::new (@_); |
17 | |
18 | |
18 | $self->{map_widget}->clr_commands; |
19 | $self->{map_widget}->clr_commands; |
19 | |
20 | |
20 | my $cmd_help = CFClient::load_pod CFClient::find_rcfile "pod/command_help.pod", command_help => 1, sub { |
21 | my $cmd_help = CFClient::Pod::load CFClient::find_rcfile "pod/command_help.pod", command_help => 1, sub { |
21 | my ($pom) = @_; |
22 | my ($pom) = @_; |
22 | |
23 | |
23 | my @cmd_help; |
24 | my @cmd_help; |
24 | |
25 | |
25 | for my $head2 ($pom->head1->[-2]->head2) { |
26 | for my $head2 ($pom->head1->[-2]->head2) { |
… | |
… | |
31 | @args = (".*") unless @args; |
32 | @args = (".*") unless @args; |
32 | |
33 | |
33 | $_ = $_ eq ".*" ? "" : " $_" |
34 | $_ = $_ eq ".*" ? "" : " $_" |
34 | for @args; |
35 | for @args; |
35 | |
36 | |
36 | my $text = CFClient::pod_to_pango $head2->content; |
37 | my $text = CFClient::Pod::as_xml $head2->content; |
37 | |
38 | |
38 | push @cmd_help, ["$cmd$_", $text] |
39 | push @cmd_help, ["$cmd$_", $text] |
39 | for sort { (length $a) <=> (length $b) } |
40 | for sort { (length $a) <=> (length $b) } |
40 | @args; |
41 | @args; |
41 | } |
42 | } |
… | |
… | |
242 | $::STATWIDS->{st_dam} ->set_text (sprintf "%d" , $stats->{+CS_STAT_DAM}); |
243 | $::STATWIDS->{st_dam} ->set_text (sprintf "%d" , $stats->{+CS_STAT_DAM}); |
243 | $::STATWIDS->{st_arm} ->set_text (sprintf "%d" , $stats->{+CS_STAT_RES_PHYS}); |
244 | $::STATWIDS->{st_arm} ->set_text (sprintf "%d" , $stats->{+CS_STAT_RES_PHYS}); |
244 | $::STATWIDS->{st_spd} ->set_text (sprintf "%.1f", $stats->{+CS_STAT_SPEED}); |
245 | $::STATWIDS->{st_spd} ->set_text (sprintf "%.1f", $stats->{+CS_STAT_SPEED}); |
245 | $::STATWIDS->{st_wspd}->set_text (sprintf "%.1f", $stats->{+CS_STAT_WEAP_SP}); |
246 | $::STATWIDS->{st_wspd}->set_text (sprintf "%.1f", $stats->{+CS_STAT_WEAP_SP}); |
246 | |
247 | |
247 | $::STATWIDS->{m_weight}->set_text (sprintf "Max weight: %.1fkg", $stats->{+CS_STAT_WEIGHT_LIM} / 1000); |
248 | $self->update_weight; |
248 | |
249 | |
249 | $::STATWIDS->{"res_$_"}->set_text (sprintf "%d%", $stats->{$RES_TBL{$_}}) |
250 | $::STATWIDS->{"res_$_"}->set_text (sprintf "%d%", $stats->{$RES_TBL{$_}}) |
250 | for keys %RES_TBL; |
251 | for keys %RES_TBL; |
251 | |
252 | |
252 | my $sktbl = $::STATWIDS->{skill_tbl}; |
253 | my $sktbl = $::STATWIDS->{skill_tbl}; |
… | |
… | |
260 | $sktbl->add (2, 0, new CFClient::UI::Label text => "Skill", expand => 1); |
261 | $sktbl->add (2, 0, new CFClient::UI::Label text => "Skill", expand => 1); |
261 | $sktbl->add (3, 0, new CFClient::UI::Label text => "Experience", align => 1); |
262 | $sktbl->add (3, 0, new CFClient::UI::Label text => "Experience", align => 1); |
262 | $sktbl->add (4, 0, new CFClient::UI::Label text => "Lvl.", align => 1); |
263 | $sktbl->add (4, 0, new CFClient::UI::Label text => "Lvl.", align => 1); |
263 | $sktbl->add (5, 0, new CFClient::UI::Label text => "Skill", expand => 1); |
264 | $sktbl->add (5, 0, new CFClient::UI::Label text => "Skill", expand => 1); |
264 | |
265 | |
265 | my ($x, $y) = (0, 0); |
266 | my ($x, $y) = (0, 1); |
266 | for ( |
267 | for ( |
267 | sort { $stats->{$b->[0]}[1] <=> $stats->{$a->[0]}[1] or $a->[1] cmp $b->[1] } |
268 | sort { $stats->{$b->[0]}[1] <=> $stats->{$a->[0]}[1] or $a->[1] cmp $b->[1] } |
268 | map [$_, $self->{skill_info}{$_}], |
269 | map [$_, $self->{skill_info}{$_}], |
269 | grep exists $stats->{$_}, |
270 | grep exists $stats->{$_}, |
270 | @skills |
271 | @skills |
… | |
… | |
585 | [0.11, 0.56, 1.00], |
586 | [0.11, 0.56, 1.00], |
586 | [0.93, 0.46, 0.00], |
587 | [0.93, 0.46, 0.00], |
587 | [0.18, 0.54, 0.34], |
588 | [0.18, 0.54, 0.34], |
588 | [0.56, 0.73, 0.56], |
589 | [0.56, 0.73, 0.56], |
589 | [0.80, 0.80, 0.80], |
590 | [0.80, 0.80, 0.80], |
590 | [0.55, 0.41, 0.13], |
591 | [0.75, 0.61, 0.20], |
591 | [0.99, 0.77, 0.26], |
592 | [0.99, 0.77, 0.26], |
592 | [0.74, 0.65, 0.41], |
593 | [0.74, 0.65, 0.41], |
593 | ); |
594 | ); |
594 | |
595 | |
595 | $self->logprint ("info: ", $text); |
596 | $self->logprint ("info: ", $text); |
… | |
… | |
597 | my $time = sprintf "%02d:%02d:%02d", (localtime time)[2,1,0]; |
598 | my $time = sprintf "%02d:%02d:%02d", (localtime time)[2,1,0]; |
598 | |
599 | |
599 | # try to create single paragraphs of multiple lines sent by the server |
600 | # try to create single paragraphs of multiple lines sent by the server |
600 | $text =~ s/(?<=\S)\n(?=\w)/ /g; |
601 | $text =~ s/(?<=\S)\n(?=\w)/ /g; |
601 | |
602 | |
602 | $text = CFClient::UI::Label::escape $text; |
603 | $text = CFClient::asxml $text; |
603 | $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g; |
604 | $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g; |
604 | $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g; |
605 | $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g; |
605 | |
606 | |
606 | $self->{logview}->add_paragraph ($color[$color], $_) |
607 | $self->{logview}->add_paragraph ($color[$color], $_) |
607 | for map "$time $_", split /\n/, $text; |
608 | for map "<span foreground='#ffffff'>$time</span> $_", split /\n/, $text; |
608 | $self->{logview}->scroll_to_bottom; |
609 | $self->{logview}->scroll_to_bottom; |
609 | |
610 | |
610 | $self->{statusbox}->add ($text, |
611 | $self->{statusbox}->add ($text, |
611 | group => $text, |
612 | group => $text, |
612 | fg => $color[$color], |
613 | fg => $color[$color], |
… | |
… | |
629 | $spell->{message} =~ s/\n+$//; |
630 | $spell->{message} =~ s/\n+$//; |
630 | $spell->{message} ||= "Server did not provide a description for this spell."; |
631 | $spell->{message} ||= "Server did not provide a description for this spell."; |
631 | |
632 | |
632 | $::SPELL_PAGE->add_spell ($spell); |
633 | $::SPELL_PAGE->add_spell ($spell); |
633 | |
634 | |
634 | $self->{map_widget}->add_command ("invoke $spell->{name}", CFClient::UI::Label::escape $spell->{message}); |
635 | $self->{map_widget}->add_command ("invoke $spell->{name}", CFClient::asxml $spell->{message}); |
635 | $self->{map_widget}->add_command ("cast $spell->{name}", CFClient::UI::Label::escape $spell->{message}); |
636 | $self->{map_widget}->add_command ("cast $spell->{name}", CFClient::asxml $spell->{message}); |
636 | } |
637 | } |
637 | |
638 | |
638 | sub spell_delete { |
639 | sub spell_delete { |
639 | my ($self, $spell) = @_; |
640 | my ($self, $spell) = @_; |
640 | |
641 | |
… | |
… | |
642 | } |
643 | } |
643 | |
644 | |
644 | sub addme_success { |
645 | sub addme_success { |
645 | my ($self) = @_; |
646 | my ($self) = @_; |
646 | |
647 | |
647 | my $skill_help = CFClient::load_pod CFClient::find_rcfile "pod/skill_help.pod", skill_help => 1, sub { |
648 | my $skill_help = CFClient::Pod::load CFClient::find_rcfile "pod/skill_help.pod", skill_help => 1, sub { |
648 | my ($pom) = @_; |
649 | my ($pom) = @_; |
649 | |
650 | |
650 | my %skill_help; |
651 | my %skill_help; |
651 | |
652 | |
652 | for my $head2 ($pom->head1->[3]->head2) { |
653 | for my $head2 ($pom->head1->[3]->head2) { |
653 | $skill_help{$head2->title} = CFClient::pod_to_pango $head2->content; |
654 | $skill_help{$head2->title} = CFClient::Pod::as_xml $head2->content; |
654 | } |
655 | } |
655 | |
656 | |
656 | \%skill_help |
657 | \%skill_help |
657 | }; |
658 | }; |
658 | |
659 | |
659 | for my $skill (values %{$self->{skill_info}}) { |
660 | for my $skill (values %{$self->{skill_info}}) { |
660 | $self->{map_widget}->add_command ("ready_skill $skill", |
661 | $self->{map_widget}->add_command ("ready_skill $skill", |
661 | (CFClient::UI::Label::escape "Ready the skill '$skill'\n\n") |
662 | (CFClient::asxml "Ready the skill '$skill'\n\n") |
662 | . $skill_help->{$skill}); |
663 | . $skill_help->{$skill}); |
663 | $self->{map_widget}->add_command ("use_skill $skill", |
664 | $self->{map_widget}->add_command ("use_skill $skill", |
664 | (CFClient::UI::Label::escape "Immediately use the skill '$skill'\n\n") |
665 | (CFClient::asxml "Immediately use the skill '$skill'\n\n") |
665 | . $skill_help->{$skill}); |
666 | . $skill_help->{$skill}); |
666 | } |
667 | } |
667 | } |
668 | } |
668 | |
669 | |
669 | sub eof { |
670 | sub eof { |
… | |
… | |
694 | |
695 | |
695 | my ($face) = splice @{ $self->{face_prefetch} }, + rand @{ $self->{face_prefetch} }, 1, (); |
696 | my ($face) = splice @{ $self->{face_prefetch} }, + rand @{ $self->{face_prefetch} }, 1, (); |
696 | |
697 | |
697 | $self->send ("requestinfo image_sums $face $face"); |
698 | $self->send ("requestinfo image_sums $face $face"); |
698 | |
699 | |
699 | $self->{statusbox}->add (CFClient::UI::Label::escape "prefetching $todo", |
700 | $self->{statusbox}->add (CFClient::asxml "prefetching $todo", |
700 | group => "prefetch", timeout => 3, fg => [1, 1, 0, 0.5]); |
701 | group => "prefetch", timeout => 3, fg => [1, 1, 0, 0.5]); |
701 | } elsif (!exists $self->{num_faces}) { |
702 | } elsif (!exists $self->{num_faces}) { |
702 | $self->send ("requestinfo image_info"); |
703 | $self->send ("requestinfo image_info"); |
703 | |
704 | |
704 | $self->{num_faces} = 0; |
705 | $self->{num_faces} = 0; |
705 | |
706 | |
706 | $self->{statusbox}->add (CFClient::UI::Label::escape "starting to prefetch", |
707 | $self->{statusbox}->add (CFClient::asxml "starting to prefetch", |
707 | group => "prefetch", timeout => 3, fg => [1, 1, 0, 0.5]); |
708 | group => "prefetch", timeout => 3, fg => [1, 1, 0, 0.5]); |
708 | } |
709 | } |
709 | } |
710 | } |
710 | |
711 | |
711 | sub update_floorbox { |
712 | sub update_floorbox { |
712 | $CFClient::UI::ROOT->on_refresh ($::FLOORBOX => sub { |
713 | $CFClient::UI::ROOT->on_refresh ($::FLOORBOX => sub { |
713 | return unless $::CONN; |
714 | return unless $::CONN; |
714 | |
715 | |
715 | $::FLOORBOX->clear; |
716 | $::FLOORBOX->clear; |
716 | |
717 | |
717 | my $row; |
718 | my $row; |
718 | for (sort { $a->{count} <=> $b->{count} } values %{ $::CONN->{container}{0} }) { |
719 | for (sort { $a->{count} <=> $b->{count} } values %{ $::CONN->{container}{$::CONN->{open_container} || 0} }) { |
719 | if ($row < 6) { |
720 | if ($row < 6) { |
720 | local $_->{face_widget}; # hack to force recreation of widget |
721 | local $_->{face_widget}; # hack to force recreation of widget |
721 | local $_->{desc_widget}; # hack to force recreation of widget |
722 | local $_->{desc_widget}; # hack to force recreation of widget |
722 | CFClient::Item::update_widgets $_; |
723 | CFClient::Item::update_widgets $_; |
723 | |
724 | |
… | |
… | |
731 | on_activate => sub { ::toggle_player_page ($::INVENTORY_PAGE); 0 }, |
732 | on_activate => sub { ::toggle_player_page ($::INVENTORY_PAGE); 0 }, |
732 | ); |
733 | ); |
733 | last; |
734 | last; |
734 | } |
735 | } |
735 | } |
736 | } |
|
|
737 | if ($::CONN->{open_container}) { |
|
|
738 | $::FLOORBOX->add (1, $row++, new CFClient::UI::Button |
|
|
739 | text => "Close container", |
|
|
740 | on_activate => sub { $::CONN->send ("apply $::CONN->{open_container}") } |
|
|
741 | ); |
|
|
742 | } |
736 | }); |
743 | }); |
737 | |
744 | |
738 | $::WANT_REFRESH++; |
745 | $::WANT_REFRESH++; |
739 | } |
746 | } |
740 | |
747 | |
741 | sub set_opencont { |
748 | sub set_opencont { |
742 | my ($conn, $tag, $name) = @_; |
749 | my ($conn, $tag, $name) = @_; |
743 | $conn->{open_container} = $tag; |
750 | $conn->{open_container} = $tag; |
|
|
751 | update_floorbox; |
744 | |
752 | |
745 | $::INV_RIGHT_HB->clear (); |
753 | $::INV_RIGHT_HB->clear (); |
746 | $::INV_RIGHT_HB->add (new CFClient::UI::Label align => 0, expand => 1, text => $name); |
754 | $::INV_RIGHT_HB->add (new CFClient::UI::Label align => 0, expand => 1, text => $name); |
747 | |
755 | |
748 | if ($tag != 0) { # Floor isn't closable, is it? |
756 | if ($tag != 0) { # Floor isn't closable, is it? |
… | |
… | |
767 | $CFClient::UI::ROOT->on_refresh ("update_containers_$self" => sub { |
775 | $CFClient::UI::ROOT->on_refresh ("update_containers_$self" => sub { |
768 | my $todo = delete $self->{update_container} |
776 | my $todo = delete $self->{update_container} |
769 | or return; |
777 | or return; |
770 | |
778 | |
771 | for my $tag (keys %$todo) { |
779 | for my $tag (keys %$todo) { |
|
|
780 | update_floorbox if $tag == 0 or $tag == $self->{open_container}; |
772 | if ($tag == 0) { |
781 | if ($tag == 0) { |
773 | update_floorbox; |
|
|
774 | $::INVR->set_items ($self->{container}{0}) |
782 | $::INVR->set_items ($self->{container}{0}) |
775 | if $tag == $self->{open_container}; |
783 | if $tag == $self->{open_container}; |
776 | } elsif ($tag == $self->{player}{tag}) { |
784 | } elsif ($tag == $self->{player}{tag}) { |
777 | $::INV->set_items ($self->{container}{$tag}) |
785 | $::INV->set_items ($self->{container}{$tag}) |
778 | } else { |
786 | } else { |
… | |
… | |
825 | } |
833 | } |
826 | } |
834 | } |
827 | |
835 | |
828 | sub player_update { |
836 | sub player_update { |
829 | my ($self, $player) = @_; |
837 | my ($self, $player) = @_; |
|
|
838 | |
|
|
839 | $self->update_weight; |
|
|
840 | } |
|
|
841 | |
|
|
842 | sub update_weight { |
|
|
843 | my ($self) = @_; |
|
|
844 | |
|
|
845 | my $weight = .001 * $self->{player}{weight}; |
|
|
846 | my $limit = .001 * $self->{stat}{+CS_STAT_WEIGHT_LIM}; |
|
|
847 | |
830 | $::STATWIDS->{weight}->set_text (sprintf "Weight: %.1fkg", $player->{weight} / 1000); |
848 | $::STATWIDS->{weight}->set_text (sprintf "Weight: %.1fkg", $weight); |
|
|
849 | $::STATWIDS->{m_weight}->set_text (sprintf "%.1fkg", $limit); |
|
|
850 | $::STATWIDS->{i_weight}->set_text (sprintf "%.1f/%.1fkg", $weight, $limit); |
831 | } |
851 | } |
832 | |
852 | |
833 | sub update_server_info { |
853 | sub update_server_info { |
834 | my ($self) = @_; |
854 | my ($self) = @_; |
835 | |
855 | |
… | |
… | |
905 | name => "npc_dialog", |
925 | name => "npc_dialog", |
906 | force_w => $::WIDTH * 0.7, |
926 | force_w => $::WIDTH * 0.7, |
907 | force_h => $::HEIGHT * 0.7, |
927 | force_h => $::HEIGHT * 0.7, |
908 | title => "NPC Dialog", |
928 | title => "NPC Dialog", |
909 | kw => { hi => 0, yes => 0, no => 0 }, |
929 | kw => { hi => 0, yes => 0, no => 0 }, |
|
|
930 | has_close_button => 1, |
910 | @_, |
931 | @_, |
911 | ); |
932 | ); |
912 | |
933 | |
913 | Scalar::Util::weaken (my $this = $self); |
934 | Scalar::Util::weaken (my $this = $self); |
|
|
935 | |
|
|
936 | $self->connect (delete => sub { $this->destroy; 1 }); |
914 | |
937 | |
915 | # better use a pane... |
938 | # better use a pane... |
916 | $self->add (my $hbox = new CFClient::UI::HBox); |
939 | $self->add (my $hbox = new CFClient::UI::HBox); |
917 | $hbox->add ($self->{textview} = new CFClient::UI::TextScroller expand => 1); |
940 | $hbox->add ($self->{textview} = new CFClient::UI::TextScroller expand => 1); |
918 | |
941 | |
… | |
… | |
940 | $vbox->add ($self->{options} = new CFClient::UI::VBox); |
963 | $vbox->add ($self->{options} = new CFClient::UI::VBox); |
941 | |
964 | |
942 | $self->{bye_button} = new CFClient::UI::Button |
965 | $self->{bye_button} = new CFClient::UI::Button |
943 | text => "Bye (close)", |
966 | text => "Bye (close)", |
944 | tooltip => "Use this button to end talking to the NPC. This also closes the dialog window.", |
967 | tooltip => "Use this button to end talking to the NPC. This also closes the dialog window.", |
945 | on_activate => sub { $this->destroy; 0 }, |
968 | on_activate => sub { $this->destroy; 1 }, |
946 | ; |
969 | ; |
947 | |
970 | |
948 | $self->update_options; |
971 | $self->update_options; |
949 | |
972 | |
950 | $self->{token} = $self->{conn}->ext_token; |
973 | $self->{token} = $self->{conn}->ext_token; |
… | |
… | |
985 | |
1008 | |
986 | my ($type, $msg) = split / /, $data, 2; |
1009 | my ($type, $msg) = split / /, $data, 2; |
987 | |
1010 | |
988 | if ($type eq "msg") { |
1011 | if ($type eq "msg") { |
989 | my ($msg, @kw) = split /\x00/, $msg; |
1012 | my ($msg, @kw) = split /\x00/, $msg; |
|
|
1013 | |
|
|
1014 | utf8::decode $_ for ($msg, @kw); |
|
|
1015 | |
990 | $self->{kw}{$_} = 1 for @kw; |
1016 | $self->{kw}{$_} = 1 for @kw; |
991 | |
1017 | |
992 | $msg = "\n" . CFClient::UI::Label::escape $msg; |
1018 | $msg = "\n" . CFClient::UI::asxml $msg; |
993 | my $match = join "|", map "\\b\Q$_\E\\b", sort { (length $b) <=> (length $a) } keys %{ $self->{kw} }; |
1019 | my $match = join "|", map "\\b\Q$_\E\\b", sort { (length $b) <=> (length $a) } keys %{ $self->{kw} }; |
994 | my @link; |
1020 | my @link; |
995 | $msg =~ s{ |
1021 | $msg =~ s{ |
996 | ($match) |
1022 | ($match) |
997 | }{ |
1023 | }{ |
… | |
… | |
1021 | } |
1047 | } |
1022 | |
1048 | |
1023 | sub send { |
1049 | sub send { |
1024 | my ($self, $msg) = @_; |
1050 | my ($self, $msg) = @_; |
1025 | |
1051 | |
|
|
1052 | $self->{textview}->add_paragraph ([1, 1, 0, 1], "\n" . CFClient::asxml $msg); |
|
|
1053 | $self->{textview}->scroll_to_bottom; |
|
|
1054 | |
|
|
1055 | utf8::encode $msg; |
1026 | $self->{conn}->send ("ext npc_dialog_tell $self->{token} $msg"); |
1056 | $self->{conn}->send ("ext npc_dialog_tell $self->{token} $msg"); |
1027 | $self->{textview}->add_paragraph ([1, 1, 0, 1], "\n" . CFClient::UI::Label::escape $msg); |
|
|
1028 | $self->{textview}->scroll_to_bottom; |
|
|
1029 | } |
1057 | } |
1030 | |
1058 | |
1031 | sub destroy { |
1059 | sub destroy { |
1032 | my ($self) = @_; |
1060 | my ($self) = @_; |
1033 | |
1061 | |