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.109 by root, Mon Jun 25 05:43:37 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
98 1 161 1
99 }; 162 };
100 } 163 }
101 164
102 if (my $widget = eval { 165 if (my $widget = eval {
166 local $SIG{__DIE__};
103 "CFPlus::UI::$arg->{class}"->new ( 167 "CFPlus::UI::$arg->{class}"->new (
104 %$args, 168 %$args,
105 s_ws => $arg->{ws}, 169 s_ws => $arg->{ws},
106 s_id => $arg->{id}, 170 s_id => $arg->{id},
107 ) 171 )
121 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";
122 $self->send_exti_msg (w_e => id => $arg->{id}, name => "destroy"); 186 $self->send_exti_msg (w_e => id => $arg->{id}, name => "destroy");
123 } 187 }
124 }); 188 });
125 189
190 # widget call
126 $self->connect_ext (w_c => sub { 191 $self->connect_ext (w_c => sub {
127 my ($arg) = @_; 192 my ($arg) = @_;
128 193
129 my $w = $self->{widget}{$arg->{id}} 194 my $w = $self->{widget}{$arg->{id}}
130 or return; 195 or return;
131 my $m = $arg->{name}; 196 my $m = $arg->{name};
132 197
133 my @a = map {
134 "HASH" eq ref && 1 == (scalar keys %$_) && exists $_->{__widget_ref__}
135 ? $self->{widget}{$_->{__widget_ref__}}
136 : $_
137 } @{ $arg->{args} || [] }; 198 my $a = $arg->{args} || [];
138 199
139 if (exists $arg->{rid}) { 200 if (exists $arg->{rid}) {
140 $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)]);
141 } else { 202 } else {
142 $w->$m (@a); 203 $w->$m (@$a);
143 } 204 }
144 }); 205 });
145 206
207 # widget set
146 $self->connect_ext (w_s => sub { 208 $self->connect_ext (w_s => sub {
147 my ($arg) = @_; 209 my ($arg) = @_;
148 210
149 my $w = $self->{widget}{$arg->{id}} 211 my $w = $self->{widget}{$arg->{id}}
150 or return; 212 or return;
151 213
152 $w->{$arg->{name}} = $arg->{value}; 214 $w->{$_->[0]} = $_->[1]
215 for @{ $arg->{attr} };
153 }); 216 });
154 217
218 # widget get
155 $self->connect_ext (w_g => sub { 219 $self->connect_ext (w_g => sub {
156 my ($arg) = @_; 220 my ($arg) = @_;
157 221
158 my $w = $self->{widget}{$arg->{id}} 222 my $w = $self->{widget}{$arg->{id}}
159 or return; 223 or return;
160 224
161 $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}}]);
162 }); 226 });
163 227
228 # destroy widgets on logout
164 $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 {
165 for my $ws (values %{delete $self->{widgetset} || {}}) { 230 for my $ws (values %{delete $self->{widgetset} || {}}) {
166 $_->destroy 231 $_->destroy
167 for values %{delete $ws->{w} || {}}; 232 for values %{delete $ws->{w} || {}};
168 } 233 }
381 my @skills = keys %{ $self->{skill_info} }; 446 my @skills = keys %{ $self->{skill_info} };
382 447
383 if (grep +(exists $stats->{$_}) != (exists $prev->{$_}), @skills) { 448 if (grep +(exists $stats->{$_}) != (exists $prev->{$_}), @skills) {
384 $sktbl->clear; 449 $sktbl->clear;
385 450
451 my @add;
452
453 push @add,
386 $sktbl->add (0, 0, new CFPlus::UI::Label text => "Experience", align => 1); 454 0, 0, (new CFPlus::UI::Label text => "Experience", align => 1),
387 $sktbl->add (1, 0, new CFPlus::UI::Label text => "Lvl.", align => 1); 455 1, 0, (new CFPlus::UI::Label text => "Lvl.", align => 1),
388 $sktbl->add (2, 0, new CFPlus::UI::Label text => "Skill", expand => 1); 456 2, 0, (new CFPlus::UI::Label text => "Skill", expand => 1),
389 $sktbl->add (3, 0, new CFPlus::UI::Label text => "Experience", align => 1); 457 3, 0, (new CFPlus::UI::Label text => "Experience", align => 1),
390 $sktbl->add (4, 0, new CFPlus::UI::Label text => "Lvl.", align => 1); 458 4, 0, (new CFPlus::UI::Label text => "Lvl.", align => 1),
391 $sktbl->add (5, 0, new CFPlus::UI::Label text => "Skill", expand => 1); 459 5, 0, (new CFPlus::UI::Label text => "Skill", expand => 1),
460 ;
392 461
393 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>";
394 463
395 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);
396 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);
424 } 493 }
425 494
426 1 495 1
427 }; 496 };
428 497
498 push @add,
429 $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
430 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),
431 $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
432 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),
433 $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,
434 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 ;
435 506
436 $x++ and ($x, $y) = (0, $y + 1); 507 $x++ and ($x, $y) = (0, $y + 1);
437 } 508 }
509
510 $sktbl->add_at (@add);
438 } 511 }
439 512
440 for (grep exists $stats->{$_}, @skills) { 513 for (grep exists $stats->{$_}, @skills) {
441 $self->{stat_widget_exp}{$_}->set_text (::formsep ($stats->{$_}[1])); 514 $self->{stat_widget_exp}{$_}->set_text (::formsep ($stats->{$_}[1]));
442 $self->{stat_widget_lvl}{$_}->set_text ($stats->{$_}[0] * 1); 515 $self->{stat_widget_lvl}{$_}->set_text ($stats->{$_}[0] * 1);
709} 782}
710 783
711sub set_texture { 784sub set_texture {
712 my ($self, $id, $data) = @_; 785 my ($self, $id, $data) = @_;
713 786
787 return unless $self->{map};
788
714 $self->{texture}[$id] = my $tex = 789 $self->{texture}[$id] = my $tex =
715 new_from_image CFPlus::Texture 790 new_from_image CFPlus::Texture
716 $data, minify => 1, mipmap => 1; 791 $data, minify => 1, mipmap => 1;
717 792
718 $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}});
719 $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 }
720} 809}
721 810
722sub sound_play { 811sub sound_play {
723 my ($self, $x, $y, $soundnum, $type) = @_; 812 my ($self, $x, $y, $soundnum, $type) = @_;
724 813
908 $CFPlus::UI::ROOT->on_refresh ($::FLOORBOX => sub { 997 $CFPlus::UI::ROOT->on_refresh ($::FLOORBOX => sub {
909 return unless $::CONN; 998 return unless $::CONN;
910 999
911 $::FLOORBOX->clear; 1000 $::FLOORBOX->clear;
912 1001
1002 my @add;
1003
913 my $row; 1004 my $row;
914 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} }) {
915 if ($row < 6) { 1006 if ($row < 6) {
916 local $_->{face_widget}; # hack to force recreation of widget 1007 local $_->{face_widget}; # hack to force recreation of widget
917 local $_->{desc_widget}; # hack to force recreation of widget 1008 local $_->{desc_widget}; # hack to force recreation of widget
918 CFPlus::Item::update_widgets $_; 1009 CFPlus::Item::update_widgets $_;
919 1010
1011 push @add,
920 $::FLOORBOX->add (0, $row, $_->{face_widget}); 1012 0, $row, $_->{face_widget},
921 $::FLOORBOX->add (1, $row, $_->{desc_widget}); 1013 1, $row, $_->{desc_widget};
922 1014
923 $row++; 1015 $row++;
924 } else { 1016 } else {
925 $::FLOORBOX->add (1, $row, new CFPlus::UI::Button 1017 push @add, 1, $row, new CFPlus::UI::Button
926 text => "More...", 1018 text => "More...",
927 on_activate => sub { ::toggle_player_page ($::INVENTORY_PAGE); 0 }, 1019 on_activate => sub { ::toggle_player_page ($::INVENTORY_PAGE); 0 },
928 ); 1020 ;
929 last; 1021 last;
930 } 1022 }
931 } 1023 }
932 if ($::CONN->{open_container}) { 1024 if ($::CONN->{open_container}) {
933 $::FLOORBOX->add (1, $row++, new CFPlus::UI::Button 1025 push @add, 1, $row++, new CFPlus::UI::Button
934 text => "Close container", 1026 text => "Close container",
935 on_activate => sub { $::CONN->send ("apply $::CONN->{open_container}") } 1027 on_activate => sub { $::CONN->send ("apply $::CONN->{open_container}") }
936 ); 1028 ;
937 } 1029 }
1030
1031 $::FLOORBOX->add_at (@add);
938 }); 1032 });
939 1033
940 $::WANT_REFRESH++; 1034 $::WANT_REFRESH++;
941} 1035}
942 1036
1129 1223
1130 (delete $self->{npc_dialog})->destroy 1224 (delete $self->{npc_dialog})->destroy
1131 if $self->{npc_dialog}; 1225 if $self->{npc_dialog};
1132 1226
1133 $self->SUPER::destroy; 1227 $self->SUPER::destroy;
1228
1229 %$self = ();
1134} 1230}
1135 1231
1136package CFPlus::NPCDialog; 1232package CFPlus::NPCDialog;
1137 1233
1138our @ISA = 'CFPlus::UI::Toplevel'; 1234our @ISA = 'CFPlus::UI::Toplevel';

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines