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.11 by root, Sat Jul 21 18:01:26 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) = @_;
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) = @_;
213} 245}
214 246
215sub set { 247sub set {
216 my ($self, $member, $value) = @_; 248 my ($self, $member, $value) = @_;
217 249
218 $self->msg (w_s => name => $member, value => $value); 250 $self->msg (w_s => attr => [ [$member, $value] ]);
219} 251}
220 252
221sub get { 253sub get {
222 my ($self, $member, $cb) = @_; 254 my ($self, $member, $cb) = @_;
223 255
224 $self->msg_cb ($cb, w_g => name => $member); 256 $self->msg_cb ($cb, w_g => attr => [$member]);
225} 257}
226 258
227sub TO_JSON { 259sub TO_JSON {
228 { __widget_ref__ => $_[0]{id} } 260 { __widget_ref__ => $_[0]{id} }
229} 261}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines