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.1 by root, Mon Jun 25 05:43:53 2007 UTC vs.
Revision 1.12 by root, Sun Jul 22 20:08:38 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
15cf::client->attach ( 15cf::client->attach (
16 on_connect => sub { 16 on_connect => sub {
17 my ($ns) = @_; 17 my ($ns) = @_;
18 18
19 Scalar::Util::weaken (my $weakns = $ns);
20
19 $ns->{id} = "a"; 21 $ns->{id} = "a";
22 $ns->{json_coder}->filter_json_single_key_object (__widget_ref__ => sub {
23 # cannot deserialise ATM
24 undef
25 });
20 }, 26 },
21); 27);
28
29sub csc_update_stats {
30 my ($ns) = @_;
31
32 while (my ($k, $v) = each %{ $ns->{csc}{stat} }) {
33 $v->set_text ($ns->pl->ob->stats->$k);
34 }
35}
36
37sub csc_start {
38 my ($ns) = @_;
39
40 my $ws = $ns->{csc} = $ns->new_widgetset;
41
42 my $w = $ws->new (Toplevel =>
43 min_w => 600,
44 min_h => 400,
45 x => "center",
46 y => "center",
47 title => "Character Creation",
48 has_close_button => 1,
49 on_delete => sub {
50 $ws->destroy;
51 },
52 );
53
54 $w->add (my $ntb = $ws->new (Notebook => expand => 1));
55
56 $ntb->add (Statistics => (my $stats = $ws->new (Table => expand => 1)), "Basic statistics of your new character");
57
58 $stats->add (0, 0, (my $statstable = $ws->new ("Table")));
59
60 for (
61 [0, "Str"],
62 [1, "Dex"],
63 [2, "Con"],
64 [3, "Int"],
65 [4, "Wis"],
66 [5, "Pow"],
67 [6, "Cha"],
68 ) {
69 my ($x, $label) = @$_;
70
71 $statstable->add_at ($x, 0, $ws->new (Label =>
72 can_hover => 1, can_events => 1,
73 align => +1, text => $label, tooltip => "#stat_$label",
74 ));
75 $statstable->add_at ($x, 1, $ws->{stat}{$label} = $ws->new (Label =>
76 can_hover => 1, can_events => 1,
77 align => +1, template => "88", tooltip => "#stat_$label",
78 ));
79 }
80
81 csc_update_stats $ns;
82
83 $w->show;
84}
22 85
23cf::player->attach ( 86cf::player->attach (
24 on_login => sub { 87 on_login => sub {
25 my ($pl) = @_; 88 my ($pl) = @_;
26 89
27 #DEMO CODE 90 return unless $cf::CFG{devel};
28 return unless $pl->ob->name eq "schmorp";
29 91
30 my $ns = $pl->ns; 92 my $ns = $pl->ns;
31 93
32 return unless $ns->{can_widgetx}; 94 return unless $ns->{can_widget};
33 95 #csc_start $ns;
34 my $ws = $ns->new_widgetset;
35
36 $ns->async (sub {
37 Coro::Timer::sleep 20;
38 warn "undef\n";#d#
39 undef $ws;#
40 });#d#
41
42 my $w = $ws->new (Toplevel =>
43 x => "center",
44 y => "center",
45 title => "Server Query",
46 has_close_button => 1,
47 on_delete => sub {
48 warn "i was being d-e-l-e-t-e-d\n";
49 },
50 );
51
52 $w->add ($ws->new (Entry =>
53 on_changed => sub {
54 warn "i was changed<@_>\n";
55 }
56 ));
57
58 $ns->async (sub {
59 warn $w->get ("parent");
60 });
61
62 $w->show;
63
64 }, 96 },
65); 97);
66 98
67cf::register_exticmd w_e => sub { 99cf::register_exticmd w_e => sub {
68 my ($ns, $pkt) = @_; 100 my ($ns, $pkt) = @_;
93 my $id = ++$self->{id}; 125 my $id = ++$self->{id};
94 126
95 my $ws = bless { 127 my $ws = bless {
96 id => $id, 128 id => $id,
97 ns => $self, 129 ns => $self,
98 w => {}, 130 _w => {},
99 }, "ext::widget::set"; 131 }, "ext::widget::set";
100 132
101 $ws->msg (ws_n => id => $id); 133 $ws->msg (ws_n => id => $id);
102 134
103 $ws 135 $ws
123sub msg { 155sub msg {
124 my ($self, $type, %msg) = @_; 156 my ($self, $type, %msg) = @_;
125 157
126 if (my $ns = shift->{ns}) { 158 if (my $ns = shift->{ns}) {
127 $msg{msgtype} = $type; 159 $msg{msgtype} = $type;
128 $ns->send_packet ("ext " . cf::to_json \%msg); 160 $ns->send_packet ("ext " . $ns->{json_coder}->encode (\%msg));
129 } 161 }
130} 162}
131 163
132sub new { 164sub new {
133 my ($self, $class, %args) = @_; 165 my ($self, $class, %args) = @_;
134 166
135 my $id = ++$self->{ns}{id}; 167 my $id = ++$self->{ns}{id};
136 168
137 my $proxy = $self->{w}{$id} = bless { 169 my $proxy = $self->{_w}{$id} = bless {
138 id => $id, 170 id => $id,
139 }, "ext::widget::proxy"; 171 }, "ext::widget::proxy";
140 172
141 Scalar::Util::weaken ($proxy->{ws} = $self); 173 Scalar::Util::weaken ($proxy->{ws} = $self);
142 Scalar::Util::weaken ($proxy->{ns} = $self->{ns}); 174 Scalar::Util::weaken ($proxy->{ns} = $self->{ns});
146 push @{$proxy->{ev}{$ev}}, $args{$ev}; 178 push @{$proxy->{ev}{$ev}}, $args{$ev};
147 $args{$ev} = 0; 179 $args{$ev} = 0;
148 } 180 }
149 181
150 $self->msg (ws_c => 182 $self->msg (ws_c =>
151 ws => $self->{w}{id}, 183 ws => $proxy->{id},
152 id => $id, 184 id => $id,
153 class => $class, 185 class => $class,
154 args => \%args, 186 args => \%args,
155 ); 187 );
156 188
164sub DESTROY { 196sub DESTROY {
165 my ($self) = @_; 197 my ($self) = @_;
166 198
167 delete $self->{ns}{widget}{$self->{id}}; 199 delete $self->{ns}{widget}{$self->{id}};
168 200
201 #warn "DES<$self> $self->{ws}\n";#d#
169 if (my $ws = $self->{ws}) { 202 if (my $ws = $self->{ws}) {
170 delete $ws->{w}{$self->{id}};
171 $self->msg (w_c => name => "destroy"); 203 $self->msg (w_c => name => "destroy");
204 delete $ws->{_w}{$self->{id}};
172 } 205 }
173} 206}
174 207
175sub msg { 208sub msg {
176 my ($self, $type, %msg) = @_; 209 my ($self, $type, %msg) = @_;
211 244
212 () 245 ()
213} 246}
214 247
215sub set { 248sub set {
216 my ($self, $member, $value) = @_; 249 my ($self, @kv) = @_;
217 250
218 $self->msg (w_s => name => $member, value => $value); 251 $self->msg (w_s => attr => \@kv);
219} 252}
220 253
221sub get { 254sub get {
222 my ($self, $member, $cb) = @_; 255 my ($self, $member, $cb) = @_;
223 256
224 $self->msg_cb ($cb, w_g => name => $member); 257 $self->msg_cb ($cb, w_g => attr => [$member]);
225} 258}
226 259
227sub TO_JSON { 260sub TO_JSON {
228 { __widget_ref__ => $_[0]{id} } 261 { __widget_ref__ => $_[0]{id} }
229} 262}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines