ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/Protocol.pm
(Generate patch)

Comparing deliantra/Deliantra-Client/DC/Protocol.pm (file contents):
Revision 1.62 by elmex, Sat Jul 22 12:18:02 2006 UTC vs.
Revision 1.67 by root, Mon Jul 24 08:23:28 2006 UTC

5 5
6use Crossfire::Protocol::Constants; 6use Crossfire::Protocol::Constants;
7 7
8use CFClient; 8use CFClient;
9use CFClient::UI; 9use CFClient::UI;
10use CFClient::Pod;
10 11
11use base 'Crossfire::Protocol::Base'; 12use base 'Crossfire::Protocol::Base';
12 13
13sub new { 14sub 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_markup $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) = (1, 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
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 ({ fg => $color[$color], markup => $_ })
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],
622} 623}
623 624
624sub spell_add { 625sub spell_add {
625 my ($self, $spell) = @_; 626 my ($self, $spell) = @_;
626 627
627 # try to create single paragraphs of multiple lines sent by the server 628 # try to create single paragraphs out of the multiple lines sent by the server
628 $spell->{message} =~ s/(?<=\S)\n(?=\w)/ /g; 629 $spell->{message} =~ s/(?<=\S)\n(?=\w)/ /g;
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
638sub spell_delete { 639sub spell_delete {
639 my ($self, $spell) = @_; 640 my ($self, $spell) = @_;
640 641
642} 643}
643 644
644sub addme_success { 645sub 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_markup $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
669sub eof { 670sub 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
711sub update_floorbox { 712sub update_floorbox {
832 } 833 }
833} 834}
834 835
835sub player_update { 836sub player_update {
836 my ($self, $player) = @_; 837 my ($self, $player) = @_;
838
839 $self->update_weight;
840}
841
842sub update_weight {
843 my ($self) = @_;
844
845 my $weight = .001 * $self->{player}{weight};
846 my $limit = .001 * $self->{stat}{+CS_STAT_WEIGHT_LIM};
847
837 $::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);
838} 851}
839 852
840sub update_server_info { 853sub update_server_info {
841 my ($self) = @_; 854 my ($self) = @_;
842 855
912 name => "npc_dialog", 925 name => "npc_dialog",
913 force_w => $::WIDTH * 0.7, 926 force_w => $::WIDTH * 0.7,
914 force_h => $::HEIGHT * 0.7, 927 force_h => $::HEIGHT * 0.7,
915 title => "NPC Dialog", 928 title => "NPC Dialog",
916 kw => { hi => 0, yes => 0, no => 0 }, 929 kw => { hi => 0, yes => 0, no => 0 },
930 has_close_button => 1,
917 @_, 931 @_,
918 ); 932 );
919 933
920 Scalar::Util::weaken (my $this = $self); 934 Scalar::Util::weaken (my $this = $self);
935
936 $self->connect (delete => sub { $this->destroy; 1 });
921 937
922 # better use a pane... 938 # better use a pane...
923 $self->add (my $hbox = new CFClient::UI::HBox); 939 $self->add (my $hbox = new CFClient::UI::HBox);
924 $hbox->add ($self->{textview} = new CFClient::UI::TextScroller expand => 1); 940 $hbox->add ($self->{textview} = new CFClient::UI::TextScroller expand => 1);
925 941
947 $vbox->add ($self->{options} = new CFClient::UI::VBox); 963 $vbox->add ($self->{options} = new CFClient::UI::VBox);
948 964
949 $self->{bye_button} = new CFClient::UI::Button 965 $self->{bye_button} = new CFClient::UI::Button
950 text => "Bye (close)", 966 text => "Bye (close)",
951 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.",
952 on_activate => sub { $this->destroy; 0 }, 968 on_activate => sub { $this->destroy; 1 },
953 ; 969 ;
954 970
955 $self->update_options; 971 $self->update_options;
956 972
957 $self->{token} = $self->{conn}->ext_token; 973 $self->{token} = $self->{conn}->ext_token;
958 $self->{conn}->connect_ext ($self->{token} => sub { $this->feed (@_) }); 974 $self->{conn}->connect_ext ($self->{token} => sub { $this->feed (@_) });
959 $self->{conn}->send ("ext npc_dialog_begin $self->{token} $self->{dx} $self->{dy}"); 975 $self->{conn}->send ("ext npc_dialog_begin $self->{token} $self->{dx} $self->{dy}");
960 976
961 $self->{entry}->grab_focus; 977 $self->{entry}->grab_focus;
962 978
963 $self->{textview}->add_paragraph ([1, 1, 0, 1], "<small>[starting conversation with <b>$self->{title}</b>]</small>\n\n"); 979 $self->{textview}->add_paragraph ({
980 fg => [1, 1, 0, 1],
981 markup => "<small>[starting conversation with <b>$self->{title}</b>]</small>\n\n",
982 });
964 983
965 $self->show; 984 $self->show;
966 $self 985 $self
967}; 986};
968 987
997 1016
998 utf8::decode $_ for ($msg, @kw); 1017 utf8::decode $_ for ($msg, @kw);
999 1018
1000 $self->{kw}{$_} = 1 for @kw; 1019 $self->{kw}{$_} = 1 for @kw;
1001 1020
1002 $msg = "\n" . CFClient::UI::Label::escape $msg; 1021 $msg = "\n" . CFClient::UI::asxml $msg;
1003 my $match = join "|", map "\\b\Q$_\E\\b", sort { (length $b) <=> (length $a) } keys %{ $self->{kw} }; 1022 my $match = join "|", map "\\b\Q$_\E\\b", sort { (length $b) <=> (length $a) } keys %{ $self->{kw} };
1004 my @link; 1023 my @link;
1005 $msg =~ s{ 1024 $msg =~ s{
1006 ($match) 1025 ($match)
1007 }{ 1026 }{
1018 }; 1037 };
1019 1038
1020 chr 0xfffc 1039 chr 0xfffc
1021 }giex; 1040 }giex;
1022 1041
1023 $self->{textview}->add_paragraph ([1, 1, 1, 1], [$msg, @link]); 1042 $self->{textview}->add_paragraph ({ markup => $msg, widget => \@link });
1024 $self->{textview}->scroll_to_bottom; 1043 $self->{textview}->scroll_to_bottom;
1025 $self->update_options; 1044 $self->update_options;
1026 } else { 1045 } else {
1027 $self->destroy; 1046 $self->destroy;
1028 } 1047 }
1031} 1050}
1032 1051
1033sub send { 1052sub send {
1034 my ($self, $msg) = @_; 1053 my ($self, $msg) = @_;
1035 1054
1036 $self->{textview}->add_paragraph ([1, 1, 0, 1], "\n" . CFClient::UI::Label::escape $msg); 1055 $self->{textview}->add_paragraph ({ markup => "\n" . CFClient::asxml $msg });
1037 $self->{textview}->scroll_to_bottom; 1056 $self->{textview}->scroll_to_bottom;
1038 1057
1039 utf8::encode $msg; 1058 utf8::encode $msg;
1040 $self->{conn}->send ("ext npc_dialog_tell $self->{token} $msg"); 1059 $self->{conn}->send ("ext npc_dialog_tell $self->{token} $msg");
1041} 1060}
1050 $self->{conn}->disconnect_ext ($self->{token}); 1069 $self->{conn}->disconnect_ext ($self->{token});
1051 1070
1052 $self->SUPER::destroy; 1071 $self->SUPER::destroy;
1053} 1072}
1054 1073
10551; 10741

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines