… | |
… | |
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; |
… | |
… | |
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 => "*"; |
43 | CFPlus::Pod::find command => "*"; |
40 | |
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 | }); |
|
|
61 | |
41 | $self->{map_widget}->add_command (@$_) |
62 | $self->{map_widget}->add_command (@$_) |
42 | for @cmd_help; |
63 | for @cmd_help; |
43 | |
64 | |
44 | $self->{noface} = new_from_file CFPlus::Texture |
65 | $self->{noface} = new_from_file CFPlus::Texture |
45 | CFPlus::find_rcfile "noface.png", minify => 1, mipmap => 1; |
66 | CFPlus::find_rcfile "noface.png", minify => 1, mipmap => 1; |
|
|
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 | } |
46 | |
73 | |
47 | $self->{open_container} = 0; |
74 | $self->{open_container} = 0; |
48 | |
75 | |
49 | # "global" |
76 | # "global" |
50 | $self->{tilecache} = CFPlus::db_table "tilecache" |
77 | $self->{tilecache} = CFPlus::db_table "tilecache" |
… | |
… | |
280 | if ($ev->{button} == 1) { |
307 | if ($ev->{button} == 1) { |
281 | $::CONN->user_send ("ready_skill $name"); |
308 | $::CONN->user_send ("ready_skill $name"); |
282 | } elsif ($ev->{button} == 2) { |
309 | } elsif ($ev->{button} == 2) { |
283 | $::CONN->user_send ("use_skill $name"); |
310 | $::CONN->user_send ("use_skill $name"); |
284 | } elsif ($ev->{button} == 3) { |
311 | } elsif ($ev->{button} == 3) { |
|
|
312 | my $shortname = CFPlus::shorten $name, 14; |
285 | (new CFPlus::UI::Menu |
313 | (new CFPlus::UI::Menu |
286 | items => [ |
314 | items => [ |
287 | ["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"] }], |
288 | ["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"] }], |
289 | ], |
317 | ], |
290 | )->popup ($ev); |
318 | )->popup ($ev); |
291 | } else { |
319 | } else { |
292 | return 0; |
320 | return 0; |
293 | } |
321 | } |
… | |
… | |
310 | $self->{stat_widget_exp}{$_}->set_text (::formsep ($stats->{$_}[1])); |
338 | $self->{stat_widget_exp}{$_}->set_text (::formsep ($stats->{$_}[1])); |
311 | $self->{stat_widget_lvl}{$_}->set_text ($stats->{$_}[0] * 1); |
339 | $self->{stat_widget_lvl}{$_}->set_text ($stats->{$_}[0] * 1); |
312 | } |
340 | } |
313 | } |
341 | } |
314 | |
342 | |
|
|
343 | sub macro_send { |
|
|
344 | my ($self, $macro) = @_; |
|
|
345 | |
|
|
346 | for my $cmd (@{ $macro->{action} }) { |
|
|
347 | $self->send_command ($cmd); |
|
|
348 | } |
|
|
349 | } |
|
|
350 | |
315 | sub user_send { |
351 | sub user_send { |
316 | my ($self, $command) = @_; |
352 | my ($self, $command) = @_; |
317 | |
353 | |
|
|
354 | $self->{record}->($command) |
318 | if ($self->{record}) { |
355 | if $self->{record}; |
319 | push @{$self->{record}}, $command; |
|
|
320 | } |
|
|
321 | |
356 | |
322 | $self->logprint ("send: ", $command); |
357 | $self->logprint ("send: ", $command); |
323 | $self->send_command ($command); |
358 | $self->send_command ($command); |
324 | ::status ($command); |
359 | ::status ($command); |
325 | } |
360 | } |
326 | |
361 | |
327 | sub start_record { |
362 | sub record { |
328 | my ($self) = @_; |
363 | my ($self, $cb) = @_; |
329 | |
364 | |
330 | $self->{record} = []; |
365 | $self->{record} = $cb; |
331 | } |
|
|
332 | |
|
|
333 | sub stop_record { |
|
|
334 | my ($self) = @_; |
|
|
335 | return delete $self->{record}; |
|
|
336 | } |
366 | } |
337 | |
367 | |
338 | sub map_scroll { |
368 | sub map_scroll { |
339 | my ($self, $dx, $dy) = @_; |
369 | my ($self, $dx, $dy) = @_; |
340 | |
370 | |
… | |
… | |
615 | [0.75, 0.61, 0.20], |
645 | [0.75, 0.61, 0.20], |
616 | [0.99, 0.77, 0.26], |
646 | [0.99, 0.77, 0.26], |
617 | [0.74, 0.65, 0.41], |
647 | [0.74, 0.65, 0.41], |
618 | ); |
648 | ); |
619 | |
649 | |
|
|
650 | my $fg = $color[$color % @color]; |
|
|
651 | |
620 | $self->logprint ("info: ", $text); |
652 | $self->logprint ("info: ", $text); |
621 | |
|
|
622 | my $time = sprintf "%02d:%02d:%02d", (localtime time)[2,1,0]; |
|
|
623 | |
653 | |
624 | # 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 |
625 | $text =~ s/(?<=\S)\n(?=\w)/ /g; |
655 | $text =~ s/(?<=\S)\n(?=\w)/ /g; |
626 | |
656 | |
627 | $text = CFPlus::asxml $text; |
657 | $text = CFPlus::asxml $text; |
628 | $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g; |
658 | $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g; |
629 | $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g; |
659 | $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g; |
630 | |
660 | |
631 | $self->{logview}->add_paragraph ({ fg => $color[$color], markup => $_ }) |
661 | ::message ({ fg => $fg, markup => $_ }) |
632 | for map "<span foreground='#ffffff'>$time</span> $_", split /\n/, $text; |
662 | for split /\n/, $text; |
633 | $self->{logview}->scroll_to_bottom; |
|
|
634 | |
663 | |
635 | $self->{statusbox}->add ($text, |
664 | $self->{statusbox}->add ($text, |
636 | group => $text, |
665 | group => $text, |
637 | fg => $color[$color], |
666 | fg => $fg, |
638 | timeout => $color >= 2 ? 180 : 10, |
667 | timeout => $color >= 2 ? 180 : 10, |
639 | tooltip_font => $::FONT_FIXED, |
668 | tooltip_font => $::FONT_FIXED, |
640 | ); |
669 | ); |
641 | } |
670 | } |
642 | |
671 | |
… | |
… | |
652 | # 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 |
653 | $spell->{message} =~ s/(?<=\S)\n(?=\w)/ /g; |
682 | $spell->{message} =~ s/(?<=\S)\n(?=\w)/ /g; |
654 | $spell->{message} =~ s/\n+$//; |
683 | $spell->{message} =~ s/\n+$//; |
655 | $spell->{message} ||= "Server did not provide a description for this spell."; |
684 | $spell->{message} ||= "Server did not provide a description for this spell."; |
656 | |
685 | |
657 | $::SPELL_PAGE->add_spell ($spell); |
686 | $::SPELL_LIST->add_spell ($spell); |
658 | |
687 | |
659 | $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}); |
660 | $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}); |
661 | } |
690 | } |
662 | |
691 | |
663 | sub spell_delete { |
692 | sub spell_delete { |
664 | my ($self, $spell) = @_; |
693 | my ($self, $spell) = @_; |
665 | |
694 | |
666 | $::SPELL_PAGE->remove_spell ($spell); |
695 | $::SPELL_LIST->remove_spell ($spell); |
|
|
696 | } |
|
|
697 | |
|
|
698 | sub setup { |
|
|
699 | my ($self, $setup) = @_; |
|
|
700 | |
|
|
701 | $self->{map_widget}->set_tilesize ($self->{tilesize}); |
|
|
702 | $::MAP->resize ($self->{mapw}, $self->{maph}); |
667 | } |
703 | } |
668 | |
704 | |
669 | sub addme_success { |
705 | sub addme_success { |
670 | my ($self) = @_; |
706 | my ($self) = @_; |
671 | |
707 | |
… | |
… | |
877 | $::SERVER_INFO->set_markup ( |
913 | $::SERVER_INFO->set_markup ( |
878 | "server <tt>$self->{host}:$self->{port}</tt>\n" |
914 | "server <tt>$self->{host}:$self->{port}</tt>\n" |
879 | . "protocol version <tt>$self->{version}</tt>\n" |
915 | . "protocol version <tt>$self->{version}</tt>\n" |
880 | . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n" |
916 | . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n" |
881 | . "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" |
882 | . "map attributes $yesno[$self->{setup}{extmap} > 0]\n" |
919 | . "map attributes $yesno[$self->{setup}{extmap} > 0]\n" |
883 | . "cfplus support $yesno[$self->{cfplus_ext} > 0]" |
920 | . "cfplus support $yesno[$self->{cfplus_ext} > 0]" |
884 | . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" |
921 | . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" |
885 | . "map size $self->{mapw}×$self->{maph}\n" |
922 | . "map size $self->{mapw}×$self->{maph}\n" |
886 | ); |
923 | ); |
|
|
924 | |
|
|
925 | ::setup_build_button ($self->{editor_support}->{builder_ui}); |
887 | } |
926 | } |
888 | |
927 | |
889 | sub logged_in { |
928 | sub logged_in { |
890 | my ($self) = @_; |
929 | my ($self) = @_; |
891 | |
930 | |
892 | $self->send_ext_req (cfplus_support => version => 1, sub { |
931 | $self->send_ext_req (cfplus_support => version => 1, sub { |
893 | $self->{cfplus_ext} = $_[0]{version}; |
932 | $self->{cfplus_ext} = $_[0]{version}; |
894 | $self->update_server_info; |
933 | $self->update_server_info; |
895 | |
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 | |
896 | 0 |
944 | 0 |
897 | }); |
945 | }); |
898 | |
946 | |
899 | $self->update_server_info; |
947 | $self->update_server_info; |
900 | |
948 | |
901 | $self->send_command ("output-sync $::CFG->{output_sync}"); |
949 | $self->send_command ("output-sync $::CFG->{output_sync}"); |
902 | $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; |
903 | $self->send_command ("pickup $::CFG->{pickup}"); |
952 | $self->send_command ("pickup $::CFG->{pickup}"); |
|
|
953 | } |
|
|
954 | |
|
|
955 | sub 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 | } |
904 | } |
961 | } |
905 | |
962 | |
906 | sub lookat { |
963 | sub lookat { |
907 | my ($self, $x, $y) = @_; |
964 | my ($self, $x, $y) = @_; |
908 | |
965 | |
… | |
… | |
951 | kw => { hi => 0, yes => 0, no => 0 }, |
1008 | kw => { hi => 0, yes => 0, no => 0 }, |
952 | has_close_button => 1, |
1009 | has_close_button => 1, |
953 | @_, |
1010 | @_, |
954 | ); |
1011 | ); |
955 | |
1012 | |
956 | Scalar::Util::weaken (my $this = $self); |
1013 | CFPlus::weaken (my $this = $self); |
957 | |
1014 | |
958 | $self->connect (delete => sub { $this->destroy; 1 }); |
1015 | $self->connect (delete => sub { $this->destroy; 1 }); |
959 | |
1016 | |
960 | # better use a pane... |
1017 | # better use a pane... |
961 | $self->add (my $hbox = new CFPlus::UI::HBox); |
1018 | $self->add (my $hbox = new CFPlus::UI::HBox); |
… | |
… | |
1005 | }; |
1062 | }; |
1006 | |
1063 | |
1007 | sub update_options { |
1064 | sub update_options { |
1008 | my ($self) = @_; |
1065 | my ($self) = @_; |
1009 | |
1066 | |
1010 | Scalar::Util::weaken $self; |
1067 | CFPlus::weaken $self; |
1011 | |
1068 | |
1012 | $self->{options}->clear; |
1069 | $self->{options}->clear; |
1013 | $self->{options}->add ($self->{bye_button}); |
1070 | $self->{options}->add ($self->{bye_button}); |
1014 | |
1071 | |
1015 | for my $kw (sort keys %{ $self->{kw} }) { |
1072 | for my $kw (sort keys %{ $self->{kw} }) { |
… | |
… | |
1024 | } |
1081 | } |
1025 | |
1082 | |
1026 | sub feed { |
1083 | sub feed { |
1027 | my ($self, $msg) = @_; |
1084 | my ($self, $msg) = @_; |
1028 | |
1085 | |
1029 | Scalar::Util::weaken $self; |
1086 | CFPlus::weaken $self; |
1030 | |
1087 | |
1031 | if ($msg->{msgtype} eq "reply") { |
1088 | if ($msg->{msgtype} eq "reply") { |
1032 | $self->{kw}{$_} = 1 for @{$msg->{add_topics} || []}; |
1089 | $self->{kw}{$_} = 1 for @{$msg->{add_topics} || []}; |
1033 | $self->{kw}{$_} = 0 for @{$msg->{del_topics} || []}; |
1090 | $self->{kw}{$_} = 0 for @{$msg->{del_topics} || []}; |
1034 | |
1091 | |
… | |
… | |
1085 | |
1142 | |
1086 | $self->SUPER::destroy; |
1143 | $self->SUPER::destroy; |
1087 | } |
1144 | } |
1088 | |
1145 | |
1089 | 1 |
1146 | 1 |
|
|
1147 | |