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.86 by root, Sun Oct 8 21:22:30 2006 UTC vs.
Revision 1.94 by root, Fri Mar 16 02:33:49 2007 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 636
628 # 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
629 $text =~ s/(?<=\S)\n(?=\w)/ /g; 638 $text =~ s/(?<=\S)\n(?=\w)/ /g;
630 639
631 $text = CFPlus::asxml $text; 640 $text = CFPlus::asxml $text;
632 $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g; 641 $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g;
633 $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g; 642 $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g;
634 643
635 ::message ({ fg => $color[$color], markup => $_ }) 644 ::message ({ fg => $fg, markup => $_ })
636 for split /\n/, $text; 645 for split /\n/, $text;
637 646
638 $self->{statusbox}->add ($text, 647 $self->{statusbox}->add ($text,
639 group => $text, 648 group => $text,
640 fg => $color[$color], 649 fg => $fg,
641 timeout => $color >= 2 ? 180 : 10, 650 timeout => $color >= 2 ? 180 : 10,
642 tooltip_font => $::FONT_FIXED, 651 tooltip_font => $::FONT_FIXED,
643 ); 652 );
644} 653}
645 654
655 # 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
656 $spell->{message} =~ s/(?<=\S)\n(?=\w)/ /g; 665 $spell->{message} =~ s/(?<=\S)\n(?=\w)/ /g;
657 $spell->{message} =~ s/\n+$//; 666 $spell->{message} =~ s/\n+$//;
658 $spell->{message} ||= "Server did not provide a description for this spell."; 667 $spell->{message} ||= "Server did not provide a description for this spell.";
659 668
660 $::SPELL_PAGE->add_spell ($spell); 669 $::SPELL_LIST->add_spell ($spell);
661 670
662 $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});
663 $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});
664} 673}
665 674
666sub spell_delete { 675sub spell_delete {
667 my ($self, $spell) = @_; 676 my ($self, $spell) = @_;
668 677
669 $::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});
670} 685}
671 686
672sub addme_success { 687sub addme_success {
673 my ($self) = @_; 688 my ($self) = @_;
674 689
886 . "map attributes $yesno[$self->{setup}{extmap} > 0]\n" 901 . "map attributes $yesno[$self->{setup}{extmap} > 0]\n"
887 . "cfplus support $yesno[$self->{cfplus_ext} > 0]" 902 . "cfplus support $yesno[$self->{cfplus_ext} > 0]"
888 . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" 903 . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n"
889 . "map size $self->{mapw}×$self->{maph}\n" 904 . "map size $self->{mapw}×$self->{maph}\n"
890 ); 905 );
906
907 ::setup_build_button ($self->{editor_support}->{builder_ui});
891} 908}
892 909
893sub logged_in { 910sub logged_in {
894 my ($self) = @_; 911 my ($self) = @_;
895 912
911 928
912 $self->update_server_info; 929 $self->update_server_info;
913 930
914 $self->send_command ("output-sync $::CFG->{output_sync}"); 931 $self->send_command ("output-sync $::CFG->{output_sync}");
915 $self->send_command ("output-count $::CFG->{output_count}"); 932 $self->send_command ("output-count $::CFG->{output_count}");
933 $self->send_command ("output-rate $::CFG->{output_rate}") if $::CFG->{output_rate} > 0;
916 $self->send_command ("pickup $::CFG->{pickup}"); 934 $self->send_command ("pickup $::CFG->{pickup}");
935}
936
937sub buildat {
938 my ($self, $builditem, $x, $y) = @_;
939
940 if ($self->{cfplus_ext}) {
941 $self->send_ext_msg (builder_build => dx => $x, dy => $y, (ref ($builditem) eq 'HASH') ? %$builditem : (item => $builditem));
942 }
917} 943}
918 944
919sub lookat { 945sub lookat {
920 my ($self, $x, $y) = @_; 946 my ($self, $x, $y) = @_;
921 947
964 kw => { hi => 0, yes => 0, no => 0 }, 990 kw => { hi => 0, yes => 0, no => 0 },
965 has_close_button => 1, 991 has_close_button => 1,
966 @_, 992 @_,
967 ); 993 );
968 994
969 Scalar::Util::weaken (my $this = $self); 995 CFPlus::weaken (my $this = $self);
970 996
971 $self->connect (delete => sub { $this->destroy; 1 }); 997 $self->connect (delete => sub { $this->destroy; 1 });
972 998
973 # better use a pane... 999 # better use a pane...
974 $self->add (my $hbox = new CFPlus::UI::HBox); 1000 $self->add (my $hbox = new CFPlus::UI::HBox);
1018}; 1044};
1019 1045
1020sub update_options { 1046sub update_options {
1021 my ($self) = @_; 1047 my ($self) = @_;
1022 1048
1023 Scalar::Util::weaken $self; 1049 CFPlus::weaken $self;
1024 1050
1025 $self->{options}->clear; 1051 $self->{options}->clear;
1026 $self->{options}->add ($self->{bye_button}); 1052 $self->{options}->add ($self->{bye_button});
1027 1053
1028 for my $kw (sort keys %{ $self->{kw} }) { 1054 for my $kw (sort keys %{ $self->{kw} }) {
1037} 1063}
1038 1064
1039sub feed { 1065sub feed {
1040 my ($self, $msg) = @_; 1066 my ($self, $msg) = @_;
1041 1067
1042 Scalar::Util::weaken $self; 1068 CFPlus::weaken $self;
1043 1069
1044 if ($msg->{msgtype} eq "reply") { 1070 if ($msg->{msgtype} eq "reply") {
1045 $self->{kw}{$_} = 1 for @{$msg->{add_topics} || []}; 1071 $self->{kw}{$_} = 1 for @{$msg->{add_topics} || []};
1046 $self->{kw}{$_} = 0 for @{$msg->{del_topics} || []}; 1072 $self->{kw}{$_} = 0 for @{$msg->{del_topics} || []};
1047 1073

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines