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.85 by root, Sun Oct 1 11:53:59 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;
286 if ($ev->{button} == 1) { 290 if ($ev->{button} == 1) {
287 $::CONN->user_send ("ready_skill $name"); 291 $::CONN->user_send ("ready_skill $name");
288 } elsif ($ev->{button} == 2) { 292 } elsif ($ev->{button} == 2) {
289 $::CONN->user_send ("use_skill $name"); 293 $::CONN->user_send ("use_skill $name");
290 } elsif ($ev->{button} == 3) { 294 } elsif ($ev->{button} == 3) {
295 my $shortname = CFPlus::shorten $name, 14;
291 (new CFPlus::UI::Menu 296 (new CFPlus::UI::Menu
292 items => [ 297 items => [
293 ["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"] }],
294 ["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"] }],
295 ], 300 ],
296 )->popup ($ev); 301 )->popup ($ev);
297 } else { 302 } else {
298 return 0; 303 return 0;
299 } 304 }
316 $self->{stat_widget_exp}{$_}->set_text (::formsep ($stats->{$_}[1])); 321 $self->{stat_widget_exp}{$_}->set_text (::formsep ($stats->{$_}[1]));
317 $self->{stat_widget_lvl}{$_}->set_text ($stats->{$_}[0] * 1); 322 $self->{stat_widget_lvl}{$_}->set_text ($stats->{$_}[0] * 1);
318 } 323 }
319} 324}
320 325
326sub macro_send {
327 my ($self, $macro) = @_;
328
329 for my $cmd (@{ $macro->{action} }) {
330 $self->send_command ($cmd);
331 }
332}
333
321sub user_send { 334sub user_send {
322 my ($self, $command) = @_; 335 my ($self, $command) = @_;
323 336
337 $self->{record}->($command)
324 if ($self->{record}) { 338 if $self->{record};
325 push @{$self->{record}}, $command;
326 }
327 339
328 $self->logprint ("send: ", $command); 340 $self->logprint ("send: ", $command);
329 $self->send_command ($command); 341 $self->send_command ($command);
330 ::status ($command); 342 ::status ($command);
331} 343}
332 344
333sub start_record { 345sub record {
334 my ($self) = @_; 346 my ($self, $cb) = @_;
335 347
336 $self->{record} = []; 348 $self->{record} = $cb;
337}
338
339sub stop_record {
340 my ($self) = @_;
341 return delete $self->{record};
342} 349}
343 350
344sub map_scroll { 351sub map_scroll {
345 my ($self, $dx, $dy) = @_; 352 my ($self, $dx, $dy) = @_;
346 353
623 [0.74, 0.65, 0.41], 630 [0.74, 0.65, 0.41],
624 ); 631 );
625 632
626 $self->logprint ("info: ", $text); 633 $self->logprint ("info: ", $text);
627 634
628 my $time = sprintf "%02d:%02d:%02d", (localtime time)[2,1,0];
629
630 # 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
631 $text =~ s/(?<=\S)\n(?=\w)/ /g; 636 $text =~ s/(?<=\S)\n(?=\w)/ /g;
632 637
633 $text = CFPlus::asxml $text; 638 $text = CFPlus::asxml $text;
634 $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g; 639 $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g;
635 $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g; 640 $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g;
636 641
637 $self->{logview}->add_paragraph ({ fg => $color[$color], markup => $_ }) 642 ::message ({ fg => $color[$color], markup => $_ })
638 for map "<span foreground='#ffffff'>$time</span> $_", split /\n/, $text; 643 for split /\n/, $text;
639 $self->{logview}->scroll_to_bottom;
640 644
641 $self->{statusbox}->add ($text, 645 $self->{statusbox}->add ($text,
642 group => $text, 646 group => $text,
643 fg => $color[$color], 647 fg => $color[$color],
644 timeout => $color >= 2 ? 180 : 10, 648 timeout => $color >= 2 ? 180 : 10,
658 # 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
659 $spell->{message} =~ s/(?<=\S)\n(?=\w)/ /g; 663 $spell->{message} =~ s/(?<=\S)\n(?=\w)/ /g;
660 $spell->{message} =~ s/\n+$//; 664 $spell->{message} =~ s/\n+$//;
661 $spell->{message} ||= "Server did not provide a description for this spell."; 665 $spell->{message} ||= "Server did not provide a description for this spell.";
662 666
663 $::SPELL_PAGE->add_spell ($spell); 667 $::SPELL_LIST->add_spell ($spell);
664 668
665 $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});
666 $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});
667} 671}
668 672
669sub spell_delete { 673sub spell_delete {
670 my ($self, $spell) = @_; 674 my ($self, $spell) = @_;
671 675
672 $::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});
673} 683}
674 684
675sub addme_success { 685sub addme_success {
676 my ($self) = @_; 686 my ($self) = @_;
677 687
883 $::SERVER_INFO->set_markup ( 893 $::SERVER_INFO->set_markup (
884 "server <tt>$self->{host}:$self->{port}</tt>\n" 894 "server <tt>$self->{host}:$self->{port}</tt>\n"
885 . "protocol version <tt>$self->{version}</tt>\n" 895 . "protocol version <tt>$self->{version}</tt>\n"
886 . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n" 896 . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n"
887 . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n" 897 . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n"
888 . "editor support $yesno[!!length $self->{cvs_root}]\n" 898 . "editing support $yesno[!!$self->{editor_support}]\n"
889 . "test server " . (length $self->{test_server} ? $self->{test_server} : $yesno[0]) . "\n"
890 . "map attributes $yesno[$self->{setup}{extmap} > 0]\n" 899 . "map attributes $yesno[$self->{setup}{extmap} > 0]\n"
891 . "cfplus support $yesno[$self->{cfplus_ext} > 0]" 900 . "cfplus support $yesno[$self->{cfplus_ext} > 0]"
892 . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" 901 . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n"
893 . "map size $self->{mapw}×$self->{maph}\n" 902 . "map size $self->{mapw}×$self->{maph}\n"
894 ); 903 );
904
905 ::setup_build_button ($self->{editor_support}->{builder_ui});
895} 906}
896 907
897sub logged_in { 908sub logged_in {
898 my ($self) = @_; 909 my ($self) = @_;
899 910
901 $self->{cfplus_ext} = $_[0]{version}; 912 $self->{cfplus_ext} = $_[0]{version};
902 $self->update_server_info; 913 $self->update_server_info;
903 914
904 if ($self->{cfplus_ext} >= 2) { 915 if ($self->{cfplus_ext} >= 2) {
905 $self->send_ext_req ("editor_support", sub { 916 $self->send_ext_req ("editor_support", sub {
906 $self->{cvs_root} = $_[0]{cvs_root}; 917 $self->{editor_support} = $_[0];
907 $self->{upload} = $_[0]{upload};
908 $self->{test_server} = $_[0]{server};
909 $self->update_server_info; 918 $self->update_server_info;
910 919
911 0 920 0
912 }); 921 });
913 } 922 }
918 $self->update_server_info; 927 $self->update_server_info;
919 928
920 $self->send_command ("output-sync $::CFG->{output_sync}"); 929 $self->send_command ("output-sync $::CFG->{output_sync}");
921 $self->send_command ("output-count $::CFG->{output_count}"); 930 $self->send_command ("output-count $::CFG->{output_count}");
922 $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 }
923} 940}
924 941
925sub lookat { 942sub lookat {
926 my ($self, $x, $y) = @_; 943 my ($self, $x, $y) = @_;
927 944
970 kw => { hi => 0, yes => 0, no => 0 }, 987 kw => { hi => 0, yes => 0, no => 0 },
971 has_close_button => 1, 988 has_close_button => 1,
972 @_, 989 @_,
973 ); 990 );
974 991
975 Scalar::Util::weaken (my $this = $self); 992 CFPlus::weaken (my $this = $self);
976 993
977 $self->connect (delete => sub { $this->destroy; 1 }); 994 $self->connect (delete => sub { $this->destroy; 1 });
978 995
979 # better use a pane... 996 # better use a pane...
980 $self->add (my $hbox = new CFPlus::UI::HBox); 997 $self->add (my $hbox = new CFPlus::UI::HBox);
1024}; 1041};
1025 1042
1026sub update_options { 1043sub update_options {
1027 my ($self) = @_; 1044 my ($self) = @_;
1028 1045
1029 Scalar::Util::weaken $self; 1046 CFPlus::weaken $self;
1030 1047
1031 $self->{options}->clear; 1048 $self->{options}->clear;
1032 $self->{options}->add ($self->{bye_button}); 1049 $self->{options}->add ($self->{bye_button});
1033 1050
1034 for my $kw (sort keys %{ $self->{kw} }) { 1051 for my $kw (sort keys %{ $self->{kw} }) {
1043} 1060}
1044 1061
1045sub feed { 1062sub feed {
1046 my ($self, $msg) = @_; 1063 my ($self, $msg) = @_;
1047 1064
1048 Scalar::Util::weaken $self; 1065 CFPlus::weaken $self;
1049 1066
1050 if ($msg->{msgtype} eq "reply") { 1067 if ($msg->{msgtype} eq "reply") {
1051 $self->{kw}{$_} = 1 for @{$msg->{add_topics} || []}; 1068 $self->{kw}{$_} = 1 for @{$msg->{add_topics} || []};
1052 $self->{kw}{$_} = 0 for @{$msg->{del_topics} || []}; 1069 $self->{kw}{$_} = 0 for @{$msg->{del_topics} || []};
1053 1070

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines