… | |
… | |
125 | ->convert_blessed |
125 | ->convert_blessed |
126 | ->filter_json_single_key_object (__widget_ref__ => sub { |
126 | ->filter_json_single_key_object (__widget_ref__ => sub { |
127 | $self->{widget}{$_[0]} |
127 | $self->{widget}{$_[0]} |
128 | }); |
128 | }); |
129 | |
129 | |
|
|
130 | # widgetset new |
130 | $self->connect_ext (ws_n => sub { |
131 | $self->connect_ext (ws_n => sub { |
131 | my ($arg) = @_; |
132 | my ($arg) = @_; |
132 | |
133 | |
133 | $self->{widgetset}{$arg{id}} = { |
134 | $self->{widgetset}{$arg{id}} = { |
134 | w => {}, |
135 | w => {}, |
135 | }; |
136 | }; |
136 | }); |
137 | }); |
137 | |
138 | |
|
|
139 | # widgetset destroy |
138 | $self->connect_ext (ws_d => sub { |
140 | $self->connect_ext (ws_d => sub { |
139 | my ($arg) = @_; |
141 | my ($arg) = @_; |
140 | |
142 | |
141 | my $ws = delete $self->{widgetset}{$arg{id}} |
143 | my $ws = delete $self->{widgetset}{$arg{id}} |
142 | or return; |
144 | or return; |
143 | |
145 | |
144 | $_->destroy |
146 | $_->destroy |
145 | for values %{$ws->{w}}; |
147 | for values %{$ws->{w}}; |
146 | }); |
148 | }); |
147 | |
149 | |
|
|
150 | # widgetset destroy |
148 | $self->connect_ext (ws_c => sub { |
151 | $self->connect_ext (ws_c => sub { |
149 | my ($arg) = @_; |
152 | my ($arg) = @_; |
150 | |
153 | |
151 | my $args = $arg->{args} || {}; |
154 | my $args = $arg->{args} || {}; |
152 | |
155 | |
… | |
… | |
182 | warn "server failed creating client-side widget " . (CFPlus::to_json $arg) . ": $@\n"; |
185 | warn "server failed creating client-side widget " . (CFPlus::to_json $arg) . ": $@\n"; |
183 | $self->send_exti_msg (w_e => id => $arg->{id}, name => "destroy"); |
186 | $self->send_exti_msg (w_e => id => $arg->{id}, name => "destroy"); |
184 | } |
187 | } |
185 | }); |
188 | }); |
186 | |
189 | |
|
|
190 | # widget call |
187 | $self->connect_ext (w_c => sub { |
191 | $self->connect_ext (w_c => sub { |
188 | my ($arg) = @_; |
192 | my ($arg) = @_; |
189 | |
193 | |
190 | my $w = $self->{widget}{$arg->{id}} |
194 | my $w = $self->{widget}{$arg->{id}} |
191 | or return; |
195 | or return; |
… | |
… | |
198 | } else { |
202 | } else { |
199 | $w->$m (@$a); |
203 | $w->$m (@$a); |
200 | } |
204 | } |
201 | }); |
205 | }); |
202 | |
206 | |
|
|
207 | # widget set |
203 | $self->connect_ext (w_s => sub { |
208 | $self->connect_ext (w_s => sub { |
204 | my ($arg) = @_; |
209 | my ($arg) = @_; |
205 | |
210 | |
206 | my $w = $self->{widget}{$arg->{id}} |
211 | my $w = $self->{widget}{$arg->{id}} |
207 | or return; |
212 | or return; |
208 | |
213 | |
209 | $w->{$arg->{name}} = $arg->{value}; |
214 | $w->{$_->[0]} = $_->[1] |
|
|
215 | for @{ $arg->{attr} }; |
210 | }); |
216 | }); |
211 | |
217 | |
|
|
218 | # widget get |
212 | $self->connect_ext (w_g => sub { |
219 | $self->connect_ext (w_g => sub { |
213 | my ($arg) = @_; |
220 | my ($arg) = @_; |
214 | |
221 | |
215 | my $w = $self->{widget}{$arg->{id}} |
222 | my $w = $self->{widget}{$arg->{id}} |
216 | or return; |
223 | or return; |
217 | |
224 | |
218 | $self->send_exti_msg (w_r => rid => $arg->{rid}, res => [$w->{$arg->{name}}]); |
225 | $self->send_exti_msg (w_r => rid => $arg->{rid}, res => [map $w->{$_}, @{$arg->{attr}}]); |
219 | }); |
226 | }); |
220 | |
227 | |
|
|
228 | # destroy widgets on logout |
221 | $self->{on_stop_game_guard} = $self->{map_widget}{root}->connect (stop_game => sub { |
229 | $self->{on_stop_game_guard} = $self->{map_widget}{root}->connect (stop_game => sub { |
222 | for my $ws (values %{delete $self->{widgetset} || {}}) { |
230 | for my $ws (values %{delete $self->{widgetset} || {}}) { |
223 | $_->destroy |
231 | $_->destroy |
224 | for values %{delete $ws->{w} || {}}; |
232 | for values %{delete $ws->{w} || {}}; |
225 | } |
233 | } |
… | |
… | |
438 | my @skills = keys %{ $self->{skill_info} }; |
446 | my @skills = keys %{ $self->{skill_info} }; |
439 | |
447 | |
440 | if (grep +(exists $stats->{$_}) != (exists $prev->{$_}), @skills) { |
448 | if (grep +(exists $stats->{$_}) != (exists $prev->{$_}), @skills) { |
441 | $sktbl->clear; |
449 | $sktbl->clear; |
442 | |
450 | |
|
|
451 | my @add; |
|
|
452 | |
|
|
453 | push @add, |
443 | $sktbl->add (0, 0, new CFPlus::UI::Label text => "Experience", align => 1); |
454 | 0, 0, (new CFPlus::UI::Label text => "Experience", align => 1), |
444 | $sktbl->add (1, 0, new CFPlus::UI::Label text => "Lvl.", align => 1); |
455 | 1, 0, (new CFPlus::UI::Label text => "Lvl.", align => 1), |
445 | $sktbl->add (2, 0, new CFPlus::UI::Label text => "Skill", expand => 1); |
456 | 2, 0, (new CFPlus::UI::Label text => "Skill", expand => 1), |
446 | $sktbl->add (3, 0, new CFPlus::UI::Label text => "Experience", align => 1); |
457 | 3, 0, (new CFPlus::UI::Label text => "Experience", align => 1), |
447 | $sktbl->add (4, 0, new CFPlus::UI::Label text => "Lvl.", align => 1); |
458 | 4, 0, (new CFPlus::UI::Label text => "Lvl.", align => 1), |
448 | $sktbl->add (5, 0, new CFPlus::UI::Label text => "Skill", expand => 1); |
459 | 5, 0, (new CFPlus::UI::Label text => "Skill", expand => 1), |
|
|
460 | ; |
449 | |
461 | |
450 | my $TOOLTIP_ALL = "\n\n<small>Left click - ready skill\nMiddle click - use spell\nRight click - further options</small>"; |
462 | my $TOOLTIP_ALL = "\n\n<small>Left click - ready skill\nMiddle click - use spell\nRight click - further options</small>"; |
451 | |
463 | |
452 | my @TOOLTIP_LVL = (tooltip => "<b>Level</b>. The level of the skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1); |
464 | my @TOOLTIP_LVL = (tooltip => "<b>Level</b>. The level of the skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1); |
453 | my @TOOLTIP_EXP = (tooltip => "<b>Experience</b>. The experience points you have in this skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1); |
465 | my @TOOLTIP_EXP = (tooltip => "<b>Experience</b>. The experience points you have in this skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1); |
… | |
… | |
481 | } |
493 | } |
482 | |
494 | |
483 | 1 |
495 | 1 |
484 | }; |
496 | }; |
485 | |
497 | |
|
|
498 | push @add, |
486 | $sktbl->add ($x * 3 + 0, $y, $self->{stat_widget_exp}{$idx} = new CFPlus::UI::Label |
499 | $x * 3 + 0, $y, ($self->{stat_widget_exp}{$idx} = new CFPlus::UI::Label |
487 | text => "0", align => 1, font => $::FONT_FIXED, fg => [1, 1, 0], on_button_down => $spell_cb, @TOOLTIP_EXP); |
500 | align => 1, font => $::FONT_FIXED, fg => [1, 1, 0], on_button_down => $spell_cb, @TOOLTIP_EXP), |
488 | $sktbl->add ($x * 3 + 1, $y, $self->{stat_widget_lvl}{$idx} = new CFPlus::UI::Label |
501 | $x * 3 + 1, $y, ($self->{stat_widget_lvl}{$idx} = new CFPlus::UI::Label |
489 | text => "0", align => 1, font => $::FONT_FIXED, fg => [0, 1, 0], padding_x => 4, on_button_down => $spell_cb, @TOOLTIP_LVL); |
502 | text => "0", align => 1, font => $::FONT_FIXED, fg => [0, 1, 0], padding_x => 4, on_button_down => $spell_cb, @TOOLTIP_LVL), |
490 | $sktbl->add ($x * 3 + 2, $y, new CFPlus::UI::Label text => $name, on_button_down => $spell_cb, |
503 | $x * 3 + 2, $y, (new CFPlus::UI::Label text => $name, on_button_down => $spell_cb, |
491 | can_events => 1, can_hover => 1, tooltip => (CFPlus::Pod::section_label skill_description => $name) . $TOOLTIP_ALL); |
504 | can_events => 1, can_hover => 1, tooltip => (CFPlus::Pod::section_label skill_description => $name) . $TOOLTIP_ALL), |
|
|
505 | ; |
492 | |
506 | |
493 | $x++ and ($x, $y) = (0, $y + 1); |
507 | $x++ and ($x, $y) = (0, $y + 1); |
494 | } |
508 | } |
|
|
509 | |
|
|
510 | $sktbl->add_at (@add); |
495 | } |
511 | } |
496 | |
512 | |
497 | for (grep exists $stats->{$_}, @skills) { |
513 | for (grep exists $stats->{$_}, @skills) { |
498 | $self->{stat_widget_exp}{$_}->set_text (::formsep ($stats->{$_}[1])); |
514 | $self->{stat_widget_exp}{$_}->set_text (::formsep ($stats->{$_}[1])); |
499 | $self->{stat_widget_lvl}{$_}->set_text ($stats->{$_}[0] * 1); |
515 | $self->{stat_widget_lvl}{$_}->set_text ($stats->{$_}[0] * 1); |
… | |
… | |
774 | new_from_image CFPlus::Texture |
790 | new_from_image CFPlus::Texture |
775 | $data, minify => 1, mipmap => 1; |
791 | $data, minify => 1, mipmap => 1; |
776 | |
792 | |
777 | $self->{map}->set_texture ($id, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
793 | $self->{map}->set_texture ($id, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
778 | $self->{map_widget}->update; |
794 | $self->{map_widget}->update; |
|
|
795 | |
|
|
796 | $_->() for @{(delete $self->{face_cb}{$id}) || []}; |
|
|
797 | } |
|
|
798 | |
|
|
799 | sub connect_face_update { |
|
|
800 | my ($self, $id, $cb) = @_; |
|
|
801 | |
|
|
802 | push @{$self->{face_cb}{$id}}, $cb; |
|
|
803 | |
|
|
804 | CFPlus::guard { |
|
|
805 | @{$self->{face_cb}{$id}} |
|
|
806 | = grep $_ != $cb, |
|
|
807 | @{$self->{face_cb}{$id}}; |
|
|
808 | } |
779 | } |
809 | } |
780 | |
810 | |
781 | sub sound_play { |
811 | sub sound_play { |
782 | my ($self, $x, $y, $soundnum, $type) = @_; |
812 | my ($self, $x, $y, $soundnum, $type) = @_; |
783 | |
813 | |
… | |
… | |
967 | $CFPlus::UI::ROOT->on_refresh ($::FLOORBOX => sub { |
997 | $CFPlus::UI::ROOT->on_refresh ($::FLOORBOX => sub { |
968 | return unless $::CONN; |
998 | return unless $::CONN; |
969 | |
999 | |
970 | $::FLOORBOX->clear; |
1000 | $::FLOORBOX->clear; |
971 | |
1001 | |
|
|
1002 | my @add; |
|
|
1003 | |
972 | my $row; |
1004 | my $row; |
973 | for (sort { $a->{count} <=> $b->{count} } values %{ $::CONN->{container}{$::CONN->{open_container} || 0} }) { |
1005 | for (sort { $a->{count} <=> $b->{count} } values %{ $::CONN->{container}{$::CONN->{open_container} || 0} }) { |
974 | if ($row < 6) { |
1006 | if ($row < 6) { |
975 | local $_->{face_widget}; # hack to force recreation of widget |
1007 | local $_->{face_widget}; # hack to force recreation of widget |
976 | local $_->{desc_widget}; # hack to force recreation of widget |
1008 | local $_->{desc_widget}; # hack to force recreation of widget |
977 | CFPlus::Item::update_widgets $_; |
1009 | CFPlus::Item::update_widgets $_; |
978 | |
1010 | |
|
|
1011 | push @add, |
979 | $::FLOORBOX->add (0, $row, $_->{face_widget}); |
1012 | 0, $row, $_->{face_widget}, |
980 | $::FLOORBOX->add (1, $row, $_->{desc_widget}); |
1013 | 1, $row, $_->{desc_widget}; |
981 | |
1014 | |
982 | $row++; |
1015 | $row++; |
983 | } else { |
1016 | } else { |
984 | $::FLOORBOX->add (1, $row, new CFPlus::UI::Button |
1017 | push @add, 1, $row, new CFPlus::UI::Button |
985 | text => "More...", |
1018 | text => "More...", |
986 | on_activate => sub { ::toggle_player_page ($::INVENTORY_PAGE); 0 }, |
1019 | on_activate => sub { ::toggle_player_page ($::INVENTORY_PAGE); 0 }, |
987 | ); |
1020 | ; |
988 | last; |
1021 | last; |
989 | } |
1022 | } |
990 | } |
1023 | } |
991 | if ($::CONN->{open_container}) { |
1024 | if ($::CONN->{open_container}) { |
992 | $::FLOORBOX->add (1, $row++, new CFPlus::UI::Button |
1025 | push @add, 1, $row++, new CFPlus::UI::Button |
993 | text => "Close container", |
1026 | text => "Close container", |
994 | on_activate => sub { $::CONN->send ("apply $::CONN->{open_container}") } |
1027 | on_activate => sub { $::CONN->send ("apply $::CONN->{open_container}") } |
995 | ); |
1028 | ; |
996 | } |
1029 | } |
|
|
1030 | |
|
|
1031 | $::FLOORBOX->add_at (@add); |
997 | }); |
1032 | }); |
998 | |
1033 | |
999 | $::WANT_REFRESH++; |
1034 | $::WANT_REFRESH++; |
1000 | } |
1035 | } |
1001 | |
1036 | |