--- deliantra/server/ext/widget.ext 2007/12/27 18:35:48 1.20 +++ deliantra/server/ext/widget.ext 2007/12/29 21:07:23 1.23 @@ -5,7 +5,7 @@ # ws_n ws # widgetset new # ws_d ws # widgetset destroy # ws_c ws id class @args # widgetset create -# ws_ct ws templateface \%cfg # widgetset create from template +# ws_ct ws ttype ttext done_cb \%cfg # widgetset create from template # w_c id rid name @args # widget method call # w_s id @attr # widget member set # w_g id rid @attr # widget member get @@ -19,12 +19,12 @@ on_connect => sub { my ($ns) = @_; - Scalar::Util::weaken (my $weakns = $ns); - $ns->{id} = "a"; $ns->{json_coder}->filter_json_single_key_object ("\fw" => sub { - $weakns->{widget}{$_[0]} + $ns->{widget}{$_[0]} }); + + cf::weaken $ns; }, ); @@ -36,28 +36,67 @@ } } -sub demo_start { - my ($ns) = @_; - - my $ws = $ns->{csc} = $ns->new_widgetset; - - my ($tl, $entry) = $ws->template (undef, - toplevel => {}, - entry => { - text => "xyz", - on_changed => sub { - warn "changed<@_>\n";#d# +my $cg_template = eval < { + s_id => "toplevel", + title => "Character Creation", + x => "center", + y => "center", + z => 5, + force_w => 760, + force_h => 440, + s_cl => [VBox => { s_cl => [ + Label => { + text => "Character Creation", + fontsize => 1, + align => 0, }, - }, - ); - - $tl->show; - - $ns->{xxxw} = [$tl, $entry];#d# - -# $ws->find ("setup_notebook")->add ($ws->{tab}); -# $ws->find ("setup_dialog")->toggle_visibility; -} + Label => { + markup => "View or Edit your character attributes below, then press Finish to create your character", + fontsize => 0.8, + align => 0, + }, + HBox => { s_cl => [ + Face => { + s_id => "face", + face => 0, + bg => [.2, .2, .2, 1], + min_w => 64, + min_h => 64, + }, + Label => { + s_id => "desc", + fontsize => 0.8, + ellipsize => 0, + }, + ]}, + Notebook => { + expand => 1, + s_cl => [ + Table => { + c_tab => ["Basics", "Title, background and other information of your character."], + }, + Table => { + c_tab => ["Stats", "Your character's primary stats such as strength, dexterity and so on."], + }, + Table => { + c_tab => ["Race", "Your character's race."], + }, + Table => { + c_tab => ["Class", "Your character's initial class."], + }, + ], + }, + Button => { + s_id => "finish", + text => "Finish", + }, + ]}], + }, +] +EOF +die if $@; sub csc_start { my ($ns) = @_; @@ -107,19 +146,37 @@ $ws->{tl} = $w; $w->show; + +# my ($tl, $entry) = $ws->template (inline => $cg_template, +# [ +# toplevel => {}, +# entry => { +# text => "xyz", +# on_changed => sub { +# warn "changed<@_>\n";#d# +# }, +# }, +# ], +# ); +# +# $tl->show; +# +# $ns->{xxxw} = [$tl, $entry];#d# +# +# $ws->find ("setup_notebook")->add ($ws->{tab}); +# $ws->find ("setup_dialog")->toggle_visibility; } cf::player->attach ( on_login => sub { my ($pl) = @_; - return unless $cf::CFG{devel}; - my $ns = $pl->ns; - return unless $ns->{can_widget}; + + return unless $cf::CFG{devel}; + #csc_start $ns; - demo_start $ns; }, ); @@ -144,6 +201,8 @@ _w => {}, }, "ext::widget::set"; + cf::weaken $ws->{ns}; + $ws->msg (ws_n => $id); $ws @@ -204,8 +263,9 @@ my $proxy = $self->alloc; - Scalar::Util::weaken ($self->{_w}{$proxy->{id}} = $proxy); - Scalar::Util::weaken ($proxy->{ws} = $self); + cf::weaken + +($self->{_w}{$proxy->{id}} = $proxy), + +($proxy->{ws} = $self); for my $ev (grep /^on_/, keys %args) { $args{$ev} = $proxy->{"_$ev"} = $proxy->cb ($args{$ev}); @@ -222,18 +282,20 @@ } sub template { - my ($self, $template, @args) = @_; + my ($self, $type, $template, $args, $done_cb) = @_; my %cfg; - my @res; - while (@args) { - my ($name, $args) = splice @args, 0, 2, (); + while (@$args) { + my ($name, $args) = splice @$args, 0, 2, (); my $proxy = $self->alloc; - Scalar::Util::weaken ($self->{_w}{$proxy->{id}} = $proxy); - Scalar::Util::weaken ($proxy->{ws} = $self); + $self->{delete $args->{alias} or $name} = $proxy; + + cf::weaken + +($self->{_w}{$proxy->{id}} = $proxy), + +($proxy->{ws} = $self); for my $ev (grep /^on_/, keys %$args) { $args->{$ev} = $proxy->{"_$ev"} = $proxy->cb ($args->{$ev}); @@ -243,17 +305,29 @@ %$args, id => $proxy->{id}, }; + } + + if ($done_cb) { + my $proxy = $self->alloc; + my $ocb = $done_cb; + $done_cb = $proxy->cb (sub { + undef $proxy; + undef $done_cb; + &$ocb + }); + } - push @res, $proxy; + if ($type eq "face") { + $self->{ns}->send_face ($template, 100); + $self->{ns}->flush_fx; } $self->msg (ws_ct => $self->{id}, - $template, + $type => $template, + $done_cb, \%cfg, ); - - @res } sub find { @@ -282,46 +356,6 @@ package ext::widget::proxy; -sub DESTROY { - my ($self) = @_; - - delete $self->{ns}{widget}{$self->{id}}; - - if (my $ws = $self->{ws}) { - $self->msg (w_c => 0, "destroy"); - delete $ws->{_w}{$self->{id}}; - } -} - -sub cb { - my ($self, $cb) = @_; - - my $proxy = bless { - ns => $self->{ns}, - id => $self->{ns}->alloc_wid, - }, "ext::widget::callback"; - - Scalar::Util::weaken $proxy->{ns}; - - $self->{ns}{widget_cb}{$proxy->{id}} = $cb; - - $proxy -} - -sub oneshot_cb { - my ($self, $cb) = @_; - - if ("CODE" eq ref $cb) { - my $ocb = $cb; - $cb = $self->cb (sub { - undef $cb; - &$ocb - }); - } - - $cb -} - sub msg { my ($self, $type, @arg) = @_; @@ -368,6 +402,46 @@ () } +sub DESTROY { + my ($self) = @_; + + delete $self->{ns}{widget}{$self->{id}}; + + if (my $ws = $self->{ws}) { + $self->msg (w_c => 0, "destroy"); + delete $ws->{_w}{$self->{id}}; + } +} + +sub cb { + my ($self, $cb) = @_; + + my $proxy = bless { + ns => $self->{ns}, + id => $self->{ns}->alloc_wid, + }, "ext::widget::callback"; + + cf::weaken $proxy->{ns}; + + $self->{ns}{widget_cb}{$proxy->{id}} = $cb; + + $proxy +} + +sub oneshot_cb { + my ($self, $cb) = @_; + + if ("CODE" eq ref $cb) { + my $ocb = $cb; + $cb = cb $self, sub { + undef $cb; + &$ocb + }; + } + + $cb +} + sub set { my ($self, @kv) = @_;