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.4 by root, Mon Jul 2 03:15:30 2007 UTC

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 ($x, 0, $ws->new (Label =>
72 can_hover => 1, can_events => 1,
73 align => +1, text => $label, tooltip => "#stat_$label",
74 ));
75 $statstable->add ($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
34 my $ws = $ns->new_widgetset; 96 csc_start $ns;
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 }, 97 },
65); 98);
66 99
67cf::register_exticmd w_e => sub { 100cf::register_exticmd w_e => sub {
68 my ($ns, $pkt) = @_; 101 my ($ns, $pkt) = @_;
123sub msg { 156sub msg {
124 my ($self, $type, %msg) = @_; 157 my ($self, $type, %msg) = @_;
125 158
126 if (my $ns = shift->{ns}) { 159 if (my $ns = shift->{ns}) {
127 $msg{msgtype} = $type; 160 $msg{msgtype} = $type;
128 $ns->send_packet ("ext " . cf::to_json \%msg); 161 $ns->send_packet ("ext " . $ns->{json_coder}->encode (\%msg));
129 } 162 }
130} 163}
131 164
132sub new { 165sub new {
133 my ($self, $class, %args) = @_; 166 my ($self, $class, %args) = @_;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines