… | |
… | |
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; |
… | |
… | |
41 | $self->{map_widget}->add_command (@$_) |
45 | $self->{map_widget}->add_command (@$_) |
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; |
|
|
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 | } |
46 | |
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" |
… | |
… | |
280 | if ($ev->{button} == 1) { |
290 | if ($ev->{button} == 1) { |
281 | $::CONN->user_send ("ready_skill $name"); |
291 | $::CONN->user_send ("ready_skill $name"); |
282 | } elsif ($ev->{button} == 2) { |
292 | } elsif ($ev->{button} == 2) { |
283 | $::CONN->user_send ("use_skill $name"); |
293 | $::CONN->user_send ("use_skill $name"); |
284 | } elsif ($ev->{button} == 3) { |
294 | } elsif ($ev->{button} == 3) { |
|
|
295 | my $shortname = CFPlus::shorten $name, 14; |
285 | (new CFPlus::UI::Menu |
296 | (new CFPlus::UI::Menu |
286 | items => [ |
297 | items => [ |
287 | ["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"] }], |
288 | ["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"] }], |
289 | ], |
300 | ], |
290 | )->popup ($ev); |
301 | )->popup ($ev); |
291 | } else { |
302 | } else { |
292 | return 0; |
303 | return 0; |
293 | } |
304 | } |
… | |
… | |
310 | $self->{stat_widget_exp}{$_}->set_text (::formsep ($stats->{$_}[1])); |
321 | $self->{stat_widget_exp}{$_}->set_text (::formsep ($stats->{$_}[1])); |
311 | $self->{stat_widget_lvl}{$_}->set_text ($stats->{$_}[0] * 1); |
322 | $self->{stat_widget_lvl}{$_}->set_text ($stats->{$_}[0] * 1); |
312 | } |
323 | } |
313 | } |
324 | } |
314 | |
325 | |
|
|
326 | sub macro_send { |
|
|
327 | my ($self, $macro) = @_; |
|
|
328 | |
|
|
329 | for my $cmd (@{ $macro->{action} }) { |
|
|
330 | $self->send_command ($cmd); |
|
|
331 | } |
|
|
332 | } |
|
|
333 | |
315 | sub user_send { |
334 | sub user_send { |
316 | my ($self, $command) = @_; |
335 | my ($self, $command) = @_; |
317 | |
336 | |
|
|
337 | $self->{record}->($command) |
318 | if ($self->{record}) { |
338 | if $self->{record}; |
319 | push @{$self->{record}}, $command; |
|
|
320 | } |
|
|
321 | |
339 | |
322 | $self->logprint ("send: ", $command); |
340 | $self->logprint ("send: ", $command); |
323 | $self->send_command ($command); |
341 | $self->send_command ($command); |
324 | ::status ($command); |
342 | ::status ($command); |
325 | } |
343 | } |
326 | |
344 | |
327 | sub start_record { |
345 | sub record { |
328 | my ($self) = @_; |
346 | my ($self, $cb) = @_; |
329 | |
347 | |
330 | $self->{record} = []; |
348 | $self->{record} = $cb; |
331 | } |
|
|
332 | |
|
|
333 | sub stop_record { |
|
|
334 | my ($self) = @_; |
|
|
335 | return delete $self->{record}; |
|
|
336 | } |
349 | } |
337 | |
350 | |
338 | sub map_scroll { |
351 | sub map_scroll { |
339 | my ($self, $dx, $dy) = @_; |
352 | my ($self, $dx, $dy) = @_; |
340 | |
353 | |
… | |
… | |
615 | [0.75, 0.61, 0.20], |
628 | [0.75, 0.61, 0.20], |
616 | [0.99, 0.77, 0.26], |
629 | [0.99, 0.77, 0.26], |
617 | [0.74, 0.65, 0.41], |
630 | [0.74, 0.65, 0.41], |
618 | ); |
631 | ); |
619 | |
632 | |
|
|
633 | my $fg = $color[$color % @color]; |
|
|
634 | |
620 | $self->logprint ("info: ", $text); |
635 | $self->logprint ("info: ", $text); |
621 | |
|
|
622 | my $time = sprintf "%02d:%02d:%02d", (localtime time)[2,1,0]; |
|
|
623 | |
636 | |
624 | # 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 |
625 | $text =~ s/(?<=\S)\n(?=\w)/ /g; |
638 | $text =~ s/(?<=\S)\n(?=\w)/ /g; |
626 | |
639 | |
627 | $text = CFPlus::asxml $text; |
640 | $text = CFPlus::asxml $text; |
628 | $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g; |
641 | $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g; |
629 | $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g; |
642 | $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g; |
630 | |
643 | |
631 | $self->{logview}->add_paragraph ({ fg => $color[$color], markup => $_ }) |
644 | ::message ({ fg => $fg, markup => $_ }) |
632 | for map "<span foreground='#ffffff'>$time</span> $_", split /\n/, $text; |
645 | for split /\n/, $text; |
633 | $self->{logview}->scroll_to_bottom; |
|
|
634 | |
646 | |
635 | $self->{statusbox}->add ($text, |
647 | $self->{statusbox}->add ($text, |
636 | group => $text, |
648 | group => $text, |
637 | fg => $color[$color], |
649 | fg => $fg, |
638 | timeout => $color >= 2 ? 180 : 10, |
650 | timeout => $color >= 2 ? 180 : 10, |
639 | tooltip_font => $::FONT_FIXED, |
651 | tooltip_font => $::FONT_FIXED, |
640 | ); |
652 | ); |
641 | } |
653 | } |
642 | |
654 | |
… | |
… | |
652 | # 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 |
653 | $spell->{message} =~ s/(?<=\S)\n(?=\w)/ /g; |
665 | $spell->{message} =~ s/(?<=\S)\n(?=\w)/ /g; |
654 | $spell->{message} =~ s/\n+$//; |
666 | $spell->{message} =~ s/\n+$//; |
655 | $spell->{message} ||= "Server did not provide a description for this spell."; |
667 | $spell->{message} ||= "Server did not provide a description for this spell."; |
656 | |
668 | |
657 | $::SPELL_PAGE->add_spell ($spell); |
669 | $::SPELL_LIST->add_spell ($spell); |
658 | |
670 | |
659 | $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}); |
660 | $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}); |
661 | } |
673 | } |
662 | |
674 | |
663 | sub spell_delete { |
675 | sub spell_delete { |
664 | my ($self, $spell) = @_; |
676 | my ($self, $spell) = @_; |
665 | |
677 | |
666 | $::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}); |
667 | } |
685 | } |
668 | |
686 | |
669 | sub addme_success { |
687 | sub addme_success { |
670 | my ($self) = @_; |
688 | my ($self) = @_; |
671 | |
689 | |
… | |
… | |
877 | $::SERVER_INFO->set_markup ( |
895 | $::SERVER_INFO->set_markup ( |
878 | "server <tt>$self->{host}:$self->{port}</tt>\n" |
896 | "server <tt>$self->{host}:$self->{port}</tt>\n" |
879 | . "protocol version <tt>$self->{version}</tt>\n" |
897 | . "protocol version <tt>$self->{version}</tt>\n" |
880 | . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n" |
898 | . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n" |
881 | . "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" |
882 | . "map attributes $yesno[$self->{setup}{extmap} > 0]\n" |
901 | . "map attributes $yesno[$self->{setup}{extmap} > 0]\n" |
883 | . "cfplus support $yesno[$self->{cfplus_ext} > 0]" |
902 | . "cfplus support $yesno[$self->{cfplus_ext} > 0]" |
884 | . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" |
903 | . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" |
885 | . "map size $self->{mapw}×$self->{maph}\n" |
904 | . "map size $self->{mapw}×$self->{maph}\n" |
886 | ); |
905 | ); |
|
|
906 | |
|
|
907 | ::setup_build_button ($self->{editor_support}->{builder_ui}); |
887 | } |
908 | } |
888 | |
909 | |
889 | sub logged_in { |
910 | sub logged_in { |
890 | my ($self) = @_; |
911 | my ($self) = @_; |
891 | |
912 | |
892 | $self->send_ext_req (cfplus_support => version => 1, sub { |
913 | $self->send_ext_req (cfplus_support => version => 1, sub { |
893 | $self->{cfplus_ext} = $_[0]{version}; |
914 | $self->{cfplus_ext} = $_[0]{version}; |
894 | $self->update_server_info; |
915 | $self->update_server_info; |
895 | |
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 | |
896 | 0 |
926 | 0 |
897 | }); |
927 | }); |
898 | |
928 | |
899 | $self->update_server_info; |
929 | $self->update_server_info; |
900 | |
930 | |
901 | $self->send_command ("output-sync $::CFG->{output_sync}"); |
931 | $self->send_command ("output-sync $::CFG->{output_sync}"); |
902 | $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; |
903 | $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 | } |
904 | } |
943 | } |
905 | |
944 | |
906 | sub lookat { |
945 | sub lookat { |
907 | my ($self, $x, $y) = @_; |
946 | my ($self, $x, $y) = @_; |
908 | |
947 | |
… | |
… | |
951 | kw => { hi => 0, yes => 0, no => 0 }, |
990 | kw => { hi => 0, yes => 0, no => 0 }, |
952 | has_close_button => 1, |
991 | has_close_button => 1, |
953 | @_, |
992 | @_, |
954 | ); |
993 | ); |
955 | |
994 | |
956 | Scalar::Util::weaken (my $this = $self); |
995 | CFPlus::weaken (my $this = $self); |
957 | |
996 | |
958 | $self->connect (delete => sub { $this->destroy; 1 }); |
997 | $self->connect (delete => sub { $this->destroy; 1 }); |
959 | |
998 | |
960 | # better use a pane... |
999 | # better use a pane... |
961 | $self->add (my $hbox = new CFPlus::UI::HBox); |
1000 | $self->add (my $hbox = new CFPlus::UI::HBox); |
… | |
… | |
1005 | }; |
1044 | }; |
1006 | |
1045 | |
1007 | sub update_options { |
1046 | sub update_options { |
1008 | my ($self) = @_; |
1047 | my ($self) = @_; |
1009 | |
1048 | |
1010 | Scalar::Util::weaken $self; |
1049 | CFPlus::weaken $self; |
1011 | |
1050 | |
1012 | $self->{options}->clear; |
1051 | $self->{options}->clear; |
1013 | $self->{options}->add ($self->{bye_button}); |
1052 | $self->{options}->add ($self->{bye_button}); |
1014 | |
1053 | |
1015 | for my $kw (sort keys %{ $self->{kw} }) { |
1054 | for my $kw (sort keys %{ $self->{kw} }) { |
… | |
… | |
1024 | } |
1063 | } |
1025 | |
1064 | |
1026 | sub feed { |
1065 | sub feed { |
1027 | my ($self, $msg) = @_; |
1066 | my ($self, $msg) = @_; |
1028 | |
1067 | |
1029 | Scalar::Util::weaken $self; |
1068 | CFPlus::weaken $self; |
1030 | |
1069 | |
1031 | if ($msg->{msgtype} eq "reply") { |
1070 | if ($msg->{msgtype} eq "reply") { |
1032 | $self->{kw}{$_} = 1 for @{$msg->{add_topics} || []}; |
1071 | $self->{kw}{$_} = 1 for @{$msg->{add_topics} || []}; |
1033 | $self->{kw}{$_} = 0 for @{$msg->{del_topics} || []}; |
1072 | $self->{kw}{$_} = 0 for @{$msg->{del_topics} || []}; |
1034 | |
1073 | |
… | |
… | |
1085 | |
1124 | |
1086 | $self->SUPER::destroy; |
1125 | $self->SUPER::destroy; |
1087 | } |
1126 | } |
1088 | |
1127 | |
1089 | 1 |
1128 | 1 |
|
|
1129 | |