… | |
… | |
11 | use DC::Pod; |
11 | use DC::Pod; |
12 | use DC::Macro; |
12 | use DC::Macro; |
13 | use DC::Item; |
13 | use DC::Item; |
14 | |
14 | |
15 | use base 'Deliantra::Protocol::Base'; |
15 | use base 'Deliantra::Protocol::Base'; |
|
|
16 | |
|
|
17 | our $TEX_DIALOGUE = new_from_resource DC::Texture |
|
|
18 | "dialogue.png", minify => 1, mipmap => 1; |
|
|
19 | |
|
|
20 | our $TEX_NOFACE = new_from_resource DC::Texture |
|
|
21 | "noface.png", minify => 1, mipmap => 1; |
|
|
22 | |
|
|
23 | our $TEX_HIDDEN = new_from_resource DC::Texture |
|
|
24 | "hidden.png", minify => 1, mipmap => 1; |
|
|
25 | |
|
|
26 | sub MIN_TEXTURE_UNUSED() { 1 }#d# |
16 | |
27 | |
17 | sub new { |
28 | sub new { |
18 | my ($class, %arg) = @_; |
29 | my ($class, %arg) = @_; |
19 | |
30 | |
20 | my $self = $class->SUPER::new (%arg, |
31 | my $self = $class->SUPER::new (%arg, |
… | |
… | |
27 | ); |
38 | ); |
28 | |
39 | |
29 | $self->{map_widget}->clr_commands; |
40 | $self->{map_widget}->clr_commands; |
30 | |
41 | |
31 | my @cmd_help = map { |
42 | my @cmd_help = map { |
32 | $_->{kw}[0] =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x |
43 | $_->[DC::Pod::N_KW][0] =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x |
33 | or die "unparseable command help: $_->{kw}[0]"; |
44 | or die "unparseable command help: $_->[DC::Pod::N_KW][0]"; |
34 | |
45 | |
35 | my $cmd = $1; |
46 | my $cmd = $1; |
36 | my @args = split /\|/, $2; |
47 | my @args = split /\|/, $2; |
37 | @args = (".*") unless @args; |
48 | @args = (".*") unless @args; |
38 | |
49 | |
… | |
… | |
43 | for @args; |
54 | for @args; |
44 | |
55 | |
45 | map ["$cmd$_", $text], |
56 | map ["$cmd$_", $text], |
46 | sort { (length $a) <=> (length $b) } |
57 | sort { (length $a) <=> (length $b) } |
47 | @args |
58 | @args |
48 | } sort { $a->{par} <=> $b->{par} } |
59 | } sort { $a->[DC::Pod::N_PAR] <=> $b->[DC::Pod::N_PAR] } |
49 | DC::Pod::find command => "*"; |
60 | DC::Pod::find command => "*"; |
50 | |
61 | |
51 | $self->{json_coder} |
62 | $self->{json_coder} |
52 | ->convert_blessed |
63 | ->convert_blessed |
53 | ->filter_json_single_key_object ("\fw" => sub { |
64 | ->filter_json_single_key_object ("\fw" => sub { |
… | |
… | |
64 | $self->{on_stop_game_guard} = $self->{map_widget}{root}->connect (stop_game => sub { |
75 | $self->{on_stop_game_guard} = $self->{map_widget}{root}->connect (stop_game => sub { |
65 | for my $ws (values %{delete $self->{widgetset} || {}}) { |
76 | for my $ws (values %{delete $self->{widgetset} || {}}) { |
66 | $_->destroy |
77 | $_->destroy |
67 | for values %{delete $ws->{w} || {}}; |
78 | for values %{delete $ws->{w} || {}}; |
68 | } |
79 | } |
|
|
80 | |
|
|
81 | delete $self->{items}; |
|
|
82 | $::INV->clear; |
|
|
83 | $::INVR->clear; |
|
|
84 | $::INVR_HB->clear; |
|
|
85 | $::FLOORBOX->clear; |
69 | }); |
86 | }); |
70 | |
87 | |
71 | $self->{map_widget}->add_command (@$_) |
88 | $self->{map_widget}->add_command (@$_) |
72 | for @cmd_help; |
89 | for @cmd_help; |
73 | |
90 | |
74 | { |
91 | { |
75 | $self->{dialogue} = my $tex = new_from_file DC::Texture |
92 | $self->{dialogue} = my $tex = $TEX_DIALOGUE; |
76 | DC::find_rcfile "dialogue.png", minify => 1, mipmap => 1; |
|
|
77 | $self->{map}->set_texture (1, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
93 | $self->{map}->set_texture (1, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
78 | } |
94 | } |
79 | |
95 | |
80 | { |
96 | { |
81 | $self->{noface} = my $tex = new_from_file DC::Texture |
97 | $self->{noface} = my $tex = $TEX_NOFACE; |
82 | DC::find_rcfile "noface.png", minify => 1, mipmap => 1; |
|
|
83 | $self->{map}->set_texture (2, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
98 | $self->{map}->set_texture (2, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
84 | } |
99 | } |
|
|
100 | |
|
|
101 | { |
|
|
102 | $self->{hidden} = my $tex = $TEX_HIDDEN; |
|
|
103 | $self->{map}->set_texture (3, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
|
|
104 | } |
|
|
105 | |
|
|
106 | # $self->{expire_count} = DC::DB::FIRST_TILE_ID; # minimum non-fixed tile id |
|
|
107 | # $self->{expire_w} = EV::timer 1, 1, sub { |
|
|
108 | # my $count = (int @{ $self->{texture} } / MIN_TEXTURE_UNUSED) || 1; |
|
|
109 | # |
|
|
110 | # for ($self->{map}->expire_textures ($self->{expire_count}, $count)) { |
|
|
111 | # warn DC::SvREFCNT $self->{texture}[$_]; |
|
|
112 | # $self->{texture}[$_]->unload; |
|
|
113 | # warn "expire texture $_\n";#d# |
|
|
114 | # } |
|
|
115 | # |
|
|
116 | # ($self->{expire_count} += $count) < @{ $self->{texture} } |
|
|
117 | # or $self->{expire_count} = DC::DB::FIRST_TILE_ID; |
|
|
118 | # warn "count is $count\n";#d# |
|
|
119 | # }; |
85 | |
120 | |
86 | $self->{open_container} = 0; |
121 | $self->{open_container} = 0; |
87 | |
122 | |
88 | # per server |
123 | # per server |
89 | $self->{mapcache} = "mapcache_$self->{host}_$self->{port}"; |
124 | $self->{mapcache} = "mapcache_$self->{host}_$self->{port}"; |
… | |
… | |
225 | @w |
260 | @w |
226 | }; |
261 | }; |
227 | |
262 | |
228 | # either array reference, or face # |
263 | # either array reference, or face # |
229 | if ($type eq "inline") { |
264 | if ($type eq "inline") { |
|
|
265 | $done_cb->(); |
230 | $parse_list->($template); |
266 | $parse_list->($template); |
231 | $done_cb->(); |
|
|
232 | } elsif ($type eq "face") { |
267 | } elsif ($type eq "face") { |
233 | #... |
268 | my $handler; $handler = $self->register_face_handler ($template, sub { |
|
|
269 | my ($face) = @_; |
|
|
270 | |
|
|
271 | undef $handler; |
234 | $done_cb->(0); |
272 | $done_cb->(); |
|
|
273 | $parse_list->($self->{json_coder}->decode ($face->{data})); |
|
|
274 | }); |
235 | } else { |
275 | } else { |
236 | $done_cb->(0); |
276 | $done_cb->(0); |
237 | } |
277 | } |
238 | } |
278 | } |
239 | |
279 | |
… | |
… | |
270 | spell_list => $::SPELL_LIST, |
310 | spell_list => $::SPELL_LIST, |
271 | |
311 | |
272 | floorbox => $::FLOORBOX, |
312 | floorbox => $::FLOORBOX, |
273 | help_window => $::HELP_WINDOW, |
313 | help_window => $::HELP_WINDOW, |
274 | message_window => $::MESSAGE_WINDOW, |
314 | message_window => $::MESSAGE_WINDOW, |
|
|
315 | message_dist => $::MESSAGE_DIST, |
275 | statusbox => $::SDTATUSBOX, |
316 | statusbox => $::SDTATUSBOX, |
276 | |
317 | |
277 | inv => $::INV, |
318 | inv => $::INV, |
278 | invr => $::INVR, |
319 | invr => $::INVR, |
279 | invr_hb => $::INVR_HB, |
320 | invr_hb => $::INVR_HB, |
… | |
… | |
328 | |
369 | |
329 | # message window |
370 | # message window |
330 | sub ext_channel_info { |
371 | sub ext_channel_info { |
331 | my ($self, $info) = @_; |
372 | my ($self, $info) = @_; |
332 | $self->{channels}->{$info->{id}} = $info; |
373 | $self->{channels}->{$info->{id}} = $info; |
333 | $::MESSAGE_WINDOW->add_channel ($info); |
374 | $::MESSAGE_DIST->add_channel ($info); |
334 | } |
375 | } |
335 | |
376 | |
336 | ############################################################################# |
377 | ############################################################################# |
337 | |
378 | |
338 | sub logprint { |
379 | sub logprint { |
… | |
… | |
520 | $sktbl->clear; |
561 | $sktbl->clear; |
521 | |
562 | |
522 | my $sw = $self->{skillwid}{""} ||= [ |
563 | my $sw = $self->{skillwid}{""} ||= [ |
523 | 0, 0, (new DC::UI::Label text => "Experience", align => 1), |
564 | 0, 0, (new DC::UI::Label text => "Experience", align => 1), |
524 | 1, 0, (new DC::UI::Label text => "Lvl.", align => 1), |
565 | 1, 0, (new DC::UI::Label text => "Lvl.", align => 1), |
525 | 2, 0, (new DC::UI::Label text => "Progress", align => 0), |
566 | 2, 0, (new DC::UI::Label text => "Progress"), |
526 | 3, 0, (new DC::UI::Label text => "Skill", expand => 1), |
567 | 3, 0, (new DC::UI::Label text => "Skill", expand => 1, align => 0), |
527 | 4, 0, (new DC::UI::Label text => "Experience", align => 1), |
568 | 4, 0, (new DC::UI::Label text => "Experience", align => 1), |
528 | 5, 0, (new DC::UI::Label text => "Lvl.", align => 1), |
569 | 5, 0, (new DC::UI::Label text => "Lvl.", align => 1), |
529 | 6, 0, (new DC::UI::Label text => "Progress", align => 0), |
570 | 6, 0, (new DC::UI::Label text => "Progress"), |
530 | 7, 0, (new DC::UI::Label text => "Skill", expand => 1), |
571 | 7, 0, (new DC::UI::Label text => "Skill", expand => 1, align => 0), |
531 | ]; |
572 | ]; |
532 | |
573 | |
533 | my @add = @$sw; |
574 | my @add = @$sw; |
534 | |
575 | |
535 | my $TOOLTIP_ALL = "\n\n<small>Left click - ready skill\nMiddle click - use spell\nRight click - further options</small>"; |
576 | my $TOOLTIP_ALL = "\n\n<small>Left click - ready skill\nMiddle click - use skill\nRight click - further options</small>"; |
536 | |
577 | |
537 | my @TOOLTIP_LVL = (tooltip => "<b>Level</b>. The level of the skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1); |
578 | my @TOOLTIP_LVL = (tooltip => "<b>Level</b>. The level of the skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1); |
538 | my @TOOLTIP_EXP = (tooltip => "<b>Experience</b>. The experience points you have in this skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1); |
579 | my @TOOLTIP_EXP = (tooltip => "<b>Experience</b>. The experience points you have in this skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1); |
539 | |
580 | |
540 | my ($x, $y) = (0, 1); |
581 | my ($x, $y) = (0, 1); |
… | |
… | |
574 | |
615 | |
575 | # progress |
616 | # progress |
576 | (new DC::UI::ExperienceProgress), |
617 | (new DC::UI::ExperienceProgress), |
577 | |
618 | |
578 | # label |
619 | # label |
579 | (new DC::UI::Label text => $name, on_button_down => $spell_cb, |
620 | (new DC::UI::Label text => $name, on_button_down => $spell_cb, align => 0, |
580 | can_events => 1, can_hover => 1, tooltip => (DC::Pod::section_label skill_description => $name) . $TOOLTIP_ALL), |
621 | can_events => 1, can_hover => 1, tooltip => (DC::Pod::section_label skill_description => $name) . $TOOLTIP_ALL), |
581 | ]; |
622 | ]; |
582 | |
623 | |
583 | push @add, |
624 | push @add, |
584 | $x * 4 + 0, $y, $sw->[0], |
625 | $x * 4 + 0, $y, $sw->[0], |
… | |
… | |
626 | } |
667 | } |
627 | |
668 | |
628 | sub map_scroll { |
669 | sub map_scroll { |
629 | my ($self, $dx, $dy) = @_; |
670 | my ($self, $dx, $dy) = @_; |
630 | |
671 | |
631 | $self->{map}->scroll ($dx, $dy); |
672 | $self->{map_widget}->scroll ($dx, $dy); |
632 | } |
673 | } |
633 | |
674 | |
634 | sub feed_map1a { |
675 | sub feed_map1a { |
635 | my ($self, $data) = @_; |
676 | my ($self, $data) = @_; |
636 | |
677 | |
… | |
… | |
640 | for my $tile (@$missing) { |
681 | for my $tile (@$missing) { |
641 | next if $self->{delay}{$tile}; |
682 | next if $self->{delay}{$tile}; |
642 | |
683 | |
643 | $delay = 1; |
684 | $delay = 1; |
644 | |
685 | |
645 | if (my $tex = $::CONN->{texture}[$tile]) { |
686 | if (my $tex = $self->{texture}[$tile]) { |
646 | $tex->upload; |
687 | $tex->upload; |
647 | } else { |
688 | } else { |
648 | $self->{delay}{$tile} = 1; |
689 | $self->{delay}{$tile} = 1; |
649 | |
690 | |
650 | # we assume the face is in-flight and will eventually come |
691 | # we assume the face is in-flight and will eventually arrive |
651 | push @{$self->{tile_cb}{$tile}}, sub { |
692 | push @{$self->{tile_cb}{$tile}}, sub { |
652 | delete $self->{delay}{$tile}; |
693 | delete $self->{delay}{$tile}; |
653 | $_[0]->upload; |
694 | $_[0]->upload; |
654 | }; |
695 | }; |
655 | } |
696 | } |
656 | } |
697 | } |
657 | |
698 | |
658 | if ($delay) { |
699 | if ($delay) { |
659 | # delay the map drawing a tiny bit in the hope of getting the missing fetched |
700 | # delay the map drawing a tiny bit in the hope of getting the missing tiles fetched |
660 | EV::once undef, 0, 0.03, sub { |
701 | EV::once undef, 0, 0.03, sub { |
661 | $self->{map_widget}->update |
702 | $self->{map_widget}->update |
662 | if $self->{map_widget}; |
703 | if $self->{map_widget}; |
663 | }; |
704 | }; |
664 | } else { |
705 | } else { |
… | |
… | |
673 | } |
714 | } |
674 | |
715 | |
675 | sub flush_map { |
716 | sub flush_map { |
676 | my ($self) = @_; |
717 | my ($self) = @_; |
677 | |
718 | |
678 | my $map_info = delete $self->{map_info} |
719 | return unless $self->{map_info}; |
679 | or return; |
|
|
680 | |
720 | |
|
|
721 | for my $map_info (values %{ $self->{map_cache} || {} }) { |
681 | my ($hash, $x, $y, $w, $h) = @$map_info; |
722 | my ($hash, $rdata, $x, $y, $w, $h) = @$map_info; |
682 | |
723 | |
683 | my $data = Compress::LZF::compress $self->{map}->get_rect ($x, $y, $w, $h); |
724 | my $data = $self->{map}->get_rect ($x, $y, $w, $h); |
684 | $self->{map_cache_new}{$hash} = \$data; |
725 | |
|
|
726 | if ($data ne $$rdata) { |
|
|
727 | $map_info->[1] = \$data; |
|
|
728 | my $cdata = Compress::LZF::compress $data; |
685 | DC::DB::put $self->{mapcache} => $hash => $data, sub { }; |
729 | DC::DB::put $self->{mapcache} => $hash => $cdata, sub { }; |
|
|
730 | } |
|
|
731 | } |
686 | } |
732 | } |
687 | |
733 | |
688 | sub map_clear { |
734 | sub map_clear { |
689 | my ($self) = @_; |
735 | my ($self) = @_; |
690 | |
736 | |
691 | $self->flush_map; |
737 | $self->flush_map; |
|
|
738 | delete $self->{map_info}; |
692 | delete $self->{neigh_map}; |
739 | delete $self->{neigh_map}; |
693 | |
740 | |
694 | $self->{map}->clear; |
741 | $self->{map}->clear; |
695 | delete $self->{map_widget}{magicmap}; |
742 | delete $self->{map_widget}{magicmap}; |
696 | } |
743 | } |
… | |
… | |
717 | |
764 | |
718 | $self->bg_fetch; |
765 | $self->bg_fetch; |
719 | }; |
766 | }; |
720 | } |
767 | } |
721 | |
768 | |
722 | sub load_map($$$) { |
769 | sub load_map($$$$$$) { |
723 | my ($self, $hash, $x, $y) = @_; |
770 | my ($self, $hash, $x, $y, $w, $h) = @_; |
724 | |
771 | |
725 | my $gen = $self->{map_change_gen}; |
772 | my $map_info = $self->{map_cache}{$hash} = [$hash, \"", $x, $y, $w, $h]; |
726 | |
773 | |
727 | my $cb = sub { |
774 | my $cb = sub { |
728 | return unless $gen == $self->{map_change_gen}; |
775 | $map_info->[1] = \$_[0]; |
729 | |
776 | |
730 | my ($data) = @_; |
|
|
731 | |
|
|
732 | if (defined $data) { |
|
|
733 | $self->{map_cache_new}{$hash} = \$data; |
|
|
734 | |
|
|
735 | my $data = Compress::LZF::decompress $data; |
|
|
736 | |
|
|
737 | my $inprogress = @{ $self->{bg_fetch} || [] }; |
777 | my $inprogress = @{ $self->{bg_fetch} || [] }; |
738 | unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $data); |
778 | unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $_[0]); |
739 | $self->bg_fetch unless $inprogress; |
779 | $self->bg_fetch unless $inprogress; |
740 | } |
|
|
741 | }; |
780 | }; |
742 | |
781 | |
743 | if (my $rdata = $self->{map_cache_old}{$hash}) { |
782 | if (my $map_info = $self->{map_cache_old}{$hash}) { |
744 | $cb->($$rdata); |
783 | $cb->(${ $map_info->[1] }); |
745 | } else { |
784 | } else { |
|
|
785 | my $gen = $self->{map_change_gen}; |
|
|
786 | |
746 | DC::DB::get $self->{mapcache} => $hash, $cb; |
787 | DC::DB::get $self->{mapcache} => $hash, sub { |
|
|
788 | return unless $gen == $self->{map_change_gen}; |
|
|
789 | return unless defined $_[0]; |
|
|
790 | $cb->(Compress::LZF::decompress $_[0]); |
|
|
791 | }; |
747 | } |
792 | } |
748 | } |
793 | } |
749 | |
794 | |
750 | # hardcode /world/world_xxx_xxx map names, the savings are enourmous, |
795 | # hardcode /world/world_xxx_xxx map names, the savings are enourmous, |
751 | # (server resource,s latency, bandwidth), so this hack is warranted. |
796 | # (server resources, latency, bandwidth), so this hack is warranted. |
752 | # the right fix is to make real tiled maps with an overview file |
797 | # the right fix is to make real tiled maps with an overview file |
753 | sub send_mapinfo { |
798 | sub send_mapinfo { |
754 | my ($self, $data, $cb) = @_; |
799 | my ($self, $data, $cb) = @_; |
755 | |
800 | |
756 | if ($self->{map_info}[0] =~ m%^/world/world_(\d\d\d)_(\d\d\d)$%) { |
801 | if ($self->{map_info}[0] =~ m%^/world/world_(\d\d\d)_(\d\d\d)$%) { |
… | |
… | |
781 | } |
826 | } |
782 | |
827 | |
783 | # this method does a "flood fill" into every tile direction |
828 | # this method does a "flood fill" into every tile direction |
784 | # it assumes that tiles are arranged in a rectangular grid, |
829 | # it assumes that tiles are arranged in a rectangular grid, |
785 | # i.e. a map is the same as the left of the right map etc. |
830 | # i.e. a map is the same as the left of the right map etc. |
786 | # failure to comply are harmless and result in display errors |
831 | # failure to comply is harmless and results in display errors |
787 | # at worst. |
832 | # at worst. |
788 | sub flood_fill { |
833 | sub flood_fill { |
789 | my ($self, $block, $gx, $gy, $path, $hash, $flags) = @_; |
834 | my ($self, $block, $gx, $gy, $path, $hash, $flags) = @_; |
790 | |
835 | |
791 | # the server does not allow map paths > 6 |
836 | # the server does not allow map paths > 6 |
… | |
… | |
827 | return if $mode ne "spatial"; |
872 | return if $mode ne "spatial"; |
828 | |
873 | |
829 | $x += $self->{map}->ox; |
874 | $x += $self->{map}->ox; |
830 | $y += $self->{map}->oy; |
875 | $y += $self->{map}->oy; |
831 | |
876 | |
832 | $self->load_map ($hash, $x, $y) |
877 | $self->load_map ($hash, $x, $y, $w, $h) |
833 | unless $self->{neigh_map}{$hash}[5]++;#d# |
878 | unless $self->{neigh_map}{$hash}[5]++;#d# |
834 | |
879 | |
835 | $neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash]; |
880 | $neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash]; |
836 | |
881 | |
837 | $self->flood_fill ($block, $gx, $gy, "$path$tile", $hash, $flags) |
882 | $self->flood_fill ($block, $gx, $gy, "$path$tile", $hash, $flags) |
… | |
… | |
845 | my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; |
890 | my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; |
846 | |
891 | |
847 | $self->flush_map; |
892 | $self->flush_map; |
848 | |
893 | |
849 | ++$self->{map_change_gen}; |
894 | ++$self->{map_change_gen}; |
850 | $self->{map_cache_old} = delete $self->{map_cache_new}; |
895 | $self->{map_cache_old} = delete $self->{map_cache}; |
851 | |
896 | |
852 | my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
897 | my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
853 | |
898 | |
854 | my $mapmapw = $self->{mapmap}->{w}; |
899 | my $mapmapw = $self->{mapmap}->{w}; |
855 | my $mapmaph = $self->{mapmap}->{h}; |
900 | my $mapmaph = $self->{mapmap}->{h}; |
… | |
… | |
867 | $self->{map_info} = [$hash, $x, $y, $w, $h]; |
912 | $self->{map_info} = [$hash, $x, $y, $w, $h]; |
868 | |
913 | |
869 | (my $map = $hash) =~ s/^.*?\/([^\/]+)$/\1/; |
914 | (my $map = $hash) =~ s/^.*?\/([^\/]+)$/\1/; |
870 | $::STATWIDS->{map}->set_text ("Map: " . $map); |
915 | $::STATWIDS->{map}->set_text ("Map: " . $map); |
871 | |
916 | |
872 | $self->load_map ($hash, $x, $y); |
917 | $self->load_map ($hash, $x, $y, $w, $h); |
873 | $self->flood_fill (0, 0, 0, "", $hash, $flags); |
918 | $self->flood_fill (0, 0, 0, "", $hash, $flags); |
874 | } |
919 | } |
875 | |
920 | |
876 | sub face_find { |
921 | sub face_find { |
877 | my ($self, $facenum, $face, $cb) = @_; |
922 | my ($self, $facenum, $face, $cb) = @_; |
… | |
… | |
1019 | s/&(?!amp;|lt;|gt;|apos;|quot;|#[0-9]+;|#x[0-9a-fA-F]+;)/&/g; |
1064 | s/&(?!amp;|lt;|gt;|apos;|quot;|#[0-9]+;|#x[0-9a-fA-F]+;)/&/g; |
1020 | |
1065 | |
1021 | # handle some elements |
1066 | # handle some elements |
1022 | s/<fg name='([^']*)'>(.*?)<\/fg>/<span foreground='$1'>$2<\/span>/gs; |
1067 | s/<fg name='([^']*)'>(.*?)<\/fg>/<span foreground='$1'>$2<\/span>/gs; |
1023 | s/<fg name="([^"]*)">(.*?)<\/fg>/<span foreground="$1">$2<\/span>/gs; |
1068 | s/<fg name="([^"]*)">(.*?)<\/fg>/<span foreground="$1">$2<\/span>/gs; |
|
|
1069 | |
|
|
1070 | s/\s+$//; |
1024 | |
1071 | |
1025 | $_ |
1072 | $_ |
1026 | } |
1073 | } |
1027 | |
1074 | |
1028 | our %NAME_TO_COLOR = ( |
1075 | our %NAME_TO_COLOR = ( |
… | |
… | |
1075 | |
1122 | |
1076 | ## try to create single paragraphs of multiple lines sent by the server |
1123 | ## try to create single paragraphs of multiple lines sent by the server |
1077 | # no longer neecssary with TRT servers |
1124 | # no longer neecssary with TRT servers |
1078 | #$text =~ s/(?<=\S)\n(?=\w)/ /g; |
1125 | #$text =~ s/(?<=\S)\n(?=\w)/ /g; |
1079 | |
1126 | |
1080 | for (split /\n/, $text) { |
|
|
1081 | ::message ({ |
1127 | ::message ({ |
1082 | fg => $fg, |
1128 | fg => $fg, |
1083 | markup => $_, |
1129 | markup => $text, |
1084 | type => $type, |
1130 | type => $type, |
1085 | extra => [@extra], |
1131 | extra => [@extra], |
1086 | color_flags => $color, #d# ugly, kill |
1132 | color_flags => $color, #d# ugly, kill |
1087 | }); |
1133 | }); |
1088 | |
1134 | |
1089 | $color &= ~NDI_CLEAR; # only clear once for multiline messages |
1135 | # $color &= ~NDI_CLEAR; # only clear once for multiline messages |
1090 | # actually, this is an ugly design. _we_ should control the channels, |
1136 | # # actually, this is an ugly design. _we_ should control the channels, |
1091 | # not some random other widget, as the channels are clearly protocol-specific. |
1137 | # # not some random other widget, as the channels are clearly protocol-specific. |
1092 | # then we could also react to flags such as CLEAR without resorting to |
1138 | # # then we could also react to flags such as CLEAR without resorting to |
1093 | # hacks such as color_flags, above. |
1139 | # # hacks such as color_flags, above. |
1094 | } |
|
|
1095 | |
1140 | |
1096 | $self->{statusbox}->add ($text, |
1141 | $self->{statusbox}->add ($text, |
1097 | group => $text, |
1142 | group => $text, |
1098 | fg => $fg, |
1143 | fg => $fg, |
1099 | timeout => $color >= 2 ? 180 : 10, |
1144 | timeout => $color >= 2 ? 180 : 10, |
… | |
… | |
1134 | |
1179 | |
1135 | my %skill_help; |
1180 | my %skill_help; |
1136 | |
1181 | |
1137 | for my $node (DC::Pod::find skill_description => "*") { |
1182 | for my $node (DC::Pod::find skill_description => "*") { |
1138 | my (undef, @par) = DC::Pod::section_of $node; |
1183 | my (undef, @par) = DC::Pod::section_of $node; |
1139 | $skill_help{$node->{kw}[0]} = DC::Pod::as_label @par; |
1184 | $skill_help{$node->[DC::Pod::N_KW][0]} = DC::Pod::as_label @par; |
1140 | }; |
1185 | }; |
1141 | |
1186 | |
1142 | for my $skill (values %{$self->{skill_info}}) { |
1187 | for my $skill (values %{$self->{skill_info}}) { |
1143 | $self->{map_widget}->add_command ("ready_skill $skill", |
1188 | $self->{map_widget}->add_command ("ready_skill $skill", |
1144 | (DC::asxml "Ready the skill '$skill'\n\n") |
1189 | (DC::asxml "Ready the skill '$skill'\n\n") |
… | |
… | |
1164 | $::FLOORBOX->clear; |
1209 | $::FLOORBOX->clear; |
1165 | |
1210 | |
1166 | my @add; |
1211 | my @add; |
1167 | |
1212 | |
1168 | my $row; |
1213 | my $row; |
1169 | for (sort { $a->{count} <=> $b->{count} } values %{ $::CONN->{container}{$::CONN->{open_container} || 0} }) { |
1214 | for (sort { $b->{count} <=> $a->{count} } values %{ $::CONN->{container}{$::CONN->{open_container} || 0} }) { |
|
|
1215 | next if $_->{tag} & 0x80000000; |
1170 | if ($row < 6) { |
1216 | if ($row < 6) { |
1171 | local $_->{face_widget}; # hack to force recreation of widget |
1217 | local $_->{face_widget}; # hack to force recreation of widget |
1172 | local $_->{desc_widget}; # hack to force recreation of widget |
1218 | local $_->{desc_widget}; # hack to force recreation of widget |
1173 | DC::Item::update_widgets $_; |
1219 | DC::Item::update_widgets $_; |
1174 | |
1220 | |
… | |
… | |
1201 | sub set_opencont { |
1247 | sub set_opencont { |
1202 | my ($conn, $tag, $name) = @_; |
1248 | my ($conn, $tag, $name) = @_; |
1203 | $conn->{open_container} = $tag; |
1249 | $conn->{open_container} = $tag; |
1204 | update_floorbox; |
1250 | update_floorbox; |
1205 | |
1251 | |
1206 | $::INVR_HB->clear (); |
1252 | $::INVR_HB->clear; |
1207 | $::INVR_HB->add (new DC::UI::Label align => 0, expand => 1, text => $name); |
1253 | $::INVR_HB->add (new DC::UI::Label expand => 1, text => $name); |
1208 | |
1254 | |
1209 | if ($tag != 0) { # Floor isn't closable, is it? |
1255 | if ($tag != 0) { # Floor isn't closable, is it? |
1210 | $::INVR_HB->add (new DC::UI::Button |
1256 | $::INVR_HB->add (new DC::UI::Button |
1211 | text => "Close container", |
1257 | text => "Close container", |
1212 | tooltip => "Close the currently open container (if one is open)", |
1258 | tooltip => "Close the currently open container (if one is open)", |
… | |
… | |
1267 | } |
1313 | } |
1268 | |
1314 | |
1269 | sub item_update { |
1315 | sub item_update { |
1270 | my ($self, $item) = @_; |
1316 | my ($self, $item) = @_; |
1271 | |
1317 | |
1272 | #d# print "item_update: $item->{tag} in $item->{container} ($self->{player}{tag}) ($::CONN->{open_container})\n"; |
1318 | #print "item_update: $item->{tag} in $item->{container} pt($self->{player}{tag}) oc($::CONN->{open_container}) f($item->{flags})\n"; |
1273 | |
1319 | |
1274 | DC::Item::update_widgets $item; |
1320 | DC::Item::update_widgets $item; |
1275 | |
1321 | |
1276 | if ($item->{tag} == $::CONN->{open_container} && not ($item->{flags} & F_OPEN)) { |
1322 | if ($item->{tag} == $::CONN->{open_container} && not ($item->{flags} & F_OPEN)) { |
1277 | set_opencont ($::CONN, 0, "Floor"); |
1323 | set_opencont ($::CONN, 0, "Floor"); |
1278 | |
1324 | |
1279 | } elsif ($item->{flags} & F_OPEN) { |
1325 | } elsif ($item->{flags} & F_OPEN) { |
1280 | set_opencont ($::CONN, $item->{tag}, DC::Item::desc_string $item); |
1326 | set_opencont ($::CONN, $item->{tag}, DC::Item::desc_string $item); |
… | |
… | |
1296 | |
1342 | |
1297 | my $weight = .001 * $self->{player}{weight}; |
1343 | my $weight = .001 * $self->{player}{weight}; |
1298 | my $limit = .001 * $self->{stat}{+CS_STAT_WEIGHT_LIM}; |
1344 | my $limit = .001 * $self->{stat}{+CS_STAT_WEIGHT_LIM}; |
1299 | |
1345 | |
1300 | $::STATWIDS->{weight}->set_text (sprintf "Weight: %.1fkg", $weight); |
1346 | $::STATWIDS->{weight}->set_text (sprintf "Weight: %.1fkg", $weight); |
1301 | $::STATWIDS->{m_weight}->set_text (sprintf "%.1fkg", $limit); |
1347 | $::STATWIDS->{m_weight}->set_text (sprintf "Max Weight: %.1fkg", $limit); |
1302 | $::STATWIDS->{i_weight}->set_text (sprintf "%.1f/%.1fkg", $weight, $limit); |
1348 | $::STATWIDS->{i_weight}->set_text (sprintf "%.1f/%.1fkg", $weight, $limit); |
1303 | } |
1349 | } |
1304 | |
1350 | |
1305 | sub update_server_info { |
1351 | sub update_server_info { |
1306 | my ($self) = @_; |
1352 | my ($self) = @_; |
… | |
… | |
1314 | . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n" |
1360 | . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n" |
1315 | . "examine command support $yesno[$self->{setup}{excmd} > 0]\n" |
1361 | . "examine command support $yesno[$self->{setup}{excmd} > 0]\n" |
1316 | . "editing support $yesno[!!$self->{editor_support}]\n" |
1362 | . "editing support $yesno[!!$self->{editor_support}]\n" |
1317 | . "map attributes $yesno[$self->{setup}{extmap} > 0]\n" |
1363 | . "map attributes $yesno[$self->{setup}{extmap} > 0]\n" |
1318 | . "big image protocol support $yesno[$self->{setup}{fxix} > 0]\n" |
1364 | . "big image protocol support $yesno[$self->{setup}{fxix} > 0]\n" |
1319 | . "cfplus support $yesno[$self->{cfplus_ext} > 0]" |
1365 | . "client support $yesno[$self->{cfplus_ext} > 0]" |
1320 | . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" |
1366 | . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" |
1321 | . "map size $self->{mapw}×$self->{maph}\n" |
1367 | . "map size $self->{mapw}×$self->{maph}\n" |
1322 | ); |
1368 | ); |
1323 | |
1369 | |
1324 | } |
1370 | } |
… | |
… | |
1346 | |
1392 | |
1347 | $self->update_server_info; |
1393 | $self->update_server_info; |
1348 | |
1394 | |
1349 | $self->send_command ("output-rate $::CFG->{output_rate}") if $::CFG->{output_rate} > 0; |
1395 | $self->send_command ("output-rate $::CFG->{output_rate}") if $::CFG->{output_rate} > 0; |
1350 | $self->send_command ("pickup $::CFG->{pickup}"); |
1396 | $self->send_command ("pickup $::CFG->{pickup}"); |
|
|
1397 | |
|
|
1398 | $self->send_exti_msg (clientlog => sprintf "OpenGL Info: %s [%s]", |
|
|
1399 | DC::OpenGL::gl_vendor, DC::OpenGL::gl_version);#d# |
1351 | } |
1400 | } |
1352 | |
1401 | |
1353 | sub lookat { |
1402 | sub lookat { |
1354 | my ($self, $x, $y) = @_; |
1403 | my ($self, $x, $y) = @_; |
1355 | |
1404 | |
… | |
… | |
1519 | } |
1568 | } |
1520 | |
1569 | |
1521 | sub send { |
1570 | sub send { |
1522 | my ($self, $msg) = @_; |
1571 | my ($self, $msg) = @_; |
1523 | |
1572 | |
1524 | $self->{textview}->add_paragraph ({ markup => "\n" . DC::asxml $msg }); |
1573 | $self->{textview}->add_paragraph ({ |
|
|
1574 | markup => |
|
|
1575 | "\n<span foreground='#ffff00'><b>" |
|
|
1576 | . (DC::asxml $msg) |
|
|
1577 | . "</b></span>" |
|
|
1578 | }); |
1525 | $self->{textview}->scroll_to_bottom; |
1579 | $self->{textview}->scroll_to_bottom; |
1526 | |
1580 | |
1527 | $self->{conn}->send_ext_msg (npc_dialog_tell => $self->{id}, $msg); |
1581 | $self->{conn}->send_ext_msg (npc_dialog_tell => $self->{id}, $msg); |
1528 | } |
1582 | } |
1529 | |
1583 | |