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.82 by root, Sat Aug 19 02:53:48 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;
41 $self->{map_widget}->add_command (@$_) 45 $self->{map_widget}->add_command (@$_)
42 for @cmd_help; 46 for @cmd_help;
43 47
44 $self->{noface} = new_from_file CFPlus::Texture 48 $self->{noface} = new_from_file CFPlus::Texture
45 CFPlus::find_rcfile "noface.png", minify => 1, mipmap => 1; 49 CFPlus::find_rcfile "noface.png", minify => 1, mipmap => 1;
50
51 {
52 $self->{dialogue} = my $tex = new_from_file CFPlus::Texture
53 CFPlus::find_rcfile "dialogue.png", minify => 1, mipmap => 1;
54 $self->{map}->set_texture (1, @$tex{qw(name w h s t)}, @{$tex->{minified}});
55 }
46 56
47 $self->{open_container} = 0; 57 $self->{open_container} = 0;
48 58
49 # "global" 59 # "global"
50 $self->{tilecache} = CFPlus::db_table "tilecache" 60 $self->{tilecache} = CFPlus::db_table "tilecache"
280 if ($ev->{button} == 1) { 290 if ($ev->{button} == 1) {
281 $::CONN->user_send ("ready_skill $name"); 291 $::CONN->user_send ("ready_skill $name");
282 } elsif ($ev->{button} == 2) { 292 } elsif ($ev->{button} == 2) {
283 $::CONN->user_send ("use_skill $name"); 293 $::CONN->user_send ("use_skill $name");
284 } elsif ($ev->{button} == 3) { 294 } elsif ($ev->{button} == 3) {
295 my $shortname = CFPlus::shorten $name, 14;
285 (new CFPlus::UI::Menu 296 (new CFPlus::UI::Menu
286 items => [ 297 items => [
287 ["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"] }],
288 ["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"] }],
289 ], 300 ],
290 )->popup ($ev); 301 )->popup ($ev);
291 } else { 302 } else {
292 return 0; 303 return 0;
293 } 304 }
310 $self->{stat_widget_exp}{$_}->set_text (::formsep ($stats->{$_}[1])); 321 $self->{stat_widget_exp}{$_}->set_text (::formsep ($stats->{$_}[1]));
311 $self->{stat_widget_lvl}{$_}->set_text ($stats->{$_}[0] * 1); 322 $self->{stat_widget_lvl}{$_}->set_text ($stats->{$_}[0] * 1);
312 } 323 }
313} 324}
314 325
326sub macro_send {
327 my ($self, $macro) = @_;
328
329 for my $cmd (@{ $macro->{action} }) {
330 $self->send_command ($cmd);
331 }
332}
333
315sub user_send { 334sub user_send {
316 my ($self, $command) = @_; 335 my ($self, $command) = @_;
317 336
337 $self->{record}->($command)
318 if ($self->{record}) { 338 if $self->{record};
319 push @{$self->{record}}, $command;
320 }
321 339
322 $self->logprint ("send: ", $command); 340 $self->logprint ("send: ", $command);
323 $self->send_command ($command); 341 $self->send_command ($command);
324 ::status ($command); 342 ::status ($command);
325} 343}
326 344
327sub start_record { 345sub record {
328 my ($self) = @_; 346 my ($self, $cb) = @_;
329 347
330 $self->{record} = []; 348 $self->{record} = $cb;
331}
332
333sub stop_record {
334 my ($self) = @_;
335 return delete $self->{record};
336} 349}
337 350
338sub map_scroll { 351sub map_scroll {
339 my ($self, $dx, $dy) = @_; 352 my ($self, $dx, $dy) = @_;
340 353
615 [0.75, 0.61, 0.20], 628 [0.75, 0.61, 0.20],
616 [0.99, 0.77, 0.26], 629 [0.99, 0.77, 0.26],
617 [0.74, 0.65, 0.41], 630 [0.74, 0.65, 0.41],
618 ); 631 );
619 632
633 my $fg = $color[$color % @color];
634
620 $self->logprint ("info: ", $text); 635 $self->logprint ("info: ", $text);
621
622 my $time = sprintf "%02d:%02d:%02d", (localtime time)[2,1,0];
623 636
624 # 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
625 $text =~ s/(?<=\S)\n(?=\w)/ /g; 638 $text =~ s/(?<=\S)\n(?=\w)/ /g;
626 639
627 $text = CFPlus::asxml $text; 640 $text = CFPlus::asxml $text;
628 $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g; 641 $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g;
629 $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g; 642 $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g;
630 643
631 $self->{logview}->add_paragraph ({ fg => $color[$color], markup => $_ }) 644 ::message ({ fg => $fg, markup => $_ })
632 for map "<span foreground='#ffffff'>$time</span> $_", split /\n/, $text; 645 for split /\n/, $text;
633 $self->{logview}->scroll_to_bottom;
634 646
635 $self->{statusbox}->add ($text, 647 $self->{statusbox}->add ($text,
636 group => $text, 648 group => $text,
637 fg => $color[$color], 649 fg => $fg,
638 timeout => $color >= 2 ? 180 : 10, 650 timeout => $color >= 2 ? 180 : 10,
639 tooltip_font => $::FONT_FIXED, 651 tooltip_font => $::FONT_FIXED,
640 ); 652 );
641} 653}
642 654
652 # 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
653 $spell->{message} =~ s/(?<=\S)\n(?=\w)/ /g; 665 $spell->{message} =~ s/(?<=\S)\n(?=\w)/ /g;
654 $spell->{message} =~ s/\n+$//; 666 $spell->{message} =~ s/\n+$//;
655 $spell->{message} ||= "Server did not provide a description for this spell."; 667 $spell->{message} ||= "Server did not provide a description for this spell.";
656 668
657 $::SPELL_PAGE->add_spell ($spell); 669 $::SPELL_LIST->add_spell ($spell);
658 670
659 $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});
660 $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});
661} 673}
662 674
663sub spell_delete { 675sub spell_delete {
664 my ($self, $spell) = @_; 676 my ($self, $spell) = @_;
665 677
666 $::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});
667} 685}
668 686
669sub addme_success { 687sub addme_success {
670 my ($self) = @_; 688 my ($self) = @_;
671 689
877 $::SERVER_INFO->set_markup ( 895 $::SERVER_INFO->set_markup (
878 "server <tt>$self->{host}:$self->{port}</tt>\n" 896 "server <tt>$self->{host}:$self->{port}</tt>\n"
879 . "protocol version <tt>$self->{version}</tt>\n" 897 . "protocol version <tt>$self->{version}</tt>\n"
880 . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n" 898 . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n"
881 . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n" 899 . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n"
900 . "editing support $yesno[!!$self->{editor_support}]\n"
882 . "map attributes $yesno[$self->{setup}{extmap} > 0]\n" 901 . "map attributes $yesno[$self->{setup}{extmap} > 0]\n"
883 . "cfplus support $yesno[$self->{cfplus_ext} > 0]" 902 . "cfplus support $yesno[$self->{cfplus_ext} > 0]"
884 . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" 903 . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n"
885 . "map size $self->{mapw}×$self->{maph}\n" 904 . "map size $self->{mapw}×$self->{maph}\n"
886 ); 905 );
906
907 ::setup_build_button ($self->{editor_support}->{builder_ui});
887} 908}
888 909
889sub logged_in { 910sub logged_in {
890 my ($self) = @_; 911 my ($self) = @_;
891 912
892 $self->send_ext_req (cfplus_support => version => 1, sub { 913 $self->send_ext_req (cfplus_support => version => 1, sub {
893 $self->{cfplus_ext} = $_[0]{version}; 914 $self->{cfplus_ext} = $_[0]{version};
894 $self->update_server_info; 915 $self->update_server_info;
895 916
917 if ($self->{cfplus_ext} >= 2) {
918 $self->send_ext_req ("editor_support", sub {
919 $self->{editor_support} = $_[0];
920 $self->update_server_info;
921
922 0
923 });
924 }
925
896 0 926 0
897 }); 927 });
898 928
899 $self->update_server_info; 929 $self->update_server_info;
900 930
901 $self->send_command ("output-sync $::CFG->{output_sync}"); 931 $self->send_command ("output-sync $::CFG->{output_sync}");
902 $self->send_command ("output-count $::CFG->{output_count}"); 932 $self->send_command ("output-count $::CFG->{output_count}");
903 $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 }
904} 942}
905 943
906sub lookat { 944sub lookat {
907 my ($self, $x, $y) = @_; 945 my ($self, $x, $y) = @_;
908 946
951 kw => { hi => 0, yes => 0, no => 0 }, 989 kw => { hi => 0, yes => 0, no => 0 },
952 has_close_button => 1, 990 has_close_button => 1,
953 @_, 991 @_,
954 ); 992 );
955 993
956 Scalar::Util::weaken (my $this = $self); 994 CFPlus::weaken (my $this = $self);
957 995
958 $self->connect (delete => sub { $this->destroy; 1 }); 996 $self->connect (delete => sub { $this->destroy; 1 });
959 997
960 # better use a pane... 998 # better use a pane...
961 $self->add (my $hbox = new CFPlus::UI::HBox); 999 $self->add (my $hbox = new CFPlus::UI::HBox);
1005}; 1043};
1006 1044
1007sub update_options { 1045sub update_options {
1008 my ($self) = @_; 1046 my ($self) = @_;
1009 1047
1010 Scalar::Util::weaken $self; 1048 CFPlus::weaken $self;
1011 1049
1012 $self->{options}->clear; 1050 $self->{options}->clear;
1013 $self->{options}->add ($self->{bye_button}); 1051 $self->{options}->add ($self->{bye_button});
1014 1052
1015 for my $kw (sort keys %{ $self->{kw} }) { 1053 for my $kw (sort keys %{ $self->{kw} }) {
1024} 1062}
1025 1063
1026sub feed { 1064sub feed {
1027 my ($self, $msg) = @_; 1065 my ($self, $msg) = @_;
1028 1066
1029 Scalar::Util::weaken $self; 1067 CFPlus::weaken $self;
1030 1068
1031 if ($msg->{msgtype} eq "reply") { 1069 if ($msg->{msgtype} eq "reply") {
1032 $self->{kw}{$_} = 1 for @{$msg->{add_topics} || []}; 1070 $self->{kw}{$_} = 1 for @{$msg->{add_topics} || []};
1033 $self->{kw}{$_} = 0 for @{$msg->{del_topics} || []}; 1071 $self->{kw}{$_} = 0 for @{$msg->{del_topics} || []};
1034 1072
1085 1123
1086 $self->SUPER::destroy; 1124 $self->SUPER::destroy;
1087} 1125}
1088 1126
10891 11271
1128

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines