… | |
… | |
3 | # sends the following ext message types |
3 | # sends the following ext message types |
4 | # ws_a id name... # associate well-known widget with given id |
4 | # ws_a id name... # associate well-known widget with given id |
5 | # ws_n ws # widgetset new |
5 | # ws_n ws # widgetset new |
6 | # ws_d ws # widgetset destroy |
6 | # ws_d ws # widgetset destroy |
7 | # ws_c ws id class @args # widgetset create |
7 | # ws_c ws id class @args # widgetset create |
8 | # ws_ct ws templateface \%cfg # widgetset create from template |
8 | # ws_ct ws ttype ttext done_cb \%cfg # widgetset create from template |
9 | # w_c id rid name @args # widget method call |
9 | # w_c id rid name @args # widget method call |
10 | # w_s id @attr # widget member set |
10 | # w_s id @attr # widget member set |
11 | # w_g id rid @attr # widget member get |
11 | # w_g id rid @attr # widget member get |
12 | # |
12 | # |
13 | # and expects the following exti message types |
13 | # and expects the following exti message types |
… | |
… | |
34 | while (my ($k, $v) = each %{ $ns->{csc}{stat} }) { |
34 | while (my ($k, $v) = each %{ $ns->{csc}{stat} }) { |
35 | $v->set_text ($ns->pl->ob->stats->$k); |
35 | $v->set_text ($ns->pl->ob->stats->$k); |
36 | } |
36 | } |
37 | } |
37 | } |
38 | |
38 | |
|
|
39 | my $cg_template = eval <<EOF; |
|
|
40 | [ |
|
|
41 | Toplevel => { |
|
|
42 | s_id => "toplevel", |
|
|
43 | title => "Character Creation", |
|
|
44 | x => "center", |
|
|
45 | y => "center", |
|
|
46 | z => 5, |
|
|
47 | force_w => 760, |
|
|
48 | force_h => 440, |
|
|
49 | s_cl => [VBox => { s_cl => [ |
|
|
50 | Label => { |
|
|
51 | text => "Character Creation", |
|
|
52 | fontsize => 1, |
|
|
53 | align => 0, |
|
|
54 | }, |
|
|
55 | Label => { |
|
|
56 | markup => "View or Edit your character attributes below, then press <b>Finish</b> to create your character", |
|
|
57 | fontsize => 0.8, |
|
|
58 | align => 0, |
|
|
59 | }, |
|
|
60 | HBox => { s_cl => [ |
|
|
61 | Face => { |
|
|
62 | s_id => "face", |
|
|
63 | face => 0, |
|
|
64 | bg => [.2, .2, .2, 1], |
|
|
65 | min_w => 64, |
|
|
66 | min_h => 64, |
|
|
67 | }, |
|
|
68 | Label => { |
|
|
69 | s_id => "desc", |
|
|
70 | fontsize => 0.8, |
|
|
71 | ellipsize => 0, |
|
|
72 | }, |
|
|
73 | ]}, |
|
|
74 | Notebook => { |
|
|
75 | expand => 1, |
|
|
76 | s_cl => [ |
|
|
77 | Table => { |
|
|
78 | c_tab => ["Basics", "Title, background and other information of your character."], |
|
|
79 | }, |
|
|
80 | Table => { |
|
|
81 | c_tab => ["Stats", "Your character's primary stats such as strength, dexterity and so on."], |
|
|
82 | }, |
|
|
83 | Table => { |
|
|
84 | c_tab => ["Race", "Your character's race."], |
|
|
85 | }, |
|
|
86 | Table => { |
|
|
87 | c_tab => ["Class", "Your character's initial class."], |
|
|
88 | }, |
|
|
89 | ], |
|
|
90 | }, |
|
|
91 | Button => { |
|
|
92 | s_id => "finish", |
|
|
93 | text => "Finish", |
|
|
94 | }, |
|
|
95 | ]}], |
|
|
96 | }, |
|
|
97 | ] |
|
|
98 | EOF |
|
|
99 | die if $@; |
|
|
100 | |
39 | sub demo_start { |
101 | sub demo_start { |
40 | my ($ns) = @_; |
102 | my ($ns) = @_; |
41 | |
103 | |
42 | my $ws = $ns->{csc} = $ns->new_widgetset; |
104 | my $ws = $ns->{csc} = $ns->new_widgetset; |
43 | |
105 | |
44 | my ($tl, $entry) = $ws->template (undef, |
106 | my ($tl, $entry) = $ws->template (inline => $cg_template, |
|
|
107 | [ |
45 | toplevel => {}, |
108 | toplevel => {}, |
46 | entry => { |
109 | entry => { |
47 | text => "xyz", |
110 | text => "xyz", |
48 | on_changed => sub { |
111 | on_changed => sub { |
49 | warn "changed<@_>\n";#d# |
112 | warn "changed<@_>\n";#d# |
|
|
113 | }, |
50 | }, |
114 | }, |
51 | }, |
115 | ], |
52 | ); |
116 | ); |
53 | |
117 | |
54 | $tl->show; |
118 | $tl->show; |
55 | |
119 | |
56 | $ns->{xxxw} = [$tl, $entry];#d# |
120 | $ns->{xxxw} = [$tl, $entry];#d# |
… | |
… | |
220 | |
284 | |
221 | $proxy |
285 | $proxy |
222 | } |
286 | } |
223 | |
287 | |
224 | sub template { |
288 | sub template { |
225 | my ($self, $template, @args) = @_; |
289 | my ($self, $type, $template, $args, $done_cb) = @_; |
226 | |
290 | |
227 | my %cfg; |
291 | my %cfg; |
228 | my @res; |
292 | my @res; |
229 | |
293 | |
230 | while (@args) { |
294 | while (@$args) { |
231 | my ($name, $args) = splice @args, 0, 2, (); |
295 | my ($name, $args) = splice @$args, 0, 2, (); |
232 | |
296 | |
233 | my $proxy = $self->alloc; |
297 | my $proxy = $self->alloc; |
234 | |
298 | |
235 | Scalar::Util::weaken ($self->{_w}{$proxy->{id}} = $proxy); |
299 | Scalar::Util::weaken ($self->{_w}{$proxy->{id}} = $proxy); |
236 | Scalar::Util::weaken ($proxy->{ws} = $self); |
300 | Scalar::Util::weaken ($proxy->{ws} = $self); |
… | |
… | |
245 | }; |
309 | }; |
246 | |
310 | |
247 | push @res, $proxy; |
311 | push @res, $proxy; |
248 | } |
312 | } |
249 | |
313 | |
|
|
314 | if ($done_cb) { |
|
|
315 | my $proxy = $self->alloc; |
|
|
316 | my $ocb = $done_cb; |
|
|
317 | $done_cb = $proxy->cb (sub { |
|
|
318 | undef $proxy; |
|
|
319 | undef $done_cb; |
|
|
320 | &$ocb |
|
|
321 | }); |
|
|
322 | } |
|
|
323 | |
250 | $self->msg (ws_ct => |
324 | $self->msg (ws_ct => |
251 | $self->{id}, |
325 | $self->{id}, |
252 | $template, |
326 | $type => $template, |
|
|
327 | $done_cb, |
253 | \%cfg, |
328 | \%cfg, |
254 | ); |
329 | ); |
255 | |
330 | |
256 | @res |
331 | @res |
257 | } |
332 | } |