--- deliantra/server/ext/widget.ext 2007/06/25 05:43:53 1.1 +++ deliantra/server/ext/widget.ext 2007/07/16 09:07:12 1.6 @@ -16,51 +16,115 @@ on_connect => sub { my ($ns) = @_; + Scalar::Util::weaken (my $weakns = $ns); + $ns->{id} = "a"; + $ns->{json_coder}->filter_json_single_key_object (__widget_ref__ => sub { + # cannot deserialise ATM + undef + }); }, ); -cf::player->attach ( - on_login => sub { - my ($pl) = @_; +sub csc_update_stats { + my ($ns) = @_; + + while (my ($k, $v) = each %{ $ns->{csc}{stat} }) { + $v->set_text ($ns->pl->ob->stats->$k); + } +} - #DEMO CODE - return unless $pl->ob->name eq "schmorp"; +sub demo_map { + my ($ns) = @_; - my $ns = $pl->ns; + my $ws = $ns->{csc} = $ns->new_widgetset; - return unless $ns->{can_widgetx}; + my $w = $ws->new (Toplevel => + w => 200, + h => 200, + x => "center", + y => "center", + title => "Worldmap", + has_close_button => 1, + on_delete => sub { + $ws->destroy; + }, + ); + + my $face = cf::face::find "res/worldmap.jpg"; + $ns->send_face ($face); + + $w->add (my $sw = $ws->new (ScrolledWindow => scroll_x => 1, scroll_y => 1)); + $sw->add (my $vb = $ws->new (VBox => expand => 1)); + #$vb->add ($ws->new (Label => text => "lb1")); + $vb->add ($ws->new (Face => expand => 1, size_w => undef, size_h => undef, face => $face)); + $sw->show; + $vb->show; - my $ws = $ns->new_widgetset; + $w->show; +} - $ns->async (sub { - Coro::Timer::sleep 20; - warn "undef\n";#d# - undef $ws;# - });#d# - - my $w = $ws->new (Toplevel => - x => "center", - y => "center", - title => "Server Query", - has_close_button => 1, - on_delete => sub { - warn "i was being d-e-l-e-t-e-d\n"; - }, - ); - - $w->add ($ws->new (Entry => - on_changed => sub { - warn "i was changed<@_>\n"; - } - )); +sub csc_start { + my ($ns) = @_; - $ns->async (sub { - warn $w->get ("parent"); - }); + my $ws = $ns->{csc} = $ns->new_widgetset; + + my $w = $ws->new (Toplevel => + min_w => 600, + min_h => 400, + x => "center", + y => "center", + title => "Character Creation", + has_close_button => 1, + on_delete => sub { + $ws->destroy; + }, + ); + + $w->add (my $ntb = $ws->new (Notebook => expand => 1)); + + $ntb->add (Statistics => (my $stats = $ws->new (Table => expand => 1)), "Basic statistics of your new character"); + + $stats->add (0, 0, (my $statstable = $ws->new ("Table"))); + + for ( + [0, "Str"], + [1, "Dex"], + [2, "Con"], + [3, "Int"], + [4, "Wis"], + [5, "Pow"], + [6, "Cha"], + ) { + my ($x, $label) = @$_; + + $statstable->add ($x, 0, $ws->new (Label => + can_hover => 1, can_events => 1, + align => +1, text => $label, tooltip => "#stat_$label", + )); + $statstable->add ($x, 1, $ws->{stat}{$label} = $ws->new (Label => + can_hover => 1, can_events => 1, + align => +1, template => "88", tooltip => "#stat_$label", + )); + } + + csc_update_stats $ns; + + $w->show; +} + +cf::player->attach ( + on_login => sub { + my ($pl) = @_; + + #return unless $cf::CFG{devel}; + + my $ns = $pl->ns; - $w->show; + return unless $ns->{can_widget}; + demo_map $ns; + #csc_start $ns; }, ); @@ -125,7 +189,7 @@ if (my $ns = shift->{ns}) { $msg{msgtype} = $type; - $ns->send_packet ("ext " . cf::to_json \%msg); + $ns->send_packet ("ext " . $ns->{json_coder}->encode (\%msg)); } }