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.88 by root, Sun Nov 19 20:31:29 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;
11 13
12use Crossfire::Protocol::Base 0.95; 14use Crossfire::Protocol::Base 0.95;
13 15
14use base 'Crossfire::Protocol::Base'; 16use base 'Crossfire::Protocol::Base';
15 17
37 map ["$cmd$_", $text], 39 map ["$cmd$_", $text],
38 sort { (length $a) <=> (length $b) } 40 sort { (length $a) <=> (length $b) }
39 @args 41 @args
40 } sort { $a->{par} <=> $b->{par} } 42 } sort { $a->{par} <=> $b->{par} }
41 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 });
42 61
43 $self->{map_widget}->add_command (@$_) 62 $self->{map_widget}->add_command (@$_)
44 for @cmd_help; 63 for @cmd_help;
45 64
46 $self->{noface} = new_from_file CFPlus::Texture 65 $self->{noface} = new_from_file CFPlus::Texture
288 if ($ev->{button} == 1) { 307 if ($ev->{button} == 1) {
289 $::CONN->user_send ("ready_skill $name"); 308 $::CONN->user_send ("ready_skill $name");
290 } elsif ($ev->{button} == 2) { 309 } elsif ($ev->{button} == 2) {
291 $::CONN->user_send ("use_skill $name"); 310 $::CONN->user_send ("use_skill $name");
292 } elsif ($ev->{button} == 3) { 311 } elsif ($ev->{button} == 3) {
312 my $shortname = CFPlus::shorten $name, 14;
293 (new CFPlus::UI::Menu 313 (new CFPlus::UI::Menu
294 items => [ 314 items => [
295 ["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"] }],
296 ["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"] }],
297 ], 317 ],
298 )->popup ($ev); 318 )->popup ($ev);
299 } else { 319 } else {
300 return 0; 320 return 0;
301 } 321 }
318 $self->{stat_widget_exp}{$_}->set_text (::formsep ($stats->{$_}[1])); 338 $self->{stat_widget_exp}{$_}->set_text (::formsep ($stats->{$_}[1]));
319 $self->{stat_widget_lvl}{$_}->set_text ($stats->{$_}[0] * 1); 339 $self->{stat_widget_lvl}{$_}->set_text ($stats->{$_}[0] * 1);
320 } 340 }
321} 341}
322 342
343sub macro_send {
344 my ($self, $macro) = @_;
345
346 for my $cmd (@{ $macro->{action} }) {
347 $self->send_command ($cmd);
348 }
349}
350
323sub user_send { 351sub user_send {
324 my ($self, $command) = @_; 352 my ($self, $command) = @_;
325 353
326 push @{$self->{record}}, $command 354 $self->{record}->($command)
327 if $self->{record}; 355 if $self->{record};
328 356
329 $self->logprint ("send: ", $command); 357 $self->logprint ("send: ", $command);
330 $self->send_command ($command); 358 $self->send_command ($command);
331 ::status ($command); 359 ::status ($command);
332} 360}
333 361
334sub start_record { 362sub record {
335 my ($self) = @_; 363 my ($self, $cb) = @_;
336 364
337 $self->{record} = []; 365 $self->{record} = $cb;
338}
339
340sub stop_record {
341 my ($self) = @_;
342 return delete $self->{record};
343} 366}
344 367
345sub map_scroll { 368sub map_scroll {
346 my ($self, $dx, $dy) = @_; 369 my ($self, $dx, $dy) = @_;
347 370
622 [0.75, 0.61, 0.20], 645 [0.75, 0.61, 0.20],
623 [0.99, 0.77, 0.26], 646 [0.99, 0.77, 0.26],
624 [0.74, 0.65, 0.41], 647 [0.74, 0.65, 0.41],
625 ); 648 );
626 649
650 my $fg = $color[$color % @color];
651
627 $self->logprint ("info: ", $text); 652 $self->logprint ("info: ", $text);
628 653
629 # 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
630 $text =~ s/(?<=\S)\n(?=\w)/ /g; 655 $text =~ s/(?<=\S)\n(?=\w)/ /g;
631 656
632 $text = CFPlus::asxml $text; 657 $text = CFPlus::asxml $text;
633 $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g; 658 $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g;
634 $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g; 659 $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g;
635 660
636 ::message ({ fg => $color[$color], markup => $_ }) 661 ::message ({ fg => $fg, markup => $_ })
637 for split /\n/, $text; 662 for split /\n/, $text;
638 663
639 $self->{statusbox}->add ($text, 664 $self->{statusbox}->add ($text,
640 group => $text, 665 group => $text,
641 fg => $color[$color], 666 fg => $fg,
642 timeout => $color >= 2 ? 180 : 10, 667 timeout => $color >= 2 ? 180 : 10,
643 tooltip_font => $::FONT_FIXED, 668 tooltip_font => $::FONT_FIXED,
644 ); 669 );
645} 670}
646 671
671} 696}
672 697
673sub setup { 698sub setup {
674 my ($self, $setup) = @_; 699 my ($self, $setup) = @_;
675 700
701 $self->{map_widget}->set_tilesize ($self->{tilesize});
676 $::MAP->resize ($self->{mapw}, $self->{maph}); 702 $::MAP->resize ($self->{mapw}, $self->{maph});
677} 703}
678 704
679sub addme_success { 705sub addme_success {
680 my ($self) = @_; 706 my ($self) = @_;
893 . "map attributes $yesno[$self->{setup}{extmap} > 0]\n" 919 . "map attributes $yesno[$self->{setup}{extmap} > 0]\n"
894 . "cfplus support $yesno[$self->{cfplus_ext} > 0]" 920 . "cfplus support $yesno[$self->{cfplus_ext} > 0]"
895 . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" 921 . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n"
896 . "map size $self->{mapw}×$self->{maph}\n" 922 . "map size $self->{mapw}×$self->{maph}\n"
897 ); 923 );
924
925 ::setup_build_button ($self->{editor_support}->{builder_ui});
898} 926}
899 927
900sub logged_in { 928sub logged_in {
901 my ($self) = @_; 929 my ($self) = @_;
902 930
918 946
919 $self->update_server_info; 947 $self->update_server_info;
920 948
921 $self->send_command ("output-sync $::CFG->{output_sync}"); 949 $self->send_command ("output-sync $::CFG->{output_sync}");
922 $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;
923 $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 }
924} 961}
925 962
926sub lookat { 963sub lookat {
927 my ($self, $x, $y) = @_; 964 my ($self, $x, $y) = @_;
928 965
971 kw => { hi => 0, yes => 0, no => 0 }, 1008 kw => { hi => 0, yes => 0, no => 0 },
972 has_close_button => 1, 1009 has_close_button => 1,
973 @_, 1010 @_,
974 ); 1011 );
975 1012
976 Scalar::Util::weaken (my $this = $self); 1013 CFPlus::weaken (my $this = $self);
977 1014
978 $self->connect (delete => sub { $this->destroy; 1 }); 1015 $self->connect (delete => sub { $this->destroy; 1 });
979 1016
980 # better use a pane... 1017 # better use a pane...
981 $self->add (my $hbox = new CFPlus::UI::HBox); 1018 $self->add (my $hbox = new CFPlus::UI::HBox);
1025}; 1062};
1026 1063
1027sub update_options { 1064sub update_options {
1028 my ($self) = @_; 1065 my ($self) = @_;
1029 1066
1030 Scalar::Util::weaken $self; 1067 CFPlus::weaken $self;
1031 1068
1032 $self->{options}->clear; 1069 $self->{options}->clear;
1033 $self->{options}->add ($self->{bye_button}); 1070 $self->{options}->add ($self->{bye_button});
1034 1071
1035 for my $kw (sort keys %{ $self->{kw} }) { 1072 for my $kw (sort keys %{ $self->{kw} }) {
1044} 1081}
1045 1082
1046sub feed { 1083sub feed {
1047 my ($self, $msg) = @_; 1084 my ($self, $msg) = @_;
1048 1085
1049 Scalar::Util::weaken $self; 1086 CFPlus::weaken $self;
1050 1087
1051 if ($msg->{msgtype} eq "reply") { 1088 if ($msg->{msgtype} eq "reply") {
1052 $self->{kw}{$_} = 1 for @{$msg->{add_topics} || []}; 1089 $self->{kw}{$_} = 1 for @{$msg->{add_topics} || []};
1053 $self->{kw}{$_} = 0 for @{$msg->{del_topics} || []}; 1090 $self->{kw}{$_} = 0 for @{$msg->{del_topics} || []};
1054 1091

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines