ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/Protocol.pm
(Generate patch)

Comparing deliantra/Deliantra-Client/DC/Protocol.pm (file contents):
Revision 1.122 by root, Sun Jul 15 22:07:48 2007 UTC vs.
Revision 1.127 by root, Mon Jul 23 15:30:45 2007 UTC

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 my $attr = $arg->{attr};
215
216 for (my $i = 0; $i < $#$attr; $i += 2) {
217 my ($member, $value) = @$attr[$i, $i+1];
218 if (defined $value) {
219 $w->{$member} = $value;
220 } else {
221 delete $w->{$member};
222 }
223 $w->{parent}->realloc if $member =~ /^c_/ && $w->{visible};
224 }
210 }); 225 });
211 226
227 # widget get
212 $self->connect_ext (w_g => sub { 228 $self->connect_ext (w_g => sub {
213 my ($arg) = @_; 229 my ($arg) = @_;
214 230
215 my $w = $self->{widget}{$arg->{id}} 231 my $w = $self->{widget}{$arg->{id}}
216 or return; 232 or return;
217 233
218 $self->send_exti_msg (w_r => rid => $arg->{rid}, res => [$w->{$arg->{name}}]); 234 $self->send_exti_msg (w_r => rid => $arg->{rid}, res => [map $w->{$_}, @{$arg->{attr}}]);
219 }); 235 });
220 236
237 # destroy widgets on logout
221 $self->{on_stop_game_guard} = $self->{map_widget}{root}->connect (stop_game => sub { 238 $self->{on_stop_game_guard} = $self->{map_widget}{root}->connect (stop_game => sub {
222 for my $ws (values %{delete $self->{widgetset} || {}}) { 239 for my $ws (values %{delete $self->{widgetset} || {}}) {
223 $_->destroy 240 $_->destroy
224 for values %{delete $ws->{w} || {}}; 241 for values %{delete $ws->{w} || {}};
225 } 242 }
438 my @skills = keys %{ $self->{skill_info} }; 455 my @skills = keys %{ $self->{skill_info} };
439 456
440 if (grep +(exists $stats->{$_}) != (exists $prev->{$_}), @skills) { 457 if (grep +(exists $stats->{$_}) != (exists $prev->{$_}), @skills) {
441 $sktbl->clear; 458 $sktbl->clear;
442 459
460 my @add;
461
462 push @add,
443 $sktbl->add (0, 0, new CFPlus::UI::Label text => "Experience", align => 1); 463 0, 0, (new CFPlus::UI::Label text => "Experience", align => 1),
444 $sktbl->add (1, 0, new CFPlus::UI::Label text => "Lvl.", align => 1); 464 1, 0, (new CFPlus::UI::Label text => "Lvl.", align => 1),
445 $sktbl->add (2, 0, new CFPlus::UI::Label text => "Skill", expand => 1); 465 2, 0, (new CFPlus::UI::Label text => "Skill", expand => 1),
446 $sktbl->add (3, 0, new CFPlus::UI::Label text => "Experience", align => 1); 466 3, 0, (new CFPlus::UI::Label text => "Experience", align => 1),
447 $sktbl->add (4, 0, new CFPlus::UI::Label text => "Lvl.", align => 1); 467 4, 0, (new CFPlus::UI::Label text => "Lvl.", align => 1),
448 $sktbl->add (5, 0, new CFPlus::UI::Label text => "Skill", expand => 1); 468 5, 0, (new CFPlus::UI::Label text => "Skill", expand => 1),
469 ;
449 470
450 my $TOOLTIP_ALL = "\n\n<small>Left click - ready skill\nMiddle click - use spell\nRight click - further options</small>"; 471 my $TOOLTIP_ALL = "\n\n<small>Left click - ready skill\nMiddle click - use spell\nRight click - further options</small>";
451 472
452 my @TOOLTIP_LVL = (tooltip => "<b>Level</b>. The level of the skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1); 473 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); 474 my @TOOLTIP_EXP = (tooltip => "<b>Experience</b>. The experience points you have in this skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1);
481 } 502 }
482 503
483 1 504 1
484 }; 505 };
485 506
507 push @add,
486 $sktbl->add ($x * 3 + 0, $y, $self->{stat_widget_exp}{$idx} = new CFPlus::UI::Label 508 $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); 509 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 510 $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); 511 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, 512 $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); 513 can_events => 1, can_hover => 1, tooltip => (CFPlus::Pod::section_label skill_description => $name) . $TOOLTIP_ALL),
514 ;
492 515
493 $x++ and ($x, $y) = (0, $y + 1); 516 $x++ and ($x, $y) = (0, $y + 1);
494 } 517 }
518
519 $sktbl->add_at (@add);
495 } 520 }
496 521
497 for (grep exists $stats->{$_}, @skills) { 522 for (grep exists $stats->{$_}, @skills) {
498 $self->{stat_widget_exp}{$_}->set_text (::formsep ($stats->{$_}[1])); 523 $self->{stat_widget_exp}{$_}->set_text (::formsep ($stats->{$_}[1]));
499 $self->{stat_widget_lvl}{$_}->set_text ($stats->{$_}[0] * 1); 524 $self->{stat_widget_lvl}{$_}->set_text ($stats->{$_}[0] * 1);
981 $CFPlus::UI::ROOT->on_refresh ($::FLOORBOX => sub { 1006 $CFPlus::UI::ROOT->on_refresh ($::FLOORBOX => sub {
982 return unless $::CONN; 1007 return unless $::CONN;
983 1008
984 $::FLOORBOX->clear; 1009 $::FLOORBOX->clear;
985 1010
1011 my @add;
1012
986 my $row; 1013 my $row;
987 for (sort { $a->{count} <=> $b->{count} } values %{ $::CONN->{container}{$::CONN->{open_container} || 0} }) { 1014 for (sort { $a->{count} <=> $b->{count} } values %{ $::CONN->{container}{$::CONN->{open_container} || 0} }) {
988 if ($row < 6) { 1015 if ($row < 6) {
989 local $_->{face_widget}; # hack to force recreation of widget 1016 local $_->{face_widget}; # hack to force recreation of widget
990 local $_->{desc_widget}; # hack to force recreation of widget 1017 local $_->{desc_widget}; # hack to force recreation of widget
991 CFPlus::Item::update_widgets $_; 1018 CFPlus::Item::update_widgets $_;
992 1019
1020 push @add,
993 $::FLOORBOX->add (0, $row, $_->{face_widget}); 1021 0, $row, $_->{face_widget},
994 $::FLOORBOX->add (1, $row, $_->{desc_widget}); 1022 1, $row, $_->{desc_widget};
995 1023
996 $row++; 1024 $row++;
997 } else { 1025 } else {
998 $::FLOORBOX->add (1, $row, new CFPlus::UI::Button 1026 push @add, 1, $row, new CFPlus::UI::Button
999 text => "More...", 1027 text => "More...",
1000 on_activate => sub { ::toggle_player_page ($::INVENTORY_PAGE); 0 }, 1028 on_activate => sub { ::toggle_player_page ($::INVENTORY_PAGE); 0 },
1001 ); 1029 ;
1002 last; 1030 last;
1003 } 1031 }
1004 } 1032 }
1005 if ($::CONN->{open_container}) { 1033 if ($::CONN->{open_container}) {
1006 $::FLOORBOX->add (1, $row++, new CFPlus::UI::Button 1034 push @add, 1, $row++, new CFPlus::UI::Button
1007 text => "Close container", 1035 text => "Close container",
1008 on_activate => sub { $::CONN->send ("apply $::CONN->{open_container}") } 1036 on_activate => sub { $::CONN->send ("apply $::CONN->{open_container}") }
1009 ); 1037 ;
1010 } 1038 }
1039
1040 $::FLOORBOX->add_at (@add);
1011 }); 1041 });
1012 1042
1013 $::WANT_REFRESH++; 1043 $::WANT_REFRESH++;
1014} 1044}
1015 1045

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines