… | |
… | |
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; |
… | |
… | |
214 | my ($face) = @_; |
217 | my ($face) = @_; |
215 | |
218 | |
216 | $CFG->{effects_enable} |
219 | $CFG->{effects_enable} |
217 | or return; |
220 | or return; |
218 | |
221 | |
|
|
222 | $AUDIO_PLAY{$face} |
|
|
223 | or return; |
|
|
224 | |
219 | if (my $chunk = $AUDIO_CHUNK{$face}) { |
225 | if (my $chunk = $AUDIO_CHUNK{$face}) { |
220 | for (grep $_->[0] >= Event::time, @{(delete $AUDIO_PLAY{$face}) || []}) { |
226 | for (grep $_->[0] >= Event::time, @{(delete $AUDIO_PLAY{$face}) || []}) { |
221 | my (undef, $dx, $dy, $vol) = @$_; |
227 | my (undef, $dx, $dy, $vol) = @$_; |
222 | |
228 | |
223 | my $channel = CFPlus::Channel::find; |
229 | my $channel = CFPlus::Channel::find; |
… | |
… | |
236 | my $meta = $CONN->{sound_meta}{$face} |
242 | my $meta = $CONN->{sound_meta}{$face} |
237 | or return; |
243 | or return; |
238 | |
244 | |
239 | # if its a jingle, play it as ambient music |
245 | # if its a jingle, play it as ambient music |
240 | if ($meta->{meta}{jingle}) { |
246 | if ($meta->{meta}{jingle}) { |
241 | delete $AUDIO_PLAY{$face}; # take the jingle out of the sound queue |
247 | if (delete $AUDIO_PLAY{$face}) { # take the jingle out of the sound queue |
242 | push @MUSIC_JINGLE, $meta; # push it oto the music/jingle queue |
248 | push @MUSIC_JINGLE, $meta; # push it oto the music/jingle queue |
243 | &audio_music_push ($face); |
249 | &audio_music_push ($face); |
|
|
250 | } |
244 | } else { |
251 | } else { |
245 | # fetch from database |
252 | # fetch from database |
246 | CFPlus::DB::get res_data => $meta->{name}, sub { |
253 | CFPlus::DB::get res_data => $meta->{name}, sub { |
247 | my $rwops = new CFPlus::RW $_[0]; |
254 | my $rwops = new CFPlus::RW $_[0]; |
248 | my $chunk = new CFPlus::MixChunk $rwops; |
255 | my $chunk = new CFPlus::MixChunk $rwops |
|
|
256 | or Carp::confess "sound face " . (JSON::XS::to_json $meta) . " unloadable: " . CFPlus::Mix_GetError; |
249 | $chunk->volume (($meta->{meta}{volume} || 1) * 128); |
257 | $chunk->volume (($meta->{meta}{volume} || 1) * 128); |
250 | $AUDIO_CHUNK{$face} = $chunk; |
258 | $AUDIO_CHUNK{$face} = $chunk; |
251 | |
259 | |
252 | audio_sound_push ($face); |
260 | audio_sound_push ($face); |
253 | }; |
261 | }; |
… | |
… | |
265 | |
273 | |
266 | my $queue = $AUDIO_PLAY{$face} ||= []; |
274 | my $queue = $AUDIO_PLAY{$face} ||= []; |
267 | push @$queue, [Event::time + 0.2, $dx, $dy, $vol]; # delay sound by max. 0.2s |
275 | push @$queue, [Event::time + 0.2, $dx, $dy, $vol]; # delay sound by max. 0.2s |
268 | audio_sound_push $face |
276 | audio_sound_push $face |
269 | unless @$queue > 1; |
277 | unless @$queue > 1; |
|
|
278 | } |
|
|
279 | |
|
|
280 | sub audio_music_set_meta { |
|
|
281 | my ($meta) = @_; |
|
|
282 | |
|
|
283 | $MUSIC_PLAYING_META = $meta; |
|
|
284 | $MUSIC_PLAYING_WIDGET->set_markup ( |
|
|
285 | "<b>Name</b>: " . (CFPlus::asxml $meta->{meta}{name}) . "\n" |
|
|
286 | . "<b>Author</b>: " . (CFPlus::asxml $meta->{meta}{author}) . "\n" |
|
|
287 | . "<b>Source</b>: " . (CFPlus::asxml $meta->{meta}{source}) . "\n" |
|
|
288 | . "<b>License</b>: " . (CFPlus::asxml $meta->{meta}{license}) |
|
|
289 | ); |
270 | } |
290 | } |
271 | |
291 | |
272 | sub audio_music_update_volume { |
292 | sub audio_music_update_volume { |
273 | return unless $MUSIC_PLAYING_META; |
293 | return unless $MUSIC_PLAYING_META; |
274 | my $volume = $MUSIC_PLAYING_META->{meta}{volume} || 1; |
294 | my $volume = $MUSIC_PLAYING_META->{meta}{volume} || 1; |
… | |
… | |
293 | my $rwops = $meta->{path} |
313 | my $rwops = $meta->{path} |
294 | ? new_from_file CFPlus::RW $meta->{path} |
314 | ? new_from_file CFPlus::RW $meta->{path} |
295 | : new CFPlus::RW $$MUSIC_PLAYING_DATA; |
315 | : new CFPlus::RW $$MUSIC_PLAYING_DATA; |
296 | |
316 | |
297 | $MUSIC_PLAYER = new CFPlus::MixMusic $rwops |
317 | $MUSIC_PLAYER = new CFPlus::MixMusic $rwops |
298 | or ((warn CFPlus::Mix_GetError), return); # pretty fatal error |
318 | or Carp::confess "music face $meta->{face} unloadable: " . CFPlus::Mix_GetError; |
299 | |
319 | |
300 | my $NOW = time; |
320 | my $NOW = time; |
301 | |
321 | |
302 | if ($MUSIC_PLAYING_META->{stop_time} > $NOW - $MUSIC_RESUME) { |
322 | if ($MUSIC_PLAYING_META->{stop_time} > $NOW - $MUSIC_RESUME) { |
303 | my $pos = $MUSIC_PLAYING_META->{stop_pos}; |
323 | my $pos = $MUSIC_PLAYING_META->{stop_pos}; |
… | |
… | |
306 | } else { |
326 | } else { |
307 | $MUSIC_PLAYER->play (0); |
327 | $MUSIC_PLAYER->play (0); |
308 | $MUSIC_START = time; |
328 | $MUSIC_START = time; |
309 | } |
329 | } |
310 | |
330 | |
311 | delete $MUSIC_PLAYING_META->{stop_time}; |
331 | delete $meta->{stop_time}; |
312 | delete $MUSIC_PLAYING_META->{stop_pos}; |
332 | delete $meta->{stop_pos}; |
313 | } |
333 | } |
314 | } |
334 | } |
315 | |
335 | |
316 | sub audio_music_push { |
336 | sub audio_music_push { |
317 | return unless $SDL_MIXER; |
337 | return unless $SDL_MIXER; |
… | |
… | |
336 | @MUSIC_HAVE = { path => CFPlus::find_rcfile "music/$MUSIC_DEFAULT" } unless @MUSIC_HAVE; |
356 | @MUSIC_HAVE = { path => CFPlus::find_rcfile "music/$MUSIC_DEFAULT" } unless @MUSIC_HAVE; |
337 | $fade_out = 1000; |
357 | $fade_out = 1000; |
338 | } |
358 | } |
339 | |
359 | |
340 | # if the currently playing song is acceptable, let it continue |
360 | # if the currently playing song is acceptable, let it continue |
341 | return if $MUSIC_PLAYING_META |
|
|
342 | && grep $MUSIC_PLAYING_META == $_, @MUSIC_HAVE; |
361 | return if grep $MUSIC_PLAYING_META == $_, @MUSIC_HAVE; |
343 | |
362 | |
344 | my $NOW = time; |
363 | my $NOW = time; |
345 | |
364 | |
346 | if ($MUSIC_PLAYING_META) { |
365 | if ($MUSIC_PLAYING_META) { |
347 | $MUSIC_PLAYING_META->{stop_time} = $NOW; |
366 | $MUSIC_PLAYING_META->{stop_time} = $NOW; |
… | |
… | |
351 | # sort by stop time, oldest first |
370 | # sort by stop time, oldest first |
352 | @MUSIC_HAVE = sort { $a->{stop_time} <=> $b->{stop_time} } @MUSIC_HAVE; |
371 | @MUSIC_HAVE = sort { $a->{stop_time} <=> $b->{stop_time} } @MUSIC_HAVE; |
353 | |
372 | |
354 | # if the most recently-played piece played very recently, |
373 | # if the most recently-played piece played very recently, |
355 | # resume it, else choose the oldest piece for rotation. |
374 | # resume it, else choose the oldest piece for rotation. |
356 | $MUSIC_PLAYING_META = |
375 | audio_music_set_meta |
357 | $MUSIC_HAVE[-1]{stop_time} > $NOW - $MUSIC_RESUME |
376 | $MUSIC_HAVE[-1]{stop_time} > $NOW - $MUSIC_RESUME |
358 | ? $MUSIC_HAVE[-1] |
377 | ? $MUSIC_HAVE[-1] |
359 | : $MUSIC_HAVE[0]; |
378 | : $MUSIC_HAVE[0]; |
360 | |
379 | |
361 | audio_music_start; |
380 | audio_music_start; |
… | |
… | |
371 | |
390 | |
372 | sub audio_music_finished { |
391 | sub audio_music_finished { |
373 | # we compress multiple jingles of the same type |
392 | # we compress multiple jingles of the same type |
374 | shift @MUSIC_JINGLE |
393 | shift @MUSIC_JINGLE |
375 | while @MUSIC_JINGLE && $MUSIC_PLAYING_META == $MUSIC_JINGLE[0]; |
394 | while @MUSIC_JINGLE && $MUSIC_PLAYING_META == $MUSIC_JINGLE[0]; |
|
|
395 | |
|
|
396 | $MUSIC_PLAYING_WIDGET->clear; |
376 | |
397 | |
377 | undef $MUSIC_PLAYER; |
398 | undef $MUSIC_PLAYER; |
378 | undef $MUSIC_PLAYING_META; |
399 | undef $MUSIC_PLAYING_META; |
379 | undef $MUSIC_PLAYING_DATA; |
400 | undef $MUSIC_PLAYING_DATA; |
380 | |
401 | |
… | |
… | |
859 | # $table->add_at (0, 9, new CFPlus::UI::Label valign => 0, align => 1, text => "Effects Volume"); |
880 | # $table->add_at (0, 9, new CFPlus::UI::Label valign => 0, align => 1, text => "Effects Volume"); |
860 | # $table->add_at (1, 8, new CFPlus::UI::Slider range => [$CFG->{effects_volume}, 0, 128, 1], on_changed => sub { |
881 | # $table->add_at (1, 8, new CFPlus::UI::Slider range => [$CFG->{effects_volume}, 0, 128, 1], on_changed => sub { |
861 | # $CFG->{effects_volume} = $_[1]; |
882 | # $CFG->{effects_volume} = $_[1]; |
862 | # }); |
883 | # }); |
863 | |
884 | |
864 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Effects Volume"); |
885 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Sound Effects"); |
865 | $table->add_at (1, $row, new CFPlus::UI::CheckBox |
886 | $table->add_at (1, $row, new CFPlus::UI::CheckBox |
866 | expand => 1, state => $CFG->{effects_enable}, |
887 | expand => 1, state => $CFG->{effects_enable}, |
867 | tooltip => "If enabled, sound effects are enabled. If disabled, no sound effects will be played.", |
888 | tooltip => "If enabled, sound effects are enabled. If disabled, no sound effects will be played.", |
|
|
889 | on_changed => sub { |
868 | on_changed => sub { $CFG->{effects_enable} = $_[1]; 0 } |
890 | $CFG->{effects_enable} = $_[1]; |
|
|
891 | $CONN->update_fx_want if $CONN; |
|
|
892 | 0 |
|
|
893 | } |
869 | ); |
894 | ); |
870 | $table->add_at (2, $row++, new CFPlus::UI::Slider |
895 | $table->add_at (2, $row++, new CFPlus::UI::Slider |
871 | expand => 1, range => [$CFG->{effects_volume}, 0, 1, 0, 1/128], |
896 | expand => 1, range => [$CFG->{effects_volume}, 0, 1, 0, 1/128], |
872 | tooltip => "The relative volume of sound effects. Best audio quality is achieved if this " |
897 | tooltip => "The relative volume of sound effects. Best audio quality is achieved if this " |
873 | . "is set highest and you use your operating system volume setting. Changes are instant.", |
898 | . "is set highest (rightmost) and you use your operating system volume setting. Changes are instant.", |
874 | on_changed => sub { $CFG->{effects_volume} = $_[1]; 0 } |
899 | on_changed => sub { $CFG->{effects_volume} = $_[1]; 0 } |
875 | ); |
900 | ); |
876 | |
901 | |
877 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Background Music"); |
902 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Background Music"); |
878 | $table->add_at (1, $row, new CFPlus::UI::CheckBox |
903 | $table->add_at (1, $row, new CFPlus::UI::CheckBox |
879 | expand => 1, state => $CFG->{bgm_enable}, |
904 | expand => 1, state => $CFG->{bgm_enable}, |
880 | tooltip => "If enabled, playing of background music is enabled. If disabled, no background music will be played.", |
905 | tooltip => "If enabled, playing of background music is enabled. If disabled, no background music will be played.", |
881 | on_changed => sub { $CFG->{bgm_enable} = $_[1]; 0 } |
906 | on_changed => sub { |
|
|
907 | $CFG->{bgm_enable} = $_[1]; |
|
|
908 | $CONN->update_fx_want if $CONN; |
|
|
909 | 0 |
|
|
910 | } |
882 | ); |
911 | ); |
883 | $table->add_at (2, $row++, new CFPlus::UI::Slider |
912 | $table->add_at (2, $row++, new CFPlus::UI::Slider |
884 | expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0, 1/128], |
913 | expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0, 1/128], |
885 | tooltip => "The volume of the background music. Changes are instant.", |
914 | tooltip => "The volume of the background music. Changes are instant.", |
886 | on_changed => sub { $CFG->{bgm_volume} = $_[1]; audio_music_update_volume; 0 } |
915 | on_changed => sub { $CFG->{bgm_volume} = $_[1]; audio_music_update_volume; 0 } |
… | |
… | |
1586 | CFPlus::Protocol::set_opencont ($::CONN, 0, "Floor"); |
1615 | CFPlus::Protocol::set_opencont ($::CONN, 0, "Floor"); |
1587 | |
1616 | |
1588 | $hb |
1617 | $hb |
1589 | } |
1618 | } |
1590 | |
1619 | |
|
|
1620 | sub media_window { |
|
|
1621 | my $vb = new CFPlus::UI::VBox; |
|
|
1622 | |
|
|
1623 | $vb->add (new CFPlus::UI::FancyFrame |
|
|
1624 | label => "Currently playing music", |
|
|
1625 | child => new CFPlus::UI::ScrolledWindow scroll_x => 1, scroll_y => 0, |
|
|
1626 | child => ($MUSIC_PLAYING_WIDGET = new CFPlus::UI::Label ellipsise => 0, fontsize => 0.8), |
|
|
1627 | ); |
|
|
1628 | |
|
|
1629 | $vb->add (new CFPlus::UI::FancyFrame |
|
|
1630 | label => "Other media used in this session", |
|
|
1631 | expand => 1, |
|
|
1632 | child => ($LICENSE_WIDGET = new CFPlus::UI::TextScroller |
|
|
1633 | expand => 1, fontsize => 0.8, padding_x => 4, padding_y => 4), |
|
|
1634 | ); |
|
|
1635 | |
|
|
1636 | $vb |
|
|
1637 | } |
|
|
1638 | |
|
|
1639 | sub add_license { |
|
|
1640 | my ($meta) = @_; |
|
|
1641 | |
|
|
1642 | $meta = $meta->{meta} |
|
|
1643 | or return; |
|
|
1644 | |
|
|
1645 | $meta->{license} || $meta->{author} || $meta->{source} |
|
|
1646 | or return; |
|
|
1647 | |
|
|
1648 | $LICENSE_WIDGET->add_paragraph ({ |
|
|
1649 | fg => [1, 1, 1, 1], |
|
|
1650 | markup => "<small>" |
|
|
1651 | . "<b>Name:</b> " . (CFPlus::asxml $meta->{name}) . "\n" |
|
|
1652 | . "<b>Author:</b> " . (CFPlus::asxml $meta->{author}) . "\n" |
|
|
1653 | . "<b>Source:</b> " . (CFPlus::asxml $meta->{source}) . "\n" |
|
|
1654 | . "<b>License:</b> " . (CFPlus::asxml $meta->{license}) . "\n" |
|
|
1655 | . "</small>", |
|
|
1656 | }); |
|
|
1657 | $LICENSE_WIDGET->scroll_to_bottom; |
|
|
1658 | } |
|
|
1659 | |
1591 | sub toggle_player_page { |
1660 | sub toggle_player_page { |
1592 | my ($widget) = @_; |
1661 | my ($widget) = @_; |
1593 | |
1662 | |
1594 | if ($PL_WINDOW->{visible} && $PL_NOTEBOOK->get_current_page == $widget) { |
1663 | if ($PL_WINDOW->{visible} && $PL_NOTEBOOK->get_current_page == $widget) { |
1595 | $PL_WINDOW->hide; |
1664 | $PL_WINDOW->hide; |
… | |
… | |
1632 | $ntb->add_tab ( |
1701 | $ntb->add_tab ( |
1633 | "Inventory (F5)" => $INVENTORY_PAGE = inventory_widget, |
1702 | "Inventory (F5)" => $INVENTORY_PAGE = inventory_widget, |
1634 | "Toggles the inventory window, where you can manage your loot (or treasures :). " |
1703 | "Toggles the inventory window, where you can manage your loot (or treasures :). " |
1635 | . "You can also hit the <b>Tab</b>-key to show/hide the Inventory." |
1704 | . "You can also hit the <b>Tab</b>-key to show/hide the Inventory." |
1636 | ); |
1705 | ); |
1637 | $ntb->add_tab (Pickup => autopickup_setup, |
1706 | $ntb->add_tab (Pickup => autopickup_setup, |
1638 | "Configure autopickup settings, i.e. which items you will pick up automatically when walking (or running) over them."); |
1707 | "Configure autopickup settings, i.e. which items you will pick up automatically when walking (or running) over them."); |
|
|
1708 | |
|
|
1709 | $ntb->add_tab (Media => media_window, |
|
|
1710 | "License, Author and Source info for media sent by the server."); |
1639 | |
1711 | |
1640 | $ntb->set_current_page ($INVENTORY_PAGE); |
1712 | $ntb->set_current_page ($INVENTORY_PAGE); |
1641 | |
1713 | |
1642 | $plwin->add ($ntb); |
1714 | $plwin->add ($ntb); |
1643 | $plwin |
1715 | $plwin |
… | |
… | |
2222 | Event::loop; |
2294 | Event::loop; |
2223 | #CFPlus::SDL_Quit; |
2295 | #CFPlus::SDL_Quit; |
2224 | #CFPlus::_exit 0; |
2296 | #CFPlus::_exit 0; |
2225 | |
2297 | |
2226 | END { |
2298 | END { |
|
|
2299 | video_shutdown; |
|
|
2300 | audio_shutdown; |
2227 | CFPlus::SDL_Quit; |
2301 | CFPlus::SDL_Quit; |
2228 | CFPlus::DB::Server::stop; |
2302 | CFPlus::DB::Server::stop; |
2229 | } |
2303 | } |
2230 | |
2304 | |
2231 | =head1 NAME |
2305 | =head1 NAME |
2232 | |
2306 | |
2233 | cfplus - A Crossfire+ and Crossfire game client |
2307 | cfplus - A Crossfire TRT and Crossfire game client |
2234 | |
2308 | |
2235 | =head1 SYNOPSIS |
2309 | =head1 SYNOPSIS |
2236 | |
2310 | |
2237 | Just run it - no commandline arguments are supported. |
2311 | Just run it - no commandline arguments are supported. |
2238 | |
2312 | |
2239 | =head1 USAGE |
2313 | =head1 USAGE |
2240 | |
2314 | |
2241 | cfplus utilises OpenGL for all UI elements and the game. It is supposed to be used |
2315 | cfplus utilises OpenGL for all UI elements and the game. It is supposed to |
2242 | fullscreen and interactively. |
2316 | be used in fullscreen mode and interactively. |
2243 | |
2317 | |
2244 | =head1 DEBUGGING |
2318 | =head1 DEBUGGING |
2245 | |
2319 | |
2246 | |
2320 | |
2247 | CFPLUS_DEBUG - environment variable |
2321 | CFPLUS_DEBUG - environment variable |