… | |
… | |
14 | |
14 | |
15 | cf::client->attach ( |
15 | cf::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 | |
|
|
29 | sub 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 | |
|
|
37 | sub 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; |
|
|
65 | } |
|
|
66 | |
|
|
67 | sub csc_start { |
|
|
68 | my ($ns) = @_; |
|
|
69 | |
|
|
70 | my $ws = $ns->{csc} = $ns->new_widgetset; |
|
|
71 | |
|
|
72 | my $w = $ws->new (Toplevel => |
|
|
73 | min_w => 600, |
|
|
74 | min_h => 400, |
|
|
75 | x => "center", |
|
|
76 | y => "center", |
|
|
77 | title => "Character Creation", |
|
|
78 | has_close_button => 1, |
|
|
79 | on_delete => sub { |
|
|
80 | $ws->destroy; |
|
|
81 | }, |
|
|
82 | ); |
|
|
83 | |
|
|
84 | $w->add (my $ntb = $ws->new (Notebook => expand => 1)); |
|
|
85 | |
|
|
86 | $ntb->add (Statistics => (my $stats = $ws->new (Table => expand => 1)), "Basic statistics of your new character"); |
|
|
87 | |
|
|
88 | $stats->add (0, 0, (my $statstable = $ws->new ("Table"))); |
|
|
89 | |
|
|
90 | for ( |
|
|
91 | [0, "Str"], |
|
|
92 | [1, "Dex"], |
|
|
93 | [2, "Con"], |
|
|
94 | [3, "Int"], |
|
|
95 | [4, "Wis"], |
|
|
96 | [5, "Pow"], |
|
|
97 | [6, "Cha"], |
|
|
98 | ) { |
|
|
99 | my ($x, $label) = @$_; |
|
|
100 | |
|
|
101 | $statstable->add ($x, 0, $ws->new (Label => |
|
|
102 | can_hover => 1, can_events => 1, |
|
|
103 | align => +1, text => $label, tooltip => "#stat_$label", |
|
|
104 | )); |
|
|
105 | $statstable->add ($x, 1, $ws->{stat}{$label} = $ws->new (Label => |
|
|
106 | can_hover => 1, can_events => 1, |
|
|
107 | align => +1, template => "88", tooltip => "#stat_$label", |
|
|
108 | )); |
|
|
109 | } |
|
|
110 | |
|
|
111 | csc_update_stats $ns; |
|
|
112 | |
|
|
113 | $w->show; |
|
|
114 | } |
22 | |
115 | |
23 | cf::player->attach ( |
116 | cf::player->attach ( |
24 | on_login => sub { |
117 | on_login => sub { |
25 | my ($pl) = @_; |
118 | my ($pl) = @_; |
26 | |
119 | |
27 | #DEMO CODE |
120 | return unless $cf::CFG{devel}; |
28 | return unless $pl->ob->name eq "schmorp"; |
|
|
29 | |
121 | |
30 | my $ns = $pl->ns; |
122 | my $ns = $pl->ns; |
31 | |
123 | |
32 | return unless $ns->{can_widgetx}; |
124 | return unless $ns->{can_widget}; |
33 | |
125 | |
34 | my $ws = $ns->new_widgetset; |
126 | demo_map $ns; |
35 | |
127 | #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 | }, |
128 | }, |
65 | ); |
129 | ); |
66 | |
130 | |
67 | cf::register_exticmd w_e => sub { |
131 | cf::register_exticmd w_e => sub { |
68 | my ($ns, $pkt) = @_; |
132 | my ($ns, $pkt) = @_; |
… | |
… | |
123 | sub msg { |
187 | sub msg { |
124 | my ($self, $type, %msg) = @_; |
188 | my ($self, $type, %msg) = @_; |
125 | |
189 | |
126 | if (my $ns = shift->{ns}) { |
190 | if (my $ns = shift->{ns}) { |
127 | $msg{msgtype} = $type; |
191 | $msg{msgtype} = $type; |
128 | $ns->send_packet ("ext " . cf::to_json \%msg); |
192 | $ns->send_packet ("ext " . $ns->{json_coder}->encode (\%msg)); |
129 | } |
193 | } |
130 | } |
194 | } |
131 | |
195 | |
132 | sub new { |
196 | sub new { |
133 | my ($self, $class, %args) = @_; |
197 | my ($self, $class, %args) = @_; |