… | |
… | |
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; |
… | |
… | |
286 | if ($ev->{button} == 1) { |
290 | if ($ev->{button} == 1) { |
287 | $::CONN->user_send ("ready_skill $name"); |
291 | $::CONN->user_send ("ready_skill $name"); |
288 | } elsif ($ev->{button} == 2) { |
292 | } elsif ($ev->{button} == 2) { |
289 | $::CONN->user_send ("use_skill $name"); |
293 | $::CONN->user_send ("use_skill $name"); |
290 | } elsif ($ev->{button} == 3) { |
294 | } elsif ($ev->{button} == 3) { |
|
|
295 | my $shortname = CFPlus::shorten $name, 14; |
291 | (new CFPlus::UI::Menu |
296 | (new CFPlus::UI::Menu |
292 | items => [ |
297 | items => [ |
293 | ["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"] }], |
294 | ["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"] }], |
295 | ], |
300 | ], |
296 | )->popup ($ev); |
301 | )->popup ($ev); |
297 | } else { |
302 | } else { |
298 | return 0; |
303 | return 0; |
299 | } |
304 | } |
… | |
… | |
316 | $self->{stat_widget_exp}{$_}->set_text (::formsep ($stats->{$_}[1])); |
321 | $self->{stat_widget_exp}{$_}->set_text (::formsep ($stats->{$_}[1])); |
317 | $self->{stat_widget_lvl}{$_}->set_text ($stats->{$_}[0] * 1); |
322 | $self->{stat_widget_lvl}{$_}->set_text ($stats->{$_}[0] * 1); |
318 | } |
323 | } |
319 | } |
324 | } |
320 | |
325 | |
|
|
326 | sub macro_send { |
|
|
327 | my ($self, $macro) = @_; |
|
|
328 | |
|
|
329 | for my $cmd (@{ $macro->{action} }) { |
|
|
330 | $self->send_command ($cmd); |
|
|
331 | } |
|
|
332 | } |
|
|
333 | |
321 | sub user_send { |
334 | sub user_send { |
322 | my ($self, $command) = @_; |
335 | my ($self, $command) = @_; |
323 | |
336 | |
|
|
337 | $self->{record}->($command) |
324 | if ($self->{record}) { |
338 | if $self->{record}; |
325 | push @{$self->{record}}, $command; |
|
|
326 | } |
|
|
327 | |
339 | |
328 | $self->logprint ("send: ", $command); |
340 | $self->logprint ("send: ", $command); |
329 | $self->send_command ($command); |
341 | $self->send_command ($command); |
330 | ::status ($command); |
342 | ::status ($command); |
331 | } |
343 | } |
332 | |
344 | |
333 | sub start_record { |
345 | sub record { |
334 | my ($self) = @_; |
346 | my ($self, $cb) = @_; |
335 | |
347 | |
336 | $self->{record} = []; |
348 | $self->{record} = $cb; |
337 | } |
|
|
338 | |
|
|
339 | sub stop_record { |
|
|
340 | my ($self) = @_; |
|
|
341 | return delete $self->{record}; |
|
|
342 | } |
349 | } |
343 | |
350 | |
344 | sub map_scroll { |
351 | sub map_scroll { |
345 | my ($self, $dx, $dy) = @_; |
352 | my ($self, $dx, $dy) = @_; |
346 | |
353 | |
… | |
… | |
623 | [0.74, 0.65, 0.41], |
630 | [0.74, 0.65, 0.41], |
624 | ); |
631 | ); |
625 | |
632 | |
626 | $self->logprint ("info: ", $text); |
633 | $self->logprint ("info: ", $text); |
627 | |
634 | |
628 | my $time = sprintf "%02d:%02d:%02d", (localtime time)[2,1,0]; |
|
|
629 | |
|
|
630 | # try to create single paragraphs of multiple lines sent by the server |
635 | # try to create single paragraphs of multiple lines sent by the server |
631 | $text =~ s/(?<=\S)\n(?=\w)/ /g; |
636 | $text =~ s/(?<=\S)\n(?=\w)/ /g; |
632 | |
637 | |
633 | $text = CFPlus::asxml $text; |
638 | $text = CFPlus::asxml $text; |
634 | $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g; |
639 | $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g; |
635 | $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g; |
640 | $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g; |
636 | |
641 | |
637 | $self->{logview}->add_paragraph ({ fg => $color[$color], markup => $_ }) |
642 | ::message ({ fg => $color[$color], markup => $_ }) |
638 | for map "<span foreground='#ffffff'>$time</span> $_", split /\n/, $text; |
643 | for split /\n/, $text; |
639 | $self->{logview}->scroll_to_bottom; |
|
|
640 | |
644 | |
641 | $self->{statusbox}->add ($text, |
645 | $self->{statusbox}->add ($text, |
642 | group => $text, |
646 | group => $text, |
643 | fg => $color[$color], |
647 | fg => $color[$color], |
644 | timeout => $color >= 2 ? 180 : 10, |
648 | timeout => $color >= 2 ? 180 : 10, |
… | |
… | |
658 | # try to create single paragraphs out of the multiple lines sent by the server |
662 | # try to create single paragraphs out of the multiple lines sent by the server |
659 | $spell->{message} =~ s/(?<=\S)\n(?=\w)/ /g; |
663 | $spell->{message} =~ s/(?<=\S)\n(?=\w)/ /g; |
660 | $spell->{message} =~ s/\n+$//; |
664 | $spell->{message} =~ s/\n+$//; |
661 | $spell->{message} ||= "Server did not provide a description for this spell."; |
665 | $spell->{message} ||= "Server did not provide a description for this spell."; |
662 | |
666 | |
663 | $::SPELL_PAGE->add_spell ($spell); |
667 | $::SPELL_LIST->add_spell ($spell); |
664 | |
668 | |
665 | $self->{map_widget}->add_command ("invoke $spell->{name}", CFPlus::asxml $spell->{message}); |
669 | $self->{map_widget}->add_command ("invoke $spell->{name}", CFPlus::asxml $spell->{message}); |
666 | $self->{map_widget}->add_command ("cast $spell->{name}", CFPlus::asxml $spell->{message}); |
670 | $self->{map_widget}->add_command ("cast $spell->{name}", CFPlus::asxml $spell->{message}); |
667 | } |
671 | } |
668 | |
672 | |
669 | sub spell_delete { |
673 | sub spell_delete { |
670 | my ($self, $spell) = @_; |
674 | my ($self, $spell) = @_; |
671 | |
675 | |
672 | $::SPELL_PAGE->remove_spell ($spell); |
676 | $::SPELL_LIST->remove_spell ($spell); |
|
|
677 | } |
|
|
678 | |
|
|
679 | sub setup { |
|
|
680 | my ($self, $setup) = @_; |
|
|
681 | |
|
|
682 | $::MAP->resize ($self->{mapw}, $self->{maph}); |
673 | } |
683 | } |
674 | |
684 | |
675 | sub addme_success { |
685 | sub addme_success { |
676 | my ($self) = @_; |
686 | my ($self) = @_; |
677 | |
687 | |
… | |
… | |
883 | $::SERVER_INFO->set_markup ( |
893 | $::SERVER_INFO->set_markup ( |
884 | "server <tt>$self->{host}:$self->{port}</tt>\n" |
894 | "server <tt>$self->{host}:$self->{port}</tt>\n" |
885 | . "protocol version <tt>$self->{version}</tt>\n" |
895 | . "protocol version <tt>$self->{version}</tt>\n" |
886 | . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n" |
896 | . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n" |
887 | . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n" |
897 | . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n" |
888 | . "editor support $yesno[!!length $self->{cvs_root}]\n" |
898 | . "editing support $yesno[!!$self->{editor_support}]\n" |
889 | . "test server " . (length $self->{test_server} ? $self->{test_server} : $yesno[0]) . "\n" |
|
|
890 | . "map attributes $yesno[$self->{setup}{extmap} > 0]\n" |
899 | . "map attributes $yesno[$self->{setup}{extmap} > 0]\n" |
891 | . "cfplus support $yesno[$self->{cfplus_ext} > 0]" |
900 | . "cfplus support $yesno[$self->{cfplus_ext} > 0]" |
892 | . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" |
901 | . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" |
893 | . "map size $self->{mapw}×$self->{maph}\n" |
902 | . "map size $self->{mapw}×$self->{maph}\n" |
894 | ); |
903 | ); |
|
|
904 | |
|
|
905 | ::setup_build_button ($self->{editor_support}->{builder_ui}); |
895 | } |
906 | } |
896 | |
907 | |
897 | sub logged_in { |
908 | sub logged_in { |
898 | my ($self) = @_; |
909 | my ($self) = @_; |
899 | |
910 | |
… | |
… | |
901 | $self->{cfplus_ext} = $_[0]{version}; |
912 | $self->{cfplus_ext} = $_[0]{version}; |
902 | $self->update_server_info; |
913 | $self->update_server_info; |
903 | |
914 | |
904 | if ($self->{cfplus_ext} >= 2) { |
915 | if ($self->{cfplus_ext} >= 2) { |
905 | $self->send_ext_req ("editor_support", sub { |
916 | $self->send_ext_req ("editor_support", sub { |
906 | $self->{cvs_root} = $_[0]{cvs_root}; |
917 | $self->{editor_support} = $_[0]; |
907 | $self->{upload} = $_[0]{upload}; |
|
|
908 | $self->{test_server} = $_[0]{server}; |
|
|
909 | $self->update_server_info; |
918 | $self->update_server_info; |
910 | |
919 | |
911 | 0 |
920 | 0 |
912 | }); |
921 | }); |
913 | } |
922 | } |
… | |
… | |
918 | $self->update_server_info; |
927 | $self->update_server_info; |
919 | |
928 | |
920 | $self->send_command ("output-sync $::CFG->{output_sync}"); |
929 | $self->send_command ("output-sync $::CFG->{output_sync}"); |
921 | $self->send_command ("output-count $::CFG->{output_count}"); |
930 | $self->send_command ("output-count $::CFG->{output_count}"); |
922 | $self->send_command ("pickup $::CFG->{pickup}"); |
931 | $self->send_command ("pickup $::CFG->{pickup}"); |
|
|
932 | } |
|
|
933 | |
|
|
934 | sub buildat { |
|
|
935 | my ($self, $builditem, $x, $y) = @_; |
|
|
936 | |
|
|
937 | if ($self->{cfplus_ext}) { |
|
|
938 | $self->send_ext_msg (builder_build => dx => $x, dy => $y, (ref ($builditem) eq 'HASH') ? %$builditem : (item => $builditem)); |
|
|
939 | } |
923 | } |
940 | } |
924 | |
941 | |
925 | sub lookat { |
942 | sub lookat { |
926 | my ($self, $x, $y) = @_; |
943 | my ($self, $x, $y) = @_; |
927 | |
944 | |