… | |
… | |
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 | |
… | |
… | |
552 | my $map_info = delete $self->{map_info} |
611 | my $map_info = delete $self->{map_info} |
553 | or return; |
612 | or return; |
554 | |
613 | |
555 | my ($hash, $x, $y, $w, $h) = @$map_info; |
614 | my ($hash, $x, $y, $w, $h) = @$map_info; |
556 | |
615 | |
557 | 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; |
558 | CFPlus::DB::put $self->{mapcache} => $hash => Compress::LZF::compress $data, sub { }; |
618 | CFPlus::DB::put $self->{mapcache} => $hash => $data, sub { }; |
559 | #warn sprintf "SAVEmap[%s] length %d\n", $hash, length $data;#d# |
|
|
560 | } |
619 | } |
561 | |
620 | |
562 | sub map_clear { |
621 | sub map_clear { |
563 | my ($self) = @_; |
622 | my ($self) = @_; |
564 | |
623 | |
… | |
… | |
582 | CFPlus::DB::exists tilecache => $id, sub { |
641 | CFPlus::DB::exists tilecache => $id, sub { |
583 | my ($exists) = @_; |
642 | my ($exists) = @_; |
584 | |
643 | |
585 | return unless $self->{map}; # stop when destroyed |
644 | return unless $self->{map}; # stop when destroyed |
586 | |
645 | |
|
|
646 | if ($exists) { |
587 | $self->have_tile ($id) |
647 | $self->have_tile ($id); |
588 | if $exists; |
648 | $self->{texture}[$id]->upload; |
|
|
649 | } |
589 | |
650 | |
590 | $self->bg_fetch; |
651 | $self->bg_fetch; |
591 | }; |
652 | }; |
592 | } |
653 | } |
593 | |
654 | |
594 | sub load_map($$$) { |
655 | sub load_map($$$) { |
595 | my ($self, $hash, $x, $y) = @_; |
656 | my ($self, $hash, $x, $y) = @_; |
596 | |
657 | |
597 | my $gen = $self->{map_change_gen}; |
658 | my $gen = $self->{map_change_gen}; |
598 | |
659 | |
599 | CFPlus::DB::get $self->{mapcache} => $hash, sub { |
660 | my $cb = sub { |
600 | return unless $gen == $self->{map_change_gen}; |
661 | return unless $gen == $self->{map_change_gen}; |
601 | |
662 | |
602 | my ($data) = @_; |
663 | my ($data) = @_; |
603 | |
664 | |
604 | if (defined $data) { |
665 | if (defined $data) { |
|
|
666 | $self->{map_cache_new}{$hash} = \$data; |
|
|
667 | |
605 | $data = Compress::LZF::decompress $data; |
668 | my $data = Compress::LZF::decompress $data; |
606 | #warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d# |
|
|
607 | |
669 | |
608 | my $inprogress = @{ $self->{bg_fetch} || [] }; |
670 | my $inprogress = @{ $self->{bg_fetch} || [] }; |
609 | unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $data); |
671 | unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $data); |
610 | $self->bg_fetch unless $inprogress; |
672 | $self->bg_fetch unless $inprogress; |
611 | } |
673 | } |
612 | }; |
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 | } |
613 | } |
681 | } |
614 | |
682 | |
615 | # hardcode /world/world_xxx_xxx map names, the savings are enourmous, |
683 | # hardcode /world/world_xxx_xxx map names, the savings are enourmous, |
616 | # (server resource,s latency, bandwidth), so this hack is warranted. |
684 | # (server resource,s latency, bandwidth), so this hack is warranted. |
617 | # 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 |
… | |
… | |
710 | my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; |
778 | my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; |
711 | |
779 | |
712 | $self->flush_map; |
780 | $self->flush_map; |
713 | |
781 | |
714 | ++$self->{map_change_gen}; |
782 | ++$self->{map_change_gen}; |
|
|
783 | $self->{map_cache_old} = delete $self->{map_cache_new}; |
715 | |
784 | |
716 | my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
785 | my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
717 | |
786 | |
718 | my $mapmapw = $self->{mapmap}->{w}; |
787 | my $mapmapw = $self->{mapmap}->{w}; |
719 | my $mapmaph = $self->{mapmap}->{h}; |
788 | my $mapmaph = $self->{mapmap}->{h}; |
… | |
… | |
903 | $self->{$type} = $text; |
972 | $self->{$type} = $text; |
904 | } else { |
973 | } else { |
905 | $self->logprint ("msg: ", $text); |
974 | $self->logprint ("msg: ", $text); |
906 | return if $color < 0; # negative color == ignore if not understood |
975 | return if $color < 0; # negative color == ignore if not understood |
907 | |
976 | |
908 | my $fg = $CF_COLOR[$color & 0x1f] || [1, 0, 0]; |
977 | my $fg = $CF_COLOR[$color & NDI_COLOR_MASK] || [1, 0, 0]; |
909 | |
978 | |
910 | ## 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 |
911 | # no longer neecssary with TRT servers |
980 | # no longer neecssary with TRT servers |
912 | #$text =~ s/(?<=\S)\n(?=\w)/ /g; |
981 | #$text =~ s/(?<=\S)\n(?=\w)/ /g; |
913 | |
982 | |
914 | ::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 |
915 | for split /\n/, $text; |
989 | }) for split /\n/, $text; |
916 | |
990 | |
917 | $self->{statusbox}->add ($text, |
991 | $self->{statusbox}->add ($text, |
918 | group => $text, |
992 | group => $text, |
919 | fg => $fg, |
993 | fg => $fg, |
920 | timeout => $color >= 2 ? 180 : 10, |
994 | timeout => $color >= 2 ? 180 : 10, |
… | |
… | |
1022 | sub set_opencont { |
1096 | sub set_opencont { |
1023 | my ($conn, $tag, $name) = @_; |
1097 | my ($conn, $tag, $name) = @_; |
1024 | $conn->{open_container} = $tag; |
1098 | $conn->{open_container} = $tag; |
1025 | update_floorbox; |
1099 | update_floorbox; |
1026 | |
1100 | |
1027 | $::INV_RIGHT_HB->clear (); |
1101 | $::INVR_HB->clear (); |
1028 | $::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); |
1029 | |
1103 | |
1030 | if ($tag != 0) { # Floor isn't closable, is it? |
1104 | if ($tag != 0) { # Floor isn't closable, is it? |
1031 | $::INV_RIGHT_HB->add (new CFPlus::UI::Button |
1105 | $::INVR_HB->add (new CFPlus::UI::Button |
1032 | text => "Close container", |
1106 | text => "Close container", |
1033 | tooltip => "Close the currently open container (if one is open)", |
1107 | tooltip => "Close the currently open container (if one is open)", |
1034 | on_activate => sub { |
1108 | on_activate => sub { |
1035 | $::CONN->send ("apply $tag") # $::CONN->{open_container}") |
1109 | $::CONN->send ("apply $tag") # $::CONN->{open_container}") |
1036 | if $tag != 0; |
1110 | if $tag != 0; |
1037 | #if $CONN->{open_container} != 0; |
|
|
1038 | 0 |
1111 | 0 |
1039 | }, |
1112 | }, |
1040 | ); |
1113 | ); |
1041 | } |
1114 | } |
1042 | |
1115 | |