… | |
… | |
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 | |
… | |
… | |
1037 | sub set_opencont { |
1096 | sub set_opencont { |
1038 | my ($conn, $tag, $name) = @_; |
1097 | my ($conn, $tag, $name) = @_; |
1039 | $conn->{open_container} = $tag; |
1098 | $conn->{open_container} = $tag; |
1040 | update_floorbox; |
1099 | update_floorbox; |
1041 | |
1100 | |
1042 | $::INV_RIGHT_HB->clear (); |
1101 | $::INVR_HB->clear (); |
1043 | $::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); |
1044 | |
1103 | |
1045 | if ($tag != 0) { # Floor isn't closable, is it? |
1104 | if ($tag != 0) { # Floor isn't closable, is it? |
1046 | $::INV_RIGHT_HB->add (new CFPlus::UI::Button |
1105 | $::INVR_HB->add (new CFPlus::UI::Button |
1047 | text => "Close container", |
1106 | text => "Close container", |
1048 | tooltip => "Close the currently open container (if one is open)", |
1107 | tooltip => "Close the currently open container (if one is open)", |
1049 | on_activate => sub { |
1108 | on_activate => sub { |
1050 | $::CONN->send ("apply $tag") # $::CONN->{open_container}") |
1109 | $::CONN->send ("apply $tag") # $::CONN->{open_container}") |
1051 | if $tag != 0; |
1110 | if $tag != 0; |
1052 | #if $CONN->{open_container} != 0; |
|
|
1053 | 0 |
1111 | 0 |
1054 | }, |
1112 | }, |
1055 | ); |
1113 | ); |
1056 | } |
1114 | } |
1057 | |
1115 | |