… | |
… | |
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 | |
11 | |
|
|
12 | use Crossfire::Protocol::Base 0.95; |
|
|
13 | |
12 | use base 'Crossfire::Protocol::Base'; |
14 | use base 'Crossfire::Protocol::Base'; |
13 | |
15 | |
14 | sub new { |
16 | sub new { |
15 | my $class = shift; |
17 | my $class = shift; |
16 | |
18 | |
17 | my $self = $class->SUPER::new (@_); |
19 | my $self = $class->SUPER::new (@_, setup_req => { extmap => 1 }); |
18 | |
20 | |
19 | $self->{map_widget}->clr_commands; |
21 | $self->{map_widget}->clr_commands; |
20 | |
22 | |
21 | my @cmd_help = map { |
23 | my @cmd_help = map { |
22 | $_->{kw}[0] =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x |
24 | $_->{kw}[0] =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x |
… | |
… | |
42 | for @cmd_help; |
44 | for @cmd_help; |
43 | |
45 | |
44 | $self->{noface} = new_from_file CFPlus::Texture |
46 | $self->{noface} = new_from_file CFPlus::Texture |
45 | CFPlus::find_rcfile "noface.png", minify => 1, mipmap => 1; |
47 | CFPlus::find_rcfile "noface.png", minify => 1, mipmap => 1; |
46 | |
48 | |
|
|
49 | { |
|
|
50 | $self->{dialogue} = my $tex = new_from_file CFPlus::Texture |
|
|
51 | CFPlus::find_rcfile "dialogue.png", minify => 1, mipmap => 1; |
|
|
52 | $self->{map}->set_texture (1, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
|
|
53 | } |
|
|
54 | |
47 | $self->{open_container} = 0; |
55 | $self->{open_container} = 0; |
48 | |
56 | |
49 | # "global" |
57 | # "global" |
50 | $self->{tilecache} = CFPlus::db_table "tilecache"; |
58 | $self->{tilecache} = CFPlus::db_table "tilecache" |
|
|
59 | or die "tilecache: unable to open database table"; |
51 | $self->{facemap} = CFPlus::db_table "facemap"; |
60 | $self->{facemap} = CFPlus::db_table "facemap" |
|
|
61 | or die "facemap: unable to open database table"; |
52 | |
62 | |
53 | # per server |
63 | # per server |
54 | $self->{mapcache} = CFPlus::db_table "mapcache_$self->{host}_$self->{port}"; |
64 | $self->{mapcache} = CFPlus::db_table "mapcache_$self->{host}_$self->{port}" |
|
|
65 | or die "mapcache_$self->{host}_$self->{port}: unable to open database table"; |
55 | |
66 | |
56 | $self |
67 | $self |
57 | } |
68 | } |
58 | |
69 | |
59 | sub logprint { |
70 | sub logprint { |
… | |
… | |
277 | if ($ev->{button} == 1) { |
288 | if ($ev->{button} == 1) { |
278 | $::CONN->user_send ("ready_skill $name"); |
289 | $::CONN->user_send ("ready_skill $name"); |
279 | } elsif ($ev->{button} == 2) { |
290 | } elsif ($ev->{button} == 2) { |
280 | $::CONN->user_send ("use_skill $name"); |
291 | $::CONN->user_send ("use_skill $name"); |
281 | } elsif ($ev->{button} == 3) { |
292 | } elsif ($ev->{button} == 3) { |
|
|
293 | my $shortname = CFPlus::shorten $name, 14; |
282 | (new CFPlus::UI::Menu |
294 | (new CFPlus::UI::Menu |
283 | items => [ |
295 | items => [ |
284 | ["bind <i>ready_skill $name</i> to a key" => sub { $::BIND_EDITOR->do_quick_binding (["ready_skill $name"]) }], |
296 | ["bind <i>ready_skill $shortname</i> to a key" => sub { $::BIND_EDITOR->do_quick_binding (["ready_skill $name"]) }], |
285 | ["bind <i>use_skill $name</i> to a key" => sub { $::BIND_EDITOR->do_quick_binding (["use_skill $name"]) }], |
297 | ["bind <i>use_skill $shortname</i> to a key" => sub { $::BIND_EDITOR->do_quick_binding (["use_skill $name"]) }], |
286 | ], |
298 | ], |
287 | )->popup ($ev); |
299 | )->popup ($ev); |
288 | } else { |
300 | } else { |
289 | return 0; |
301 | return 0; |
290 | } |
302 | } |
… | |
… | |
310 | } |
322 | } |
311 | |
323 | |
312 | sub user_send { |
324 | sub user_send { |
313 | my ($self, $command) = @_; |
325 | my ($self, $command) = @_; |
314 | |
326 | |
315 | if ($self->{record}) { |
|
|
316 | push @{$self->{record}}, $command; |
327 | push @{$self->{record}}, $command |
317 | } |
328 | if $self->{record}; |
318 | |
329 | |
319 | $self->logprint ("send: ", $command); |
330 | $self->logprint ("send: ", $command); |
320 | $self->send_command ($command); |
331 | $self->send_command ($command); |
321 | ::status ($command); |
332 | ::status ($command); |
322 | } |
333 | } |
… | |
… | |
339 | } |
350 | } |
340 | |
351 | |
341 | sub feed_map1a { |
352 | sub feed_map1a { |
342 | my ($self, $data) = @_; |
353 | my ($self, $data) = @_; |
343 | |
354 | |
344 | $self->{map}->map1a_update ($data); |
355 | $self->{map}->map1a_update ($data, $self->{setup}{extmap}); |
345 | $self->{map_widget}->update; |
356 | $self->{map_widget}->update; |
346 | } |
357 | } |
347 | |
358 | |
348 | sub magicmap { |
359 | sub magicmap { |
349 | my ($self, $w, $h, $x, $y, $data) = @_; |
360 | my ($self, $w, $h, $x, $y, $data) = @_; |
… | |
… | |
614 | [0.74, 0.65, 0.41], |
625 | [0.74, 0.65, 0.41], |
615 | ); |
626 | ); |
616 | |
627 | |
617 | $self->logprint ("info: ", $text); |
628 | $self->logprint ("info: ", $text); |
618 | |
629 | |
619 | my $time = sprintf "%02d:%02d:%02d", (localtime time)[2,1,0]; |
|
|
620 | |
|
|
621 | # try to create single paragraphs of multiple lines sent by the server |
630 | # try to create single paragraphs of multiple lines sent by the server |
622 | $text =~ s/(?<=\S)\n(?=\w)/ /g; |
631 | $text =~ s/(?<=\S)\n(?=\w)/ /g; |
623 | |
632 | |
624 | $text = CFPlus::asxml $text; |
633 | $text = CFPlus::asxml $text; |
625 | $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g; |
634 | $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g; |
626 | $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g; |
635 | $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g; |
627 | |
636 | |
628 | $self->{logview}->add_paragraph ({ fg => $color[$color], markup => $_ }) |
637 | ::message ({ fg => $color[$color], markup => $_ }) |
629 | for map "<span foreground='#ffffff'>$time</span> $_", split /\n/, $text; |
638 | for split /\n/, $text; |
630 | $self->{logview}->scroll_to_bottom; |
|
|
631 | |
639 | |
632 | $self->{statusbox}->add ($text, |
640 | $self->{statusbox}->add ($text, |
633 | group => $text, |
641 | group => $text, |
634 | fg => $color[$color], |
642 | fg => $color[$color], |
635 | timeout => $color >= 2 ? 180 : 10, |
643 | timeout => $color >= 2 ? 180 : 10, |
… | |
… | |
649 | # try to create single paragraphs out of the multiple lines sent by the server |
657 | # try to create single paragraphs out of the multiple lines sent by the server |
650 | $spell->{message} =~ s/(?<=\S)\n(?=\w)/ /g; |
658 | $spell->{message} =~ s/(?<=\S)\n(?=\w)/ /g; |
651 | $spell->{message} =~ s/\n+$//; |
659 | $spell->{message} =~ s/\n+$//; |
652 | $spell->{message} ||= "Server did not provide a description for this spell."; |
660 | $spell->{message} ||= "Server did not provide a description for this spell."; |
653 | |
661 | |
654 | $::SPELL_PAGE->add_spell ($spell); |
662 | $::SPELL_LIST->add_spell ($spell); |
655 | |
663 | |
656 | $self->{map_widget}->add_command ("invoke $spell->{name}", CFPlus::asxml $spell->{message}); |
664 | $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}); |
665 | $self->{map_widget}->add_command ("cast $spell->{name}", CFPlus::asxml $spell->{message}); |
658 | } |
666 | } |
659 | |
667 | |
660 | sub spell_delete { |
668 | sub spell_delete { |
661 | my ($self, $spell) = @_; |
669 | my ($self, $spell) = @_; |
662 | |
670 | |
663 | $::SPELL_PAGE->remove_spell ($spell); |
671 | $::SPELL_LIST->remove_spell ($spell); |
|
|
672 | } |
|
|
673 | |
|
|
674 | sub setup { |
|
|
675 | my ($self, $setup) = @_; |
|
|
676 | |
|
|
677 | $::MAP->resize ($self->{mapw}, $self->{maph}); |
664 | } |
678 | } |
665 | |
679 | |
666 | sub addme_success { |
680 | sub addme_success { |
667 | my ($self) = @_; |
681 | my ($self) = @_; |
668 | |
682 | |
… | |
… | |
874 | $::SERVER_INFO->set_markup ( |
888 | $::SERVER_INFO->set_markup ( |
875 | "server <tt>$self->{host}:$self->{port}</tt>\n" |
889 | "server <tt>$self->{host}:$self->{port}</tt>\n" |
876 | . "protocol version <tt>$self->{version}</tt>\n" |
890 | . "protocol version <tt>$self->{version}</tt>\n" |
877 | . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n" |
891 | . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n" |
878 | . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n" |
892 | . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n" |
|
|
893 | . "editing support $yesno[!!$self->{editor_support}]\n" |
|
|
894 | . "map attributes $yesno[$self->{setup}{extmap} > 0]\n" |
879 | . "cfplus support $yesno[$self->{cfplus_ext} > 0]" |
895 | . "cfplus support $yesno[$self->{cfplus_ext} > 0]" |
880 | . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" |
896 | . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" |
881 | . "map size $self->{mapw}×$self->{maph}\n" |
897 | . "map size $self->{mapw}×$self->{maph}\n" |
882 | ); |
898 | ); |
|
|
899 | |
|
|
900 | ::setup_build_button ($self->{editor_support}->{builder_ui}); |
883 | } |
901 | } |
884 | |
902 | |
885 | sub logged_in { |
903 | sub logged_in { |
886 | my ($self) = @_; |
904 | my ($self) = @_; |
887 | |
905 | |
888 | $self->send_ext_req (cfplus_support => version => 1, sub { |
906 | $self->send_ext_req (cfplus_support => version => 1, sub { |
889 | $self->{cfplus_ext} = $_[0]{version}; |
907 | $self->{cfplus_ext} = $_[0]{version}; |
890 | $self->update_server_info; |
908 | $self->update_server_info; |
891 | |
909 | |
|
|
910 | if ($self->{cfplus_ext} >= 2) { |
|
|
911 | $self->send_ext_req ("editor_support", sub { |
|
|
912 | $self->{editor_support} = $_[0]; |
|
|
913 | $self->update_server_info; |
|
|
914 | |
|
|
915 | 0 |
|
|
916 | }); |
|
|
917 | } |
|
|
918 | |
892 | 0 |
919 | 0 |
893 | }); |
920 | }); |
894 | |
921 | |
895 | $self->update_server_info; |
922 | $self->update_server_info; |
896 | |
923 | |
897 | $self->send_command ("output-sync $::CFG->{output_sync}"); |
924 | $self->send_command ("output-sync $::CFG->{output_sync}"); |
898 | $self->send_command ("output-count $::CFG->{output_count}"); |
925 | $self->send_command ("output-count $::CFG->{output_count}"); |
899 | $self->send_command ("pickup $::CFG->{pickup}"); |
926 | $self->send_command ("pickup $::CFG->{pickup}"); |
|
|
927 | } |
|
|
928 | |
|
|
929 | sub buildat { |
|
|
930 | my ($self, $builditem, $x, $y) = @_; |
|
|
931 | |
|
|
932 | if ($self->{cfplus_ext}) { |
|
|
933 | $self->send_ext_msg (builder_build => dx => $x, dy => $y, (ref ($builditem) eq 'HASH') ? %$builditem : (item => $builditem)); |
|
|
934 | } |
900 | } |
935 | } |
901 | |
936 | |
902 | sub lookat { |
937 | sub lookat { |
903 | my ($self, $x, $y) = @_; |
938 | my ($self, $x, $y) = @_; |
904 | |
939 | |
… | |
… | |
922 | } |
957 | } |
923 | |
958 | |
924 | sub destroy { |
959 | sub destroy { |
925 | my ($self) = @_; |
960 | my ($self) = @_; |
926 | |
961 | |
927 | $self->{npc_dialog}->destroy |
962 | (delete $self->{npc_dialog})->destroy |
928 | if $self->{npc_dialog}; |
963 | if $self->{npc_dialog}; |
929 | |
964 | |
930 | $self->SUPER::destroy; |
965 | $self->SUPER::destroy; |
931 | } |
966 | } |
932 | |
967 | |
… | |
… | |
1081 | |
1116 | |
1082 | $self->SUPER::destroy; |
1117 | $self->SUPER::destroy; |
1083 | } |
1118 | } |
1084 | |
1119 | |
1085 | 1 |
1120 | 1 |
|
|
1121 | |