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.84 by root, Fri Sep 29 00:56:06 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
628 my $time = sprintf "%02d:%02d:%02d", (localtime time)[2,1,0];
629 653
630 # 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
631 $text =~ s/(?<=\S)\n(?=\w)/ /g; 655 $text =~ s/(?<=\S)\n(?=\w)/ /g;
632 656
633 $text = CFPlus::asxml $text; 657 $text = CFPlus::asxml $text;
634 $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g; 658 $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g;
635 $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g; 659 $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g;
636 660
637 $self->{logview}->add_paragraph ({ fg => $color[$color], markup => $_ }) 661 ::message ({ fg => $fg, markup => $_ })
638 for map "<span foreground='#ffffff'>$time</span> $_", split /\n/, $text; 662 for split /\n/, $text;
639 $self->{logview}->scroll_to_bottom;
640 663
641 $self->{statusbox}->add ($text, 664 $self->{statusbox}->add ($text,
642 group => $text, 665 group => $text,
643 fg => $color[$color], 666 fg => $fg,
644 timeout => $color >= 2 ? 180 : 10, 667 timeout => $color >= 2 ? 180 : 10,
645 tooltip_font => $::FONT_FIXED, 668 tooltip_font => $::FONT_FIXED,
646 ); 669 );
647} 670}
648 671
658 # 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
659 $spell->{message} =~ s/(?<=\S)\n(?=\w)/ /g; 682 $spell->{message} =~ s/(?<=\S)\n(?=\w)/ /g;
660 $spell->{message} =~ s/\n+$//; 683 $spell->{message} =~ s/\n+$//;
661 $spell->{message} ||= "Server did not provide a description for this spell."; 684 $spell->{message} ||= "Server did not provide a description for this spell.";
662 685
663 $::SPELL_PAGE->add_spell ($spell); 686 $::SPELL_LIST->add_spell ($spell);
664 687
665 $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});
666 $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});
667} 690}
668 691
669sub spell_delete { 692sub spell_delete {
670 my ($self, $spell) = @_; 693 my ($self, $spell) = @_;
671 694
672 $::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});
673} 703}
674 704
675sub addme_success { 705sub addme_success {
676 my ($self) = @_; 706 my ($self) = @_;
677 707
883 $::SERVER_INFO->set_markup ( 913 $::SERVER_INFO->set_markup (
884 "server <tt>$self->{host}:$self->{port}</tt>\n" 914 "server <tt>$self->{host}:$self->{port}</tt>\n"
885 . "protocol version <tt>$self->{version}</tt>\n" 915 . "protocol version <tt>$self->{version}</tt>\n"
886 . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n" 916 . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n"
887 . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n" 917 . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n"
918 . "editing support $yesno[!!$self->{editor_support}]\n"
888 . "map attributes $yesno[$self->{setup}{extmap} > 0]\n" 919 . "map attributes $yesno[$self->{setup}{extmap} > 0]\n"
889 . "cfplus support $yesno[$self->{cfplus_ext} > 0]" 920 . "cfplus support $yesno[$self->{cfplus_ext} > 0]"
890 . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" 921 . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n"
891 . "map size $self->{mapw}×$self->{maph}\n" 922 . "map size $self->{mapw}×$self->{maph}\n"
892 ); 923 );
924
925 ::setup_build_button ($self->{editor_support}->{builder_ui});
893} 926}
894 927
895sub logged_in { 928sub logged_in {
896 my ($self) = @_; 929 my ($self) = @_;
897 930
898 $self->send_ext_req (cfplus_support => version => 1, sub { 931 $self->send_ext_req (cfplus_support => version => 1, sub {
899 $self->{cfplus_ext} = $_[0]{version}; 932 $self->{cfplus_ext} = $_[0]{version};
900 $self->update_server_info; 933 $self->update_server_info;
901 934
935 if ($self->{cfplus_ext} >= 2) {
936 $self->send_ext_req ("editor_support", sub {
937 $self->{editor_support} = $_[0];
938 $self->update_server_info;
939
940 0
941 });
942 }
943
902 0 944 0
903 }); 945 });
904 946
905 $self->update_server_info; 947 $self->update_server_info;
906 948
907 $self->send_command ("output-sync $::CFG->{output_sync}"); 949 $self->send_command ("output-sync $::CFG->{output_sync}");
908 $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;
909 $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 }
910} 961}
911 962
912sub lookat { 963sub lookat {
913 my ($self, $x, $y) = @_; 964 my ($self, $x, $y) = @_;
914 965
957 kw => { hi => 0, yes => 0, no => 0 }, 1008 kw => { hi => 0, yes => 0, no => 0 },
958 has_close_button => 1, 1009 has_close_button => 1,
959 @_, 1010 @_,
960 ); 1011 );
961 1012
962 Scalar::Util::weaken (my $this = $self); 1013 CFPlus::weaken (my $this = $self);
963 1014
964 $self->connect (delete => sub { $this->destroy; 1 }); 1015 $self->connect (delete => sub { $this->destroy; 1 });
965 1016
966 # better use a pane... 1017 # better use a pane...
967 $self->add (my $hbox = new CFPlus::UI::HBox); 1018 $self->add (my $hbox = new CFPlus::UI::HBox);
1011}; 1062};
1012 1063
1013sub update_options { 1064sub update_options {
1014 my ($self) = @_; 1065 my ($self) = @_;
1015 1066
1016 Scalar::Util::weaken $self; 1067 CFPlus::weaken $self;
1017 1068
1018 $self->{options}->clear; 1069 $self->{options}->clear;
1019 $self->{options}->add ($self->{bye_button}); 1070 $self->{options}->add ($self->{bye_button});
1020 1071
1021 for my $kw (sort keys %{ $self->{kw} }) { 1072 for my $kw (sort keys %{ $self->{kw} }) {
1030} 1081}
1031 1082
1032sub feed { 1083sub feed {
1033 my ($self, $msg) = @_; 1084 my ($self, $msg) = @_;
1034 1085
1035 Scalar::Util::weaken $self; 1086 CFPlus::weaken $self;
1036 1087
1037 if ($msg->{msgtype} eq "reply") { 1088 if ($msg->{msgtype} eq "reply") {
1038 $self->{kw}{$_} = 1 for @{$msg->{add_topics} || []}; 1089 $self->{kw}{$_} = 1 for @{$msg->{add_topics} || []};
1039 $self->{kw}{$_} = 0 for @{$msg->{del_topics} || []}; 1090 $self->{kw}{$_} = 0 for @{$msg->{del_topics} || []};
1040 1091

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines