… | |
… | |
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 | |
… | |
… | |
37 | map ["$cmd$_", $text], |
39 | map ["$cmd$_", $text], |
38 | sort { (length $a) <=> (length $b) } |
40 | sort { (length $a) <=> (length $b) } |
39 | @args |
41 | @args |
40 | } sort { $a->{par} <=> $b->{par} } |
42 | } sort { $a->{par} <=> $b->{par} } |
41 | CFPlus::Pod::find command => "*"; |
43 | CFPlus::Pod::find command => "*"; |
|
|
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 | }); |
42 | |
61 | |
43 | $self->{map_widget}->add_command (@$_) |
62 | $self->{map_widget}->add_command (@$_) |
44 | for @cmd_help; |
63 | for @cmd_help; |
45 | |
64 | |
46 | $self->{noface} = new_from_file CFPlus::Texture |
65 | $self->{noface} = new_from_file CFPlus::Texture |
… | |
… | |
291 | $::CONN->user_send ("use_skill $name"); |
310 | $::CONN->user_send ("use_skill $name"); |
292 | } elsif ($ev->{button} == 3) { |
311 | } elsif ($ev->{button} == 3) { |
293 | my $shortname = CFPlus::shorten $name, 14; |
312 | my $shortname = CFPlus::shorten $name, 14; |
294 | (new CFPlus::UI::Menu |
313 | (new CFPlus::UI::Menu |
295 | items => [ |
314 | items => [ |
296 | ["bind <i>ready_skill $shortname</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"] }], |
297 | ["bind <i>use_skill $shortname</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"] }], |
298 | ], |
317 | ], |
299 | )->popup ($ev); |
318 | )->popup ($ev); |
300 | } else { |
319 | } else { |
301 | return 0; |
320 | return 0; |
302 | } |
321 | } |
… | |
… | |
319 | $self->{stat_widget_exp}{$_}->set_text (::formsep ($stats->{$_}[1])); |
338 | $self->{stat_widget_exp}{$_}->set_text (::formsep ($stats->{$_}[1])); |
320 | $self->{stat_widget_lvl}{$_}->set_text ($stats->{$_}[0] * 1); |
339 | $self->{stat_widget_lvl}{$_}->set_text ($stats->{$_}[0] * 1); |
321 | } |
340 | } |
322 | } |
341 | } |
323 | |
342 | |
|
|
343 | sub macro_send { |
|
|
344 | my ($self, $macro) = @_; |
|
|
345 | |
|
|
346 | for my $cmd (@{ $macro->{action} }) { |
|
|
347 | $self->send_command ($cmd); |
|
|
348 | } |
|
|
349 | } |
|
|
350 | |
324 | sub user_send { |
351 | sub user_send { |
325 | my ($self, $command) = @_; |
352 | my ($self, $command) = @_; |
326 | |
353 | |
327 | push @{$self->{record}}, $command |
354 | $self->{record}->($command) |
328 | if $self->{record}; |
355 | if $self->{record}; |
329 | |
356 | |
330 | $self->logprint ("send: ", $command); |
357 | $self->logprint ("send: ", $command); |
331 | $self->send_command ($command); |
358 | $self->send_command ($command); |
332 | ::status ($command); |
359 | ::status ($command); |
333 | } |
360 | } |
334 | |
361 | |
335 | sub start_record { |
362 | sub record { |
336 | my ($self) = @_; |
363 | my ($self, $cb) = @_; |
337 | |
364 | |
338 | $self->{record} = []; |
365 | $self->{record} = $cb; |
339 | } |
|
|
340 | |
|
|
341 | sub stop_record { |
|
|
342 | my ($self) = @_; |
|
|
343 | return delete $self->{record}; |
|
|
344 | } |
366 | } |
345 | |
367 | |
346 | sub map_scroll { |
368 | sub map_scroll { |
347 | my ($self, $dx, $dy) = @_; |
369 | my ($self, $dx, $dy) = @_; |
348 | |
370 | |
… | |
… | |
623 | [0.75, 0.61, 0.20], |
645 | [0.75, 0.61, 0.20], |
624 | [0.99, 0.77, 0.26], |
646 | [0.99, 0.77, 0.26], |
625 | [0.74, 0.65, 0.41], |
647 | [0.74, 0.65, 0.41], |
626 | ); |
648 | ); |
627 | |
649 | |
|
|
650 | my $fg = $color[$color % @color]; |
|
|
651 | |
628 | $self->logprint ("info: ", $text); |
652 | $self->logprint ("info: ", $text); |
629 | |
653 | |
630 | # 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 |
631 | $text =~ s/(?<=\S)\n(?=\w)/ /g; |
655 | $text =~ s/(?<=\S)\n(?=\w)/ /g; |
632 | |
656 | |
633 | $text = CFPlus::asxml $text; |
657 | $text = CFPlus::asxml $text; |
634 | $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g; |
658 | $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g; |
635 | $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g; |
659 | $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g; |
636 | |
660 | |
637 | ::message ({ fg => $color[$color], markup => $_ }) |
661 | ::message ({ fg => $fg, markup => $_ }) |
638 | for split /\n/, $text; |
662 | for split /\n/, $text; |
639 | |
663 | |
640 | $self->{statusbox}->add ($text, |
664 | $self->{statusbox}->add ($text, |
641 | group => $text, |
665 | group => $text, |
642 | fg => $color[$color], |
666 | fg => $fg, |
643 | timeout => $color >= 2 ? 180 : 10, |
667 | timeout => $color >= 2 ? 180 : 10, |
644 | tooltip_font => $::FONT_FIXED, |
668 | tooltip_font => $::FONT_FIXED, |
645 | ); |
669 | ); |
646 | } |
670 | } |
647 | |
671 | |
… | |
… | |
672 | } |
696 | } |
673 | |
697 | |
674 | sub setup { |
698 | sub setup { |
675 | my ($self, $setup) = @_; |
699 | my ($self, $setup) = @_; |
676 | |
700 | |
|
|
701 | $self->{map_widget}->set_tilesize ($self->{tilesize}); |
677 | $::MAP->resize ($self->{mapw}, $self->{maph}); |
702 | $::MAP->resize ($self->{mapw}, $self->{maph}); |
678 | } |
703 | } |
679 | |
704 | |
680 | sub addme_success { |
705 | sub addme_success { |
681 | my ($self) = @_; |
706 | my ($self) = @_; |
… | |
… | |
921 | |
946 | |
922 | $self->update_server_info; |
947 | $self->update_server_info; |
923 | |
948 | |
924 | $self->send_command ("output-sync $::CFG->{output_sync}"); |
949 | $self->send_command ("output-sync $::CFG->{output_sync}"); |
925 | $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; |
926 | $self->send_command ("pickup $::CFG->{pickup}"); |
952 | $self->send_command ("pickup $::CFG->{pickup}"); |
927 | } |
953 | } |
928 | |
954 | |
929 | sub buildat { |
955 | sub buildat { |
930 | my ($self, $builditem, $x, $y) = @_; |
956 | my ($self, $builditem, $x, $y) = @_; |
… | |
… | |
982 | kw => { hi => 0, yes => 0, no => 0 }, |
1008 | kw => { hi => 0, yes => 0, no => 0 }, |
983 | has_close_button => 1, |
1009 | has_close_button => 1, |
984 | @_, |
1010 | @_, |
985 | ); |
1011 | ); |
986 | |
1012 | |
987 | Scalar::Util::weaken (my $this = $self); |
1013 | CFPlus::weaken (my $this = $self); |
988 | |
1014 | |
989 | $self->connect (delete => sub { $this->destroy; 1 }); |
1015 | $self->connect (delete => sub { $this->destroy; 1 }); |
990 | |
1016 | |
991 | # better use a pane... |
1017 | # better use a pane... |
992 | $self->add (my $hbox = new CFPlus::UI::HBox); |
1018 | $self->add (my $hbox = new CFPlus::UI::HBox); |
… | |
… | |
1036 | }; |
1062 | }; |
1037 | |
1063 | |
1038 | sub update_options { |
1064 | sub update_options { |
1039 | my ($self) = @_; |
1065 | my ($self) = @_; |
1040 | |
1066 | |
1041 | Scalar::Util::weaken $self; |
1067 | CFPlus::weaken $self; |
1042 | |
1068 | |
1043 | $self->{options}->clear; |
1069 | $self->{options}->clear; |
1044 | $self->{options}->add ($self->{bye_button}); |
1070 | $self->{options}->add ($self->{bye_button}); |
1045 | |
1071 | |
1046 | for my $kw (sort keys %{ $self->{kw} }) { |
1072 | for my $kw (sort keys %{ $self->{kw} }) { |
… | |
… | |
1055 | } |
1081 | } |
1056 | |
1082 | |
1057 | sub feed { |
1083 | sub feed { |
1058 | my ($self, $msg) = @_; |
1084 | my ($self, $msg) = @_; |
1059 | |
1085 | |
1060 | Scalar::Util::weaken $self; |
1086 | CFPlus::weaken $self; |
1061 | |
1087 | |
1062 | if ($msg->{msgtype} eq "reply") { |
1088 | if ($msg->{msgtype} eq "reply") { |
1063 | $self->{kw}{$_} = 1 for @{$msg->{add_topics} || []}; |
1089 | $self->{kw}{$_} = 1 for @{$msg->{add_topics} || []}; |
1064 | $self->{kw}{$_} = 0 for @{$msg->{del_topics} || []}; |
1090 | $self->{kw}{$_} = 0 for @{$msg->{del_topics} || []}; |
1065 | |
1091 | |