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.79 by root, Fri Aug 18 01:01:01 2006 UTC vs.
Revision 1.92 by root, Sat Dec 9 21:26:46 2006 UTC

6use Crossfire::Protocol::Constants; 6use Crossfire::Protocol::Constants;
7 7
8use CFPlus; 8use CFPlus;
9use CFPlus::UI; 9use CFPlus::UI;
10use CFPlus::Pod; 10use CFPlus::Pod;
11use CFPlus::Macro;
12use CFPlus::Item;
13
14use Crossfire::Protocol::Base 0.95;
11 15
12use base 'Crossfire::Protocol::Base'; 16use base 'Crossfire::Protocol::Base';
13 17
14sub new { 18sub new {
15 my $class = shift; 19 my $class = shift;
41 $self->{map_widget}->add_command (@$_) 45 $self->{map_widget}->add_command (@$_)
42 for @cmd_help; 46 for @cmd_help;
43 47
44 $self->{noface} = new_from_file CFPlus::Texture 48 $self->{noface} = new_from_file CFPlus::Texture
45 CFPlus::find_rcfile "noface.png", minify => 1, mipmap => 1; 49 CFPlus::find_rcfile "noface.png", minify => 1, mipmap => 1;
50
51 {
52 $self->{dialogue} = my $tex = new_from_file CFPlus::Texture
53 CFPlus::find_rcfile "dialogue.png", minify => 1, mipmap => 1;
54 $self->{map}->set_texture (1, @$tex{qw(name w h s t)}, @{$tex->{minified}});
55 }
46 56
47 $self->{open_container} = 0; 57 $self->{open_container} = 0;
48 58
49 # "global" 59 # "global"
50 $self->{tilecache} = CFPlus::db_table "tilecache" 60 $self->{tilecache} = CFPlus::db_table "tilecache"
280 if ($ev->{button} == 1) { 290 if ($ev->{button} == 1) {
281 $::CONN->user_send ("ready_skill $name"); 291 $::CONN->user_send ("ready_skill $name");
282 } elsif ($ev->{button} == 2) { 292 } elsif ($ev->{button} == 2) {
283 $::CONN->user_send ("use_skill $name"); 293 $::CONN->user_send ("use_skill $name");
284 } elsif ($ev->{button} == 3) { 294 } elsif ($ev->{button} == 3) {
295 my $shortname = CFPlus::shorten $name, 14;
285 (new CFPlus::UI::Menu 296 (new CFPlus::UI::Menu
286 items => [ 297 items => [
287 ["bind <i>ready_skill $name</i> to a key" => sub { $::BIND_EDITOR->do_quick_binding (["ready_skill $name"]) }], 298 ["bind <i>ready_skill $shortname</i> to a key" => sub { CFPlus::Macro::quick_macro ["ready_skill $name"] }],
288 ["bind <i>use_skill $name</i> to a key" => sub { $::BIND_EDITOR->do_quick_binding (["use_skill $name"]) }], 299 ["bind <i>use_skill $shortname</i> to a key" => sub { CFPlus::Macro::quick_macro ["use_skill $name"] }],
289 ], 300 ],
290 )->popup ($ev); 301 )->popup ($ev);
291 } else { 302 } else {
292 return 0; 303 return 0;
293 } 304 }
310 $self->{stat_widget_exp}{$_}->set_text (::formsep ($stats->{$_}[1])); 321 $self->{stat_widget_exp}{$_}->set_text (::formsep ($stats->{$_}[1]));
311 $self->{stat_widget_lvl}{$_}->set_text ($stats->{$_}[0] * 1); 322 $self->{stat_widget_lvl}{$_}->set_text ($stats->{$_}[0] * 1);
312 } 323 }
313} 324}
314 325
326sub macro_send {
327 my ($self, $macro) = @_;
328
329 for my $cmd (@{ $macro->{action} }) {
330 $self->send_command ($cmd);
331 }
332}
333
315sub user_send { 334sub user_send {
316 my ($self, $command) = @_; 335 my ($self, $command) = @_;
317 336
337 $self->{record}->($command)
318 if ($self->{record}) { 338 if $self->{record};
319 push @{$self->{record}}, $command;
320 }
321 339
322 $self->logprint ("send: ", $command); 340 $self->logprint ("send: ", $command);
323 $self->send_command ($command); 341 $self->send_command ($command);
324 ::status ($command); 342 ::status ($command);
325} 343}
326 344
327sub start_record { 345sub record {
328 my ($self) = @_; 346 my ($self, $cb) = @_;
329 347
330 $self->{record} = []; 348 $self->{record} = $cb;
331}
332
333sub stop_record {
334 my ($self) = @_;
335 return delete $self->{record};
336} 349}
337 350
338sub map_scroll { 351sub map_scroll {
339 my ($self, $dx, $dy) = @_; 352 my ($self, $dx, $dy) = @_;
340 353
617 [0.74, 0.65, 0.41], 630 [0.74, 0.65, 0.41],
618 ); 631 );
619 632
620 $self->logprint ("info: ", $text); 633 $self->logprint ("info: ", $text);
621 634
622 my $time = sprintf "%02d:%02d:%02d", (localtime time)[2,1,0];
623
624 # try to create single paragraphs of multiple lines sent by the server 635 # try to create single paragraphs of multiple lines sent by the server
625 $text =~ s/(?<=\S)\n(?=\w)/ /g; 636 $text =~ s/(?<=\S)\n(?=\w)/ /g;
626 637
627 $text = CFPlus::asxml $text; 638 $text = CFPlus::asxml $text;
628 $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g; 639 $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g;
629 $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g; 640 $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g;
630 641
631 $self->{logview}->add_paragraph ({ fg => $color[$color], markup => $_ }) 642 ::message ({ fg => $color[$color], markup => $_ })
632 for map "<span foreground='#ffffff'>$time</span> $_", split /\n/, $text; 643 for split /\n/, $text;
633 $self->{logview}->scroll_to_bottom;
634 644
635 $self->{statusbox}->add ($text, 645 $self->{statusbox}->add ($text,
636 group => $text, 646 group => $text,
637 fg => $color[$color], 647 fg => $color[$color],
638 timeout => $color >= 2 ? 180 : 10, 648 timeout => $color >= 2 ? 180 : 10,
652 # try to create single paragraphs out of the multiple lines sent by the server 662 # try to create single paragraphs out of the multiple lines sent by the server
653 $spell->{message} =~ s/(?<=\S)\n(?=\w)/ /g; 663 $spell->{message} =~ s/(?<=\S)\n(?=\w)/ /g;
654 $spell->{message} =~ s/\n+$//; 664 $spell->{message} =~ s/\n+$//;
655 $spell->{message} ||= "Server did not provide a description for this spell."; 665 $spell->{message} ||= "Server did not provide a description for this spell.";
656 666
657 $::SPELL_PAGE->add_spell ($spell); 667 $::SPELL_LIST->add_spell ($spell);
658 668
659 $self->{map_widget}->add_command ("invoke $spell->{name}", CFPlus::asxml $spell->{message}); 669 $self->{map_widget}->add_command ("invoke $spell->{name}", CFPlus::asxml $spell->{message});
660 $self->{map_widget}->add_command ("cast $spell->{name}", CFPlus::asxml $spell->{message}); 670 $self->{map_widget}->add_command ("cast $spell->{name}", CFPlus::asxml $spell->{message});
661} 671}
662 672
663sub spell_delete { 673sub spell_delete {
664 my ($self, $spell) = @_; 674 my ($self, $spell) = @_;
665 675
666 $::SPELL_PAGE->remove_spell ($spell); 676 $::SPELL_LIST->remove_spell ($spell);
677}
678
679sub setup {
680 my ($self, $setup) = @_;
681
682 $::MAP->resize ($self->{mapw}, $self->{maph});
667} 683}
668 684
669sub addme_success { 685sub addme_success {
670 my ($self) = @_; 686 my ($self) = @_;
671 687
877 $::SERVER_INFO->set_markup ( 893 $::SERVER_INFO->set_markup (
878 "server <tt>$self->{host}:$self->{port}</tt>\n" 894 "server <tt>$self->{host}:$self->{port}</tt>\n"
879 . "protocol version <tt>$self->{version}</tt>\n" 895 . "protocol version <tt>$self->{version}</tt>\n"
880 . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n" 896 . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n"
881 . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n" 897 . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n"
898 . "editing support $yesno[!!$self->{editor_support}]\n"
899 . "map attributes $yesno[$self->{setup}{extmap} > 0]\n"
882 . "cfplus support $yesno[$self->{cfplus_ext} > 0]" 900 . "cfplus support $yesno[$self->{cfplus_ext} > 0]"
883 . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" 901 . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n"
884 . "map size $self->{mapw}×$self->{maph}\n" 902 . "map size $self->{mapw}×$self->{maph}\n"
885 ); 903 );
904
905 ::setup_build_button ($self->{editor_support}->{builder_ui});
886} 906}
887 907
888sub logged_in { 908sub logged_in {
889 my ($self) = @_; 909 my ($self) = @_;
890 910
891 $self->send_ext_req (cfplus_support => version => 1, sub { 911 $self->send_ext_req (cfplus_support => version => 1, sub {
892 $self->{cfplus_ext} = $_[0]{version}; 912 $self->{cfplus_ext} = $_[0]{version};
893 $self->update_server_info; 913 $self->update_server_info;
894 914
915 if ($self->{cfplus_ext} >= 2) {
916 $self->send_ext_req ("editor_support", sub {
917 $self->{editor_support} = $_[0];
918 $self->update_server_info;
919
920 0
921 });
922 }
923
895 0 924 0
896 }); 925 });
897 926
898 $self->update_server_info; 927 $self->update_server_info;
899 928
900 $self->send_command ("output-sync $::CFG->{output_sync}"); 929 $self->send_command ("output-sync $::CFG->{output_sync}");
901 $self->send_command ("output-count $::CFG->{output_count}"); 930 $self->send_command ("output-count $::CFG->{output_count}");
902 $self->send_command ("pickup $::CFG->{pickup}"); 931 $self->send_command ("pickup $::CFG->{pickup}");
932}
933
934sub buildat {
935 my ($self, $builditem, $x, $y) = @_;
936
937 if ($self->{cfplus_ext}) {
938 $self->send_ext_msg (builder_build => dx => $x, dy => $y, (ref ($builditem) eq 'HASH') ? %$builditem : (item => $builditem));
939 }
903} 940}
904 941
905sub lookat { 942sub lookat {
906 my ($self, $x, $y) = @_; 943 my ($self, $x, $y) = @_;
907 944
950 kw => { hi => 0, yes => 0, no => 0 }, 987 kw => { hi => 0, yes => 0, no => 0 },
951 has_close_button => 1, 988 has_close_button => 1,
952 @_, 989 @_,
953 ); 990 );
954 991
955 Scalar::Util::weaken (my $this = $self); 992 CFPlus::weaken (my $this = $self);
956 993
957 $self->connect (delete => sub { $this->destroy; 1 }); 994 $self->connect (delete => sub { $this->destroy; 1 });
958 995
959 # better use a pane... 996 # better use a pane...
960 $self->add (my $hbox = new CFPlus::UI::HBox); 997 $self->add (my $hbox = new CFPlus::UI::HBox);
1004}; 1041};
1005 1042
1006sub update_options { 1043sub update_options {
1007 my ($self) = @_; 1044 my ($self) = @_;
1008 1045
1009 Scalar::Util::weaken $self; 1046 CFPlus::weaken $self;
1010 1047
1011 $self->{options}->clear; 1048 $self->{options}->clear;
1012 $self->{options}->add ($self->{bye_button}); 1049 $self->{options}->add ($self->{bye_button});
1013 1050
1014 for my $kw (sort keys %{ $self->{kw} }) { 1051 for my $kw (sort keys %{ $self->{kw} }) {
1023} 1060}
1024 1061
1025sub feed { 1062sub feed {
1026 my ($self, $msg) = @_; 1063 my ($self, $msg) = @_;
1027 1064
1028 Scalar::Util::weaken $self; 1065 CFPlus::weaken $self;
1029 1066
1030 if ($msg->{msgtype} eq "reply") { 1067 if ($msg->{msgtype} eq "reply") {
1031 $self->{kw}{$_} = 1 for @{$msg->{add_topics} || []}; 1068 $self->{kw}{$_} = 1 for @{$msg->{add_topics} || []};
1032 $self->{kw}{$_} = 0 for @{$msg->{del_topics} || []}; 1069 $self->{kw}{$_} = 0 for @{$msg->{del_topics} || []};
1033 1070
1084 1121
1085 $self->SUPER::destroy; 1122 $self->SUPER::destroy;
1086} 1123}
1087 1124
10881 11251
1126

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines