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