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.95 by root, Wed Apr 4 02:43:30 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;
35 map ["$cmd$_", $text], 39 map ["$cmd$_", $text],
36 sort { (length $a) <=> (length $b) } 40 sort { (length $a) <=> (length $b) }
37 @args 41 @args
38 } sort { $a->{par} <=> $b->{par} } 42 } sort { $a->{par} <=> $b->{par} }
39 CFPlus::Pod::find command => "*"; 43 CFPlus::Pod::find command => "*";
44
45 $self->connect_ext (event_capabilities => sub {
46 my ($cap) = @_;
47
48 if (my $ts = $cap->{tileset}) {
49 if (my ($default) = grep $_->[2] & 1, @$ts) {
50 $self->{tileset} = $default;
51 $self->{tilesize} = $default->[3];
52 $self->setup_req (tileset => $default->[0]);
53
54 my $w = int $self->{mapw} * 32 / $self->{tilesize};
55 my $h = int $self->{maph} * 32 / $self->{tilesize};
56
57 $self->setup_req (mapsize => "${w}x${h}");
58 }
59 }
60 });
40 61
41 $self->{map_widget}->add_command (@$_) 62 $self->{map_widget}->add_command (@$_)
42 for @cmd_help; 63 for @cmd_help;
43 64
44 $self->{noface} = new_from_file CFPlus::Texture 65 $self->{noface} = new_from_file CFPlus::Texture
286 if ($ev->{button} == 1) { 307 if ($ev->{button} == 1) {
287 $::CONN->user_send ("ready_skill $name"); 308 $::CONN->user_send ("ready_skill $name");
288 } elsif ($ev->{button} == 2) { 309 } elsif ($ev->{button} == 2) {
289 $::CONN->user_send ("use_skill $name"); 310 $::CONN->user_send ("use_skill $name");
290 } elsif ($ev->{button} == 3) { 311 } elsif ($ev->{button} == 3) {
312 my $shortname = CFPlus::shorten $name, 14;
291 (new CFPlus::UI::Menu 313 (new CFPlus::UI::Menu
292 items => [ 314 items => [
293 ["bind <i>ready_skill $name</i> to a key" => sub { $::BIND_EDITOR->do_quick_binding (["ready_skill $name"]) }], 315 ["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"]) }], 316 ["bind <i>use_skill $shortname</i> to a key" => sub { CFPlus::Macro::quick_macro ["use_skill $name"] }],
295 ], 317 ],
296 )->popup ($ev); 318 )->popup ($ev);
297 } else { 319 } else {
298 return 0; 320 return 0;
299 } 321 }
316 $self->{stat_widget_exp}{$_}->set_text (::formsep ($stats->{$_}[1])); 338 $self->{stat_widget_exp}{$_}->set_text (::formsep ($stats->{$_}[1]));
317 $self->{stat_widget_lvl}{$_}->set_text ($stats->{$_}[0] * 1); 339 $self->{stat_widget_lvl}{$_}->set_text ($stats->{$_}[0] * 1);
318 } 340 }
319} 341}
320 342
343sub macro_send {
344 my ($self, $macro) = @_;
345
346 for my $cmd (@{ $macro->{action} }) {
347 $self->send_command ($cmd);
348 }
349}
350
321sub user_send { 351sub user_send {
322 my ($self, $command) = @_; 352 my ($self, $command) = @_;
323 353
354 $self->{record}->($command)
324 if ($self->{record}) { 355 if $self->{record};
325 push @{$self->{record}}, $command;
326 }
327 356
328 $self->logprint ("send: ", $command); 357 $self->logprint ("send: ", $command);
329 $self->send_command ($command); 358 $self->send_command ($command);
330 ::status ($command); 359 ::status ($command);
331} 360}
332 361
333sub start_record { 362sub record {
334 my ($self) = @_; 363 my ($self, $cb) = @_;
335 364
336 $self->{record} = []; 365 $self->{record} = $cb;
337}
338
339sub stop_record {
340 my ($self) = @_;
341 return delete $self->{record};
342} 366}
343 367
344sub map_scroll { 368sub map_scroll {
345 my ($self, $dx, $dy) = @_; 369 my ($self, $dx, $dy) = @_;
346 370
621 [0.75, 0.61, 0.20], 645 [0.75, 0.61, 0.20],
622 [0.99, 0.77, 0.26], 646 [0.99, 0.77, 0.26],
623 [0.74, 0.65, 0.41], 647 [0.74, 0.65, 0.41],
624 ); 648 );
625 649
650 my $fg = $color[$color % @color];
651
626 $self->logprint ("info: ", $text); 652 $self->logprint ("info: ", $text);
627 653
628 # try to create single paragraphs of multiple lines sent by the server 654 # try to create single paragraphs of multiple lines sent by the server
629 $text =~ s/(?<=\S)\n(?=\w)/ /g; 655 $text =~ s/(?<=\S)\n(?=\w)/ /g;
630 656
631 $text = CFPlus::asxml $text; 657 $text = CFPlus::asxml $text;
632 $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g; 658 $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g;
633 $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g; 659 $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g;
634 660
635 ::message ({ fg => $color[$color], markup => $_ }) 661 ::message ({ fg => $fg, markup => $_ })
636 for split /\n/, $text; 662 for split /\n/, $text;
637 663
638 $self->{statusbox}->add ($text, 664 $self->{statusbox}->add ($text,
639 group => $text, 665 group => $text,
640 fg => $color[$color], 666 fg => $fg,
641 timeout => $color >= 2 ? 180 : 10, 667 timeout => $color >= 2 ? 180 : 10,
642 tooltip_font => $::FONT_FIXED, 668 tooltip_font => $::FONT_FIXED,
643 ); 669 );
644} 670}
645 671
655 # try to create single paragraphs out of the multiple lines sent by the server 681 # try to create single paragraphs out of the multiple lines sent by the server
656 $spell->{message} =~ s/(?<=\S)\n(?=\w)/ /g; 682 $spell->{message} =~ s/(?<=\S)\n(?=\w)/ /g;
657 $spell->{message} =~ s/\n+$//; 683 $spell->{message} =~ s/\n+$//;
658 $spell->{message} ||= "Server did not provide a description for this spell."; 684 $spell->{message} ||= "Server did not provide a description for this spell.";
659 685
660 $::SPELL_PAGE->add_spell ($spell); 686 $::SPELL_LIST->add_spell ($spell);
661 687
662 $self->{map_widget}->add_command ("invoke $spell->{name}", CFPlus::asxml $spell->{message}); 688 $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}); 689 $self->{map_widget}->add_command ("cast $spell->{name}", CFPlus::asxml $spell->{message});
664} 690}
665 691
666sub spell_delete { 692sub spell_delete {
667 my ($self, $spell) = @_; 693 my ($self, $spell) = @_;
668 694
669 $::SPELL_PAGE->remove_spell ($spell); 695 $::SPELL_LIST->remove_spell ($spell);
696}
697
698sub setup {
699 my ($self, $setup) = @_;
700
701 $self->{map_widget}->set_tilesize ($self->{tilesize});
702 $::MAP->resize ($self->{mapw}, $self->{maph});
670} 703}
671 704
672sub addme_success { 705sub addme_success {
673 my ($self) = @_; 706 my ($self) = @_;
674 707
886 . "map attributes $yesno[$self->{setup}{extmap} > 0]\n" 919 . "map attributes $yesno[$self->{setup}{extmap} > 0]\n"
887 . "cfplus support $yesno[$self->{cfplus_ext} > 0]" 920 . "cfplus support $yesno[$self->{cfplus_ext} > 0]"
888 . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" 921 . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n"
889 . "map size $self->{mapw}×$self->{maph}\n" 922 . "map size $self->{mapw}×$self->{maph}\n"
890 ); 923 );
924
925 ::setup_build_button ($self->{editor_support}->{builder_ui});
891} 926}
892 927
893sub logged_in { 928sub logged_in {
894 my ($self) = @_; 929 my ($self) = @_;
895 930
911 946
912 $self->update_server_info; 947 $self->update_server_info;
913 948
914 $self->send_command ("output-sync $::CFG->{output_sync}"); 949 $self->send_command ("output-sync $::CFG->{output_sync}");
915 $self->send_command ("output-count $::CFG->{output_count}"); 950 $self->send_command ("output-count $::CFG->{output_count}");
951 $self->send_command ("output-rate $::CFG->{output_rate}") if $::CFG->{output_rate} > 0;
916 $self->send_command ("pickup $::CFG->{pickup}"); 952 $self->send_command ("pickup $::CFG->{pickup}");
953}
954
955sub buildat {
956 my ($self, $builditem, $x, $y) = @_;
957
958 if ($self->{cfplus_ext}) {
959 $self->send_ext_msg (builder_build => dx => $x, dy => $y, (ref ($builditem) eq 'HASH') ? %$builditem : (item => $builditem));
960 }
917} 961}
918 962
919sub lookat { 963sub lookat {
920 my ($self, $x, $y) = @_; 964 my ($self, $x, $y) = @_;
921 965
964 kw => { hi => 0, yes => 0, no => 0 }, 1008 kw => { hi => 0, yes => 0, no => 0 },
965 has_close_button => 1, 1009 has_close_button => 1,
966 @_, 1010 @_,
967 ); 1011 );
968 1012
969 Scalar::Util::weaken (my $this = $self); 1013 CFPlus::weaken (my $this = $self);
970 1014
971 $self->connect (delete => sub { $this->destroy; 1 }); 1015 $self->connect (delete => sub { $this->destroy; 1 });
972 1016
973 # better use a pane... 1017 # better use a pane...
974 $self->add (my $hbox = new CFPlus::UI::HBox); 1018 $self->add (my $hbox = new CFPlus::UI::HBox);
1018}; 1062};
1019 1063
1020sub update_options { 1064sub update_options {
1021 my ($self) = @_; 1065 my ($self) = @_;
1022 1066
1023 Scalar::Util::weaken $self; 1067 CFPlus::weaken $self;
1024 1068
1025 $self->{options}->clear; 1069 $self->{options}->clear;
1026 $self->{options}->add ($self->{bye_button}); 1070 $self->{options}->add ($self->{bye_button});
1027 1071
1028 for my $kw (sort keys %{ $self->{kw} }) { 1072 for my $kw (sort keys %{ $self->{kw} }) {
1037} 1081}
1038 1082
1039sub feed { 1083sub feed {
1040 my ($self, $msg) = @_; 1084 my ($self, $msg) = @_;
1041 1085
1042 Scalar::Util::weaken $self; 1086 CFPlus::weaken $self;
1043 1087
1044 if ($msg->{msgtype} eq "reply") { 1088 if ($msg->{msgtype} eq "reply") {
1045 $self->{kw}{$_} = 1 for @{$msg->{add_topics} || []}; 1089 $self->{kw}{$_} = 1 for @{$msg->{add_topics} || []};
1046 $self->{kw}{$_} = 0 for @{$msg->{del_topics} || []}; 1090 $self->{kw}{$_} = 0 for @{$msg->{del_topics} || []};
1047 1091

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines