… | |
… | |
21 | |
21 | |
22 | my $self = $class->SUPER::new (%arg, |
22 | my $self = $class->SUPER::new (%arg, |
23 | setup_req => { |
23 | setup_req => { |
24 | extmap => 1, |
24 | extmap => 1, |
25 | excmd => 1, |
25 | excmd => 1, |
26 | ywidget => 1,#d# |
26 | xwidget1 => 1,#d# |
27 | %{$arg{setup_req} || {}}, |
27 | %{$arg{setup_req} || {}}, |
28 | }, |
28 | }, |
29 | ); |
29 | ); |
30 | |
30 | |
31 | $self->{map_widget}->clr_commands; |
31 | $self->{map_widget}->clr_commands; |
… | |
… | |
59 | my (%cap) = @_; |
59 | my (%cap) = @_; |
60 | |
60 | |
61 | #$self->send ("setup sound 0"); # we use a different protocol |
61 | #$self->send ("setup sound 0"); # we use a different protocol |
62 | $self->update_fx_want; |
62 | $self->update_fx_want; |
63 | |
63 | |
|
|
64 | $self->send_exti_req (resource => "exp_table", sub { |
|
|
65 | my ($exp_table) = @_; |
|
|
66 | |
|
|
67 | $self->register_face_handler ($exp_table, sub { |
|
|
68 | my ($face) = @_; |
|
|
69 | |
|
|
70 | $self->{exp_table} = $self->{json_coder}->decode (delete $face->{data}); |
|
|
71 | |
|
|
72 | #TODO: update all interested parties |
|
|
73 | }); |
|
|
74 | |
|
|
75 | () |
|
|
76 | }); |
|
|
77 | |
64 | if (my $ts = $cap{tileset}) { |
78 | if (my $ts = $cap{tileset}) { |
65 | if (my ($default) = grep $_->[2] & 1, @$ts) { |
79 | if (my ($default) = grep $_->[2] & 1, @$ts) { |
66 | $self->{tileset} = $default; |
80 | $self->{tileset} = $default; |
67 | $self->{tilesize} = $default->[3]; |
81 | $self->{tilesize} = $default->[3]; |
68 | $self->setup_req (tileset => $default->[0]); |
82 | $self->setup_req (tileset => $default->[0]); |
… | |
… | |
104 | # widgetset create |
118 | # widgetset create |
105 | $self->connect_ext (ws_c => sub { |
119 | $self->connect_ext (ws_c => sub { |
106 | my ($ws, $id, $class, $args) = @_; |
120 | my ($ws, $id, $class, $args) = @_; |
107 | |
121 | |
108 | for my $ev (grep /^on_/, keys %$args) { |
122 | for my $ev (grep /^on_/, keys %$args) { |
|
|
123 | my $rid = $args->{$ev}; |
109 | $args->{$ev} = sub { |
124 | $args->{$ev} = sub { |
110 | my $id = shift->{s_id}; |
125 | my $id = shift->{s_id}; |
111 | $self->send_exti_msg (w_e => $id, $ev, \@_); |
126 | $self->send_exti_msg (w_e => $id, $rid, @_); |
112 | |
127 | |
113 | 1 |
128 | 1 |
114 | }; |
129 | }; |
115 | } |
130 | } |
116 | |
131 | |
117 | if (my $widget = eval { |
132 | $self->widget_associate ( |
|
|
133 | $ws, $id => scalar eval { |
118 | local $SIG{__DIE__}; |
134 | local $SIG{__DIE__}; |
119 | "CFPlus::UI::$class"->new ( |
135 | "CFPlus::UI::$class"->new (%$args) |
120 | %$args, |
|
|
121 | s_ws => $ws, |
|
|
122 | s_id => $id, |
|
|
123 | ) |
|
|
124 | } |
136 | } |
125 | ) { |
|
|
126 | $self->{widget}{$id} |
|
|
127 | = $self->{widgetset}{$ws}{w}{$id} |
|
|
128 | = $widget; |
|
|
129 | |
|
|
130 | $widget->connect (on_destroy => sub { |
|
|
131 | my ($widget) = @_; |
|
|
132 | |
|
|
133 | delete $self->{widget}{$widget->{s_id}}; |
|
|
134 | delete $self->{widgetset}{$widget->{s_ws}}{$widget->{s_id}}; |
|
|
135 | }); |
|
|
136 | } else { |
|
|
137 | warn "server failed creating client-side widget " . (CFPlus::to_json $class) . ": $@\n"; |
137 | ) or warn "server failed creating client-side widget " . (CFPlus::to_json $class) . ": $@\n"; |
138 | $self->send_exti_msg (w_e => $id, "destroy"); |
138 | }); |
|
|
139 | |
|
|
140 | # widgetset associate |
|
|
141 | $self->connect_ext (ws_a => sub { |
|
|
142 | my (%ass) = @_; |
|
|
143 | |
|
|
144 | # everything that has a name, wether conceivably useful or not |
|
|
145 | my %wkw = ( |
|
|
146 | root => $CFPlus::UI::ROOT, |
|
|
147 | tooltip => $CFPlus::UI::TOOLTIP, |
|
|
148 | |
|
|
149 | mapwidget => $::MAPWIDGET, |
|
|
150 | buttonbar => $::BUTTONBAR, |
|
|
151 | metaserver => $::METASERVER, |
|
|
152 | buttonbar => $::BUTTONBAR, |
|
|
153 | login_button => $::LOGIN_BUTTON, |
|
|
154 | quit_dialog => $::QUIT_DIALOG, |
|
|
155 | host_entry => $::HOST_ENTRY, |
|
|
156 | metaserver => $::METASERVER, |
|
|
157 | server_info => $::SERVER_INFO, |
|
|
158 | |
|
|
159 | setup_dialog => $::SETUP_DIALOG, |
|
|
160 | setup_notebook => $::SETUP_NOTEBOOK, |
|
|
161 | setup_server => $::SETUP_SERVER, |
|
|
162 | setup_keyboard => $::SETUP_KEYBOARD, |
|
|
163 | |
|
|
164 | pl_notebook => $::PL_NOTEBOOK, |
|
|
165 | pl_window => $::PL_WINDOW, |
|
|
166 | inventory_page => $::INVENTORY_PAGE, |
|
|
167 | stats_page => $::STATS_PAGE, |
|
|
168 | skill_page => $::SKILL_PAGE, |
|
|
169 | spell_page => $::SPELL_PAGE, |
|
|
170 | spell_list => $::SPELL_LIST, |
|
|
171 | |
|
|
172 | floorbox => $::FLOORBOX, |
|
|
173 | help_window => $::HELP_WINDOW, |
|
|
174 | message_window => $::MESSAGE_WINDOW, |
|
|
175 | statusbox => $::SDTATUSBOX, |
|
|
176 | |
|
|
177 | inv => $::INV, |
|
|
178 | invr => $::INVR, |
|
|
179 | invr_hb => $::INVR_HB, |
|
|
180 | |
|
|
181 | ); |
|
|
182 | |
|
|
183 | while (my ($id, $name) = each %ass) { |
|
|
184 | $self->widget_associate (undef, $id => $wkw{$name}) |
|
|
185 | or warn "server failed to associate non-existent well-known widget $name\n"; |
139 | } |
186 | } |
140 | }); |
187 | }); |
141 | |
188 | |
142 | # widget call |
189 | # widget call |
143 | $self->connect_ext (w_c => sub { |
190 | $self->connect_ext (w_c => sub { |
144 | my ($id, $rid, $method, $args) = @_; |
191 | my ($id, $rid, $method, @args) = @_; |
145 | |
192 | |
146 | my $w = $self->{widget}{$id} |
193 | my $w = $self->{widget}{$id} |
147 | or return; |
194 | or return; |
148 | |
195 | |
149 | $args ||= []; |
|
|
150 | |
|
|
151 | if ($rid) { |
196 | if ($rid) { |
152 | $self->send_exti_msg (w_r => $rid, [$w->$method (@$args)]); |
197 | $self->send_exti_msg (w_r => $rid, $w->$method (@args)); |
153 | } else { |
198 | } else { |
154 | $w->$method (@$args); |
199 | $w->$method (@args); |
155 | } |
200 | } |
156 | }); |
201 | }); |
157 | |
202 | |
158 | # widget set |
203 | # widget set |
159 | $self->connect_ext (w_s => sub { |
204 | $self->connect_ext (w_s => sub { |
… | |
… | |
219 | $self->{mapcache} = "mapcache_$self->{host}_$self->{port}"; |
264 | $self->{mapcache} = "mapcache_$self->{host}_$self->{port}"; |
220 | |
265 | |
221 | $self |
266 | $self |
222 | } |
267 | } |
223 | |
268 | |
|
|
269 | sub widget_associate { |
|
|
270 | my ($self, $ws, $id, $widget) = @_; |
|
|
271 | |
|
|
272 | if ($widget) { |
|
|
273 | $widget->{s_id} = $id; |
|
|
274 | $self->{widget}{$id} = $widget; |
|
|
275 | |
|
|
276 | if ($ws) { |
|
|
277 | $widget->{s_ws} = $ws; |
|
|
278 | $self->{widgetset}{$ws}{w}{$id} = $widget; |
|
|
279 | } |
|
|
280 | |
|
|
281 | $widget->connect (on_destroy => sub { |
|
|
282 | my ($widget) = @_; |
|
|
283 | |
|
|
284 | delete $self->{widget}{$widget->{s_id}}; |
|
|
285 | delete $self->{widgetset}{$widget->{s_ws}}{$widget->{s_id}} |
|
|
286 | if exists $widget->{s_ws}; |
|
|
287 | }); |
|
|
288 | |
|
|
289 | 1 |
|
|
290 | } else { |
|
|
291 | $self->send_exti_msg (w_e => $id, undef); |
|
|
292 | |
|
|
293 | 0 |
|
|
294 | } |
|
|
295 | } |
|
|
296 | |
224 | sub update_fx_want { |
297 | sub update_fx_want { |
225 | my ($self) = @_; |
298 | my ($self) = @_; |
226 | |
299 | |
227 | $self->send_exti_msg (fx_want => { |
300 | $self->send_exti_msg (fx_want => { |
228 | 3 => !!$::CFG->{bgm_enable}, # FT_MUSIC |
301 | 3 => !!$::CFG->{bgm_enable}, # FT_MUSIC |
229 | 5 => !!$::CFG->{audio_enable}, # FT_SOUND |
302 | 5 => !!$::CFG->{audio_enable}, # FT_SOUND |
|
|
303 | 6 => 1, # FT_RSRC |
230 | }); |
304 | }); |
231 | } |
305 | } |
232 | |
306 | |
233 | sub logprint { |
307 | sub logprint { |
234 | my ($self, @a) = @_; |
308 | my ($self, @a) = @_; |
… | |
… | |
520 | $tex->upload; |
594 | $tex->upload; |
521 | } else { |
595 | } else { |
522 | $self->{delay}{$tile} = 1; |
596 | $self->{delay}{$tile} = 1; |
523 | |
597 | |
524 | # we assume the face is in-flight and will eventually come |
598 | # we assume the face is in-flight and will eventually come |
525 | push @{$self->{face_cb}{$tile}}, sub { |
599 | push @{$self->{tile_cb}{$tile}}, sub { |
526 | delete $self->{delay}{$tile}; |
600 | delete $self->{delay}{$tile}; |
527 | $_[0]->upload; |
601 | $_[0]->upload; |
528 | }; |
602 | }; |
529 | } |
603 | } |
530 | } |
604 | } |
… | |
… | |
552 | my $map_info = delete $self->{map_info} |
626 | my $map_info = delete $self->{map_info} |
553 | or return; |
627 | or return; |
554 | |
628 | |
555 | my ($hash, $x, $y, $w, $h) = @$map_info; |
629 | my ($hash, $x, $y, $w, $h) = @$map_info; |
556 | |
630 | |
557 | my $data = $self->{map}->get_rect ($x, $y, $w, $h); |
631 | my $data = Compress::LZF::compress $self->{map}->get_rect ($x, $y, $w, $h); |
|
|
632 | $self->{map_cache_new}{$hash} = \$data; |
558 | CFPlus::DB::put $self->{mapcache} => $hash => Compress::LZF::compress $data, sub { }; |
633 | CFPlus::DB::put $self->{mapcache} => $hash => $data, sub { }; |
559 | #warn sprintf "SAVEmap[%s] length %d\n", $hash, length $data;#d# |
|
|
560 | } |
634 | } |
561 | |
635 | |
562 | sub map_clear { |
636 | sub map_clear { |
563 | my ($self) = @_; |
637 | my ($self) = @_; |
564 | |
638 | |
… | |
… | |
570 | } |
644 | } |
571 | |
645 | |
572 | sub bg_fetch { |
646 | sub bg_fetch { |
573 | my ($self) = @_; |
647 | my ($self) = @_; |
574 | |
648 | |
575 | my $id; |
649 | my $tile; |
576 | |
650 | |
577 | do { |
651 | do { |
578 | $id = pop @{$self->{bg_fetch}} |
652 | $tile = pop @{$self->{bg_fetch}} |
579 | or return; |
653 | or return; |
580 | } while $self->{texture}[$id]; |
654 | } while $self->{texture}[$tile]; |
581 | |
655 | |
582 | CFPlus::DB::exists tilecache => $id, sub { |
656 | CFPlus::DB::get tilecache => $tile, sub { |
583 | my ($exists) = @_; |
657 | my ($data) = @_; |
584 | |
658 | |
585 | return unless $self->{map}; # stop when destroyed |
659 | return unless $self->{map}; # stop when destroyed |
586 | |
660 | |
587 | if ($exists) { |
661 | if (defined $data) { |
588 | $self->have_tile ($id); |
662 | $self->have_tile ($tile, $data); |
589 | $self->{texture}[$id]->upload; |
663 | $self->{texture}[$tile]->upload; |
590 | } |
664 | } |
591 | |
665 | |
592 | $self->bg_fetch; |
666 | $self->bg_fetch; |
593 | }; |
667 | }; |
594 | } |
668 | } |
… | |
… | |
596 | sub load_map($$$) { |
670 | sub load_map($$$) { |
597 | my ($self, $hash, $x, $y) = @_; |
671 | my ($self, $hash, $x, $y) = @_; |
598 | |
672 | |
599 | my $gen = $self->{map_change_gen}; |
673 | my $gen = $self->{map_change_gen}; |
600 | |
674 | |
601 | CFPlus::DB::get $self->{mapcache} => $hash, sub { |
675 | my $cb = sub { |
602 | return unless $gen == $self->{map_change_gen}; |
676 | return unless $gen == $self->{map_change_gen}; |
603 | |
677 | |
604 | my ($data) = @_; |
678 | my ($data) = @_; |
605 | |
679 | |
606 | if (defined $data) { |
680 | if (defined $data) { |
|
|
681 | $self->{map_cache_new}{$hash} = \$data; |
|
|
682 | |
607 | $data = Compress::LZF::decompress $data; |
683 | my $data = Compress::LZF::decompress $data; |
608 | #warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d# |
|
|
609 | |
684 | |
610 | my $inprogress = @{ $self->{bg_fetch} || [] }; |
685 | my $inprogress = @{ $self->{bg_fetch} || [] }; |
611 | unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $data); |
686 | unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $data); |
612 | $self->bg_fetch unless $inprogress; |
687 | $self->bg_fetch unless $inprogress; |
613 | } |
688 | } |
614 | }; |
689 | }; |
|
|
690 | |
|
|
691 | if (my $rdata = $self->{map_cache_old}{$hash}) { |
|
|
692 | $cb->($$rdata); |
|
|
693 | } else { |
|
|
694 | CFPlus::DB::get $self->{mapcache} => $hash, $cb; |
|
|
695 | } |
615 | } |
696 | } |
616 | |
697 | |
617 | # hardcode /world/world_xxx_xxx map names, the savings are enourmous, |
698 | # hardcode /world/world_xxx_xxx map names, the savings are enourmous, |
618 | # (server resource,s latency, bandwidth), so this hack is warranted. |
699 | # (server resource,s latency, bandwidth), so this hack is warranted. |
619 | # the right fix is to make real tiled maps with an overview file |
700 | # the right fix is to make real tiled maps with an overview file |
… | |
… | |
712 | my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; |
793 | my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; |
713 | |
794 | |
714 | $self->flush_map; |
795 | $self->flush_map; |
715 | |
796 | |
716 | ++$self->{map_change_gen}; |
797 | ++$self->{map_change_gen}; |
|
|
798 | $self->{map_cache_old} = delete $self->{map_cache_new}; |
717 | |
799 | |
718 | my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
800 | my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
719 | |
801 | |
720 | my $mapmapw = $self->{mapmap}->{w}; |
802 | my $mapmapw = $self->{mapmap}->{w}; |
721 | my $mapmaph = $self->{mapmap}->{h}; |
803 | my $mapmaph = $self->{mapmap}->{h}; |
… | |
… | |
743 | my ($self, $facenum, $face, $cb) = @_; |
825 | my ($self, $facenum, $face, $cb) = @_; |
744 | |
826 | |
745 | if ($face->{type} == 0) { # FT_FACE |
827 | if ($face->{type} == 0) { # FT_FACE |
746 | my $id = CFPlus::DB::get_tile_id_sync $face->{name}; |
828 | my $id = CFPlus::DB::get_tile_id_sync $face->{name}; |
747 | |
829 | |
748 | $face->{id} = $id; |
830 | $face->{id} = $id; |
749 | $self->{faceid}[$facenum] = $id; |
|
|
750 | |
|
|
751 | $self->{map}->set_tileid ($facenum => $id); |
831 | $self->{map}->set_tileid ($facenum => $id); |
752 | |
832 | |
753 | CFPlus::DB::get tilecache => $id, $cb; |
833 | CFPlus::DB::get tilecache => $id, $cb; |
754 | |
834 | |
755 | } elsif ($face->{type} & 1) { # with metadata |
835 | } elsif ($face->{type} & 1) { # with metadata |
756 | CFPlus::DB::get res_meta => $face->{name}, $cb; |
836 | CFPlus::DB::get res_meta => $face->{name}, $cb; |
|
|
837 | |
|
|
838 | } else { # no metadata |
|
|
839 | CFPlus::DB::get res_data => $face->{name}, $cb; |
757 | } |
840 | } |
758 | } |
841 | } |
759 | |
842 | |
760 | sub face_update { |
843 | sub face_update { |
761 | my ($self, $facenum, $face, $changed) = @_; |
844 | my ($self, $facenum, $face, $changed) = @_; |
762 | |
845 | |
763 | if ($face->{type} == 0) { # FT_FACE |
846 | if ($face->{type} == 0) { |
|
|
847 | # image, FT_FACE |
764 | CFPlus::DB::put tilecache => $face->{id} => $face->{data}, sub { } |
848 | CFPlus::DB::put tilecache => $face->{id} => $face->{data}, sub { } |
765 | if $changed; |
849 | if $changed; |
766 | |
850 | |
767 | $self->have_tile ($face->{id}); |
851 | $self->have_tile ($face->{id}, delete $face->{data}); |
768 | |
852 | |
769 | } elsif ($face->{type} & 1) { # split metadata |
853 | } elsif ($face->{type} & 1) { |
|
|
854 | # split metadata case, FT_MUSIC, FT_SOUND |
770 | if ($changed) { # new data |
855 | if ($changed) { # new data |
771 | my ($meta_json, $data) = unpack "(w/a*)*", delete $face->{data}; |
856 | my ($meta, $data) = unpack "(w/a*)*", $face->{data}; |
772 | $face->{meta} = $self->{json_coder}->decode ($meta_json); |
857 | $face->{data} = $meta; |
773 | |
858 | |
774 | CFPlus::DB::put res_data => $face->{name} => $data, sub { }; |
859 | CFPlus::DB::put res_data => $face->{name} => $data, sub { }; |
775 | CFPlus::DB::put res_meta => $face->{name} => $meta_json, sub { }; |
860 | CFPlus::DB::put res_meta => $face->{name} => $meta, sub { }; |
776 | } else { |
861 | } |
|
|
862 | |
777 | $face->{meta} = $self->{json_coder}->decode (delete $face->{data}); |
863 | $face->{data} = $self->{json_coder}->decode ($face->{data}); |
778 | } |
|
|
779 | |
864 | |
780 | ::add_license ($face); |
865 | ::add_license ($face); |
781 | |
866 | |
782 | if ($face->{type} == 3) { # FT_MUSIC |
867 | if ($face->{type} == 3) { # FT_MUSIC |
783 | $self->{music_meta}{$facenum} = $face; |
|
|
784 | |
|
|
785 | ::message ({ markup => "downloaded song #$facenum" }) |
868 | ::message ({ markup => "downloaded song #$facenum" }) |
786 | if $changed; |
869 | if $changed; |
787 | |
870 | |
788 | &::audio_music_push ($facenum); |
871 | &::audio_music_push ($facenum); |
789 | } elsif ($face->{type} == 5) { # FT_SOUND |
872 | } elsif ($face->{type} == 5) { # FT_SOUND |
790 | $self->{sound_meta}{$facenum} = $face; |
|
|
791 | |
|
|
792 | ::message ({ markup => "downloaded sound #$facenum" }) |
873 | ::message ({ markup => "downloaded sound #$facenum" }) |
793 | if $changed; |
874 | if $changed; |
794 | |
875 | |
795 | &::audio_sound_push ($facenum); |
876 | &::audio_sound_push ($facenum); |
796 | } |
877 | } |
797 | |
878 | |
|
|
879 | } else { |
|
|
880 | # flat resource case, FT_RSRC |
|
|
881 | CFPlus::DB::put res_data => $face->{name} => $face->{data}, sub { } |
|
|
882 | if $changed; |
|
|
883 | } |
|
|
884 | |
|
|
885 | if (my $cbs = $self->{face_cb}{$facenum}) { |
|
|
886 | $_->($face, $changed) for @$cbs; |
798 | } |
887 | } |
799 | } |
888 | } |
800 | |
889 | |
801 | sub smooth_update { |
890 | sub smooth_update { |
802 | my ($self, $facenum, $face) = @_; |
891 | my ($self, $facenum, $face) = @_; |
803 | |
892 | |
804 | $self->{map}->set_smooth ($facenum, $face->{smoothface}, $face->{smoothlevel}); |
893 | $self->{map}->set_smooth ($facenum, $face->{smoothface}, $face->{smoothlevel}); |
805 | } |
894 | } |
806 | |
895 | |
807 | sub have_tile { |
896 | sub have_tile { |
808 | my ($self, $tile) = @_; |
897 | my ($self, $tile, $data) = @_; |
809 | |
898 | |
810 | return unless $self->{map}; |
899 | return unless $self->{map}; |
811 | |
900 | |
812 | my $tex = $self->{texture}[$tile] ||= |
901 | my $tex = $self->{texture}[$tile] ||= |
813 | new CFPlus::Texture |
902 | new CFPlus::Texture |
814 | tile => $tile, minify => 1, mipmap => 1, delay => 1; |
903 | tile => $tile, |
|
|
904 | image => $data, delete_image => 1, |
|
|
905 | minify => 1, mipmap => 1; |
815 | |
906 | |
816 | $_->($tex) for @{(delete $self->{face_cb}{$tile}) || []}; |
907 | if (my $cbs = delete $self->{tile_cb}{$tile}) { |
|
|
908 | $_->($tex) for @$cbs; |
|
|
909 | } |
817 | } |
910 | } |
818 | |
911 | |
819 | sub connect_face_update { |
912 | # call in non-void context registers a temporary |
|
|
913 | # hook with handle, otherwise its permanent |
|
|
914 | sub on_face_change { |
820 | my ($self, $id, $cb) = @_; |
915 | my ($self, $num, $cb) = @_; |
821 | |
916 | |
822 | push @{$self->{face_cb}{$id}}, $cb; |
917 | push @{$self->{face_cb}{$num}}, $cb; |
823 | |
918 | |
|
|
919 | defined wantarray |
824 | CFPlus::guard { |
920 | ? CFPlus::guard { |
825 | @{$self->{face_cb}{$id}} |
921 | @{$self->{face_cb}{$num}} |
826 | = grep $_ != $cb, |
922 | = grep $_ != $cb, |
827 | @{$self->{face_cb}{$id}}; |
923 | @{$self->{face_cb}{$num}}; |
828 | } |
924 | } |
|
|
925 | : () |
|
|
926 | } |
|
|
927 | |
|
|
928 | # call in non-void context registers a temporary |
|
|
929 | # hook with handle, otherwise its permanent |
|
|
930 | sub register_face_handler { |
|
|
931 | my ($self, $num, $cb) = @_; |
|
|
932 | |
|
|
933 | # invoke if available right now |
|
|
934 | $cb->($self->{face}[$num], 0) |
|
|
935 | unless exists $self->{face}[$num]{loading}; |
|
|
936 | |
|
|
937 | # future changes |
|
|
938 | $self->on_face_change ($num => $cb) |
829 | } |
939 | } |
830 | |
940 | |
831 | sub sound_play { |
941 | sub sound_play { |
832 | my ($self, $type, $face, $dx, $dy, $vol) = @_; |
942 | my ($self, $type, $face, $dx, $dy, $vol) = @_; |
833 | |
943 | |
… | |
… | |
905 | $self->{$type} = $text; |
1015 | $self->{$type} = $text; |
906 | } else { |
1016 | } else { |
907 | $self->logprint ("msg: ", $text); |
1017 | $self->logprint ("msg: ", $text); |
908 | return if $color < 0; # negative color == ignore if not understood |
1018 | return if $color < 0; # negative color == ignore if not understood |
909 | |
1019 | |
910 | my $fg = $CF_COLOR[$color & 0x1f] || [1, 0, 0]; |
1020 | my $fg = $CF_COLOR[$color & NDI_COLOR_MASK] || [1, 0, 0]; |
911 | |
1021 | |
912 | ## try to create single paragraphs of multiple lines sent by the server |
1022 | ## try to create single paragraphs of multiple lines sent by the server |
913 | # no longer neecssary with TRT servers |
1023 | # no longer neecssary with TRT servers |
914 | #$text =~ s/(?<=\S)\n(?=\w)/ /g; |
1024 | #$text =~ s/(?<=\S)\n(?=\w)/ /g; |
915 | |
1025 | |
916 | ::message ({ fg => $fg, markup => $_, type => $type, extra => [@extra] }) |
1026 | ::message ({ |
|
|
1027 | fg => $fg, |
|
|
1028 | markup => $_, |
|
|
1029 | type => $type, |
|
|
1030 | extra => [@extra], |
|
|
1031 | color_flags => $color |
917 | for split /\n/, $text; |
1032 | }) for split /\n/, $text; |
918 | |
1033 | |
919 | $self->{statusbox}->add ($text, |
1034 | $self->{statusbox}->add ($text, |
920 | group => $text, |
1035 | group => $text, |
921 | fg => $fg, |
1036 | fg => $fg, |
922 | timeout => $color >= 2 ? 180 : 10, |
1037 | timeout => $color >= 2 ? 180 : 10, |
… | |
… | |
1024 | sub set_opencont { |
1139 | sub set_opencont { |
1025 | my ($conn, $tag, $name) = @_; |
1140 | my ($conn, $tag, $name) = @_; |
1026 | $conn->{open_container} = $tag; |
1141 | $conn->{open_container} = $tag; |
1027 | update_floorbox; |
1142 | update_floorbox; |
1028 | |
1143 | |
1029 | $::INV_RIGHT_HB->clear (); |
1144 | $::INVR_HB->clear (); |
1030 | $::INV_RIGHT_HB->add (new CFPlus::UI::Label align => 0, expand => 1, text => $name); |
1145 | $::INVR_HB->add (new CFPlus::UI::Label align => 0, expand => 1, text => $name); |
1031 | |
1146 | |
1032 | if ($tag != 0) { # Floor isn't closable, is it? |
1147 | if ($tag != 0) { # Floor isn't closable, is it? |
1033 | $::INV_RIGHT_HB->add (new CFPlus::UI::Button |
1148 | $::INVR_HB->add (new CFPlus::UI::Button |
1034 | text => "Close container", |
1149 | text => "Close container", |
1035 | tooltip => "Close the currently open container (if one is open)", |
1150 | tooltip => "Close the currently open container (if one is open)", |
1036 | on_activate => sub { |
1151 | on_activate => sub { |
1037 | $::CONN->send ("apply $tag") # $::CONN->{open_container}") |
1152 | $::CONN->send ("apply $tag") # $::CONN->{open_container}") |
1038 | if $tag != 0; |
1153 | if $tag != 0; |
1039 | #if $CONN->{open_container} != 0; |
|
|
1040 | 0 |
1154 | 0 |
1041 | }, |
1155 | }, |
1042 | ); |
1156 | ); |
1043 | } |
1157 | } |
1044 | |
1158 | |