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.73 by root, Sun Aug 13 15:14:17 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;
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
33 for @args; 37 for @args;
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
42 } sort { $a->{par} <=> $b->{par} }
38 } CFPlus::Pod::find command_help => "*"; 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 });
39 61
40 $self->{map_widget}->add_command (@$_) 62 $self->{map_widget}->add_command (@$_)
41 for @cmd_help; 63 for @cmd_help;
42 64
43 $self->{noface} = new_from_file CFPlus::Texture 65 $self->{noface} = new_from_file CFPlus::Texture
44 CFPlus::find_rcfile "noface.png", minify => 1, mipmap => 1; 66 CFPlus::find_rcfile "noface.png", minify => 1, mipmap => 1;
45 67
68 {
69 $self->{dialogue} = my $tex = new_from_file CFPlus::Texture
70 CFPlus::find_rcfile "dialogue.png", minify => 1, mipmap => 1;
71 $self->{map}->set_texture (1, @$tex{qw(name w h s t)}, @{$tex->{minified}});
72 }
73
46 $self->{open_container} = 0; 74 $self->{open_container} = 0;
47 75
48 # "global" 76 # "global"
49 $self->{tilecache} = CFPlus::db_table "tilecache"; 77 $self->{tilecache} = CFPlus::db_table "tilecache"
78 or die "tilecache: unable to open database table";
50 $self->{facemap} = CFPlus::db_table "facemap"; 79 $self->{facemap} = CFPlus::db_table "facemap"
80 or die "facemap: unable to open database table";
51 81
52 # per server 82 # per server
53 $self->{mapcache} = CFPlus::db_table "mapcache_$self->{host}_$self->{port}"; 83 $self->{mapcache} = CFPlus::db_table "mapcache_$self->{host}_$self->{port}"
84 or die "mapcache_$self->{host}_$self->{port}: unable to open database table";
54 85
55 $self 86 $self
56} 87}
57 88
58sub logprint { 89sub logprint {
258 289
259 my $TOOLTIP_ALL = "\n\n<small>Left click - ready skill\nMiddle click - use spell\nRight click - further options</small>"; 290 my $TOOLTIP_ALL = "\n\n<small>Left click - ready skill\nMiddle click - use spell\nRight click - further options</small>";
260 291
261 my @TOOLTIP_LVL = (tooltip => "<b>Level</b>. The level of the skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1); 292 my @TOOLTIP_LVL = (tooltip => "<b>Level</b>. The level of the skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1);
262 my @TOOLTIP_EXP = (tooltip => "<b>Experience</b>. The experience points you have in this skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1); 293 my @TOOLTIP_EXP = (tooltip => "<b>Experience</b>. The experience points you have in this skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1);
263 my @TOOLTIP_NAME = (tooltip => "<b>Name</b>. The name of the skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1);
264 294
265 my ($x, $y) = (0, 1); 295 my ($x, $y) = (0, 1);
266 for ( 296 for (
267 sort { $stats->{$b->[0]}[1] <=> $stats->{$a->[0]}[1] or $a->[1] cmp $b->[1] } 297 sort { $stats->{$b->[0]}[1] <=> $stats->{$a->[0]}[1] or $a->[1] cmp $b->[1] }
268 map [$_, $self->{skill_info}{$_}], 298 map [$_, $self->{skill_info}{$_}],
277 if ($ev->{button} == 1) { 307 if ($ev->{button} == 1) {
278 $::CONN->user_send ("ready_skill $name"); 308 $::CONN->user_send ("ready_skill $name");
279 } elsif ($ev->{button} == 2) { 309 } elsif ($ev->{button} == 2) {
280 $::CONN->user_send ("use_skill $name"); 310 $::CONN->user_send ("use_skill $name");
281 } elsif ($ev->{button} == 3) { 311 } elsif ($ev->{button} == 3) {
312 my $shortname = CFPlus::shorten $name, 14;
282 (new CFPlus::UI::Menu 313 (new CFPlus::UI::Menu
283 items => [ 314 items => [
284 ["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"] }],
285 ["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"] }],
286 ], 317 ],
287 )->popup ($ev); 318 )->popup ($ev);
288 } else { 319 } else {
289 return 0; 320 return 0;
290 } 321 }
294 325
295 $sktbl->add ($x * 3 + 0, $y, $self->{stat_widget_exp}{$idx} = new CFPlus::UI::Label 326 $sktbl->add ($x * 3 + 0, $y, $self->{stat_widget_exp}{$idx} = new CFPlus::UI::Label
296 text => "0", align => 1, font => $::FONT_FIXED, fg => [1, 1, 0], on_button_down => $spell_cb, @TOOLTIP_EXP); 327 text => "0", align => 1, font => $::FONT_FIXED, fg => [1, 1, 0], on_button_down => $spell_cb, @TOOLTIP_EXP);
297 $sktbl->add ($x * 3 + 1, $y, $self->{stat_widget_lvl}{$idx} = new CFPlus::UI::Label 328 $sktbl->add ($x * 3 + 1, $y, $self->{stat_widget_lvl}{$idx} = new CFPlus::UI::Label
298 text => "0", align => 1, font => $::FONT_FIXED, fg => [0, 1, 0], padding_x => 4, on_button_down => $spell_cb, @TOOLTIP_LVL); 329 text => "0", align => 1, font => $::FONT_FIXED, fg => [0, 1, 0], padding_x => 4, on_button_down => $spell_cb, @TOOLTIP_LVL);
299 $sktbl->add ($x * 3 + 2, $y, new CFPlus::UI::Label text => $name, on_button_down => $spell_cb, @TOOLTIP_NAME); 330 $sktbl->add ($x * 3 + 2, $y, new CFPlus::UI::Label text => $name, on_button_down => $spell_cb,
331 can_events => 1, can_hover => 1, tooltip => (CFPlus::Pod::section_label skill_description => $name) . $TOOLTIP_ALL);
300 332
301 $x++ and ($x, $y) = (0, $y + 1); 333 $x++ and ($x, $y) = (0, $y + 1);
302 } 334 }
303 } 335 }
304 336
306 $self->{stat_widget_exp}{$_}->set_text (::formsep ($stats->{$_}[1])); 338 $self->{stat_widget_exp}{$_}->set_text (::formsep ($stats->{$_}[1]));
307 $self->{stat_widget_lvl}{$_}->set_text ($stats->{$_}[0] * 1); 339 $self->{stat_widget_lvl}{$_}->set_text ($stats->{$_}[0] * 1);
308 } 340 }
309} 341}
310 342
343sub macro_send {
344 my ($self, $macro) = @_;
345
346 for my $cmd (@{ $macro->{action} }) {
347 $self->send_command ($cmd);
348 }
349}
350
311sub user_send { 351sub user_send {
312 my ($self, $command) = @_; 352 my ($self, $command) = @_;
313 353
354 $self->{record}->($command)
314 if ($self->{record}) { 355 if $self->{record};
315 push @{$self->{record}}, $command;
316 }
317 356
318 $self->logprint ("send: ", $command); 357 $self->logprint ("send: ", $command);
319 $self->send_command ($command); 358 $self->send_command ($command);
320 ::status ($command); 359 ::status ($command);
321} 360}
322 361
323sub start_record { 362sub record {
324 my ($self) = @_; 363 my ($self, $cb) = @_;
325 364
326 $self->{record} = []; 365 $self->{record} = $cb;
327}
328
329sub stop_record {
330 my ($self) = @_;
331 return delete $self->{record};
332} 366}
333 367
334sub map_scroll { 368sub map_scroll {
335 my ($self, $dx, $dy) = @_; 369 my ($self, $dx, $dy) = @_;
336 370
338} 372}
339 373
340sub feed_map1a { 374sub feed_map1a {
341 my ($self, $data) = @_; 375 my ($self, $data) = @_;
342 376
343 $self->{map}->map1a_update ($data); 377 $self->{map}->map1a_update ($data, $self->{setup}{extmap});
344 $self->{map_widget}->update; 378 $self->{map_widget}->update;
345} 379}
346 380
347sub magicmap { 381sub magicmap {
348 my ($self, $w, $h, $x, $y, $data) = @_; 382 my ($self, $w, $h, $x, $y, $data) = @_;
611 [0.75, 0.61, 0.20], 645 [0.75, 0.61, 0.20],
612 [0.99, 0.77, 0.26], 646 [0.99, 0.77, 0.26],
613 [0.74, 0.65, 0.41], 647 [0.74, 0.65, 0.41],
614 ); 648 );
615 649
650 my $fg = $color[$color % @color];
651
616 $self->logprint ("info: ", $text); 652 $self->logprint ("info: ", $text);
617
618 my $time = sprintf "%02d:%02d:%02d", (localtime time)[2,1,0];
619 653
620 # 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
621 $text =~ s/(?<=\S)\n(?=\w)/ /g; 655 $text =~ s/(?<=\S)\n(?=\w)/ /g;
622 656
623 $text = CFPlus::asxml $text; 657 $text = CFPlus::asxml $text;
624 $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g; 658 $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g;
625 $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g; 659 $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g;
626 660
627 $self->{logview}->add_paragraph ({ fg => $color[$color], markup => $_ }) 661 ::message ({ fg => $fg, markup => $_ })
628 for map "<span foreground='#ffffff'>$time</span> $_", split /\n/, $text; 662 for split /\n/, $text;
629 $self->{logview}->scroll_to_bottom;
630 663
631 $self->{statusbox}->add ($text, 664 $self->{statusbox}->add ($text,
632 group => $text, 665 group => $text,
633 fg => $color[$color], 666 fg => $fg,
634 timeout => $color >= 2 ? 180 : 10, 667 timeout => $color >= 2 ? 180 : 10,
635 tooltip_font => $::FONT_FIXED, 668 tooltip_font => $::FONT_FIXED,
636 ); 669 );
637} 670}
638 671
648 # 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
649 $spell->{message} =~ s/(?<=\S)\n(?=\w)/ /g; 682 $spell->{message} =~ s/(?<=\S)\n(?=\w)/ /g;
650 $spell->{message} =~ s/\n+$//; 683 $spell->{message} =~ s/\n+$//;
651 $spell->{message} ||= "Server did not provide a description for this spell."; 684 $spell->{message} ||= "Server did not provide a description for this spell.";
652 685
653 $::SPELL_PAGE->add_spell ($spell); 686 $::SPELL_LIST->add_spell ($spell);
654 687
655 $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});
656 $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});
657} 690}
658 691
659sub spell_delete { 692sub spell_delete {
660 my ($self, $spell) = @_; 693 my ($self, $spell) = @_;
661 694
662 $::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});
663} 703}
664 704
665sub addme_success { 705sub addme_success {
666 my ($self) = @_; 706 my ($self) = @_;
667 707
873 $::SERVER_INFO->set_markup ( 913 $::SERVER_INFO->set_markup (
874 "server <tt>$self->{host}:$self->{port}</tt>\n" 914 "server <tt>$self->{host}:$self->{port}</tt>\n"
875 . "protocol version <tt>$self->{version}</tt>\n" 915 . "protocol version <tt>$self->{version}</tt>\n"
876 . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n" 916 . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n"
877 . "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"
919 . "map attributes $yesno[$self->{setup}{extmap} > 0]\n"
878 . "cfplus support $yesno[$self->{cfplus_ext} > 0]" 920 . "cfplus support $yesno[$self->{cfplus_ext} > 0]"
879 . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" 921 . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n"
880 . "map size $self->{mapw}×$self->{maph}\n" 922 . "map size $self->{mapw}×$self->{maph}\n"
881 ); 923 );
924
925 ::setup_build_button ($self->{editor_support}->{builder_ui});
882} 926}
883 927
884sub logged_in { 928sub logged_in {
885 my ($self) = @_; 929 my ($self) = @_;
886 930
887 $self->send_ext_req (cfplus_support => version => 1, sub { 931 $self->send_ext_req (cfplus_support => version => 1, sub {
888 $self->{cfplus_ext} = $_[0]{version}; 932 $self->{cfplus_ext} = $_[0]{version};
889 $self->update_server_info; 933 $self->update_server_info;
890 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
891 0 944 0
892 }); 945 });
893 946
894 $self->update_server_info; 947 $self->update_server_info;
895 948
896 $self->send_command ("output-sync $::CFG->{output_sync}"); 949 $self->send_command ("output-sync $::CFG->{output_sync}");
897 $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;
898 $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 }
899} 961}
900 962
901sub lookat { 963sub lookat {
902 my ($self, $x, $y) = @_; 964 my ($self, $x, $y) = @_;
903 965
921} 983}
922 984
923sub destroy { 985sub destroy {
924 my ($self) = @_; 986 my ($self) = @_;
925 987
926 $self->{npc_dialog}->destroy 988 (delete $self->{npc_dialog})->destroy
927 if $self->{npc_dialog}; 989 if $self->{npc_dialog};
928 990
929 $self->SUPER::destroy; 991 $self->SUPER::destroy;
930} 992}
931 993
932package CFPlus::NPCDialog; 994package CFPlus::NPCDialog;
933 995
934our @ISA = 'CFPlus::UI::FancyFrame'; 996our @ISA = 'CFPlus::UI::Toplevel';
935 997
936sub new { 998sub new {
937 my $class = shift; 999 my $class = shift;
938 1000
939 my $self = $class->SUPER::new ( 1001 my $self = $class->SUPER::new (
946 kw => { hi => 0, yes => 0, no => 0 }, 1008 kw => { hi => 0, yes => 0, no => 0 },
947 has_close_button => 1, 1009 has_close_button => 1,
948 @_, 1010 @_,
949 ); 1011 );
950 1012
951 Scalar::Util::weaken (my $this = $self); 1013 CFPlus::weaken (my $this = $self);
952 1014
953 $self->connect (delete => sub { $this->destroy; 1 }); 1015 $self->connect (delete => sub { $this->destroy; 1 });
954 1016
955 # better use a pane... 1017 # better use a pane...
956 $self->add (my $hbox = new CFPlus::UI::HBox); 1018 $self->add (my $hbox = new CFPlus::UI::HBox);
1000}; 1062};
1001 1063
1002sub update_options { 1064sub update_options {
1003 my ($self) = @_; 1065 my ($self) = @_;
1004 1066
1005 Scalar::Util::weaken $self; 1067 CFPlus::weaken $self;
1006 1068
1007 $self->{options}->clear; 1069 $self->{options}->clear;
1008 $self->{options}->add ($self->{bye_button}); 1070 $self->{options}->add ($self->{bye_button});
1009 1071
1010 for my $kw (sort keys %{ $self->{kw} }) { 1072 for my $kw (sort keys %{ $self->{kw} }) {
1019} 1081}
1020 1082
1021sub feed { 1083sub feed {
1022 my ($self, $msg) = @_; 1084 my ($self, $msg) = @_;
1023 1085
1024 Scalar::Util::weaken $self; 1086 CFPlus::weaken $self;
1025 1087
1026 if ($msg->{msgtype} eq "reply") { 1088 if ($msg->{msgtype} eq "reply") {
1027 $self->{kw}{$_} = 1 for @{$msg->{add_topics} || []}; 1089 $self->{kw}{$_} = 1 for @{$msg->{add_topics} || []};
1028 $self->{kw}{$_} = 0 for @{$msg->{del_topics} || []}; 1090 $self->{kw}{$_} = 0 for @{$msg->{del_topics} || []};
1029 1091
1043 padding_y => 0, 1105 padding_y => 0,
1044 on_button_up => sub { 1106 on_button_up => sub {
1045 $self->send ($kw); 1107 $self->send ($kw);
1046 }; 1108 };
1047 1109
1048 chr 0xfffc 1110 "\x{fffc}"
1049 }giex; 1111 }giex;
1050 1112
1051 $self->{textview}->add_paragraph ({ markup => $text, widget => \@link }); 1113 $self->{textview}->add_paragraph ({ markup => $text, widget => \@link });
1052 $self->{textview}->scroll_to_bottom; 1114 $self->{textview}->scroll_to_bottom;
1053 $self->update_options; 1115 $self->update_options;
1080 1142
1081 $self->SUPER::destroy; 1143 $self->SUPER::destroy;
1082} 1144}
1083 1145
10841 11461
1147

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines