ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/widget.ext
(Generate patch)

Comparing deliantra/server/ext/widget.ext (file contents):
Revision 1.2 by root, Mon Jun 25 07:40:53 2007 UTC vs.
Revision 1.13 by root, Mon Jul 23 21:02:50 2007 UTC

3# sends the following ext message types 3# sends the following ext message types
4# ws_n id # widgetset new 4# ws_n id # widgetset new
5# ws_d id # widgetset destroy 5# ws_d id # widgetset destroy
6# ws_c ws id class args # widgetset create 6# ws_c ws id class args # widgetset create
7# w_c id [rid] name args # widget method call 7# w_c id [rid] name args # widget method call
8# w_s id name value # widget member set 8# w_s id @attr # widget member set
9# w_g id rid name # widget member get 9# w_g id rid @attr # widget member get
10# 10#
11# and expects the following exti message types 11# and expects the following exti message types
12# w_r rid res # widget call return 12# w_r rid res # widget call return
13# w_e id name args # widget_event 13# w_e id name args # widget_event
14 14
15our $DEBUG = 1;
16
15cf::client->attach ( 17cf::client->attach (
16 on_connect => sub { 18 on_connect => sub {
17 my ($ns) = @_; 19 my ($ns) = @_;
18 20
21 Scalar::Util::weaken (my $weakns = $ns);
22
19 $ns->{id} = "a"; 23 $ns->{id} = "a";
24 $ns->{json_coder}->filter_json_single_key_object (__widget_ref__ => sub {
25 # cannot deserialise ATM
26 undef
27 });
20 }, 28 },
21); 29);
22 30
23sub csc_update_stats { 31sub csc_update_stats {
24 my ($ns) = @_; 32 my ($ns) = @_;
37 min_w => 600, 45 min_w => 600,
38 min_h => 400, 46 min_h => 400,
39 x => "center", 47 x => "center",
40 y => "center", 48 y => "center",
41 title => "Character Creation", 49 title => "Character Creation",
50 has_close_button => 1,
51 on_delete => sub {
52 $ws->destroy;
53 },
42 ); 54 );
43 55
44 $w->add (my $ntb = $ws->new (Notebook => expand => 1)); 56 $w->add (my $ntb = $ws->new (Notebook => expand => 1));
45 57
46 $ntb->add (Statistics => (my $stats = $ws->new (Table => expand => 1)), "Basic statistics of your new character"); 58 $ntb->add (Statistics => (my $stats = $ws->new (Table => expand => 1)), "Basic statistics of your new character");
47 59
48 $stats->add (0, 0, (my $statstable = $ws->new ("Table"))); 60 $stats->add (0, 0, (my $statstable = $ws->new ("Table")));
49 61
50 for ( 62 for (
51 [0, "Str", "Strength"], 63 [0, "Str"],
52 [1, "Dex", "Dexterity"], 64 [1, "Dex"],
53 [2, "Con", "Constitution"], 65 [2, "Con"],
54 [3, "Int", "Intelligence"], 66 [3, "Int"],
55 [4, "Wis", "Wisdom"], 67 [4, "Wis"],
56 [5, "Pow", "Power"], 68 [5, "Pow"],
57 [6, "Cha", "Charisma"], 69 [6, "Cha"],
58 ) { 70 ) {
59 my ($x, $label, $description) = @$_; 71 my ($x, $label) = @$_;
60 72
61 $statstable->add ($x, 0, $ws->new (Label => 73 $statstable->add_at ($x, 0, $ws->new (Label =>
62 can_hover => 1, can_events => 1, 74 can_hover => 1, can_events => 1,
63 align => +1, text => $label, tooltip => "#stat_$label", 75 align => +1, text => $label, tooltip => "#stat_$label",
64 )); 76 ));
65 $statstable->add ($x, 1, $ws->{stat}{$label} = $ws->new (Label => 77 $statstable->add_at ($x, 1, $ws->{stat}{$label} = $ws->new (Label =>
66 can_hover => 1, can_events => 1, 78 can_hover => 1, can_events => 1,
67 align => +1, template => "88", tooltip => "#stat_$label", 79 align => +1, template => "88", tooltip => "#stat_$label",
68 )); 80 ));
69 } 81 }
70 82
80 return unless $cf::CFG{devel}; 92 return unless $cf::CFG{devel};
81 93
82 my $ns = $pl->ns; 94 my $ns = $pl->ns;
83 95
84 return unless $ns->{can_widget}; 96 return unless $ns->{can_widget};
85
86 csc_start $ns; 97 #csc_start $ns;
87 }, 98 },
88); 99);
89 100
90cf::register_exticmd w_e => sub { 101cf::register_exticmd w_e => sub {
91 my ($ns, $pkt) = @_; 102 my ($ns, $pkt) = @_;
116 my $id = ++$self->{id}; 127 my $id = ++$self->{id};
117 128
118 my $ws = bless { 129 my $ws = bless {
119 id => $id, 130 id => $id,
120 ns => $self, 131 ns => $self,
121 w => {}, 132 _w => {},
122 }, "ext::widget::set"; 133 }, "ext::widget::set";
123 134
124 $ws->msg (ws_n => id => $id); 135 $ws->msg (ws_n => id => $id);
125 136
126 $ws 137 $ws
146sub msg { 157sub msg {
147 my ($self, $type, %msg) = @_; 158 my ($self, $type, %msg) = @_;
148 159
149 if (my $ns = shift->{ns}) { 160 if (my $ns = shift->{ns}) {
150 $msg{msgtype} = $type; 161 $msg{msgtype} = $type;
151 $ns->send_packet ("ext " . cf::to_json \%msg); 162 warn "msg " . $ns->{json_coder}->encode (\%msg) if $DEBUG;#d#
163 $ns->send_packet ("ext " . $ns->{json_coder}->encode (\%msg));
152 } 164 }
153} 165}
154 166
155sub new { 167sub new {
156 my ($self, $class, %args) = @_; 168 my ($self, $class, %args) = @_;
157 169
158 my $id = ++$self->{ns}{id}; 170 my $id = ++$self->{ns}{id};
159 171
160 my $proxy = $self->{w}{$id} = bless { 172 my $proxy = bless {
161 id => $id, 173 id => $id,
162 }, "ext::widget::proxy"; 174 }, "ext::widget::proxy";
163 175
176 Scalar::Util::weaken ($self->{_w}{$id} = $proxy);
164 Scalar::Util::weaken ($proxy->{ws} = $self); 177 Scalar::Util::weaken ($proxy->{ws} = $self);
165 Scalar::Util::weaken ($proxy->{ns} = $self->{ns}); 178 Scalar::Util::weaken ($proxy->{ns} = $self->{ns});
166 Scalar::Util::weaken ($self->{ns}{widget}{$id} = $proxy); 179 Scalar::Util::weaken ($self->{ns}{widget}{$id} = $proxy);
167 180
168 for my $ev (grep /^on_/, keys %args) { 181 for my $ev (grep /^on_/, keys %args) {
169 push @{$proxy->{ev}{$ev}}, $args{$ev}; 182 push @{$proxy->{ev}{$ev}}, $args{$ev};
170 $args{$ev} = 0; 183 $args{$ev} = 0;
171 } 184 }
172 185
173 $self->msg (ws_c => 186 $self->msg (ws_c =>
174 ws => $self->{w}{id}, 187 ws => $proxy->{id},
175 id => $id, 188 id => $id,
176 class => $class, 189 class => $class,
177 args => \%args, 190 args => \%args,
178 ); 191 );
179 192
188 my ($self) = @_; 201 my ($self) = @_;
189 202
190 delete $self->{ns}{widget}{$self->{id}}; 203 delete $self->{ns}{widget}{$self->{id}};
191 204
192 if (my $ws = $self->{ws}) { 205 if (my $ws = $self->{ws}) {
193 delete $ws->{w}{$self->{id}};
194 $self->msg (w_c => name => "destroy"); 206 $self->msg (w_c => name => "destroy");
207 delete $ws->{_w}{$self->{id}};
195 } 208 }
196} 209}
197 210
198sub msg { 211sub msg {
199 my ($self, $type, %msg) = @_; 212 my ($self, $type, %msg) = @_;
234 247
235 () 248 ()
236} 249}
237 250
238sub set { 251sub set {
239 my ($self, $member, $value) = @_; 252 my ($self, @kv) = @_;
240 253
241 $self->msg (w_s => name => $member, value => $value); 254 $self->msg (w_s => attr => \@kv);
242} 255}
243 256
244sub get { 257sub get {
245 my ($self, $member, $cb) = @_; 258 my ($self, $member, $cb) = @_;
246 259
247 $self->msg_cb ($cb, w_g => name => $member); 260 $self->msg_cb ($cb, w_g => attr => [$member]);
248} 261}
249 262
250sub TO_JSON { 263sub TO_JSON {
251 { __widget_ref__ => $_[0]{id} } 264 { __widget_ref__ => $_[0]{id} }
252} 265}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines