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.110 by root, Tue Jun 26 05:06:01 2007 UTC vs.
Revision 1.125 by root, Sat Jul 21 15:04:27 2007 UTC

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 xwidget => 1, 26 ywidget => 1,
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;
48 sort { (length $a) <=> (length $b) } 48 sort { (length $a) <=> (length $b) }
49 @args 49 @args
50 } sort { $a->{par} <=> $b->{par} } 50 } sort { $a->{par} <=> $b->{par} }
51 CFPlus::Pod::find command => "*"; 51 CFPlus::Pod::find command => "*";
52 52
53 $self->connect_ext (event_music => sub {
54 my ($ev) = @_;
55
56 return unless $::CFG->{bgm_enable};
57
58 my $faces = $ev->{faces};
59 my @songs;
60
61 # request music from server if appropriate
62 if (my $faces = $ev->{faces}) {
63 for (@$faces) {
64 my ($face, $pri, $chksum) = @$_;
65 utf8::downgrade $chksum;
66
67 $chksum = unpack "H*", $chksum;
68 $self->{music_map}{$face} = $chksum;
69
70 # check if already cached
71 CFPlus::DB::get "res-metadata" => $chksum, sub {
72 my ($meta_json) = @_;
73 my $path = CFPlus::DB::path_of_res $chksum;
74
75 if (defined $meta_json) {
76 my $meta = $self->{json_coder}->decode ($meta_json);
77 $meta->{path} = $path;
78 $self->{music_meta}{$chksum} = $meta;
79 &::audio_music_set ($self->{songs});
80 } else {
81 ::message ({ markup => "starting to download song #$face/$pri, check your output-rate setting if your connection gets laggy." });
82 $self->ask_face ($face, -100 - $pri, undef, sub {
83 my $len = length $_[1];
84 my ($meta_json, $data) = unpack "(w/a*)*", $_[1];
85
86 CFPlus::DB::write_file $path, $data, sub {
87 CFPlus::DB::put "res-metadata" => $chksum => $meta_json, sub {
88 my $meta = $self->{json_coder}->decode ($meta_json);
89 $meta->{path} = $path;
90 $self->{music_meta}{$chksum} = $meta;
91
92 ::message ({ markup => "downloaded song #$face, size $len octets" });
93 &::audio_music_set ($self->{songs});
94 };
95 };
96 });
97 }
98 }
99 }
100 }
101
102 if (my $play = $ev->{play}) {
103 &::audio_music_set ($self->{songs} = [map $self->{music_map}{$_}, @$play]);
104 }
105 });
106
53 $self->connect_ext (event_capabilities => sub { 107 $self->connect_ext (event_capabilities => sub {
54 my ($cap) = @_; 108 my ($cap) = @_;
55 109
56 if (my $ts = $cap->{tileset}) { 110 if (my $ts = $cap->{tileset}) {
57 if (my ($default) = grep $_->[2] & 1, @$ts) { 111 if (my ($default) = grep $_->[2] & 1, @$ts) {
65 $self->setup_req (mapsize => "${w}x${h}"); 119 $self->setup_req (mapsize => "${w}x${h}");
66 } 120 }
67 } 121 }
68 }); 122 });
69 123
124 $self->{json_coder}
125 ->convert_blessed
126 ->filter_json_single_key_object (__widget_ref__ => sub {
127 $self->{widget}{$_[0]}
128 });
129
130 # widgetset new
70 $self->connect_ext (ws_n => sub { 131 $self->connect_ext (ws_n => sub {
71 my ($arg) = @_; 132 my ($arg) = @_;
72 133
73 $self->{widgetset}{$arg{id}} = { 134 $self->{widgetset}{$arg{id}} = {
74 w => {}, 135 w => {},
75 }; 136 };
76 }); 137 });
77 138
139 # widgetset destroy
78 $self->connect_ext (ws_d => sub { 140 $self->connect_ext (ws_d => sub {
79 my ($arg) = @_; 141 my ($arg) = @_;
80 142
81 my $ws = delete $self->{widgetset}{$arg{id}} 143 my $ws = delete $self->{widgetset}{$arg{id}}
82 or return; 144 or return;
83 145
84 $_->destroy 146 $_->destroy
85 for values %{$ws->{w}}; 147 for values %{$ws->{w}};
86 }); 148 });
87 149
150 # widgetset destroy
88 $self->connect_ext (ws_c => sub { 151 $self->connect_ext (ws_c => sub {
89 my ($arg) = @_; 152 my ($arg) = @_;
90 153
91 my $args = $arg->{args} || {}; 154 my $args = $arg->{args} || {};
92 155
122 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";
123 $self->send_exti_msg (w_e => id => $arg->{id}, name => "destroy"); 186 $self->send_exti_msg (w_e => id => $arg->{id}, name => "destroy");
124 } 187 }
125 }); 188 });
126 189
190 # widget call
127 $self->connect_ext (w_c => sub { 191 $self->connect_ext (w_c => sub {
128 my ($arg) = @_; 192 my ($arg) = @_;
129 193
130 my $w = $self->{widget}{$arg->{id}} 194 my $w = $self->{widget}{$arg->{id}}
131 or return; 195 or return;
132 my $m = $arg->{name}; 196 my $m = $arg->{name};
133 197
134 my @a = map {
135 "HASH" eq ref && 1 == (scalar keys %$_) && exists $_->{__widget_ref__}
136 ? $self->{widget}{$_->{__widget_ref__}}
137 : $_
138 } @{ $arg->{args} || [] }; 198 my $a = $arg->{args} || [];
139 199
140 if (exists $arg->{rid}) { 200 if (exists $arg->{rid}) {
141 $self->send_exti_msg (w_r => rid => $arg->{rid}, res => [$w->$m (@a)]); 201 $self->send_exti_msg (w_r => rid => $arg->{rid}, res => [$w->$m (@$a)]);
142 } else { 202 } else {
143 $w->$m (@a); 203 $w->$m (@$a);
144 } 204 }
145 }); 205 });
146 206
207 # widget set
147 $self->connect_ext (w_s => sub { 208 $self->connect_ext (w_s => sub {
148 my ($arg) = @_; 209 my ($arg) = @_;
149 210
150 my $w = $self->{widget}{$arg->{id}} 211 my $w = $self->{widget}{$arg->{id}}
151 or return; 212 or return;
152 213
153 $w->{$arg->{name}} = $arg->{value}; 214 $w->{$_->[0]} = $_->[1]
215 for @{ $arg->{attr} };
154 }); 216 });
155 217
218 # widget get
156 $self->connect_ext (w_g => sub { 219 $self->connect_ext (w_g => sub {
157 my ($arg) = @_; 220 my ($arg) = @_;
158 221
159 my $w = $self->{widget}{$arg->{id}} 222 my $w = $self->{widget}{$arg->{id}}
160 or return; 223 or return;
161 224
162 $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}}]);
163 }); 226 });
164 227
228 # destroy widgets on logout
165 $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 {
166 for my $ws (values %{delete $self->{widgetset} || {}}) { 230 for my $ws (values %{delete $self->{widgetset} || {}}) {
167 $_->destroy 231 $_->destroy
168 for values %{delete $ws->{w} || {}}; 232 for values %{delete $ws->{w} || {}};
169 } 233 }
382 my @skills = keys %{ $self->{skill_info} }; 446 my @skills = keys %{ $self->{skill_info} };
383 447
384 if (grep +(exists $stats->{$_}) != (exists $prev->{$_}), @skills) { 448 if (grep +(exists $stats->{$_}) != (exists $prev->{$_}), @skills) {
385 $sktbl->clear; 449 $sktbl->clear;
386 450
451 my @add;
452
453 push @add,
387 $sktbl->add (0, 0, new CFPlus::UI::Label text => "Experience", align => 1); 454 0, 0, (new CFPlus::UI::Label text => "Experience", align => 1),
388 $sktbl->add (1, 0, new CFPlus::UI::Label text => "Lvl.", align => 1); 455 1, 0, (new CFPlus::UI::Label text => "Lvl.", align => 1),
389 $sktbl->add (2, 0, new CFPlus::UI::Label text => "Skill", expand => 1); 456 2, 0, (new CFPlus::UI::Label text => "Skill", expand => 1),
390 $sktbl->add (3, 0, new CFPlus::UI::Label text => "Experience", align => 1); 457 3, 0, (new CFPlus::UI::Label text => "Experience", align => 1),
391 $sktbl->add (4, 0, new CFPlus::UI::Label text => "Lvl.", align => 1); 458 4, 0, (new CFPlus::UI::Label text => "Lvl.", align => 1),
392 $sktbl->add (5, 0, new CFPlus::UI::Label text => "Skill", expand => 1); 459 5, 0, (new CFPlus::UI::Label text => "Skill", expand => 1),
460 ;
393 461
394 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>";
395 463
396 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);
397 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);
425 } 493 }
426 494
427 1 495 1
428 }; 496 };
429 497
498 push @add,
430 $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
431 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),
432 $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
433 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),
434 $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,
435 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 ;
436 506
437 $x++ and ($x, $y) = (0, $y + 1); 507 $x++ and ($x, $y) = (0, $y + 1);
438 } 508 }
509
510 $sktbl->add_at (@add);
439 } 511 }
440 512
441 for (grep exists $stats->{$_}, @skills) { 513 for (grep exists $stats->{$_}, @skills) {
442 $self->{stat_widget_exp}{$_}->set_text (::formsep ($stats->{$_}[1])); 514 $self->{stat_widget_exp}{$_}->set_text (::formsep ($stats->{$_}[1]));
443 $self->{stat_widget_lvl}{$_}->set_text ($stats->{$_}[0] * 1); 515 $self->{stat_widget_lvl}{$_}->set_text ($stats->{$_}[0] * 1);
710} 782}
711 783
712sub set_texture { 784sub set_texture {
713 my ($self, $id, $data) = @_; 785 my ($self, $id, $data) = @_;
714 786
787 return unless $self->{map};
788
715 $self->{texture}[$id] = my $tex = 789 $self->{texture}[$id] = my $tex =
716 new_from_image CFPlus::Texture 790 new_from_image CFPlus::Texture
717 $data, minify => 1, mipmap => 1; 791 $data, minify => 1, mipmap => 1;
718 792
719 $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}});
720 $self->{map_widget}->update; 794 $self->{map_widget}->update;
795
796 $_->() for @{(delete $self->{face_cb}{$id}) || []};
797}
798
799sub 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 }
721} 809}
722 810
723sub sound_play { 811sub sound_play {
724 my ($self, $x, $y, $soundnum, $type) = @_; 812 my ($self, $x, $y, $soundnum, $type) = @_;
725 813
909 $CFPlus::UI::ROOT->on_refresh ($::FLOORBOX => sub { 997 $CFPlus::UI::ROOT->on_refresh ($::FLOORBOX => sub {
910 return unless $::CONN; 998 return unless $::CONN;
911 999
912 $::FLOORBOX->clear; 1000 $::FLOORBOX->clear;
913 1001
1002 my @add;
1003
914 my $row; 1004 my $row;
915 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} }) {
916 if ($row < 6) { 1006 if ($row < 6) {
917 local $_->{face_widget}; # hack to force recreation of widget 1007 local $_->{face_widget}; # hack to force recreation of widget
918 local $_->{desc_widget}; # hack to force recreation of widget 1008 local $_->{desc_widget}; # hack to force recreation of widget
919 CFPlus::Item::update_widgets $_; 1009 CFPlus::Item::update_widgets $_;
920 1010
1011 push @add,
921 $::FLOORBOX->add (0, $row, $_->{face_widget}); 1012 0, $row, $_->{face_widget},
922 $::FLOORBOX->add (1, $row, $_->{desc_widget}); 1013 1, $row, $_->{desc_widget};
923 1014
924 $row++; 1015 $row++;
925 } else { 1016 } else {
926 $::FLOORBOX->add (1, $row, new CFPlus::UI::Button 1017 push @add, 1, $row, new CFPlus::UI::Button
927 text => "More...", 1018 text => "More...",
928 on_activate => sub { ::toggle_player_page ($::INVENTORY_PAGE); 0 }, 1019 on_activate => sub { ::toggle_player_page ($::INVENTORY_PAGE); 0 },
929 ); 1020 ;
930 last; 1021 last;
931 } 1022 }
932 } 1023 }
933 if ($::CONN->{open_container}) { 1024 if ($::CONN->{open_container}) {
934 $::FLOORBOX->add (1, $row++, new CFPlus::UI::Button 1025 push @add, 1, $row++, new CFPlus::UI::Button
935 text => "Close container", 1026 text => "Close container",
936 on_activate => sub { $::CONN->send ("apply $::CONN->{open_container}") } 1027 on_activate => sub { $::CONN->send ("apply $::CONN->{open_container}") }
937 ); 1028 ;
938 } 1029 }
1030
1031 $::FLOORBOX->add_at (@add);
939 }); 1032 });
940 1033
941 $::WANT_REFRESH++; 1034 $::WANT_REFRESH++;
942} 1035}
943 1036
1130 1223
1131 (delete $self->{npc_dialog})->destroy 1224 (delete $self->{npc_dialog})->destroy
1132 if $self->{npc_dialog}; 1225 if $self->{npc_dialog};
1133 1226
1134 $self->SUPER::destroy; 1227 $self->SUPER::destroy;
1228
1229 %$self = ();
1135} 1230}
1136 1231
1137package CFPlus::NPCDialog; 1232package CFPlus::NPCDialog;
1138 1233
1139our @ISA = 'CFPlus::UI::Toplevel'; 1234our @ISA = 'CFPlus::UI::Toplevel';

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines