… | |
… | |
144 | our $SETUP_KEYBOARD; |
144 | our $SETUP_KEYBOARD; |
145 | |
145 | |
146 | our $PL_NOTEBOOK; |
146 | our $PL_NOTEBOOK; |
147 | our $PL_WINDOW; |
147 | our $PL_WINDOW; |
148 | |
148 | |
|
|
149 | our $MUSIC_PLAYING_WIDGET; |
|
|
150 | our $LICENSE_WIDGET; |
|
|
151 | |
149 | our $INVENTORY_PAGE; |
152 | our $INVENTORY_PAGE; |
150 | our $STATS_PAGE; |
153 | our $STATS_PAGE; |
151 | our $SKILL_PAGE; |
154 | our $SKILL_PAGE; |
152 | our $SPELL_PAGE; |
155 | our $SPELL_PAGE; |
153 | our $SPELL_LIST; |
156 | our $SPELL_LIST; |
… | |
… | |
159 | our $STATWIDS; |
162 | our $STATWIDS; |
160 | |
163 | |
161 | our $SDL_ACTIVE; |
164 | our $SDL_ACTIVE; |
162 | our %SDL_CB; |
165 | our %SDL_CB; |
163 | |
166 | |
|
|
167 | our $ALT_ENTER_MESSAGE; |
|
|
168 | our $STATUSBOX; |
|
|
169 | our $DEBUG_STATUS; |
|
|
170 | |
|
|
171 | our $INV; |
|
|
172 | our $INVR; |
|
|
173 | our $INV_RIGHT_HB; |
|
|
174 | |
|
|
175 | our $PICKUP_CFG; |
|
|
176 | |
|
|
177 | ############################################################################# |
|
|
178 | |
|
|
179 | sub status { |
|
|
180 | $STATUSBOX->add (CFPlus::asxml $_[0], pri => -10, group => "status", timeout => 10, fg => [1, 1, 0, 1]); |
|
|
181 | } |
|
|
182 | |
|
|
183 | sub debug { |
|
|
184 | $DEBUG_STATUS->set_text ($_[0]); |
|
|
185 | } |
|
|
186 | |
|
|
187 | sub message { |
|
|
188 | my ($para) = @_; |
|
|
189 | $MESSAGE_WINDOW->message ($para); |
|
|
190 | } |
|
|
191 | |
|
|
192 | ############################################################################# |
|
|
193 | #TODO: maybe move into own audio module... |
|
|
194 | |
164 | our $SDL_MIXER; |
195 | our $SDL_MIXER; |
|
|
196 | |
165 | our $MUSIC_DEFAULT = "in_a_heartbeat.ogg"; |
197 | our $MUSIC_DEFAULT = "in_a_heartbeat.ogg"; |
166 | our $MUSIC_WANT; # arryref of ambient music |
198 | our $MUSIC_WANT; # arryref of ambient music we want to play |
167 | our @MUSIC_HAVE; # ambient music we want now |
199 | our @MUSIC_HAVE; # ambient music we have on disk |
168 | our $MUSIC_START; |
200 | our $MUSIC_START; |
|
|
201 | our @MUSIC_JINGLE; # which jingles to play next |
169 | our $MUSIC_PLAYING_DATA; |
202 | our $MUSIC_PLAYING_DATA; |
170 | our $MUSIC_PLAYING_META; |
203 | our $MUSIC_PLAYING_META; |
171 | our $MUSIC_PLAYER; |
204 | our $MUSIC_PLAYER; |
172 | our $MUSIC_RESUME = 30; # resume music when players less than these many seconds before |
205 | our $MUSIC_RESUME = 30; # resume music when played less than these many seconds before |
173 | our @SOUNDS; # event => file mapping |
206 | |
174 | our %AUDIO_CHUNK; # audio files |
207 | our %AUDIO_CHUNK; # audio "files" |
175 | |
208 | our %AUDIO_PLAY; # which audio faces should be played |
176 | our $ALT_ENTER_MESSAGE; |
|
|
177 | our $STATUSBOX; |
|
|
178 | our $DEBUG_STATUS; |
|
|
179 | |
|
|
180 | our $INV; |
|
|
181 | our $INVR; |
|
|
182 | our $INV_RIGHT_HB; |
|
|
183 | |
|
|
184 | our $PICKUP_CFG; |
|
|
185 | |
|
|
186 | ############################################################################# |
|
|
187 | #TODO: maybe move into own audio module... |
|
|
188 | |
209 | |
189 | sub audio_channel_finished { |
210 | sub audio_channel_finished { |
190 | my ($channel) = @_; |
211 | my ($channel) = @_; |
191 | |
212 | |
192 | # warn "channel $channel finished\n";#d# |
213 | # warn "channel $channel finished\n";#d# |
193 | } |
214 | } |
194 | |
215 | |
195 | our %AUDIO_PLAY; |
|
|
196 | our %AUDIO_CHUNK; |
|
|
197 | |
|
|
198 | sub audio_sound_push($) { |
216 | sub audio_sound_push($) { |
199 | my ($face) = @_; |
217 | my ($face) = @_; |
|
|
218 | |
|
|
219 | $CFG->{effects_enable} |
|
|
220 | or return; |
200 | |
221 | |
201 | if (my $chunk = $AUDIO_CHUNK{$face}) { |
222 | if (my $chunk = $AUDIO_CHUNK{$face}) { |
202 | for (grep $_->[0] >= Event::time, @{(delete $AUDIO_PLAY{$face}) || []}) { |
223 | for (grep $_->[0] >= Event::time, @{(delete $AUDIO_PLAY{$face}) || []}) { |
203 | my (undef, $dx, $dy, $vol) = @$_; |
224 | my (undef, $dx, $dy, $vol) = @$_; |
204 | |
225 | |
205 | my $channel = CFPlus::Channel::find; |
226 | my $channel = CFPlus::Channel::find; |
206 | $channel->volume ($vol * 128 / 255); |
227 | $channel->volume ($vol * $CFG->{effects_volume} * 128 / 255); |
207 | $dx = $dx / 10 * 255; |
228 | $dx = $dx / 10 * 255; |
208 | $channel->set_panning (255 - $dx, 255 + $dx); |
229 | $channel->set_panning (255 - $dx, 255 + $dx); |
209 | |
230 | |
210 | # my $angle = $dx ? : $dx < 0 ? |
231 | # my $angle = $dx ? : $dx < 0 ? |
211 | # my $distance = -$vol; |
232 | # my $distance = -$vol; |
… | |
… | |
216 | } else { |
237 | } else { |
217 | # sound_meta not set means data is in flight either way |
238 | # sound_meta not set means data is in flight either way |
218 | my $meta = $CONN->{sound_meta}{$face} |
239 | my $meta = $CONN->{sound_meta}{$face} |
219 | or return; |
240 | or return; |
220 | |
241 | |
|
|
242 | # if its a jingle, play it as ambient music |
|
|
243 | if ($meta->{meta}{jingle}) { |
|
|
244 | if (delete $AUDIO_PLAY{$face}) { # take the jingle out of the sound queue |
|
|
245 | push @MUSIC_JINGLE, $meta; # push it oto the music/jingle queue |
|
|
246 | &audio_music_push ($face); |
|
|
247 | } |
|
|
248 | } else { |
221 | # fetch from database |
249 | # fetch from database |
222 | CFPlus::DB::get res_data => $meta->{name}, sub { |
250 | CFPlus::DB::get res_data => $meta->{name}, sub { |
223 | my $rwops = new CFPlus::RW $_[0]; |
251 | my $rwops = new CFPlus::RW $_[0]; |
224 | my $chunk = new CFPlus::MixChunk $rwops; |
252 | my $chunk = new CFPlus::MixChunk $rwops |
|
|
253 | or Carp::confess "sound face $meta->{face} unloadable: " . CFPlus::Mix_GetError; |
225 | $chunk->volume (($meta->{meta}{volume} || 1) * 128); |
254 | $chunk->volume (($meta->{meta}{volume} || 1) * 128); |
226 | $AUDIO_CHUNK{$face} = $chunk; |
255 | $AUDIO_CHUNK{$face} = $chunk; |
227 | |
256 | |
228 | audio_sound_push ($face); |
257 | audio_sound_push ($face); |
|
|
258 | }; |
229 | }; |
259 | } |
230 | } |
260 | } |
231 | } |
261 | } |
232 | |
262 | |
233 | sub audio_sound_play { |
263 | sub audio_sound_play { |
234 | my ($face, $dx, $dy, $vol) = @_; |
264 | my ($face, $dx, $dy, $vol) = @_; |
235 | |
265 | |
236 | $SDL_MIXER |
266 | $SDL_MIXER |
|
|
267 | or return; |
|
|
268 | $CFG->{effects_enable} |
237 | or return; |
269 | or return; |
238 | |
270 | |
239 | my $queue = $AUDIO_PLAY{$face} ||= []; |
271 | my $queue = $AUDIO_PLAY{$face} ||= []; |
240 | push @$queue, [Event::time + 0.2, $dx, $dy, $vol]; # delay sound by max. 0.2s |
272 | push @$queue, [Event::time + 0.2, $dx, $dy, $vol]; # delay sound by max. 0.2s |
241 | audio_sound_push $face |
273 | audio_sound_push $face |
242 | unless @$queue > 1; |
274 | unless @$queue > 1; |
243 | } |
275 | } |
244 | |
276 | |
|
|
277 | sub audio_music_set_meta { |
|
|
278 | my ($meta) = @_; |
|
|
279 | |
|
|
280 | $MUSIC_PLAYING_META = $meta; |
|
|
281 | $MUSIC_PLAYING_WIDGET->set_markup ( |
|
|
282 | "<b>Name</b>: " . (CFPlus::asxml $meta->{meta}{name}) . "\n" |
|
|
283 | . "<b>Author</b>: " . (CFPlus::asxml $meta->{meta}{author}) . "\n" |
|
|
284 | . "<b>Source</b>: " . (CFPlus::asxml $meta->{meta}{source}) . "\n" |
|
|
285 | . "<b>License</b>: " . (CFPlus::asxml $meta->{meta}{license}) |
|
|
286 | ); |
|
|
287 | } |
|
|
288 | |
245 | sub audio_music_update_volume { |
289 | sub audio_music_update_volume { |
246 | return unless $MUSIC_PLAYING_META; |
290 | return unless $MUSIC_PLAYING_META; |
247 | my $volume = $MUSIC_PLAYING_META->{meta}{volume} || 1; |
291 | my $volume = $MUSIC_PLAYING_META->{meta}{volume} || 1; |
248 | my $base = $CFG->{bgm_volume}; |
292 | my $base = $MUSIC_PLAYING_META->{meta}{jingle} ? 1 : $CFG->{bgm_volume}; |
249 | CFPlus::MixMusic::volume $base * $volume * 128; |
293 | CFPlus::MixMusic::volume $base * $volume * 128; |
250 | } |
|
|
251 | |
|
|
252 | sub audio_music_push { |
|
|
253 | my @have = |
|
|
254 | grep $_, |
|
|
255 | map $CONN->{music_meta}{$_}, |
|
|
256 | @$MUSIC_WANT; |
|
|
257 | |
|
|
258 | if (@have) { |
|
|
259 | @MUSIC_HAVE = @have; |
|
|
260 | &audio_music_changed (); |
|
|
261 | } |
|
|
262 | } |
|
|
263 | |
|
|
264 | sub audio_music_set_ambient { |
|
|
265 | my ($songs) = @_; |
|
|
266 | |
|
|
267 | $MUSIC_WANT = $songs; |
|
|
268 | |
|
|
269 | audio_music_push; |
|
|
270 | } |
294 | } |
271 | |
295 | |
272 | sub audio_music_start { |
296 | sub audio_music_start { |
273 | my $meta = $MUSIC_PLAYING_META; |
297 | my $meta = $MUSIC_PLAYING_META; |
274 | |
298 | |
… | |
… | |
286 | my $rwops = $meta->{path} |
310 | my $rwops = $meta->{path} |
287 | ? new_from_file CFPlus::RW $meta->{path} |
311 | ? new_from_file CFPlus::RW $meta->{path} |
288 | : new CFPlus::RW $$MUSIC_PLAYING_DATA; |
312 | : new CFPlus::RW $$MUSIC_PLAYING_DATA; |
289 | |
313 | |
290 | $MUSIC_PLAYER = new CFPlus::MixMusic $rwops |
314 | $MUSIC_PLAYER = new CFPlus::MixMusic $rwops |
291 | or ((warn CFPlus::Mix_GetError), return); # pretty fatal error |
315 | or Carp::confess "music face $meta->{face} unloadable: " . CFPlus::Mix_GetError; |
292 | |
316 | |
293 | my $NOW = time; |
317 | my $NOW = time; |
294 | |
318 | |
295 | if ($MUSIC_PLAYING_META->{stop_time} > $NOW - $MUSIC_RESUME) { |
319 | if ($MUSIC_PLAYING_META->{stop_time} > $NOW - $MUSIC_RESUME) { |
296 | my $pos = $MUSIC_PLAYING_META->{stop_pos}; |
320 | my $pos = $MUSIC_PLAYING_META->{stop_pos}; |
… | |
… | |
299 | } else { |
323 | } else { |
300 | $MUSIC_PLAYER->play (0); |
324 | $MUSIC_PLAYER->play (0); |
301 | $MUSIC_START = time; |
325 | $MUSIC_START = time; |
302 | } |
326 | } |
303 | |
327 | |
304 | delete $MUSIC_PLAYING_META->{stop_time}; |
328 | delete $meta->{stop_time}; |
305 | delete $MUSIC_PLAYING_META->{stop_pos}; |
329 | delete $meta->{stop_pos}; |
306 | } |
330 | } |
307 | } |
331 | } |
308 | |
332 | |
309 | sub audio_music_changed { |
333 | sub audio_music_push { |
310 | return unless $CFG->{bgm_enable}; |
|
|
311 | return unless $SDL_MIXER; |
334 | return unless $SDL_MIXER; |
312 | |
335 | |
|
|
336 | my $fade_out; |
|
|
337 | |
|
|
338 | if (@MUSIC_JINGLE) { |
|
|
339 | @MUSIC_HAVE = $MUSIC_JINGLE[0]; |
|
|
340 | $fade_out = 333; |
|
|
341 | } else { |
|
|
342 | return unless $CFG->{bgm_enable}; |
|
|
343 | |
|
|
344 | my @have = |
|
|
345 | grep $_, |
|
|
346 | map $CONN->{music_meta}{$_}, |
|
|
347 | @$MUSIC_WANT; |
|
|
348 | |
|
|
349 | @MUSIC_HAVE = @have |
|
|
350 | if @have; |
|
|
351 | |
313 | # default MUSIC_HAVE == MUSIC_DEFAULT |
352 | # default MUSIC_HAVE == MUSIC_DEFAULT |
314 | @MUSIC_HAVE = { path => CFPlus::find_rcfile "music/$MUSIC_DEFAULT" } unless @MUSIC_HAVE; |
353 | @MUSIC_HAVE = { path => CFPlus::find_rcfile "music/$MUSIC_DEFAULT" } unless @MUSIC_HAVE; |
|
|
354 | $fade_out = 1000; |
|
|
355 | } |
315 | |
356 | |
316 | # if the currently playing song is acceptable, let it continue |
357 | # if the currently playing song is acceptable, let it continue |
317 | return if $MUSIC_PLAYING_META |
|
|
318 | && grep $MUSIC_PLAYING_META == $_, @MUSIC_HAVE; |
358 | return if grep $MUSIC_PLAYING_META == $_, @MUSIC_HAVE; |
319 | |
359 | |
320 | my $NOW = time; |
360 | my $NOW = time; |
321 | |
361 | |
322 | if ($MUSIC_PLAYING_META) { |
362 | if ($MUSIC_PLAYING_META) { |
323 | $MUSIC_PLAYING_META->{stop_time} = $NOW; |
363 | $MUSIC_PLAYING_META->{stop_time} = $NOW; |
324 | $MUSIC_PLAYING_META->{stop_pos} = $NOW - $MUSIC_START; |
364 | $MUSIC_PLAYING_META->{stop_pos} = $NOW - $MUSIC_START; |
325 | CFPlus::MixMusic::fade_out 1000; |
365 | CFPlus::MixMusic::fade_out $fade_out; |
326 | } else { |
366 | } else { |
327 | # sort by stop time, oldest first |
367 | # sort by stop time, oldest first |
328 | @MUSIC_HAVE = sort { $a->{stop_time} <=> $b->{stop_time} } @MUSIC_HAVE; |
368 | @MUSIC_HAVE = sort { $a->{stop_time} <=> $b->{stop_time} } @MUSIC_HAVE; |
329 | |
369 | |
330 | # if the most recently-played piece played very recently, |
370 | # if the most recently-played piece played very recently, |
331 | # resume it, else choose the oldest piece for rotation. |
371 | # resume it, else choose the oldest piece for rotation. |
332 | $MUSIC_PLAYING_META = |
372 | audio_music_set_meta |
333 | $MUSIC_HAVE[-1]{stop_time} > $NOW - $MUSIC_RESUME |
373 | $MUSIC_HAVE[-1]{stop_time} > $NOW - $MUSIC_RESUME |
334 | ? $MUSIC_HAVE[-1] |
374 | ? $MUSIC_HAVE[-1] |
335 | : $MUSIC_HAVE[0]; |
375 | : $MUSIC_HAVE[0]; |
336 | |
376 | |
337 | audio_music_start; |
377 | audio_music_start; |
338 | } |
378 | } |
339 | } |
379 | } |
340 | |
380 | |
|
|
381 | sub audio_music_set_ambient { |
|
|
382 | my ($songs) = @_; |
|
|
383 | |
|
|
384 | $MUSIC_WANT = $songs; |
|
|
385 | audio_music_push; |
|
|
386 | } |
|
|
387 | |
341 | sub audio_music_finished { |
388 | sub audio_music_finished { |
|
|
389 | # we compress multiple jingles of the same type |
|
|
390 | shift @MUSIC_JINGLE |
|
|
391 | while @MUSIC_JINGLE && $MUSIC_PLAYING_META == $MUSIC_JINGLE[0]; |
|
|
392 | |
|
|
393 | $MUSIC_PLAYING_WIDGET->clear; |
|
|
394 | |
342 | undef $MUSIC_PLAYER; |
395 | undef $MUSIC_PLAYER; |
343 | undef $MUSIC_PLAYING_META; |
396 | undef $MUSIC_PLAYING_META; |
344 | undef $MUSIC_PLAYING_DATA; |
397 | undef $MUSIC_PLAYING_DATA; |
345 | |
398 | |
346 | audio_music_changed; |
399 | audio_music_push; |
|
|
400 | } |
|
|
401 | |
|
|
402 | sub audio_init { |
|
|
403 | if ($CFG->{audio_enable}) { |
|
|
404 | $ENV{MIX_EFFECTSMAXSPEED} = 1; |
|
|
405 | $SDL_MIXER = !CFPlus::Mix_OpenAudio; |
|
|
406 | |
|
|
407 | unless ($SDL_MIXER) { |
|
|
408 | status "Unable to open sound device: there will be no sound"; |
|
|
409 | return; |
|
|
410 | } |
|
|
411 | |
|
|
412 | CFPlus::Mix_AllocateChannels 16; |
|
|
413 | |
|
|
414 | audio_music_finished; |
|
|
415 | } else { |
|
|
416 | undef $SDL_MIXER; |
|
|
417 | } |
|
|
418 | } |
|
|
419 | |
|
|
420 | sub audio_shutdown { |
|
|
421 | undef $MUSIC_PLAYER; |
|
|
422 | undef $MUSIC_PLAYING_META; |
|
|
423 | undef $MUSIC_PLAYING_DATA; |
|
|
424 | |
|
|
425 | $MUSIC_WANT = []; |
|
|
426 | @MUSIC_JINGLE = (); |
|
|
427 | %AUDIO_PLAY = (); |
|
|
428 | %AUDIO_CHUNK = (); |
|
|
429 | |
|
|
430 | CFPlus::Mix_CloseAudio if $SDL_MIXER; |
|
|
431 | undef $SDL_MIXER; |
347 | } |
432 | } |
348 | |
433 | |
349 | ############################################################################# |
434 | ############################################################################# |
350 | |
|
|
351 | sub status { |
|
|
352 | $STATUSBOX->add (CFPlus::asxml $_[0], pri => -10, group => "status", timeout => 10, fg => [1, 1, 0, 1]); |
|
|
353 | } |
|
|
354 | |
|
|
355 | sub debug { |
|
|
356 | $DEBUG_STATUS->set_text ($_[0]); |
|
|
357 | } |
|
|
358 | |
|
|
359 | sub message { |
|
|
360 | my ($para) = @_; |
|
|
361 | $MESSAGE_WINDOW->message ($para); |
|
|
362 | } |
|
|
363 | |
435 | |
364 | sub destroy_query_dialog { |
436 | sub destroy_query_dialog { |
365 | (delete $_[0]{query_dialog})->destroy |
437 | (delete $_[0]{query_dialog})->destroy |
366 | if $_[0]{query_dialog}; |
438 | if $_[0]{query_dialog}; |
367 | } |
439 | } |
… | |
… | |
790 | } |
862 | } |
791 | |
863 | |
792 | sub audio_setup { |
864 | sub audio_setup { |
793 | my $vbox = new CFPlus::UI::VBox; |
865 | my $vbox = new CFPlus::UI::VBox; |
794 | |
866 | |
795 | $vbox->add (my $table = new CFPlus::UI::Table expand => 1, col_expand => [0, 1]); |
867 | $vbox->add (my $table = new CFPlus::UI::Table expand => 1, col_expand => [0, 0, 1]); |
796 | |
868 | |
797 | my $row = 0; |
869 | my $row = 0; |
798 | |
870 | |
799 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Audio Enable"); |
871 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Audio Enable"); |
800 | $table->add_at (1, $row++, new CFPlus::UI::CheckBox |
872 | $table->add_at (1, $row++, new CFPlus::UI::CheckBox |
… | |
… | |
804 | ); |
876 | ); |
805 | # $table->add_at (0, 9, new CFPlus::UI::Label valign => 0, align => 1, text => "Effects Volume"); |
877 | # $table->add_at (0, 9, new CFPlus::UI::Label valign => 0, align => 1, text => "Effects Volume"); |
806 | # $table->add_at (1, 8, new CFPlus::UI::Slider range => [$CFG->{effects_volume}, 0, 128, 1], on_changed => sub { |
878 | # $table->add_at (1, 8, new CFPlus::UI::Slider range => [$CFG->{effects_volume}, 0, 128, 1], on_changed => sub { |
807 | # $CFG->{effects_volume} = $_[1]; |
879 | # $CFG->{effects_volume} = $_[1]; |
808 | # }); |
880 | # }); |
|
|
881 | |
|
|
882 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Effects Volume"); |
|
|
883 | $table->add_at (1, $row, new CFPlus::UI::CheckBox |
|
|
884 | expand => 1, state => $CFG->{effects_enable}, |
|
|
885 | tooltip => "If enabled, sound effects are enabled. If disabled, no sound effects will be played.", |
|
|
886 | on_changed => sub { $CFG->{effects_enable} = $_[1]; 0 } |
|
|
887 | ); |
|
|
888 | $table->add_at (2, $row++, new CFPlus::UI::Slider |
|
|
889 | expand => 1, range => [$CFG->{effects_volume}, 0, 1, 0, 1/128], |
|
|
890 | tooltip => "The relative volume of sound effects. Best audio quality is achieved if this " |
|
|
891 | . "is set highest and you use your operating system volume setting. Changes are instant.", |
|
|
892 | on_changed => sub { $CFG->{effects_volume} = $_[1]; 0 } |
|
|
893 | ); |
|
|
894 | |
809 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Background Music"); |
895 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Background Music"); |
810 | $table->add_at (1, $row++, my $hbox = new CFPlus::UI::HBox); |
896 | $table->add_at (1, $row, new CFPlus::UI::CheckBox |
811 | $hbox->add (new CFPlus::UI::CheckBox |
|
|
812 | expand => 1, state => $CFG->{bgm_enable}, |
897 | expand => 1, state => $CFG->{bgm_enable}, |
813 | tooltip => "If enabled, playing of background music is enabled. If disabled, no background music will be played.", |
898 | tooltip => "If enabled, playing of background music is enabled. If disabled, no background music will be played.", |
814 | on_changed => sub { $CFG->{bgm_enable} = $_[1]; 0 } |
899 | on_changed => sub { $CFG->{bgm_enable} = $_[1]; 0 } |
815 | ); |
900 | ); |
816 | $hbox->add (new CFPlus::UI::Slider |
901 | $table->add_at (2, $row++, new CFPlus::UI::Slider |
817 | expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0, 1/128], |
902 | expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0, 1/128], |
818 | tooltip => "The volume of the background music. Changes are instant.", |
903 | tooltip => "The volume of the background music. Changes are instant.", |
819 | on_changed => sub { $CFG->{bgm_volume} = $_[1]; audio_music_update_volume; 0 } |
904 | on_changed => sub { $CFG->{bgm_volume} = $_[1]; audio_music_update_volume; 0 } |
820 | ); |
905 | ); |
821 | |
906 | |
822 | $table->add_at (1, $row++, new CFPlus::UI::Button |
907 | $table->add_at (1, $row++, new CFPlus::UI::Button |
823 | expand => 1, align => 0, text => "Apply", |
908 | c_colspan => 2, expand => 1, align => 0, text => "Apply", |
824 | tooltip => "Apply the audio settings", |
909 | tooltip => "Apply the audio settings", |
825 | on_activate => sub { |
910 | on_activate => sub { |
826 | audio_shutdown (); |
911 | audio_shutdown (); |
827 | audio_init (); |
912 | audio_init (); |
828 | 0 |
913 | 0 |
… | |
… | |
899 | $table->add_at (0, 4, new CFPlus::UI::Button text => "die on click(tm)", on_activate => sub { &CFPlus::debug() } ); |
984 | $table->add_at (0, 4, new CFPlus::UI::Button text => "die on click(tm)", on_activate => sub { &CFPlus::debug() } ); |
900 | |
985 | |
901 | $table->add_at (0, 5, new CFPlus::UI::TextEdit text => "line1\0152\0153");#d# |
986 | $table->add_at (0, 5, new CFPlus::UI::TextEdit text => "line1\0152\0153");#d# |
902 | |
987 | |
903 | $table->add_at (7,7, my $t = new CFPlus::UI::Table expand => 0); |
988 | $table->add_at (7,7, my $t = new CFPlus::UI::Table expand => 0); |
904 | $t->add_at (0,0, new CFPlus::UI::Label text => "a a a a", rowspan => 1, colspan => 2); |
989 | $t->add_at (0,0, new CFPlus::UI::Label text => "a a a a", c_rowspan => 1, c_colspan => 2); |
905 | $t->add_at (2,0, new CFPlus::UI::Label text => "b\nb", rowspan => 2, colspan => 1); |
990 | $t->add_at (2,0, new CFPlus::UI::Label text => "b\nb", c_rowspan => 2, c_colspan => 1); |
906 | $t->add_at (1,2, new CFPlus::UI::Label text => "c c c c", rowspan => 1, colspan => 2); |
991 | $t->add_at (1,2, new CFPlus::UI::Label text => "c c c c", c_rowspan => 1, c_colspan => 2); |
907 | $t->add_at (0,1, new CFPlus::UI::Label text => "d\nd", rowspan => 2, colspan => 1); |
992 | $t->add_at (0,1, new CFPlus::UI::Label text => "d\nd", c_rowspan => 2, c_colspan => 1); |
908 | $t->add_at (1,1, new CFPlus::UI::Label text => "e"); |
993 | $t->add_at (1,1, new CFPlus::UI::Label text => "e"); |
909 | |
994 | |
910 | $table->add_at (7, 6, my $c = new CFPlus::UI::Canvas); |
995 | $table->add_at (7, 6, my $c = new CFPlus::UI::Canvas); |
911 | |
996 | |
912 | $c->add_items ({ |
997 | $c->add_items ({ |
… | |
… | |
1519 | CFPlus::Protocol::set_opencont ($::CONN, 0, "Floor"); |
1604 | CFPlus::Protocol::set_opencont ($::CONN, 0, "Floor"); |
1520 | |
1605 | |
1521 | $hb |
1606 | $hb |
1522 | } |
1607 | } |
1523 | |
1608 | |
|
|
1609 | sub media_window { |
|
|
1610 | my $vb = new CFPlus::UI::VBox; |
|
|
1611 | |
|
|
1612 | $vb->add (new CFPlus::UI::FancyFrame |
|
|
1613 | label => "Currently playing music", |
|
|
1614 | child => new CFPlus::UI::ScrolledWindow scroll_x => 1, scroll_y => 0, |
|
|
1615 | child => ($MUSIC_PLAYING_WIDGET = new CFPlus::UI::Label ellipsise => 0, fontsize => 0.8), |
|
|
1616 | ); |
|
|
1617 | |
|
|
1618 | $vb->add (new CFPlus::UI::FancyFrame |
|
|
1619 | label => "Other media used in this session", |
|
|
1620 | expand => 1, |
|
|
1621 | child => ($LICENSE_WIDGET = new CFPlus::UI::TextScroller |
|
|
1622 | expand => 1, fontsize => 0.8, padding_x => 4, padding_y => 4), |
|
|
1623 | ); |
|
|
1624 | |
|
|
1625 | $vb |
|
|
1626 | } |
|
|
1627 | |
|
|
1628 | sub add_license { |
|
|
1629 | my ($meta) = @_; |
|
|
1630 | |
|
|
1631 | $meta = $meta->{meta} |
|
|
1632 | or return; |
|
|
1633 | |
|
|
1634 | $meta->{license} || $meta->{author} || $meta->{source} |
|
|
1635 | or return; |
|
|
1636 | |
|
|
1637 | $LICENSE_WIDGET->add_paragraph ({ |
|
|
1638 | fg => [1, 1, 1, 1], |
|
|
1639 | markup => "<small>" |
|
|
1640 | . "<b>Name:</b> " . (CFPlus::asxml $meta->{name}) . "\n" |
|
|
1641 | . "<b>Author:</b> " . (CFPlus::asxml $meta->{author}) . "\n" |
|
|
1642 | . "<b>Source:</b> " . (CFPlus::asxml $meta->{source}) . "\n" |
|
|
1643 | . "<b>License:</b> " . (CFPlus::asxml $meta->{license}) . "\n" |
|
|
1644 | . "</small>", |
|
|
1645 | }); |
|
|
1646 | $LICENSE_WIDGET->scroll_to_bottom; |
|
|
1647 | } |
|
|
1648 | |
1524 | sub toggle_player_page { |
1649 | sub toggle_player_page { |
1525 | my ($widget) = @_; |
1650 | my ($widget) = @_; |
1526 | |
1651 | |
1527 | if ($PL_WINDOW->{visible} && $PL_NOTEBOOK->get_current_page == $widget) { |
1652 | if ($PL_WINDOW->{visible} && $PL_NOTEBOOK->get_current_page == $widget) { |
1528 | $PL_WINDOW->hide; |
1653 | $PL_WINDOW->hide; |
… | |
… | |
1565 | $ntb->add_tab ( |
1690 | $ntb->add_tab ( |
1566 | "Inventory (F5)" => $INVENTORY_PAGE = inventory_widget, |
1691 | "Inventory (F5)" => $INVENTORY_PAGE = inventory_widget, |
1567 | "Toggles the inventory window, where you can manage your loot (or treasures :). " |
1692 | "Toggles the inventory window, where you can manage your loot (or treasures :). " |
1568 | . "You can also hit the <b>Tab</b>-key to show/hide the Inventory." |
1693 | . "You can also hit the <b>Tab</b>-key to show/hide the Inventory." |
1569 | ); |
1694 | ); |
1570 | $ntb->add_tab (Pickup => autopickup_setup, |
1695 | $ntb->add_tab (Pickup => autopickup_setup, |
1571 | "Configure autopickup settings, i.e. which items you will pick up automatically when walking (or running) over them."); |
1696 | "Configure autopickup settings, i.e. which items you will pick up automatically when walking (or running) over them."); |
|
|
1697 | |
|
|
1698 | $ntb->add_tab (Media => media_window, |
|
|
1699 | "License, Author and Source info for media sent by the server."); |
1572 | |
1700 | |
1573 | $ntb->set_current_page ($INVENTORY_PAGE); |
1701 | $ntb->set_current_page ($INVENTORY_PAGE); |
1574 | |
1702 | |
1575 | $plwin->add ($ntb); |
1703 | $plwin->add ($ntb); |
1576 | $plwin |
1704 | $plwin |
… | |
… | |
1951 | |
2079 | |
1952 | sub video_shutdown { |
2080 | sub video_shutdown { |
1953 | CFPlus::OpenGL::shutdown; |
2081 | CFPlus::OpenGL::shutdown; |
1954 | |
2082 | |
1955 | undef $SDL_ACTIVE; |
2083 | undef $SDL_ACTIVE; |
1956 | } |
|
|
1957 | |
|
|
1958 | sub audio_init { |
|
|
1959 | if ($CFG->{audio_enable}) { |
|
|
1960 | $ENV{MIX_EFFECTSMAXSPEED} = 1; |
|
|
1961 | $SDL_MIXER = !CFPlus::Mix_OpenAudio; |
|
|
1962 | |
|
|
1963 | unless ($SDL_MIXER) { |
|
|
1964 | status "Unable to open sound device: there will be no sound"; |
|
|
1965 | return; |
|
|
1966 | } |
|
|
1967 | |
|
|
1968 | CFPlus::Mix_AllocateChannels 16; |
|
|
1969 | |
|
|
1970 | audio_music_finished; |
|
|
1971 | } else { |
|
|
1972 | undef $SDL_MIXER; |
|
|
1973 | } |
|
|
1974 | } |
|
|
1975 | |
|
|
1976 | sub audio_shutdown { |
|
|
1977 | CFPlus::Mix_CloseAudio if $SDL_MIXER; |
|
|
1978 | undef $SDL_MIXER; |
|
|
1979 | @SOUNDS = (); |
|
|
1980 | %AUDIO_CHUNK = (); |
|
|
1981 | } |
2084 | } |
1982 | |
2085 | |
1983 | my %animate_object; |
2086 | my %animate_object; |
1984 | my $animate_timer; |
2087 | my $animate_timer; |
1985 | |
2088 | |
… | |
… | |
2089 | gauge_fontsize => 1, |
2192 | gauge_fontsize => 1, |
2090 | gauge_size => 0.35, |
2193 | gauge_size => 0.35, |
2091 | stat_fontsize => 0.7, |
2194 | stat_fontsize => 0.7, |
2092 | mapsize => 100, |
2195 | mapsize => 100, |
2093 | audio_enable => 1, |
2196 | audio_enable => 1, |
|
|
2197 | effects_enable => 1, |
|
|
2198 | effects_volume => 1, |
2094 | bgm_enable => 1, |
2199 | bgm_enable => 1, |
2095 | bgm_volume => 0.25, |
2200 | bgm_volume => 0.5, |
2096 | output_sync => 1, |
2201 | output_sync => 1, |
2097 | output_count => 1, |
2202 | output_count => 1, |
2098 | output_rate => "", |
2203 | output_rate => "", |
2099 | pickup => 0, |
2204 | pickup => 0, |
2100 | inv_sort => "mtime", |
2205 | inv_sort => "mtime", |
… | |
… | |
2178 | Event::loop; |
2283 | Event::loop; |
2179 | #CFPlus::SDL_Quit; |
2284 | #CFPlus::SDL_Quit; |
2180 | #CFPlus::_exit 0; |
2285 | #CFPlus::_exit 0; |
2181 | |
2286 | |
2182 | END { |
2287 | END { |
|
|
2288 | video_shutdown; |
|
|
2289 | audio_shutdown; |
2183 | CFPlus::SDL_Quit; |
2290 | CFPlus::SDL_Quit; |
2184 | CFPlus::DB::Server::stop; |
2291 | CFPlus::DB::Server::stop; |
2185 | } |
2292 | } |
2186 | |
2293 | |
2187 | =head1 NAME |
2294 | =head1 NAME |
2188 | |
2295 | |
2189 | cfplus - A Crossfire+ and Crossfire game client |
2296 | cfplus - A Crossfire TRT and Crossfire game client |
2190 | |
2297 | |
2191 | =head1 SYNOPSIS |
2298 | =head1 SYNOPSIS |
2192 | |
2299 | |
2193 | Just run it - no commandline arguments are supported. |
2300 | Just run it - no commandline arguments are supported. |
2194 | |
2301 | |
2195 | =head1 USAGE |
2302 | =head1 USAGE |
2196 | |
2303 | |
2197 | cfplus utilises OpenGL for all UI elements and the game. It is supposed to be used |
2304 | cfplus utilises OpenGL for all UI elements and the game. It is supposed to |
2198 | fullscreen and interactively. |
2305 | be used in fullscreen mode and interactively. |
2199 | |
2306 | |
2200 | =head1 DEBUGGING |
2307 | =head1 DEBUGGING |
2201 | |
2308 | |
2202 | |
2309 | |
2203 | CFPLUS_DEBUG - environment variable |
2310 | CFPLUS_DEBUG - environment variable |