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.2 by root, Mon Jun 25 07:40:53 2007 UTC vs.
Revision 1.5 by root, Sun Jul 15 22:39:48 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);
22 28
23sub csc_update_stats { 29sub csc_update_stats {
24 my ($ns) = @_; 30 my ($ns) = @_;
25 31
26 while (my ($k, $v) = each %{ $ns->{csc}{stat} }) { 32 while (my ($k, $v) = each %{ $ns->{csc}{stat} }) {
27 $v->set_text ($ns->pl->ob->stats->$k); 33 $v->set_text ($ns->pl->ob->stats->$k);
28 } 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 $vb = $ws->new (VBox => expand => 1));
59 #$vb->add ($ws->new (Label => text => "lb1"));
60 $vb->add ($ws->new (Face => expand => 1, size_w => undef, size_h => undef, face => $face));
61 $sw->show;
62 $vb->show;
63
64 $w->show;
29} 65}
30 66
31sub csc_start { 67sub csc_start {
32 my ($ns) = @_; 68 my ($ns) = @_;
33 69
37 min_w => 600, 73 min_w => 600,
38 min_h => 400, 74 min_h => 400,
39 x => "center", 75 x => "center",
40 y => "center", 76 y => "center",
41 title => "Character Creation", 77 title => "Character Creation",
78 has_close_button => 1,
79 on_delete => sub {
80 $ws->destroy;
81 },
42 ); 82 );
43 83
44 $w->add (my $ntb = $ws->new (Notebook => expand => 1)); 84 $w->add (my $ntb = $ws->new (Notebook => expand => 1));
45 85
46 $ntb->add (Statistics => (my $stats = $ws->new (Table => expand => 1)), "Basic statistics of your new character"); 86 $ntb->add (Statistics => (my $stats = $ws->new (Table => expand => 1)), "Basic statistics of your new character");
47 87
48 $stats->add (0, 0, (my $statstable = $ws->new ("Table"))); 88 $stats->add (0, 0, (my $statstable = $ws->new ("Table")));
49 89
50 for ( 90 for (
51 [0, "Str", "Strength"], 91 [0, "Str"],
52 [1, "Dex", "Dexterity"], 92 [1, "Dex"],
53 [2, "Con", "Constitution"], 93 [2, "Con"],
54 [3, "Int", "Intelligence"], 94 [3, "Int"],
55 [4, "Wis", "Wisdom"], 95 [4, "Wis"],
56 [5, "Pow", "Power"], 96 [5, "Pow"],
57 [6, "Cha", "Charisma"], 97 [6, "Cha"],
58 ) { 98 ) {
59 my ($x, $label, $description) = @$_; 99 my ($x, $label) = @$_;
60 100
61 $statstable->add ($x, 0, $ws->new (Label => 101 $statstable->add ($x, 0, $ws->new (Label =>
62 can_hover => 1, can_events => 1, 102 can_hover => 1, can_events => 1,
63 align => +1, text => $label, tooltip => "#stat_$label", 103 align => +1, text => $label, tooltip => "#stat_$label",
64 )); 104 ));
81 121
82 my $ns = $pl->ns; 122 my $ns = $pl->ns;
83 123
84 return unless $ns->{can_widget}; 124 return unless $ns->{can_widget};
85 125
126 demo_map $ns;
86 csc_start $ns; 127 #csc_start $ns;
87 }, 128 },
88); 129);
89 130
90cf::register_exticmd w_e => sub { 131cf::register_exticmd w_e => sub {
91 my ($ns, $pkt) = @_; 132 my ($ns, $pkt) = @_;
146sub msg { 187sub msg {
147 my ($self, $type, %msg) = @_; 188 my ($self, $type, %msg) = @_;
148 189
149 if (my $ns = shift->{ns}) { 190 if (my $ns = shift->{ns}) {
150 $msg{msgtype} = $type; 191 $msg{msgtype} = $type;
151 $ns->send_packet ("ext " . cf::to_json \%msg); 192 $ns->send_packet ("ext " . $ns->{json_coder}->encode (\%msg));
152 } 193 }
153} 194}
154 195
155sub new { 196sub new {
156 my ($self, $class, %args) = @_; 197 my ($self, $class, %args) = @_;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines