… | |
… | |
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 |
… | |
… | |
34 | |
36 | |
35 | map ["$cmd$_", $text], |
37 | map ["$cmd$_", $text], |
36 | sort { (length $a) <=> (length $b) } |
38 | sort { (length $a) <=> (length $b) } |
37 | @args |
39 | @args |
38 | } sort { $a->{par} <=> $b->{par} } |
40 | } sort { $a->{par} <=> $b->{par} } |
39 | CFPlus::Pod::find command_help => "*"; |
41 | CFPlus::Pod::find command => "*"; |
40 | |
42 | |
41 | $self->{map_widget}->add_command (@$_) |
43 | $self->{map_widget}->add_command (@$_) |
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 { |
… | |
… | |
310 | } |
321 | } |
311 | |
322 | |
312 | sub user_send { |
323 | sub user_send { |
313 | my ($self, $command) = @_; |
324 | my ($self, $command) = @_; |
314 | |
325 | |
315 | if ($self->{record}) { |
|
|
316 | push @{$self->{record}}, $command; |
326 | push @{$self->{record}}, $command |
317 | } |
327 | if $self->{record}; |
318 | |
328 | |
319 | $self->logprint ("send: ", $command); |
329 | $self->logprint ("send: ", $command); |
320 | $self->send_command ($command); |
330 | $self->send_command ($command); |
321 | ::status ($command); |
331 | ::status ($command); |
322 | } |
332 | } |
… | |
… | |
339 | } |
349 | } |
340 | |
350 | |
341 | sub feed_map1a { |
351 | sub feed_map1a { |
342 | my ($self, $data) = @_; |
352 | my ($self, $data) = @_; |
343 | |
353 | |
344 | $self->{map}->map1a_update ($data); |
354 | $self->{map}->map1a_update ($data, $self->{setup}{extmap}); |
345 | $self->{map_widget}->update; |
355 | $self->{map_widget}->update; |
346 | } |
356 | } |
347 | |
357 | |
348 | sub magicmap { |
358 | sub magicmap { |
349 | my ($self, $w, $h, $x, $y, $data) = @_; |
359 | my ($self, $w, $h, $x, $y, $data) = @_; |
… | |
… | |
614 | [0.74, 0.65, 0.41], |
624 | [0.74, 0.65, 0.41], |
615 | ); |
625 | ); |
616 | |
626 | |
617 | $self->logprint ("info: ", $text); |
627 | $self->logprint ("info: ", $text); |
618 | |
628 | |
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 |
629 | # try to create single paragraphs of multiple lines sent by the server |
622 | $text =~ s/(?<=\S)\n(?=\w)/ /g; |
630 | $text =~ s/(?<=\S)\n(?=\w)/ /g; |
623 | |
631 | |
624 | $text = CFPlus::asxml $text; |
632 | $text = CFPlus::asxml $text; |
625 | $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g; |
633 | $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g; |
626 | $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g; |
634 | $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g; |
627 | |
635 | |
628 | $self->{logview}->add_paragraph ({ fg => $color[$color], markup => $_ }) |
636 | ::message ({ fg => $color[$color], markup => $_ }) |
629 | for map "<span foreground='#ffffff'>$time</span> $_", split /\n/, $text; |
637 | for split /\n/, $text; |
630 | $self->{logview}->scroll_to_bottom; |
|
|
631 | |
638 | |
632 | $self->{statusbox}->add ($text, |
639 | $self->{statusbox}->add ($text, |
633 | group => $text, |
640 | group => $text, |
634 | fg => $color[$color], |
641 | fg => $color[$color], |
635 | timeout => $color >= 2 ? 180 : 10, |
642 | timeout => $color >= 2 ? 180 : 10, |
… | |
… | |
649 | # try to create single paragraphs out of the multiple lines sent by the server |
656 | # try to create single paragraphs out of the multiple lines sent by the server |
650 | $spell->{message} =~ s/(?<=\S)\n(?=\w)/ /g; |
657 | $spell->{message} =~ s/(?<=\S)\n(?=\w)/ /g; |
651 | $spell->{message} =~ s/\n+$//; |
658 | $spell->{message} =~ s/\n+$//; |
652 | $spell->{message} ||= "Server did not provide a description for this spell."; |
659 | $spell->{message} ||= "Server did not provide a description for this spell."; |
653 | |
660 | |
654 | $::SPELL_PAGE->add_spell ($spell); |
661 | $::SPELL_LIST->add_spell ($spell); |
655 | |
662 | |
656 | $self->{map_widget}->add_command ("invoke $spell->{name}", CFPlus::asxml $spell->{message}); |
663 | $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}); |
664 | $self->{map_widget}->add_command ("cast $spell->{name}", CFPlus::asxml $spell->{message}); |
658 | } |
665 | } |
659 | |
666 | |
660 | sub spell_delete { |
667 | sub spell_delete { |
661 | my ($self, $spell) = @_; |
668 | my ($self, $spell) = @_; |
662 | |
669 | |
663 | $::SPELL_PAGE->remove_spell ($spell); |
670 | $::SPELL_LIST->remove_spell ($spell); |
|
|
671 | } |
|
|
672 | |
|
|
673 | sub setup { |
|
|
674 | my ($self, $setup) = @_; |
|
|
675 | |
|
|
676 | $::MAP->resize ($self->{mapw}, $self->{maph}); |
664 | } |
677 | } |
665 | |
678 | |
666 | sub addme_success { |
679 | sub addme_success { |
667 | my ($self) = @_; |
680 | my ($self) = @_; |
668 | |
681 | |
… | |
… | |
874 | $::SERVER_INFO->set_markup ( |
887 | $::SERVER_INFO->set_markup ( |
875 | "server <tt>$self->{host}:$self->{port}</tt>\n" |
888 | "server <tt>$self->{host}:$self->{port}</tt>\n" |
876 | . "protocol version <tt>$self->{version}</tt>\n" |
889 | . "protocol version <tt>$self->{version}</tt>\n" |
877 | . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n" |
890 | . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n" |
878 | . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n" |
891 | . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n" |
|
|
892 | . "editing support $yesno[!!$self->{editor_support}]\n" |
|
|
893 | . "map attributes $yesno[$self->{setup}{extmap} > 0]\n" |
879 | . "cfplus support $yesno[$self->{cfplus_ext} > 0]" |
894 | . "cfplus support $yesno[$self->{cfplus_ext} > 0]" |
880 | . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" |
895 | . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" |
881 | . "map size $self->{mapw}×$self->{maph}\n" |
896 | . "map size $self->{mapw}×$self->{maph}\n" |
882 | ); |
897 | ); |
|
|
898 | |
|
|
899 | ::setup_build_button ($self->{editor_support}->{builder_ui}); |
883 | } |
900 | } |
884 | |
901 | |
885 | sub logged_in { |
902 | sub logged_in { |
886 | my ($self) = @_; |
903 | my ($self) = @_; |
887 | |
904 | |
888 | $self->send_ext_req (cfplus_support => version => 1, sub { |
905 | $self->send_ext_req (cfplus_support => version => 1, sub { |
889 | $self->{cfplus_ext} = $_[0]{version}; |
906 | $self->{cfplus_ext} = $_[0]{version}; |
890 | $self->update_server_info; |
907 | $self->update_server_info; |
891 | |
908 | |
|
|
909 | if ($self->{cfplus_ext} >= 2) { |
|
|
910 | $self->send_ext_req ("editor_support", sub { |
|
|
911 | $self->{editor_support} = $_[0]; |
|
|
912 | $self->update_server_info; |
|
|
913 | |
|
|
914 | 0 |
|
|
915 | }); |
|
|
916 | } |
|
|
917 | |
892 | 0 |
918 | 0 |
893 | }); |
919 | }); |
894 | |
920 | |
895 | $self->update_server_info; |
921 | $self->update_server_info; |
896 | |
922 | |
897 | $self->send_command ("output-sync $::CFG->{output_sync}"); |
923 | $self->send_command ("output-sync $::CFG->{output_sync}"); |
898 | $self->send_command ("output-count $::CFG->{output_count}"); |
924 | $self->send_command ("output-count $::CFG->{output_count}"); |
899 | $self->send_command ("pickup $::CFG->{pickup}"); |
925 | $self->send_command ("pickup $::CFG->{pickup}"); |
|
|
926 | } |
|
|
927 | |
|
|
928 | sub buildat { |
|
|
929 | my ($self, $builditem, $x, $y) = @_; |
|
|
930 | |
|
|
931 | if ($self->{cfplus_ext}) { |
|
|
932 | $self->send_ext_msg (builder_build => dx => $x, dy => $y, (ref ($builditem) eq 'HASH') ? %$builditem : (item => $builditem)); |
|
|
933 | } |
900 | } |
934 | } |
901 | |
935 | |
902 | sub lookat { |
936 | sub lookat { |
903 | my ($self, $x, $y) = @_; |
937 | my ($self, $x, $y) = @_; |
904 | |
938 | |
… | |
… | |
922 | } |
956 | } |
923 | |
957 | |
924 | sub destroy { |
958 | sub destroy { |
925 | my ($self) = @_; |
959 | my ($self) = @_; |
926 | |
960 | |
927 | $self->{npc_dialog}->destroy |
961 | (delete $self->{npc_dialog})->destroy |
928 | if $self->{npc_dialog}; |
962 | if $self->{npc_dialog}; |
929 | |
963 | |
930 | $self->SUPER::destroy; |
964 | $self->SUPER::destroy; |
931 | } |
965 | } |
932 | |
966 | |
933 | package CFPlus::NPCDialog; |
967 | package CFPlus::NPCDialog; |
934 | |
968 | |
935 | our @ISA = 'CFPlus::UI::FancyFrame'; |
969 | our @ISA = 'CFPlus::UI::Toplevel'; |
936 | |
970 | |
937 | sub new { |
971 | sub new { |
938 | my $class = shift; |
972 | my $class = shift; |
939 | |
973 | |
940 | my $self = $class->SUPER::new ( |
974 | my $self = $class->SUPER::new ( |
… | |
… | |
1044 | padding_y => 0, |
1078 | padding_y => 0, |
1045 | on_button_up => sub { |
1079 | on_button_up => sub { |
1046 | $self->send ($kw); |
1080 | $self->send ($kw); |
1047 | }; |
1081 | }; |
1048 | |
1082 | |
1049 | chr 0xfffc |
1083 | "\x{fffc}" |
1050 | }giex; |
1084 | }giex; |
1051 | |
1085 | |
1052 | $self->{textview}->add_paragraph ({ markup => $text, widget => \@link }); |
1086 | $self->{textview}->add_paragraph ({ markup => $text, widget => \@link }); |
1053 | $self->{textview}->scroll_to_bottom; |
1087 | $self->{textview}->scroll_to_bottom; |
1054 | $self->update_options; |
1088 | $self->update_options; |
… | |
… | |
1081 | |
1115 | |
1082 | $self->SUPER::destroy; |
1116 | $self->SUPER::destroy; |
1083 | } |
1117 | } |
1084 | |
1118 | |
1085 | 1 |
1119 | 1 |
|
|
1120 | |