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