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.9 by root, Fri Jul 20 22:34:56 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 demo_map {
38 my ($ns) = @_;
39
40 my $ws = $ns->{csc} = $ns->new_widgetset;
41
42 my $w = $ws->new (Toplevel =>
43 w => 200,
44 h => 200,
45 x => "center",
46 y => "center",
47 title => "Worldmap",
48 has_close_button => 1,
49 on_delete => sub {
50 $ws->destroy;
51 },
52 );
53
54 my $face = cf::face::find "res/worldmap.jpg";
55 $ns->send_face ($face);
56
57 $w->add (my $sw = $ws->new (ScrolledWindow => scroll_x => 1, scroll_y => 1));
58 $sw->add (my $fixed = $ws->new (Fixed => expand => 1));
59 $fixed->add ($ws->new (Face => expand => 1, size_w => undef, size_h => undef, face => $face), abs => 0, 0, rel => 1, 1);
60 $fixed->add ($ws->new (Label => text => "lb1"), abs => 10, 10, rel => 1, 1);
61
62 $w->show;
63}
64
65sub csc_start {
66 my ($ns) = @_;
67
68 my $ws = $ns->{csc} = $ns->new_widgetset;
69
70 my $w = $ws->new (Toplevel =>
71 min_w => 600,
72 min_h => 400,
73 x => "center",
74 y => "center",
75 title => "Character Creation",
76 has_close_button => 1,
77 on_delete => sub {
78 $ws->destroy;
79 },
80 );
81
82 $w->add (my $ntb = $ws->new (Notebook => expand => 1));
83
84 $ntb->add (Statistics => (my $stats = $ws->new (Table => expand => 1)), "Basic statistics of your new character");
85
86 $stats->add (0, 0, (my $statstable = $ws->new ("Table")));
87
88 for (
89 [0, "Str"],
90 [1, "Dex"],
91 [2, "Con"],
92 [3, "Int"],
93 [4, "Wis"],
94 [5, "Pow"],
95 [6, "Cha"],
96 ) {
97 my ($x, $label) = @$_;
98
99 $statstable->add_at ($x, 0, $ws->new (Label =>
100 can_hover => 1, can_events => 1,
101 align => +1, text => $label, tooltip => "#stat_$label",
102 ));
103 $statstable->add_at ($x, 1, $ws->{stat}{$label} = $ws->new (Label =>
104 can_hover => 1, can_events => 1,
105 align => +1, template => "88", tooltip => "#stat_$label",
106 ));
107 }
108
109 csc_update_stats $ns;
110
111 $w->show;
112}
22 113
23cf::player->attach ( 114cf::player->attach (
24 on_login => sub { 115 on_login => sub {
25 my ($pl) = @_; 116 my ($pl) = @_;
26 117
27 #DEMO CODE 118 return unless $cf::CFG{devel};
28 return unless $pl->ob->name eq "schmorp";
29 119
30 my $ns = $pl->ns; 120 my $ns = $pl->ns;
31 121
32 return unless $ns->{can_widgetx}; 122 return unless $ns->{can_widget};
33 123
34 my $ws = $ns->new_widgetset; 124 demo_map $ns;
35 125 #csc_start $ns;
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 }, 126 },
65); 127);
66 128
67cf::register_exticmd w_e => sub { 129cf::register_exticmd w_e => sub {
68 my ($ns, $pkt) = @_; 130 my ($ns, $pkt) = @_;
123sub msg { 185sub msg {
124 my ($self, $type, %msg) = @_; 186 my ($self, $type, %msg) = @_;
125 187
126 if (my $ns = shift->{ns}) { 188 if (my $ns = shift->{ns}) {
127 $msg{msgtype} = $type; 189 $msg{msgtype} = $type;
128 $ns->send_packet ("ext " . cf::to_json \%msg); 190 $ns->send_packet ("ext " . $ns->{json_coder}->encode (\%msg));
129 } 191 }
130} 192}
131 193
132sub new { 194sub new {
133 my ($self, $class, %args) = @_; 195 my ($self, $class, %args) = @_;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines