… | |
… | |
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; |
11 | |
13 | |
12 | use Crossfire::Protocol::Base 0.95; |
14 | use Crossfire::Protocol::Base 0.95; |
13 | |
15 | |
14 | use base 'Crossfire::Protocol::Base'; |
16 | use base 'Crossfire::Protocol::Base'; |
15 | |
17 | |
… | |
… | |
288 | if ($ev->{button} == 1) { |
290 | if ($ev->{button} == 1) { |
289 | $::CONN->user_send ("ready_skill $name"); |
291 | $::CONN->user_send ("ready_skill $name"); |
290 | } elsif ($ev->{button} == 2) { |
292 | } elsif ($ev->{button} == 2) { |
291 | $::CONN->user_send ("use_skill $name"); |
293 | $::CONN->user_send ("use_skill $name"); |
292 | } elsif ($ev->{button} == 3) { |
294 | } elsif ($ev->{button} == 3) { |
|
|
295 | my $shortname = CFPlus::shorten $name, 14; |
293 | (new CFPlus::UI::Menu |
296 | (new CFPlus::UI::Menu |
294 | items => [ |
297 | items => [ |
295 | ["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"] }], |
296 | ["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"] }], |
297 | ], |
300 | ], |
298 | )->popup ($ev); |
301 | )->popup ($ev); |
299 | } else { |
302 | } else { |
300 | return 0; |
303 | return 0; |
301 | } |
304 | } |
… | |
… | |
318 | $self->{stat_widget_exp}{$_}->set_text (::formsep ($stats->{$_}[1])); |
321 | $self->{stat_widget_exp}{$_}->set_text (::formsep ($stats->{$_}[1])); |
319 | $self->{stat_widget_lvl}{$_}->set_text ($stats->{$_}[0] * 1); |
322 | $self->{stat_widget_lvl}{$_}->set_text ($stats->{$_}[0] * 1); |
320 | } |
323 | } |
321 | } |
324 | } |
322 | |
325 | |
|
|
326 | sub macro_send { |
|
|
327 | my ($self, $macro) = @_; |
|
|
328 | |
|
|
329 | for my $cmd (@{ $macro->{action} }) { |
|
|
330 | $self->send_command ($cmd); |
|
|
331 | } |
|
|
332 | } |
|
|
333 | |
323 | sub user_send { |
334 | sub user_send { |
324 | my ($self, $command) = @_; |
335 | my ($self, $command) = @_; |
325 | |
336 | |
326 | push @{$self->{record}}, $command |
337 | $self->{record}->($command) |
327 | if $self->{record}; |
338 | if $self->{record}; |
328 | |
339 | |
329 | $self->logprint ("send: ", $command); |
340 | $self->logprint ("send: ", $command); |
330 | $self->send_command ($command); |
341 | $self->send_command ($command); |
331 | ::status ($command); |
342 | ::status ($command); |
332 | } |
343 | } |
333 | |
344 | |
334 | sub start_record { |
345 | sub record { |
335 | my ($self) = @_; |
346 | my ($self, $cb) = @_; |
336 | |
347 | |
337 | $self->{record} = []; |
348 | $self->{record} = $cb; |
338 | } |
|
|
339 | |
|
|
340 | sub stop_record { |
|
|
341 | my ($self) = @_; |
|
|
342 | return delete $self->{record}; |
|
|
343 | } |
349 | } |
344 | |
350 | |
345 | sub map_scroll { |
351 | sub map_scroll { |
346 | my ($self, $dx, $dy) = @_; |
352 | my ($self, $dx, $dy) = @_; |
347 | |
353 | |
… | |
… | |
622 | [0.75, 0.61, 0.20], |
628 | [0.75, 0.61, 0.20], |
623 | [0.99, 0.77, 0.26], |
629 | [0.99, 0.77, 0.26], |
624 | [0.74, 0.65, 0.41], |
630 | [0.74, 0.65, 0.41], |
625 | ); |
631 | ); |
626 | |
632 | |
|
|
633 | my $fg = $color[$color % @color]; |
|
|
634 | |
627 | $self->logprint ("info: ", $text); |
635 | $self->logprint ("info: ", $text); |
628 | |
636 | |
629 | # 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 |
630 | $text =~ s/(?<=\S)\n(?=\w)/ /g; |
638 | $text =~ s/(?<=\S)\n(?=\w)/ /g; |
631 | |
639 | |
632 | $text = CFPlus::asxml $text; |
640 | $text = CFPlus::asxml $text; |
633 | $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g; |
641 | $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g; |
634 | $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g; |
642 | $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g; |
635 | |
643 | |
636 | ::message ({ fg => $color[$color], markup => $_ }) |
644 | ::message ({ fg => $fg, markup => $_ }) |
637 | for split /\n/, $text; |
645 | for split /\n/, $text; |
638 | |
646 | |
639 | $self->{statusbox}->add ($text, |
647 | $self->{statusbox}->add ($text, |
640 | group => $text, |
648 | group => $text, |
641 | fg => $color[$color], |
649 | fg => $fg, |
642 | timeout => $color >= 2 ? 180 : 10, |
650 | timeout => $color >= 2 ? 180 : 10, |
643 | tooltip_font => $::FONT_FIXED, |
651 | tooltip_font => $::FONT_FIXED, |
644 | ); |
652 | ); |
645 | } |
653 | } |
646 | |
654 | |
… | |
… | |
656 | # 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 |
657 | $spell->{message} =~ s/(?<=\S)\n(?=\w)/ /g; |
665 | $spell->{message} =~ s/(?<=\S)\n(?=\w)/ /g; |
658 | $spell->{message} =~ s/\n+$//; |
666 | $spell->{message} =~ s/\n+$//; |
659 | $spell->{message} ||= "Server did not provide a description for this spell."; |
667 | $spell->{message} ||= "Server did not provide a description for this spell."; |
660 | |
668 | |
661 | $::SPELL_PAGE->add_spell ($spell); |
669 | $::SPELL_LIST->add_spell ($spell); |
662 | |
670 | |
663 | $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}); |
664 | $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}); |
665 | } |
673 | } |
666 | |
674 | |
667 | sub spell_delete { |
675 | sub spell_delete { |
668 | my ($self, $spell) = @_; |
676 | my ($self, $spell) = @_; |
669 | |
677 | |
670 | $::SPELL_PAGE->remove_spell ($spell); |
678 | $::SPELL_LIST->remove_spell ($spell); |
671 | } |
679 | } |
672 | |
680 | |
673 | sub setup { |
681 | sub setup { |
674 | my ($self, $setup) = @_; |
682 | my ($self, $setup) = @_; |
675 | |
683 | |
… | |
… | |
893 | . "map attributes $yesno[$self->{setup}{extmap} > 0]\n" |
901 | . "map attributes $yesno[$self->{setup}{extmap} > 0]\n" |
894 | . "cfplus support $yesno[$self->{cfplus_ext} > 0]" |
902 | . "cfplus support $yesno[$self->{cfplus_ext} > 0]" |
895 | . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" |
903 | . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" |
896 | . "map size $self->{mapw}×$self->{maph}\n" |
904 | . "map size $self->{mapw}×$self->{maph}\n" |
897 | ); |
905 | ); |
|
|
906 | |
|
|
907 | ::setup_build_button ($self->{editor_support}->{builder_ui}); |
898 | } |
908 | } |
899 | |
909 | |
900 | sub logged_in { |
910 | sub logged_in { |
901 | my ($self) = @_; |
911 | my ($self) = @_; |
902 | |
912 | |
… | |
… | |
918 | |
928 | |
919 | $self->update_server_info; |
929 | $self->update_server_info; |
920 | |
930 | |
921 | $self->send_command ("output-sync $::CFG->{output_sync}"); |
931 | $self->send_command ("output-sync $::CFG->{output_sync}"); |
922 | $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; |
923 | $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 | } |
924 | } |
943 | } |
925 | |
944 | |
926 | sub lookat { |
945 | sub lookat { |
927 | my ($self, $x, $y) = @_; |
946 | my ($self, $x, $y) = @_; |
928 | |
947 | |
… | |
… | |
971 | kw => { hi => 0, yes => 0, no => 0 }, |
990 | kw => { hi => 0, yes => 0, no => 0 }, |
972 | has_close_button => 1, |
991 | has_close_button => 1, |
973 | @_, |
992 | @_, |
974 | ); |
993 | ); |
975 | |
994 | |
976 | Scalar::Util::weaken (my $this = $self); |
995 | CFPlus::weaken (my $this = $self); |
977 | |
996 | |
978 | $self->connect (delete => sub { $this->destroy; 1 }); |
997 | $self->connect (delete => sub { $this->destroy; 1 }); |
979 | |
998 | |
980 | # better use a pane... |
999 | # better use a pane... |
981 | $self->add (my $hbox = new CFPlus::UI::HBox); |
1000 | $self->add (my $hbox = new CFPlus::UI::HBox); |
… | |
… | |
1025 | }; |
1044 | }; |
1026 | |
1045 | |
1027 | sub update_options { |
1046 | sub update_options { |
1028 | my ($self) = @_; |
1047 | my ($self) = @_; |
1029 | |
1048 | |
1030 | Scalar::Util::weaken $self; |
1049 | CFPlus::weaken $self; |
1031 | |
1050 | |
1032 | $self->{options}->clear; |
1051 | $self->{options}->clear; |
1033 | $self->{options}->add ($self->{bye_button}); |
1052 | $self->{options}->add ($self->{bye_button}); |
1034 | |
1053 | |
1035 | for my $kw (sort keys %{ $self->{kw} }) { |
1054 | for my $kw (sort keys %{ $self->{kw} }) { |
… | |
… | |
1044 | } |
1063 | } |
1045 | |
1064 | |
1046 | sub feed { |
1065 | sub feed { |
1047 | my ($self, $msg) = @_; |
1066 | my ($self, $msg) = @_; |
1048 | |
1067 | |
1049 | Scalar::Util::weaken $self; |
1068 | CFPlus::weaken $self; |
1050 | |
1069 | |
1051 | if ($msg->{msgtype} eq "reply") { |
1070 | if ($msg->{msgtype} eq "reply") { |
1052 | $self->{kw}{$_} = 1 for @{$msg->{add_topics} || []}; |
1071 | $self->{kw}{$_} = 1 for @{$msg->{add_topics} || []}; |
1053 | $self->{kw}{$_} = 0 for @{$msg->{del_topics} || []}; |
1072 | $self->{kw}{$_} = 0 for @{$msg->{del_topics} || []}; |
1054 | |
1073 | |