… | |
… | |
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}"; |
… | |
… | |
194 | ); |
229 | ); |
195 | } |
230 | } |
196 | |
231 | |
197 | # widgetset create template |
232 | # widgetset create template |
198 | sub ext_ws_ct { |
233 | sub ext_ws_ct { |
199 | my ($self, $ws, $template, $cfg) = @_; |
234 | my ($self, $ws, $type, $template, $done_cb, $cfg) = @_; |
200 | |
235 | |
201 | $template = eval <<EOF; |
236 | $done_cb ||= sub { }; |
202 | [ |
|
|
203 | Toplevel => { |
|
|
204 | s_id => "toplevel", |
|
|
205 | title => "Character Creation", |
|
|
206 | x => "center", |
|
|
207 | y => "center", |
|
|
208 | z => 5, |
|
|
209 | s_cl => [VBox => {s_cl => [ |
|
|
210 | Label => { |
|
|
211 | text => "Character Creation", |
|
|
212 | fontsize => 1, |
|
|
213 | align => 0, |
|
|
214 | }, |
|
|
215 | Label => { |
|
|
216 | markup => "View or Edit your character attributes below, then press <b>Finish</b> to create your character", |
|
|
217 | fontsize => 0.8, |
|
|
218 | align => 0, |
|
|
219 | }, |
|
|
220 | Notebook => { |
|
|
221 | s_cl => [ |
|
|
222 | Label => { |
|
|
223 | text => "hulla-hoop" |
|
|
224 | }, |
|
|
225 | Entry => { |
|
|
226 | s_id => "entry", |
|
|
227 | }, |
|
|
228 | ], |
|
|
229 | }, |
|
|
230 | Button => { |
|
|
231 | s_id => "finish", |
|
|
232 | title => "Finish", |
|
|
233 | }, |
|
|
234 | ]}], |
|
|
235 | }, |
|
|
236 | ] |
|
|
237 | EOF |
|
|
238 | die if $@; |
|
|
239 | |
237 | |
240 | my $parse_list; $parse_list = sub { |
238 | my $parse_list; $parse_list = sub { |
241 | my ($list) = @_; |
239 | my ($list) = @_; |
242 | my @w; |
240 | my @w; |
243 | |
241 | |
… | |
… | |
260 | } |
258 | } |
261 | |
259 | |
262 | @w |
260 | @w |
263 | }; |
261 | }; |
264 | |
262 | |
|
|
263 | # either array reference, or face # |
|
|
264 | if ($type eq "inline") { |
|
|
265 | $done_cb->(); |
265 | $parse_list->($template); |
266 | $parse_list->($template); |
|
|
267 | } elsif ($type eq "face") { |
|
|
268 | my $handler; $handler = $self->register_face_handler ($template, sub { |
|
|
269 | my ($face) = @_; |
266 | |
270 | |
|
|
271 | undef $handler; |
|
|
272 | $done_cb->(); |
|
|
273 | $parse_list->($self->{json_coder}->decode ($face->{data})); |
|
|
274 | }); |
|
|
275 | } else { |
|
|
276 | $done_cb->(0); |
|
|
277 | } |
267 | } |
278 | } |
268 | |
279 | |
269 | # widgetset associate |
280 | # widgetset associate |
270 | sub ext_ws_a { |
281 | sub ext_ws_a { |
271 | my ($self, %ass) = @_; |
282 | my ($self, %ass) = @_; |
… | |
… | |
299 | spell_list => $::SPELL_LIST, |
310 | spell_list => $::SPELL_LIST, |
300 | |
311 | |
301 | floorbox => $::FLOORBOX, |
312 | floorbox => $::FLOORBOX, |
302 | help_window => $::HELP_WINDOW, |
313 | help_window => $::HELP_WINDOW, |
303 | message_window => $::MESSAGE_WINDOW, |
314 | message_window => $::MESSAGE_WINDOW, |
|
|
315 | message_dist => $::MESSAGE_DIST, |
304 | statusbox => $::SDTATUSBOX, |
316 | statusbox => $::SDTATUSBOX, |
305 | |
317 | |
306 | inv => $::INV, |
318 | inv => $::INV, |
307 | invr => $::INVR, |
319 | invr => $::INVR, |
308 | invr_hb => $::INVR_HB, |
320 | invr_hb => $::INVR_HB, |
… | |
… | |
357 | |
369 | |
358 | # message window |
370 | # message window |
359 | sub ext_channel_info { |
371 | sub ext_channel_info { |
360 | my ($self, $info) = @_; |
372 | my ($self, $info) = @_; |
361 | $self->{channels}->{$info->{id}} = $info; |
373 | $self->{channels}->{$info->{id}} = $info; |
362 | $::MESSAGE_WINDOW->add_channel ($info); |
374 | $::MESSAGE_DIST->add_channel ($info); |
363 | } |
375 | } |
364 | |
376 | |
365 | ############################################################################# |
377 | ############################################################################# |
366 | |
378 | |
367 | sub logprint { |
379 | sub logprint { |
… | |
… | |
549 | $sktbl->clear; |
561 | $sktbl->clear; |
550 | |
562 | |
551 | my $sw = $self->{skillwid}{""} ||= [ |
563 | my $sw = $self->{skillwid}{""} ||= [ |
552 | 0, 0, (new DC::UI::Label text => "Experience", align => 1), |
564 | 0, 0, (new DC::UI::Label text => "Experience", align => 1), |
553 | 1, 0, (new DC::UI::Label text => "Lvl.", align => 1), |
565 | 1, 0, (new DC::UI::Label text => "Lvl.", align => 1), |
554 | 2, 0, (new DC::UI::Label text => "Progress", align => 0), |
566 | 2, 0, (new DC::UI::Label text => "Progress"), |
555 | 3, 0, (new DC::UI::Label text => "Skill", expand => 1), |
567 | 3, 0, (new DC::UI::Label text => "Skill", expand => 1, align => 0), |
556 | 4, 0, (new DC::UI::Label text => "Experience", align => 1), |
568 | 4, 0, (new DC::UI::Label text => "Experience", align => 1), |
557 | 5, 0, (new DC::UI::Label text => "Lvl.", align => 1), |
569 | 5, 0, (new DC::UI::Label text => "Lvl.", align => 1), |
558 | 6, 0, (new DC::UI::Label text => "Progress", align => 0), |
570 | 6, 0, (new DC::UI::Label text => "Progress"), |
559 | 7, 0, (new DC::UI::Label text => "Skill", expand => 1), |
571 | 7, 0, (new DC::UI::Label text => "Skill", expand => 1, align => 0), |
560 | ]; |
572 | ]; |
561 | |
573 | |
562 | my @add = @$sw; |
574 | my @add = @$sw; |
563 | |
575 | |
564 | 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>"; |
565 | |
577 | |
566 | 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); |
567 | 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); |
568 | |
580 | |
569 | my ($x, $y) = (0, 1); |
581 | my ($x, $y) = (0, 1); |
… | |
… | |
603 | |
615 | |
604 | # progress |
616 | # progress |
605 | (new DC::UI::ExperienceProgress), |
617 | (new DC::UI::ExperienceProgress), |
606 | |
618 | |
607 | # label |
619 | # label |
608 | (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, |
609 | 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), |
610 | ]; |
622 | ]; |
611 | |
623 | |
612 | push @add, |
624 | push @add, |
613 | $x * 4 + 0, $y, $sw->[0], |
625 | $x * 4 + 0, $y, $sw->[0], |
… | |
… | |
655 | } |
667 | } |
656 | |
668 | |
657 | sub map_scroll { |
669 | sub map_scroll { |
658 | my ($self, $dx, $dy) = @_; |
670 | my ($self, $dx, $dy) = @_; |
659 | |
671 | |
660 | $self->{map}->scroll ($dx, $dy); |
672 | $self->{map_widget}->scroll ($dx, $dy); |
661 | } |
673 | } |
662 | |
674 | |
663 | sub feed_map1a { |
675 | sub feed_map1a { |
664 | my ($self, $data) = @_; |
676 | my ($self, $data) = @_; |
665 | |
677 | |
… | |
… | |
669 | for my $tile (@$missing) { |
681 | for my $tile (@$missing) { |
670 | next if $self->{delay}{$tile}; |
682 | next if $self->{delay}{$tile}; |
671 | |
683 | |
672 | $delay = 1; |
684 | $delay = 1; |
673 | |
685 | |
674 | if (my $tex = $::CONN->{texture}[$tile]) { |
686 | if (my $tex = $self->{texture}[$tile]) { |
675 | $tex->upload; |
687 | $tex->upload; |
676 | } else { |
688 | } else { |
677 | $self->{delay}{$tile} = 1; |
689 | $self->{delay}{$tile} = 1; |
678 | |
690 | |
679 | # we assume the face is in-flight and will eventually come |
691 | # we assume the face is in-flight and will eventually arrive |
680 | push @{$self->{tile_cb}{$tile}}, sub { |
692 | push @{$self->{tile_cb}{$tile}}, sub { |
681 | delete $self->{delay}{$tile}; |
693 | delete $self->{delay}{$tile}; |
682 | $_[0]->upload; |
694 | $_[0]->upload; |
683 | }; |
695 | }; |
684 | } |
696 | } |
685 | } |
697 | } |
686 | |
698 | |
687 | if ($delay) { |
699 | if ($delay) { |
688 | # 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 |
689 | EV::once undef, 0, 0.03, sub { |
701 | EV::once undef, 0, 0.03, sub { |
690 | $self->{map_widget}->update |
702 | $self->{map_widget}->update |
691 | if $self->{map_widget}; |
703 | if $self->{map_widget}; |
692 | }; |
704 | }; |
693 | } else { |
705 | } else { |
… | |
… | |
702 | } |
714 | } |
703 | |
715 | |
704 | sub flush_map { |
716 | sub flush_map { |
705 | my ($self) = @_; |
717 | my ($self) = @_; |
706 | |
718 | |
707 | my $map_info = delete $self->{map_info} |
719 | return unless $self->{map_info}; |
708 | or return; |
|
|
709 | |
720 | |
|
|
721 | for my $map_info (values %{ $self->{map_cache} || {} }) { |
710 | my ($hash, $x, $y, $w, $h) = @$map_info; |
722 | my ($hash, $rdata, $x, $y, $w, $h) = @$map_info; |
711 | |
723 | |
712 | my $data = Compress::LZF::compress $self->{map}->get_rect ($x, $y, $w, $h); |
724 | my $data = $self->{map}->get_rect ($x, $y, $w, $h); |
713 | $self->{map_cache_new}{$hash} = \$data; |
725 | |
|
|
726 | if ($data ne $$rdata) { |
|
|
727 | $map_info->[1] = \$data; |
|
|
728 | my $cdata = Compress::LZF::compress $data; |
714 | DC::DB::put $self->{mapcache} => $hash => $data, sub { }; |
729 | DC::DB::put $self->{mapcache} => $hash => $cdata, sub { }; |
|
|
730 | } |
|
|
731 | } |
715 | } |
732 | } |
716 | |
733 | |
717 | sub map_clear { |
734 | sub map_clear { |
718 | my ($self) = @_; |
735 | my ($self) = @_; |
719 | |
736 | |
720 | $self->flush_map; |
737 | $self->flush_map; |
|
|
738 | delete $self->{map_info}; |
721 | delete $self->{neigh_map}; |
739 | delete $self->{neigh_map}; |
722 | |
740 | |
723 | $self->{map}->clear; |
741 | $self->{map}->clear; |
724 | delete $self->{map_widget}{magicmap}; |
742 | delete $self->{map_widget}{magicmap}; |
725 | } |
743 | } |
… | |
… | |
746 | |
764 | |
747 | $self->bg_fetch; |
765 | $self->bg_fetch; |
748 | }; |
766 | }; |
749 | } |
767 | } |
750 | |
768 | |
751 | sub load_map($$$) { |
769 | sub load_map($$$$$$) { |
752 | my ($self, $hash, $x, $y) = @_; |
770 | my ($self, $hash, $x, $y, $w, $h) = @_; |
753 | |
771 | |
754 | my $gen = $self->{map_change_gen}; |
772 | my $map_info = $self->{map_cache}{$hash} = [$hash, \"", $x, $y, $w, $h]; |
755 | |
773 | |
756 | my $cb = sub { |
774 | my $cb = sub { |
757 | return unless $gen == $self->{map_change_gen}; |
775 | $map_info->[1] = \$_[0]; |
758 | |
776 | |
759 | my ($data) = @_; |
|
|
760 | |
|
|
761 | if (defined $data) { |
|
|
762 | $self->{map_cache_new}{$hash} = \$data; |
|
|
763 | |
|
|
764 | my $data = Compress::LZF::decompress $data; |
|
|
765 | |
|
|
766 | my $inprogress = @{ $self->{bg_fetch} || [] }; |
777 | my $inprogress = @{ $self->{bg_fetch} || [] }; |
767 | unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $data); |
778 | unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $_[0]); |
768 | $self->bg_fetch unless $inprogress; |
779 | $self->bg_fetch unless $inprogress; |
769 | } |
|
|
770 | }; |
780 | }; |
771 | |
781 | |
772 | if (my $rdata = $self->{map_cache_old}{$hash}) { |
782 | if (my $map_info = $self->{map_cache_old}{$hash}) { |
773 | $cb->($$rdata); |
783 | $cb->(${ $map_info->[1] }); |
774 | } else { |
784 | } else { |
|
|
785 | my $gen = $self->{map_change_gen}; |
|
|
786 | |
775 | 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 | }; |
776 | } |
792 | } |
777 | } |
793 | } |
778 | |
794 | |
779 | # hardcode /world/world_xxx_xxx map names, the savings are enourmous, |
795 | # hardcode /world/world_xxx_xxx map names, the savings are enourmous, |
780 | # (server resource,s latency, bandwidth), so this hack is warranted. |
796 | # (server resources, latency, bandwidth), so this hack is warranted. |
781 | # 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 |
782 | sub send_mapinfo { |
798 | sub send_mapinfo { |
783 | my ($self, $data, $cb) = @_; |
799 | my ($self, $data, $cb) = @_; |
784 | |
800 | |
785 | 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)$%) { |
… | |
… | |
810 | } |
826 | } |
811 | |
827 | |
812 | # this method does a "flood fill" into every tile direction |
828 | # this method does a "flood fill" into every tile direction |
813 | # it assumes that tiles are arranged in a rectangular grid, |
829 | # it assumes that tiles are arranged in a rectangular grid, |
814 | # 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. |
815 | # failure to comply are harmless and result in display errors |
831 | # failure to comply is harmless and results in display errors |
816 | # at worst. |
832 | # at worst. |
817 | sub flood_fill { |
833 | sub flood_fill { |
818 | my ($self, $block, $gx, $gy, $path, $hash, $flags) = @_; |
834 | my ($self, $block, $gx, $gy, $path, $hash, $flags) = @_; |
819 | |
835 | |
820 | # the server does not allow map paths > 6 |
836 | # the server does not allow map paths > 6 |
… | |
… | |
856 | return if $mode ne "spatial"; |
872 | return if $mode ne "spatial"; |
857 | |
873 | |
858 | $x += $self->{map}->ox; |
874 | $x += $self->{map}->ox; |
859 | $y += $self->{map}->oy; |
875 | $y += $self->{map}->oy; |
860 | |
876 | |
861 | $self->load_map ($hash, $x, $y) |
877 | $self->load_map ($hash, $x, $y, $w, $h) |
862 | unless $self->{neigh_map}{$hash}[5]++;#d# |
878 | unless $self->{neigh_map}{$hash}[5]++;#d# |
863 | |
879 | |
864 | $neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash]; |
880 | $neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash]; |
865 | |
881 | |
866 | $self->flood_fill ($block, $gx, $gy, "$path$tile", $hash, $flags) |
882 | $self->flood_fill ($block, $gx, $gy, "$path$tile", $hash, $flags) |
… | |
… | |
874 | my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; |
890 | my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; |
875 | |
891 | |
876 | $self->flush_map; |
892 | $self->flush_map; |
877 | |
893 | |
878 | ++$self->{map_change_gen}; |
894 | ++$self->{map_change_gen}; |
879 | $self->{map_cache_old} = delete $self->{map_cache_new}; |
895 | $self->{map_cache_old} = delete $self->{map_cache}; |
880 | |
896 | |
881 | my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
897 | my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
882 | |
898 | |
883 | my $mapmapw = $self->{mapmap}->{w}; |
899 | my $mapmapw = $self->{mapmap}->{w}; |
884 | my $mapmaph = $self->{mapmap}->{h}; |
900 | my $mapmaph = $self->{mapmap}->{h}; |
… | |
… | |
896 | $self->{map_info} = [$hash, $x, $y, $w, $h]; |
912 | $self->{map_info} = [$hash, $x, $y, $w, $h]; |
897 | |
913 | |
898 | (my $map = $hash) =~ s/^.*?\/([^\/]+)$/\1/; |
914 | (my $map = $hash) =~ s/^.*?\/([^\/]+)$/\1/; |
899 | $::STATWIDS->{map}->set_text ("Map: " . $map); |
915 | $::STATWIDS->{map}->set_text ("Map: " . $map); |
900 | |
916 | |
901 | $self->load_map ($hash, $x, $y); |
917 | $self->load_map ($hash, $x, $y, $w, $h); |
902 | $self->flood_fill (0, 0, 0, "", $hash, $flags); |
918 | $self->flood_fill (0, 0, 0, "", $hash, $flags); |
903 | } |
919 | } |
904 | |
920 | |
905 | sub face_find { |
921 | sub face_find { |
906 | my ($self, $facenum, $face, $cb) = @_; |
922 | my ($self, $facenum, $face, $cb) = @_; |
… | |
… | |
1048 | 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; |
1049 | |
1065 | |
1050 | # handle some elements |
1066 | # handle some elements |
1051 | s/<fg name='([^']*)'>(.*?)<\/fg>/<span foreground='$1'>$2<\/span>/gs; |
1067 | s/<fg name='([^']*)'>(.*?)<\/fg>/<span foreground='$1'>$2<\/span>/gs; |
1052 | 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+$//; |
1053 | |
1071 | |
1054 | $_ |
1072 | $_ |
1055 | } |
1073 | } |
1056 | |
1074 | |
1057 | our %NAME_TO_COLOR = ( |
1075 | our %NAME_TO_COLOR = ( |
… | |
… | |
1104 | |
1122 | |
1105 | ## 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 |
1106 | # no longer neecssary with TRT servers |
1124 | # no longer neecssary with TRT servers |
1107 | #$text =~ s/(?<=\S)\n(?=\w)/ /g; |
1125 | #$text =~ s/(?<=\S)\n(?=\w)/ /g; |
1108 | |
1126 | |
1109 | for (split /\n/, $text) { |
|
|
1110 | ::message ({ |
1127 | ::message ({ |
1111 | fg => $fg, |
1128 | fg => $fg, |
1112 | markup => $_, |
1129 | markup => $text, |
1113 | type => $type, |
1130 | type => $type, |
1114 | extra => [@extra], |
1131 | extra => [@extra], |
1115 | color_flags => $color, #d# ugly, kill |
1132 | color_flags => $color, #d# ugly, kill |
1116 | }); |
1133 | }); |
1117 | |
1134 | |
1118 | $color &= ~NDI_CLEAR; # only clear once for multiline messages |
1135 | # $color &= ~NDI_CLEAR; # only clear once for multiline messages |
1119 | # actually, this is an ugly design. _we_ should control the channels, |
1136 | # # actually, this is an ugly design. _we_ should control the channels, |
1120 | # 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. |
1121 | # 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 |
1122 | # hacks such as color_flags, above. |
1139 | # # hacks such as color_flags, above. |
1123 | } |
|
|
1124 | |
1140 | |
1125 | $self->{statusbox}->add ($text, |
1141 | $self->{statusbox}->add ($text, |
1126 | group => $text, |
1142 | group => $text, |
1127 | fg => $fg, |
1143 | fg => $fg, |
1128 | timeout => $color >= 2 ? 180 : 10, |
1144 | timeout => $color >= 2 ? 180 : 10, |
… | |
… | |
1163 | |
1179 | |
1164 | my %skill_help; |
1180 | my %skill_help; |
1165 | |
1181 | |
1166 | for my $node (DC::Pod::find skill_description => "*") { |
1182 | for my $node (DC::Pod::find skill_description => "*") { |
1167 | my (undef, @par) = DC::Pod::section_of $node; |
1183 | my (undef, @par) = DC::Pod::section_of $node; |
1168 | $skill_help{$node->{kw}[0]} = DC::Pod::as_label @par; |
1184 | $skill_help{$node->[DC::Pod::N_KW][0]} = DC::Pod::as_label @par; |
1169 | }; |
1185 | }; |
1170 | |
1186 | |
1171 | for my $skill (values %{$self->{skill_info}}) { |
1187 | for my $skill (values %{$self->{skill_info}}) { |
1172 | $self->{map_widget}->add_command ("ready_skill $skill", |
1188 | $self->{map_widget}->add_command ("ready_skill $skill", |
1173 | (DC::asxml "Ready the skill '$skill'\n\n") |
1189 | (DC::asxml "Ready the skill '$skill'\n\n") |
… | |
… | |
1193 | $::FLOORBOX->clear; |
1209 | $::FLOORBOX->clear; |
1194 | |
1210 | |
1195 | my @add; |
1211 | my @add; |
1196 | |
1212 | |
1197 | my $row; |
1213 | my $row; |
1198 | 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; |
1199 | if ($row < 6) { |
1216 | if ($row < 6) { |
1200 | local $_->{face_widget}; # hack to force recreation of widget |
1217 | local $_->{face_widget}; # hack to force recreation of widget |
1201 | local $_->{desc_widget}; # hack to force recreation of widget |
1218 | local $_->{desc_widget}; # hack to force recreation of widget |
1202 | DC::Item::update_widgets $_; |
1219 | DC::Item::update_widgets $_; |
1203 | |
1220 | |
… | |
… | |
1230 | sub set_opencont { |
1247 | sub set_opencont { |
1231 | my ($conn, $tag, $name) = @_; |
1248 | my ($conn, $tag, $name) = @_; |
1232 | $conn->{open_container} = $tag; |
1249 | $conn->{open_container} = $tag; |
1233 | update_floorbox; |
1250 | update_floorbox; |
1234 | |
1251 | |
1235 | $::INVR_HB->clear (); |
1252 | $::INVR_HB->clear; |
1236 | $::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); |
1237 | |
1254 | |
1238 | if ($tag != 0) { # Floor isn't closable, is it? |
1255 | if ($tag != 0) { # Floor isn't closable, is it? |
1239 | $::INVR_HB->add (new DC::UI::Button |
1256 | $::INVR_HB->add (new DC::UI::Button |
1240 | text => "Close container", |
1257 | text => "Close container", |
1241 | tooltip => "Close the currently open container (if one is open)", |
1258 | tooltip => "Close the currently open container (if one is open)", |
… | |
… | |
1296 | } |
1313 | } |
1297 | |
1314 | |
1298 | sub item_update { |
1315 | sub item_update { |
1299 | my ($self, $item) = @_; |
1316 | my ($self, $item) = @_; |
1300 | |
1317 | |
1301 | #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"; |
1302 | |
1319 | |
1303 | DC::Item::update_widgets $item; |
1320 | DC::Item::update_widgets $item; |
1304 | |
1321 | |
1305 | if ($item->{tag} == $::CONN->{open_container} && not ($item->{flags} & F_OPEN)) { |
1322 | if ($item->{tag} == $::CONN->{open_container} && not ($item->{flags} & F_OPEN)) { |
1306 | set_opencont ($::CONN, 0, "Floor"); |
1323 | set_opencont ($::CONN, 0, "Floor"); |
1307 | |
1324 | |
1308 | } elsif ($item->{flags} & F_OPEN) { |
1325 | } elsif ($item->{flags} & F_OPEN) { |
1309 | set_opencont ($::CONN, $item->{tag}, DC::Item::desc_string $item); |
1326 | set_opencont ($::CONN, $item->{tag}, DC::Item::desc_string $item); |
… | |
… | |
1325 | |
1342 | |
1326 | my $weight = .001 * $self->{player}{weight}; |
1343 | my $weight = .001 * $self->{player}{weight}; |
1327 | my $limit = .001 * $self->{stat}{+CS_STAT_WEIGHT_LIM}; |
1344 | my $limit = .001 * $self->{stat}{+CS_STAT_WEIGHT_LIM}; |
1328 | |
1345 | |
1329 | $::STATWIDS->{weight}->set_text (sprintf "Weight: %.1fkg", $weight); |
1346 | $::STATWIDS->{weight}->set_text (sprintf "Weight: %.1fkg", $weight); |
1330 | $::STATWIDS->{m_weight}->set_text (sprintf "%.1fkg", $limit); |
1347 | $::STATWIDS->{m_weight}->set_text (sprintf "Max Weight: %.1fkg", $limit); |
1331 | $::STATWIDS->{i_weight}->set_text (sprintf "%.1f/%.1fkg", $weight, $limit); |
1348 | $::STATWIDS->{i_weight}->set_text (sprintf "%.1f/%.1fkg", $weight, $limit); |
1332 | } |
1349 | } |
1333 | |
1350 | |
1334 | sub update_server_info { |
1351 | sub update_server_info { |
1335 | my ($self) = @_; |
1352 | my ($self) = @_; |
… | |
… | |
1343 | . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n" |
1360 | . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n" |
1344 | . "examine command support $yesno[$self->{setup}{excmd} > 0]\n" |
1361 | . "examine command support $yesno[$self->{setup}{excmd} > 0]\n" |
1345 | . "editing support $yesno[!!$self->{editor_support}]\n" |
1362 | . "editing support $yesno[!!$self->{editor_support}]\n" |
1346 | . "map attributes $yesno[$self->{setup}{extmap} > 0]\n" |
1363 | . "map attributes $yesno[$self->{setup}{extmap} > 0]\n" |
1347 | . "big image protocol support $yesno[$self->{setup}{fxix} > 0]\n" |
1364 | . "big image protocol support $yesno[$self->{setup}{fxix} > 0]\n" |
1348 | . "cfplus support $yesno[$self->{cfplus_ext} > 0]" |
1365 | . "client support $yesno[$self->{cfplus_ext} > 0]" |
1349 | . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" |
1366 | . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" |
1350 | . "map size $self->{mapw}×$self->{maph}\n" |
1367 | . "map size $self->{mapw}×$self->{maph}\n" |
1351 | ); |
1368 | ); |
1352 | |
1369 | |
1353 | } |
1370 | } |
… | |
… | |
1375 | |
1392 | |
1376 | $self->update_server_info; |
1393 | $self->update_server_info; |
1377 | |
1394 | |
1378 | $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; |
1379 | $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# |
1380 | } |
1400 | } |
1381 | |
1401 | |
1382 | sub lookat { |
1402 | sub lookat { |
1383 | my ($self, $x, $y) = @_; |
1403 | my ($self, $x, $y) = @_; |
1384 | |
1404 | |
… | |
… | |
1548 | } |
1568 | } |
1549 | |
1569 | |
1550 | sub send { |
1570 | sub send { |
1551 | my ($self, $msg) = @_; |
1571 | my ($self, $msg) = @_; |
1552 | |
1572 | |
1553 | $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 | }); |
1554 | $self->{textview}->scroll_to_bottom; |
1579 | $self->{textview}->scroll_to_bottom; |
1555 | |
1580 | |
1556 | $self->{conn}->send_ext_msg (npc_dialog_tell => $self->{id}, $msg); |
1581 | $self->{conn}->send_ext_msg (npc_dialog_tell => $self->{id}, $msg); |
1557 | } |
1582 | } |
1558 | |
1583 | |