… | |
… | |
21 | |
21 | |
22 | my $self = $class->SUPER::new (%arg, |
22 | my $self = $class->SUPER::new (%arg, |
23 | setup_req => { |
23 | setup_req => { |
24 | extmap => 1, |
24 | extmap => 1, |
25 | excmd => 1, |
25 | excmd => 1, |
26 | xwidget => 1, |
26 | ywidget => 1, |
27 | %{$arg{setup_req} || {}}, |
27 | %{$arg{setup_req} || {}}, |
28 | }, |
28 | }, |
29 | ); |
29 | ); |
30 | |
30 | |
31 | $self->{map_widget}->clr_commands; |
31 | $self->{map_widget}->clr_commands; |
… | |
… | |
48 | sort { (length $a) <=> (length $b) } |
48 | sort { (length $a) <=> (length $b) } |
49 | @args |
49 | @args |
50 | } sort { $a->{par} <=> $b->{par} } |
50 | } sort { $a->{par} <=> $b->{par} } |
51 | CFPlus::Pod::find command => "*"; |
51 | CFPlus::Pod::find command => "*"; |
52 | |
52 | |
|
|
53 | $self->connect_ext (event_music => sub { |
|
|
54 | my ($ev) = @_; |
|
|
55 | |
|
|
56 | return unless $::CFG->{bgm_enable}; |
|
|
57 | |
|
|
58 | my $faces = $ev->{faces}; |
|
|
59 | my @songs; |
|
|
60 | |
|
|
61 | # request music from server if appropriate |
|
|
62 | if (my $faces = $ev->{faces}) { |
|
|
63 | for (@$faces) { |
|
|
64 | my ($face, $pri, $chksum) = @$_; |
|
|
65 | utf8::downgrade $chksum; |
|
|
66 | |
|
|
67 | $chksum = unpack "H*", $chksum; |
|
|
68 | $self->{music_map}{$face} = $chksum; |
|
|
69 | |
|
|
70 | # check if already cached |
|
|
71 | CFPlus::DB::get resmap => $chksum, sub { |
|
|
72 | my ($meta) = @_; |
|
|
73 | |
|
|
74 | if (defined $meta) { |
|
|
75 | $self->{music_meta}{$chksum} = $self->{json_coder}->decode ($meta); |
|
|
76 | } else { |
|
|
77 | ::message ({ markup => "starting to download song #$face/$pri, check your output-rate setting if your connection gets laggy." }); |
|
|
78 | $self->ask_face ($face, -100 - $pri, undef, sub { |
|
|
79 | my $len = length $_[1]; |
|
|
80 | my ($meta, $data) = unpack "(w/a*)*", $_[1]; |
|
|
81 | |
|
|
82 | CFPlus::DB::write_file $chksum, $data, sub { }; |
|
|
83 | CFPlus::DB::put resmap => $chksum => $meta, sub { }; |
|
|
84 | |
|
|
85 | $self->{music_meta}{$chksum} = $self->{json_coder}->decode ($meta); |
|
|
86 | ::message ({ markup => "downloaded song #$face, size $len octets" }); |
|
|
87 | |
|
|
88 | &::audio_music_set ($self->{songs}); |
|
|
89 | }); |
|
|
90 | } |
|
|
91 | } |
|
|
92 | } |
|
|
93 | } |
|
|
94 | |
|
|
95 | if (my $play = $ev->{play}) { |
|
|
96 | &::audio_music_set ($self->{songs} = [map $self->{music_map}{$_}, @$play]); |
|
|
97 | use Data::Dumper; |
|
|
98 | warn Dumper $self->{songs};#d# |
|
|
99 | } |
|
|
100 | }); |
|
|
101 | |
53 | $self->connect_ext (event_capabilities => sub { |
102 | $self->connect_ext (event_capabilities => sub { |
54 | my ($cap) = @_; |
103 | my ($cap) = @_; |
55 | |
104 | |
56 | if (my $ts = $cap->{tileset}) { |
105 | if (my $ts = $cap->{tileset}) { |
57 | if (my ($default) = grep $_->[2] & 1, @$ts) { |
106 | if (my ($default) = grep $_->[2] & 1, @$ts) { |
… | |
… | |
65 | $self->setup_req (mapsize => "${w}x${h}"); |
114 | $self->setup_req (mapsize => "${w}x${h}"); |
66 | } |
115 | } |
67 | } |
116 | } |
68 | }); |
117 | }); |
69 | |
118 | |
|
|
119 | $self->{json_coder} |
|
|
120 | ->convert_blessed |
|
|
121 | ->filter_json_single_key_object (__widget_ref__ => sub { |
|
|
122 | $self->{widget}{$_[0]} |
|
|
123 | }); |
|
|
124 | |
70 | $self->connect_ext (ws_n => sub { |
125 | $self->connect_ext (ws_n => sub { |
71 | my ($arg) = @_; |
126 | my ($arg) = @_; |
72 | |
127 | |
73 | $self->{widgetset}{$arg{id}} = { |
128 | $self->{widgetset}{$arg{id}} = { |
74 | w => {}, |
129 | w => {}, |
… | |
… | |
98 | 1 |
153 | 1 |
99 | }; |
154 | }; |
100 | } |
155 | } |
101 | |
156 | |
102 | if (my $widget = eval { |
157 | if (my $widget = eval { |
|
|
158 | local $SIG{__DIE__}; |
103 | "CFPlus::UI::$arg->{class}"->new ( |
159 | "CFPlus::UI::$arg->{class}"->new ( |
104 | %$args, |
160 | %$args, |
105 | s_ws => $arg->{ws}, |
161 | s_ws => $arg->{ws}, |
106 | s_id => $arg->{id}, |
162 | s_id => $arg->{id}, |
107 | ) |
163 | ) |
… | |
… | |
128 | |
184 | |
129 | my $w = $self->{widget}{$arg->{id}} |
185 | my $w = $self->{widget}{$arg->{id}} |
130 | or return; |
186 | or return; |
131 | my $m = $arg->{name}; |
187 | my $m = $arg->{name}; |
132 | |
188 | |
133 | my @a = map { |
|
|
134 | "HASH" eq ref && 1 == (scalar keys %$_) && exists $_->{__widget_ref__} |
|
|
135 | ? $self->{widget}{$_->{__widget_ref__}} |
|
|
136 | : $_ |
|
|
137 | } @{ $arg->{args} || [] }; |
189 | my $a = $arg->{args} || []; |
138 | |
190 | |
139 | if (exists $arg->{rid}) { |
191 | if (exists $arg->{rid}) { |
140 | $self->send_exti_msg (w_r => rid => $arg->{rid}, res => [$w->$m (@a)]); |
192 | $self->send_exti_msg (w_r => rid => $arg->{rid}, res => [$w->$m (@$a)]); |
141 | } else { |
193 | } else { |
142 | $w->$m (@a); |
194 | $w->$m (@$a); |
143 | } |
195 | } |
144 | }); |
196 | }); |
145 | |
197 | |
146 | $self->connect_ext (w_s => sub { |
198 | $self->connect_ext (w_s => sub { |
147 | my ($arg) = @_; |
199 | my ($arg) = @_; |
… | |
… | |
1129 | |
1181 | |
1130 | (delete $self->{npc_dialog})->destroy |
1182 | (delete $self->{npc_dialog})->destroy |
1131 | if $self->{npc_dialog}; |
1183 | if $self->{npc_dialog}; |
1132 | |
1184 | |
1133 | $self->SUPER::destroy; |
1185 | $self->SUPER::destroy; |
|
|
1186 | |
|
|
1187 | %$self = (); |
1134 | } |
1188 | } |
1135 | |
1189 | |
1136 | package CFPlus::NPCDialog; |
1190 | package CFPlus::NPCDialog; |
1137 | |
1191 | |
1138 | our @ISA = 'CFPlus::UI::Toplevel'; |
1192 | our @ISA = 'CFPlus::UI::Toplevel'; |