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.75 by root, Sun Aug 13 19:47:05 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;
16 20
17 my $self = $class->SUPER::new (@_); 21 my $self = $class->SUPER::new (@_, setup_req => { extmap => 1 });
18 22
19 $self->{map_widget}->clr_commands; 23 $self->{map_widget}->clr_commands;
20 24
21 my @cmd_help = map { 25 my @cmd_help = map {
22 $_->{kw}[0] =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x 26 $_->{kw}[0] =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x
34 38
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_help => "*"; 43 CFPlus::Pod::find command => "*";
40 44
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;
46 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 }
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"
61 or die "tilecache: unable to open database table";
51 $self->{facemap} = CFPlus::db_table "facemap"; 62 $self->{facemap} = CFPlus::db_table "facemap"
63 or die "facemap: unable to open database table";
52 64
53 # per server 65 # per server
54 $self->{mapcache} = CFPlus::db_table "mapcache_$self->{host}_$self->{port}"; 66 $self->{mapcache} = CFPlus::db_table "mapcache_$self->{host}_$self->{port}"
67 or die "mapcache_$self->{host}_$self->{port}: unable to open database table";
55 68
56 $self 69 $self
57} 70}
58 71
59sub logprint { 72sub logprint {
277 if ($ev->{button} == 1) { 290 if ($ev->{button} == 1) {
278 $::CONN->user_send ("ready_skill $name"); 291 $::CONN->user_send ("ready_skill $name");
279 } elsif ($ev->{button} == 2) { 292 } elsif ($ev->{button} == 2) {
280 $::CONN->user_send ("use_skill $name"); 293 $::CONN->user_send ("use_skill $name");
281 } elsif ($ev->{button} == 3) { 294 } elsif ($ev->{button} == 3) {
295 my $shortname = CFPlus::shorten $name, 14;
282 (new CFPlus::UI::Menu 296 (new CFPlus::UI::Menu
283 items => [ 297 items => [
284 ["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"] }],
285 ["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"] }],
286 ], 300 ],
287 )->popup ($ev); 301 )->popup ($ev);
288 } else { 302 } else {
289 return 0; 303 return 0;
290 } 304 }
307 $self->{stat_widget_exp}{$_}->set_text (::formsep ($stats->{$_}[1])); 321 $self->{stat_widget_exp}{$_}->set_text (::formsep ($stats->{$_}[1]));
308 $self->{stat_widget_lvl}{$_}->set_text ($stats->{$_}[0] * 1); 322 $self->{stat_widget_lvl}{$_}->set_text ($stats->{$_}[0] * 1);
309 } 323 }
310} 324}
311 325
326sub macro_send {
327 my ($self, $macro) = @_;
328
329 for my $cmd (@{ $macro->{action} }) {
330 $self->send_command ($cmd);
331 }
332}
333
312sub user_send { 334sub user_send {
313 my ($self, $command) = @_; 335 my ($self, $command) = @_;
314 336
337 $self->{record}->($command)
315 if ($self->{record}) { 338 if $self->{record};
316 push @{$self->{record}}, $command;
317 }
318 339
319 $self->logprint ("send: ", $command); 340 $self->logprint ("send: ", $command);
320 $self->send_command ($command); 341 $self->send_command ($command);
321 ::status ($command); 342 ::status ($command);
322} 343}
323 344
324sub start_record { 345sub record {
325 my ($self) = @_; 346 my ($self, $cb) = @_;
326 347
327 $self->{record} = []; 348 $self->{record} = $cb;
328}
329
330sub stop_record {
331 my ($self) = @_;
332 return delete $self->{record};
333} 349}
334 350
335sub map_scroll { 351sub map_scroll {
336 my ($self, $dx, $dy) = @_; 352 my ($self, $dx, $dy) = @_;
337 353
339} 355}
340 356
341sub feed_map1a { 357sub feed_map1a {
342 my ($self, $data) = @_; 358 my ($self, $data) = @_;
343 359
344 $self->{map}->map1a_update ($data); 360 $self->{map}->map1a_update ($data, $self->{setup}{extmap});
345 $self->{map_widget}->update; 361 $self->{map_widget}->update;
346} 362}
347 363
348sub magicmap { 364sub magicmap {
349 my ($self, $w, $h, $x, $y, $data) = @_; 365 my ($self, $w, $h, $x, $y, $data) = @_;
612 [0.75, 0.61, 0.20], 628 [0.75, 0.61, 0.20],
613 [0.99, 0.77, 0.26], 629 [0.99, 0.77, 0.26],
614 [0.74, 0.65, 0.41], 630 [0.74, 0.65, 0.41],
615 ); 631 );
616 632
633 my $fg = $color[$color % @color];
634
617 $self->logprint ("info: ", $text); 635 $self->logprint ("info: ", $text);
618
619 my $time = sprintf "%02d:%02d:%02d", (localtime time)[2,1,0];
620 636
621 # 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
622 $text =~ s/(?<=\S)\n(?=\w)/ /g; 638 $text =~ s/(?<=\S)\n(?=\w)/ /g;
623 639
624 $text = CFPlus::asxml $text; 640 $text = CFPlus::asxml $text;
625 $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g; 641 $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g;
626 $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g; 642 $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g;
627 643
628 $self->{logview}->add_paragraph ({ fg => $color[$color], markup => $_ }) 644 ::message ({ fg => $fg, markup => $_ })
629 for map "<span foreground='#ffffff'>$time</span> $_", split /\n/, $text; 645 for split /\n/, $text;
630 $self->{logview}->scroll_to_bottom;
631 646
632 $self->{statusbox}->add ($text, 647 $self->{statusbox}->add ($text,
633 group => $text, 648 group => $text,
634 fg => $color[$color], 649 fg => $fg,
635 timeout => $color >= 2 ? 180 : 10, 650 timeout => $color >= 2 ? 180 : 10,
636 tooltip_font => $::FONT_FIXED, 651 tooltip_font => $::FONT_FIXED,
637 ); 652 );
638} 653}
639 654
649 # 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
650 $spell->{message} =~ s/(?<=\S)\n(?=\w)/ /g; 665 $spell->{message} =~ s/(?<=\S)\n(?=\w)/ /g;
651 $spell->{message} =~ s/\n+$//; 666 $spell->{message} =~ s/\n+$//;
652 $spell->{message} ||= "Server did not provide a description for this spell."; 667 $spell->{message} ||= "Server did not provide a description for this spell.";
653 668
654 $::SPELL_PAGE->add_spell ($spell); 669 $::SPELL_LIST->add_spell ($spell);
655 670
656 $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});
657 $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});
658} 673}
659 674
660sub spell_delete { 675sub spell_delete {
661 my ($self, $spell) = @_; 676 my ($self, $spell) = @_;
662 677
663 $::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});
664} 685}
665 686
666sub addme_success { 687sub addme_success {
667 my ($self) = @_; 688 my ($self) = @_;
668 689
874 $::SERVER_INFO->set_markup ( 895 $::SERVER_INFO->set_markup (
875 "server <tt>$self->{host}:$self->{port}</tt>\n" 896 "server <tt>$self->{host}:$self->{port}</tt>\n"
876 . "protocol version <tt>$self->{version}</tt>\n" 897 . "protocol version <tt>$self->{version}</tt>\n"
877 . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n" 898 . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n"
878 . "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"
901 . "map attributes $yesno[$self->{setup}{extmap} > 0]\n"
879 . "cfplus support $yesno[$self->{cfplus_ext} > 0]" 902 . "cfplus support $yesno[$self->{cfplus_ext} > 0]"
880 . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" 903 . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n"
881 . "map size $self->{mapw}×$self->{maph}\n" 904 . "map size $self->{mapw}×$self->{maph}\n"
882 ); 905 );
906
907 ::setup_build_button ($self->{editor_support}->{builder_ui});
883} 908}
884 909
885sub logged_in { 910sub logged_in {
886 my ($self) = @_; 911 my ($self) = @_;
887 912
888 $self->send_ext_req (cfplus_support => version => 1, sub { 913 $self->send_ext_req (cfplus_support => version => 1, sub {
889 $self->{cfplus_ext} = $_[0]{version}; 914 $self->{cfplus_ext} = $_[0]{version};
890 $self->update_server_info; 915 $self->update_server_info;
891 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
892 0 926 0
893 }); 927 });
894 928
895 $self->update_server_info; 929 $self->update_server_info;
896 930
897 $self->send_command ("output-sync $::CFG->{output_sync}"); 931 $self->send_command ("output-sync $::CFG->{output_sync}");
898 $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;
899 $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 }
900} 943}
901 944
902sub lookat { 945sub lookat {
903 my ($self, $x, $y) = @_; 946 my ($self, $x, $y) = @_;
904 947
922} 965}
923 966
924sub destroy { 967sub destroy {
925 my ($self) = @_; 968 my ($self) = @_;
926 969
927 $self->{npc_dialog}->destroy 970 (delete $self->{npc_dialog})->destroy
928 if $self->{npc_dialog}; 971 if $self->{npc_dialog};
929 972
930 $self->SUPER::destroy; 973 $self->SUPER::destroy;
931} 974}
932 975
933package CFPlus::NPCDialog; 976package CFPlus::NPCDialog;
934 977
935our @ISA = 'CFPlus::UI::FancyFrame'; 978our @ISA = 'CFPlus::UI::Toplevel';
936 979
937sub new { 980sub new {
938 my $class = shift; 981 my $class = shift;
939 982
940 my $self = $class->SUPER::new ( 983 my $self = $class->SUPER::new (
947 kw => { hi => 0, yes => 0, no => 0 }, 990 kw => { hi => 0, yes => 0, no => 0 },
948 has_close_button => 1, 991 has_close_button => 1,
949 @_, 992 @_,
950 ); 993 );
951 994
952 Scalar::Util::weaken (my $this = $self); 995 CFPlus::weaken (my $this = $self);
953 996
954 $self->connect (delete => sub { $this->destroy; 1 }); 997 $self->connect (delete => sub { $this->destroy; 1 });
955 998
956 # better use a pane... 999 # better use a pane...
957 $self->add (my $hbox = new CFPlus::UI::HBox); 1000 $self->add (my $hbox = new CFPlus::UI::HBox);
1001}; 1044};
1002 1045
1003sub update_options { 1046sub update_options {
1004 my ($self) = @_; 1047 my ($self) = @_;
1005 1048
1006 Scalar::Util::weaken $self; 1049 CFPlus::weaken $self;
1007 1050
1008 $self->{options}->clear; 1051 $self->{options}->clear;
1009 $self->{options}->add ($self->{bye_button}); 1052 $self->{options}->add ($self->{bye_button});
1010 1053
1011 for my $kw (sort keys %{ $self->{kw} }) { 1054 for my $kw (sort keys %{ $self->{kw} }) {
1020} 1063}
1021 1064
1022sub feed { 1065sub feed {
1023 my ($self, $msg) = @_; 1066 my ($self, $msg) = @_;
1024 1067
1025 Scalar::Util::weaken $self; 1068 CFPlus::weaken $self;
1026 1069
1027 if ($msg->{msgtype} eq "reply") { 1070 if ($msg->{msgtype} eq "reply") {
1028 $self->{kw}{$_} = 1 for @{$msg->{add_topics} || []}; 1071 $self->{kw}{$_} = 1 for @{$msg->{add_topics} || []};
1029 $self->{kw}{$_} = 0 for @{$msg->{del_topics} || []}; 1072 $self->{kw}{$_} = 0 for @{$msg->{del_topics} || []};
1030 1073
1081 1124
1082 $self->SUPER::destroy; 1125 $self->SUPER::destroy;
1083} 1126}
1084 1127
10851 11281
1129

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines