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.93 by root, Fri Dec 22 03:43:05 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
621 [0.75, 0.61, 0.20], 628 [0.75, 0.61, 0.20],
622 [0.99, 0.77, 0.26], 629 [0.99, 0.77, 0.26],
623 [0.74, 0.65, 0.41], 630 [0.74, 0.65, 0.41],
624 ); 631 );
625 632
633 my $fg = $color[$color % @color];
634
626 $self->logprint ("info: ", $text); 635 $self->logprint ("info: ", $text);
627
628 my $time = sprintf "%02d:%02d:%02d", (localtime time)[2,1,0];
629 636
630 # try to create single paragraphs of multiple lines sent by the server 637 # try to create single paragraphs of multiple lines sent by the server
631 $text =~ s/(?<=\S)\n(?=\w)/ /g; 638 $text =~ s/(?<=\S)\n(?=\w)/ /g;
632 639
633 $text = CFPlus::asxml $text; 640 $text = CFPlus::asxml $text;
634 $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g; 641 $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g;
635 $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g; 642 $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g;
636 643
637 $self->{logview}->add_paragraph ({ fg => $color[$color], markup => $_ }) 644 ::message ({ fg => $fg, markup => $_ })
638 for map "<span foreground='#ffffff'>$time</span> $_", split /\n/, $text; 645 for split /\n/, $text;
639 $self->{logview}->scroll_to_bottom;
640 646
641 $self->{statusbox}->add ($text, 647 $self->{statusbox}->add ($text,
642 group => $text, 648 group => $text,
643 fg => $color[$color], 649 fg => $fg,
644 timeout => $color >= 2 ? 180 : 10, 650 timeout => $color >= 2 ? 180 : 10,
645 tooltip_font => $::FONT_FIXED, 651 tooltip_font => $::FONT_FIXED,
646 ); 652 );
647} 653}
648 654
658 # try to create single paragraphs out of the multiple lines sent by the server 664 # try to create single paragraphs out of the multiple lines sent by the server
659 $spell->{message} =~ s/(?<=\S)\n(?=\w)/ /g; 665 $spell->{message} =~ s/(?<=\S)\n(?=\w)/ /g;
660 $spell->{message} =~ s/\n+$//; 666 $spell->{message} =~ s/\n+$//;
661 $spell->{message} ||= "Server did not provide a description for this spell."; 667 $spell->{message} ||= "Server did not provide a description for this spell.";
662 668
663 $::SPELL_PAGE->add_spell ($spell); 669 $::SPELL_LIST->add_spell ($spell);
664 670
665 $self->{map_widget}->add_command ("invoke $spell->{name}", CFPlus::asxml $spell->{message}); 671 $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}); 672 $self->{map_widget}->add_command ("cast $spell->{name}", CFPlus::asxml $spell->{message});
667} 673}
668 674
669sub spell_delete { 675sub spell_delete {
670 my ($self, $spell) = @_; 676 my ($self, $spell) = @_;
671 677
672 $::SPELL_PAGE->remove_spell ($spell); 678 $::SPELL_LIST->remove_spell ($spell);
679}
680
681sub setup {
682 my ($self, $setup) = @_;
683
684 $::MAP->resize ($self->{mapw}, $self->{maph});
673} 685}
674 686
675sub addme_success { 687sub addme_success {
676 my ($self) = @_; 688 my ($self) = @_;
677 689
883 $::SERVER_INFO->set_markup ( 895 $::SERVER_INFO->set_markup (
884 "server <tt>$self->{host}:$self->{port}</tt>\n" 896 "server <tt>$self->{host}:$self->{port}</tt>\n"
885 . "protocol version <tt>$self->{version}</tt>\n" 897 . "protocol version <tt>$self->{version}</tt>\n"
886 . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n" 898 . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n"
887 . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n" 899 . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n"
888 . "editor support $yesno[!!length $self->{cvs_root}]\n" 900 . "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" 901 . "map attributes $yesno[$self->{setup}{extmap} > 0]\n"
891 . "cfplus support $yesno[$self->{cfplus_ext} > 0]" 902 . "cfplus support $yesno[$self->{cfplus_ext} > 0]"
892 . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" 903 . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n"
893 . "map size $self->{mapw}×$self->{maph}\n" 904 . "map size $self->{mapw}×$self->{maph}\n"
894 ); 905 );
906
907 ::setup_build_button ($self->{editor_support}->{builder_ui});
895} 908}
896 909
897sub logged_in { 910sub logged_in {
898 my ($self) = @_; 911 my ($self) = @_;
899 912
901 $self->{cfplus_ext} = $_[0]{version}; 914 $self->{cfplus_ext} = $_[0]{version};
902 $self->update_server_info; 915 $self->update_server_info;
903 916
904 if ($self->{cfplus_ext} >= 2) { 917 if ($self->{cfplus_ext} >= 2) {
905 $self->send_ext_req ("editor_support", sub { 918 $self->send_ext_req ("editor_support", sub {
906 $self->{cvs_root} = $_[0]{cvs_root}; 919 $self->{editor_support} = $_[0];
907 $self->{upload} = $_[0]{upload};
908 $self->{test_server} = $_[0]{server};
909 $self->update_server_info; 920 $self->update_server_info;
910 921
911 0 922 0
912 }); 923 });
913 } 924 }
918 $self->update_server_info; 929 $self->update_server_info;
919 930
920 $self->send_command ("output-sync $::CFG->{output_sync}"); 931 $self->send_command ("output-sync $::CFG->{output_sync}");
921 $self->send_command ("output-count $::CFG->{output_count}"); 932 $self->send_command ("output-count $::CFG->{output_count}");
922 $self->send_command ("pickup $::CFG->{pickup}"); 933 $self->send_command ("pickup $::CFG->{pickup}");
934}
935
936sub buildat {
937 my ($self, $builditem, $x, $y) = @_;
938
939 if ($self->{cfplus_ext}) {
940 $self->send_ext_msg (builder_build => dx => $x, dy => $y, (ref ($builditem) eq 'HASH') ? %$builditem : (item => $builditem));
941 }
923} 942}
924 943
925sub lookat { 944sub lookat {
926 my ($self, $x, $y) = @_; 945 my ($self, $x, $y) = @_;
927 946
970 kw => { hi => 0, yes => 0, no => 0 }, 989 kw => { hi => 0, yes => 0, no => 0 },
971 has_close_button => 1, 990 has_close_button => 1,
972 @_, 991 @_,
973 ); 992 );
974 993
975 Scalar::Util::weaken (my $this = $self); 994 CFPlus::weaken (my $this = $self);
976 995
977 $self->connect (delete => sub { $this->destroy; 1 }); 996 $self->connect (delete => sub { $this->destroy; 1 });
978 997
979 # better use a pane... 998 # better use a pane...
980 $self->add (my $hbox = new CFPlus::UI::HBox); 999 $self->add (my $hbox = new CFPlus::UI::HBox);
1024}; 1043};
1025 1044
1026sub update_options { 1045sub update_options {
1027 my ($self) = @_; 1046 my ($self) = @_;
1028 1047
1029 Scalar::Util::weaken $self; 1048 CFPlus::weaken $self;
1030 1049
1031 $self->{options}->clear; 1050 $self->{options}->clear;
1032 $self->{options}->add ($self->{bye_button}); 1051 $self->{options}->add ($self->{bye_button});
1033 1052
1034 for my $kw (sort keys %{ $self->{kw} }) { 1053 for my $kw (sort keys %{ $self->{kw} }) {
1043} 1062}
1044 1063
1045sub feed { 1064sub feed {
1046 my ($self, $msg) = @_; 1065 my ($self, $msg) = @_;
1047 1066
1048 Scalar::Util::weaken $self; 1067 CFPlus::weaken $self;
1049 1068
1050 if ($msg->{msgtype} eq "reply") { 1069 if ($msg->{msgtype} eq "reply") {
1051 $self->{kw}{$_} = 1 for @{$msg->{add_topics} || []}; 1070 $self->{kw}{$_} = 1 for @{$msg->{add_topics} || []};
1052 $self->{kw}{$_} = 0 for @{$msg->{del_topics} || []}; 1071 $self->{kw}{$_} = 0 for @{$msg->{del_topics} || []};
1053 1072

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines