… | |
… | |
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; |
… | |
… | |
104 | # widgetset create |
104 | # widgetset create |
105 | $self->connect_ext (ws_c => sub { |
105 | $self->connect_ext (ws_c => sub { |
106 | my ($ws, $id, $class, $args) = @_; |
106 | my ($ws, $id, $class, $args) = @_; |
107 | |
107 | |
108 | for my $ev (grep /^on_/, keys %$args) { |
108 | for my $ev (grep /^on_/, keys %$args) { |
|
|
109 | my $rid = $args->{$ev}; |
109 | $args->{$ev} = sub { |
110 | $args->{$ev} = sub { |
110 | my $id = shift->{s_id}; |
111 | my $id = shift->{s_id}; |
111 | $self->send_exti_msg (w_e => $id, $ev, \@_); |
112 | $self->send_exti_msg (w_e => $id, $rid, @_); |
112 | |
113 | |
113 | 1 |
114 | 1 |
114 | }; |
115 | }; |
115 | } |
116 | } |
116 | |
117 | |
117 | if (my $widget = eval { |
118 | $self->widget_associate ( |
|
|
119 | $ws, $id => scalar eval { |
118 | local $SIG{__DIE__}; |
120 | local $SIG{__DIE__}; |
119 | "CFPlus::UI::$class"->new ( |
121 | "CFPlus::UI::$class"->new (%$args) |
120 | %$args, |
|
|
121 | s_ws => $ws, |
|
|
122 | s_id => $id, |
|
|
123 | ) |
|
|
124 | } |
122 | } |
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"; |
123 | ) or warn "server failed creating client-side widget " . (CFPlus::to_json $class) . ": $@\n"; |
138 | $self->send_exti_msg (w_e => $id, "destroy"); |
124 | }); |
|
|
125 | |
|
|
126 | # widgetset associate |
|
|
127 | $self->connect_ext (ws_a => sub { |
|
|
128 | my (%ass) = @_; |
|
|
129 | |
|
|
130 | # everything that has a name, wether conceivably useful or not |
|
|
131 | my %wkw = ( |
|
|
132 | root => $CFPlus::UI::ROOT, |
|
|
133 | tooltip => $CFPlus::UI::TOOLTIP, |
|
|
134 | |
|
|
135 | mapwidget => $::MAPWIDGET, |
|
|
136 | buttonbar => $::BUTTONBAR, |
|
|
137 | metaserver => $::METASERVER, |
|
|
138 | buttonbar => $::BUTTONBAR, |
|
|
139 | login_button => $::LOGIN_BUTTON, |
|
|
140 | quit_dialog => $::QUIT_DIALOG, |
|
|
141 | host_entry => $::HOST_ENTRY, |
|
|
142 | metaserver => $::METASERVER, |
|
|
143 | server_info => $::SERVER_INFO, |
|
|
144 | |
|
|
145 | setup_dialog => $::SETUP_DIALOG, |
|
|
146 | setup_notebook => $::SETUP_NOTEBOOK, |
|
|
147 | setup_server => $::SETUP_SERVER, |
|
|
148 | setup_keyboard => $::SETUP_KEYBOARD, |
|
|
149 | |
|
|
150 | pl_notebook => $::PL_NOTEBOOK, |
|
|
151 | pl_window => $::PL_WINDOW, |
|
|
152 | inventory_page => $::INVENTORY_PAGE, |
|
|
153 | stats_page => $::STATS_PAGE, |
|
|
154 | skill_page => $::SKILL_PAGE, |
|
|
155 | spell_page => $::SPELL_PAGE, |
|
|
156 | spell_list => $::SPELL_LIST, |
|
|
157 | |
|
|
158 | floorbox => $::FLOORBOX, |
|
|
159 | help_window => $::HELP_WINDOW, |
|
|
160 | message_window => $::MESSAGE_WINDOW, |
|
|
161 | statusbox => $::SDTATUSBOX, |
|
|
162 | |
|
|
163 | inv => $::INV, |
|
|
164 | invr => $::INVR, |
|
|
165 | invr_hb => $::INVR_HB, |
|
|
166 | |
|
|
167 | ); |
|
|
168 | |
|
|
169 | while (my ($id, $name) = each %ass) { |
|
|
170 | $self->widget_associate (undef, $id => $wkw{$name}) |
|
|
171 | or warn "server failed to associate non-existent well-known widget $name\n"; |
139 | } |
172 | } |
140 | }); |
173 | }); |
141 | |
174 | |
142 | # widget call |
175 | # widget call |
143 | $self->connect_ext (w_c => sub { |
176 | $self->connect_ext (w_c => sub { |
144 | my ($id, $rid, $method, $args) = @_; |
177 | my ($id, $rid, $method, @args) = @_; |
145 | |
178 | |
146 | my $w = $self->{widget}{$id} |
179 | my $w = $self->{widget}{$id} |
147 | or return; |
180 | or return; |
148 | |
181 | |
149 | $args ||= []; |
|
|
150 | |
|
|
151 | if ($rid) { |
182 | if ($rid) { |
152 | $self->send_exti_msg (w_r => $rid, [$w->$method (@$args)]); |
183 | $self->send_exti_msg (w_r => $rid, $w->$method (@args)); |
153 | } else { |
184 | } else { |
154 | $w->$method (@$args); |
185 | $w->$method (@args); |
155 | } |
186 | } |
156 | }); |
187 | }); |
157 | |
188 | |
158 | # widget set |
189 | # widget set |
159 | $self->connect_ext (w_s => sub { |
190 | $self->connect_ext (w_s => sub { |
… | |
… | |
217 | |
248 | |
218 | # per server |
249 | # per server |
219 | $self->{mapcache} = "mapcache_$self->{host}_$self->{port}"; |
250 | $self->{mapcache} = "mapcache_$self->{host}_$self->{port}"; |
220 | |
251 | |
221 | $self |
252 | $self |
|
|
253 | } |
|
|
254 | |
|
|
255 | sub widget_associate { |
|
|
256 | my ($self, $ws, $id, $widget) = @_; |
|
|
257 | |
|
|
258 | if ($widget) { |
|
|
259 | $widget->{s_id} = $id; |
|
|
260 | $self->{widget}{$id} = $widget; |
|
|
261 | |
|
|
262 | if ($ws) { |
|
|
263 | $widget->{s_ws} = $ws; |
|
|
264 | $self->{widgetset}{$ws}{w}{$id} = $widget; |
|
|
265 | } |
|
|
266 | |
|
|
267 | $widget->connect (on_destroy => sub { |
|
|
268 | my ($widget) = @_; |
|
|
269 | |
|
|
270 | delete $self->{widget}{$widget->{s_id}}; |
|
|
271 | delete $self->{widgetset}{$widget->{s_ws}}{$widget->{s_id}} |
|
|
272 | if exists $widget->{s_ws}; |
|
|
273 | }); |
|
|
274 | |
|
|
275 | 1 |
|
|
276 | } else { |
|
|
277 | $self->send_exti_msg (w_e => $id, undef); |
|
|
278 | |
|
|
279 | 0 |
|
|
280 | } |
222 | } |
281 | } |
223 | |
282 | |
224 | sub update_fx_want { |
283 | sub update_fx_want { |
225 | my ($self) = @_; |
284 | my ($self) = @_; |
226 | |
285 | |
… | |
… | |
506 | } |
565 | } |
507 | |
566 | |
508 | sub feed_map1a { |
567 | sub feed_map1a { |
509 | my ($self, $data) = @_; |
568 | my ($self, $data) = @_; |
510 | |
569 | |
511 | $self->{map}->map1a_update ($data, $self->{setup}{extmap}); |
570 | my $missing = $self->{map}->map1a_update ($data, $self->{setup}{extmap}); |
|
|
571 | my $delay; |
|
|
572 | |
|
|
573 | for my $tile (@$missing) { |
|
|
574 | next if $self->{delay}{$tile}; |
|
|
575 | |
|
|
576 | $delay = 1; |
|
|
577 | |
|
|
578 | if (my $tex = $::CONN->{texture}[$tile]) { |
|
|
579 | $tex->upload; |
|
|
580 | } else { |
|
|
581 | $self->{delay}{$tile} = 1; |
|
|
582 | |
|
|
583 | # we assume the face is in-flight and will eventually come |
|
|
584 | push @{$self->{face_cb}{$tile}}, sub { |
|
|
585 | delete $self->{delay}{$tile}; |
|
|
586 | $_[0]->upload; |
|
|
587 | }; |
|
|
588 | } |
|
|
589 | } |
|
|
590 | |
|
|
591 | if ($delay) { |
|
|
592 | # delay the map drawing a tiny bit in the hope of getting the missing fetched |
|
|
593 | Event->timer (after => 0.03, cb => sub { |
|
|
594 | $_[0]->w->cancel; |
|
|
595 | $self->{map_widget}->update; |
|
|
596 | }); |
|
|
597 | } else { |
512 | $self->{map_widget}->update; |
598 | $self->{map_widget}->update; |
|
|
599 | } |
513 | } |
600 | } |
514 | |
601 | |
515 | sub magicmap { |
602 | sub magicmap { |
516 | my ($self, $w, $h, $x, $y, $data) = @_; |
603 | my ($self, $w, $h, $x, $y, $data) = @_; |
517 | |
604 | |
… | |
… | |
524 | my $map_info = delete $self->{map_info} |
611 | my $map_info = delete $self->{map_info} |
525 | or return; |
612 | or return; |
526 | |
613 | |
527 | my ($hash, $x, $y, $w, $h) = @$map_info; |
614 | my ($hash, $x, $y, $w, $h) = @$map_info; |
528 | |
615 | |
529 | my $data = $self->{map}->get_rect ($x, $y, $w, $h); |
616 | my $data = Compress::LZF::compress $self->{map}->get_rect ($x, $y, $w, $h); |
|
|
617 | $self->{map_cache_new}{$hash} = \$data; |
530 | CFPlus::DB::put $self->{mapcache} => $hash => Compress::LZF::compress $data, sub { }; |
618 | CFPlus::DB::put $self->{mapcache} => $hash => $data, sub { }; |
531 | #warn sprintf "SAVEmap[%s] length %d\n", $hash, length $data;#d# |
|
|
532 | } |
619 | } |
533 | |
620 | |
534 | sub map_clear { |
621 | sub map_clear { |
535 | my ($self) = @_; |
622 | my ($self) = @_; |
536 | |
623 | |
… | |
… | |
554 | CFPlus::DB::exists tilecache => $id, sub { |
641 | CFPlus::DB::exists tilecache => $id, sub { |
555 | my ($exists) = @_; |
642 | my ($exists) = @_; |
556 | |
643 | |
557 | return unless $self->{map}; # stop when destroyed |
644 | return unless $self->{map}; # stop when destroyed |
558 | |
645 | |
|
|
646 | if ($exists) { |
559 | $self->have_tile ($id) |
647 | $self->have_tile ($id); |
560 | if $exists; |
648 | $self->{texture}[$id]->upload; |
|
|
649 | } |
561 | |
650 | |
562 | $self->bg_fetch; |
651 | $self->bg_fetch; |
563 | }; |
652 | }; |
564 | } |
653 | } |
565 | |
654 | |
566 | sub load_map($$$) { |
655 | sub load_map($$$) { |
567 | my ($self, $hash, $x, $y) = @_; |
656 | my ($self, $hash, $x, $y) = @_; |
568 | |
657 | |
569 | my $gen = $self->{map_change_gen}; |
658 | my $gen = $self->{map_change_gen}; |
570 | |
659 | |
571 | CFPlus::DB::get $self->{mapcache} => $hash, sub { |
660 | my $cb = sub { |
572 | return unless $gen == $self->{map_change_gen}; |
661 | return unless $gen == $self->{map_change_gen}; |
573 | |
662 | |
574 | my ($data) = @_; |
663 | my ($data) = @_; |
575 | |
664 | |
576 | if (defined $data) { |
665 | if (defined $data) { |
|
|
666 | $self->{map_cache_new}{$hash} = \$data; |
|
|
667 | |
577 | $data = Compress::LZF::decompress $data; |
668 | my $data = Compress::LZF::decompress $data; |
578 | #warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d# |
|
|
579 | |
669 | |
580 | my $inprogress = @{ $self->{bg_fetch} || [] }; |
670 | my $inprogress = @{ $self->{bg_fetch} || [] }; |
581 | unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $data); |
671 | unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $data); |
582 | $self->bg_fetch unless $inprogress; |
672 | $self->bg_fetch unless $inprogress; |
583 | } |
673 | } |
584 | }; |
674 | }; |
|
|
675 | |
|
|
676 | if (my $rdata = $self->{map_cache_old}{$hash}) { |
|
|
677 | $cb->($$rdata); |
|
|
678 | } else { |
|
|
679 | CFPlus::DB::get $self->{mapcache} => $hash, $cb; |
|
|
680 | } |
585 | } |
681 | } |
586 | |
682 | |
587 | # hardcode /world/world_xxx_xxx map names, the savings are enourmous, |
683 | # hardcode /world/world_xxx_xxx map names, the savings are enourmous, |
588 | # (server resource,s latency, bandwidth), so this hack is warranted. |
684 | # (server resource,s latency, bandwidth), so this hack is warranted. |
589 | # the right fix is to make real tiled maps with an overview file |
685 | # the right fix is to make real tiled maps with an overview file |
… | |
… | |
682 | my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; |
778 | my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; |
683 | |
779 | |
684 | $self->flush_map; |
780 | $self->flush_map; |
685 | |
781 | |
686 | ++$self->{map_change_gen}; |
782 | ++$self->{map_change_gen}; |
|
|
783 | $self->{map_cache_old} = delete $self->{map_cache_new}; |
687 | |
784 | |
688 | my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
785 | my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
689 | |
786 | |
690 | my $mapmapw = $self->{mapmap}->{w}; |
787 | my $mapmapw = $self->{mapmap}->{w}; |
691 | my $mapmaph = $self->{mapmap}->{h}; |
788 | my $mapmaph = $self->{mapmap}->{h}; |
… | |
… | |
721 | $self->{map}->set_tileid ($facenum => $id); |
818 | $self->{map}->set_tileid ($facenum => $id); |
722 | |
819 | |
723 | CFPlus::DB::get tilecache => $id, $cb; |
820 | CFPlus::DB::get tilecache => $id, $cb; |
724 | |
821 | |
725 | } elsif ($face->{type} & 1) { # with metadata |
822 | } elsif ($face->{type} & 1) { # with metadata |
726 | #::message ({ markup => "starting to download song #$face/$pri, check your output-rate setting if your connection gets laggy." }); |
|
|
727 | CFPlus::DB::get res_meta => $face->{name}, $cb; |
823 | CFPlus::DB::get res_meta => $face->{name}, $cb; |
728 | } |
824 | } |
729 | } |
825 | } |
730 | |
826 | |
731 | sub face_update { |
827 | sub face_update { |
… | |
… | |
778 | sub have_tile { |
874 | sub have_tile { |
779 | my ($self, $tile) = @_; |
875 | my ($self, $tile) = @_; |
780 | |
876 | |
781 | return unless $self->{map}; |
877 | return unless $self->{map}; |
782 | |
878 | |
783 | $self->{texture}[$tile] ||= my $tex = |
879 | my $tex = $self->{texture}[$tile] ||= |
784 | new CFPlus::Texture |
880 | new CFPlus::Texture |
785 | tile => $tile, minify => 1, mipmap => 1, delay => 1; |
881 | tile => $tile, minify => 1, mipmap => 1, delay => 1; |
786 | |
882 | |
787 | $_->() for @{(delete $self->{face_cb}{$tile}) || []}; |
883 | $_->($tex) for @{(delete $self->{face_cb}{$tile}) || []}; |
788 | } |
884 | } |
789 | |
885 | |
790 | sub connect_face_update { |
886 | sub connect_face_update { |
791 | my ($self, $id, $cb) = @_; |
887 | my ($self, $id, $cb) = @_; |
792 | |
888 | |
… | |
… | |
876 | $self->{$type} = $text; |
972 | $self->{$type} = $text; |
877 | } else { |
973 | } else { |
878 | $self->logprint ("msg: ", $text); |
974 | $self->logprint ("msg: ", $text); |
879 | return if $color < 0; # negative color == ignore if not understood |
975 | return if $color < 0; # negative color == ignore if not understood |
880 | |
976 | |
881 | my $fg = $CF_COLOR[$color & 0x1f] || [1, 0, 0]; |
977 | my $fg = $CF_COLOR[$color & NDI_COLOR_MASK] || [1, 0, 0]; |
882 | |
978 | |
883 | ## try to create single paragraphs of multiple lines sent by the server |
979 | ## try to create single paragraphs of multiple lines sent by the server |
884 | # no longer neecssary with TRT servers |
980 | # no longer neecssary with TRT servers |
885 | #$text =~ s/(?<=\S)\n(?=\w)/ /g; |
981 | #$text =~ s/(?<=\S)\n(?=\w)/ /g; |
886 | |
982 | |
887 | ::message ({ fg => $fg, markup => $_, type => $type, extra => [@extra] }) |
983 | ::message ({ |
|
|
984 | fg => $fg, |
|
|
985 | markup => $_, |
|
|
986 | type => $type, |
|
|
987 | extra => [@extra], |
|
|
988 | color_flags => $color |
888 | for split /\n/, $text; |
989 | }) for split /\n/, $text; |
889 | |
990 | |
890 | $self->{statusbox}->add ($text, |
991 | $self->{statusbox}->add ($text, |
891 | group => $text, |
992 | group => $text, |
892 | fg => $fg, |
993 | fg => $fg, |
893 | timeout => $color >= 2 ? 180 : 10, |
994 | timeout => $color >= 2 ? 180 : 10, |
… | |
… | |
987 | } |
1088 | } |
988 | |
1089 | |
989 | $::FLOORBOX->add_at (@add); |
1090 | $::FLOORBOX->add_at (@add); |
990 | }); |
1091 | }); |
991 | |
1092 | |
992 | $::WANT_REFRESH++; |
1093 | $::WANT_REFRESH->start; |
993 | } |
1094 | } |
994 | |
1095 | |
995 | sub set_opencont { |
1096 | sub set_opencont { |
996 | my ($conn, $tag, $name) = @_; |
1097 | my ($conn, $tag, $name) = @_; |
997 | $conn->{open_container} = $tag; |
1098 | $conn->{open_container} = $tag; |
998 | update_floorbox; |
1099 | update_floorbox; |
999 | |
1100 | |
1000 | $::INV_RIGHT_HB->clear (); |
1101 | $::INVR_HB->clear (); |
1001 | $::INV_RIGHT_HB->add (new CFPlus::UI::Label align => 0, expand => 1, text => $name); |
1102 | $::INVR_HB->add (new CFPlus::UI::Label align => 0, expand => 1, text => $name); |
1002 | |
1103 | |
1003 | if ($tag != 0) { # Floor isn't closable, is it? |
1104 | if ($tag != 0) { # Floor isn't closable, is it? |
1004 | $::INV_RIGHT_HB->add (new CFPlus::UI::Button |
1105 | $::INVR_HB->add (new CFPlus::UI::Button |
1005 | text => "Close container", |
1106 | text => "Close container", |
1006 | tooltip => "Close the currently open container (if one is open)", |
1107 | tooltip => "Close the currently open container (if one is open)", |
1007 | on_activate => sub { |
1108 | on_activate => sub { |
1008 | $::CONN->send ("apply $tag") # $::CONN->{open_container}") |
1109 | $::CONN->send ("apply $tag") # $::CONN->{open_container}") |
1009 | if $tag != 0; |
1110 | if $tag != 0; |
1010 | #if $CONN->{open_container} != 0; |
|
|
1011 | 0 |
1111 | 0 |
1012 | }, |
1112 | }, |
1013 | ); |
1113 | ); |
1014 | } |
1114 | } |
1015 | |
1115 | |