--- deliantra/Deliantra-Client/bin/cfplus 2007/06/24 19:17:47 1.156 +++ deliantra/Deliantra-Client/bin/cfplus 2007/07/12 17:56:51 1.163 @@ -1,6 +1,7 @@ #!/opt/bin/perl my $startup_done = sub { }; +our $PANGO = "1.5.0"; # do splash-screen thingy on win32 BEGIN { @@ -45,8 +46,8 @@ # relocatable } else { # unix, need to patch pango rc file - open my $fh, "<:perlio", "$tmp/usr/lib/pango/1.5.0/module-files.d/libpango1.0-0.modules" - or die "$tmp/usr/lib/1.5.0/module-files.d/libpango1.0-0.modules: $!"; + open my $fh, "<:perlio", "$tmp/usr/lib/pango/$PANGO/module-files.d/libpango1.0-0.modules" + or die "$tmp/usr/lib/$PANGO/module-files.d/libpango1.0-0.modules: $!"; local $/; my $rc = <$fh>; $rc =~ s/^\//$tmp\//gm; # replace abs paths by relative ones @@ -160,6 +161,10 @@ our %SDL_CB; our $SDL_MIXER; +our $MUSIC_DEFAULT = "in_a_heartbeat.ogg"; +our @MUSIC_WANT; +our $MUSIC_PLAYING; +our $MUSIC_PLAYER; our @SOUNDS; # event => file mapping our %AUDIO_CHUNKS; # audio files @@ -748,7 +753,7 @@ $table->add (1, 2, new CFPlus::UI::CheckBox on_changed => sub { $ENV{CFPLUS_DEBUG} ^= 4; 0 }); $table->add (0, 3, new CFPlus::UI::Label text => "Suppress Tooltips"); $table->add (1, 3, new CFPlus::UI::CheckBox on_changed => sub { $ENV{CFPLUS_DEBUG} ^= 8; 0 }); - $table->add (0, 4, new CFPlus::UI::Button text => "die on click(tm)", on_activate => sub { die "violator" } ); + $table->add (0, 4, new CFPlus::UI::Button text => "die on click(tm)", on_activate => sub { &CFPlus::debug() } ); my @default_smooth = (0.05, 0.13, 0.05, 0.13, 0.30, 0.13, 0.05, 0.13, 0.05); @@ -1456,7 +1461,7 @@ my $ntb = $PL_NOTEBOOK = - new CFPlus::UI::Notebook expand => 1, debug => 1; + new CFPlus::UI::Notebook expand => 1; $ntb->add ( "Statistics (F2)" => $STATS_PAGE = stats_window, @@ -2003,23 +2008,67 @@ undef $SDL_ACTIVE; } -my @bgmusic = qw(game1.ogg game2.ogg game3.ogg game5.ogg game6.ogg ross1.ogg ross2.ogg ross3.ogg ross4.ogg ross5.ogg); #d# -my $bgmusic;#TODO#hack#d# - sub audio_channel_finished { my ($channel) = @_; #warn "channel $channel finished\n";#d# } -sub audio_music_finished { +sub audio_music_set { + my ($songs) = @_; + + my $count = @$songs; + my @meta; + + for my $name (@$songs) { + CFPlus::DB::get resmap => $name, sub { + my ($data) = @_; + + if ($data) { + $data = JSON::XS->new->utf8->decode ($data); + $data->{path} = CFPlus::DB::path_of $name; + push @meta, $data; + } + + unless (--$count) { + if (@meta) { + @MUSIC_WANT = @meta; + &audio_music_changed (); + } + } + }; + } +} + +sub audio_music_changed { return unless $CFG->{bgm_enable}; - # TODO: hack, do play loop and mood music - $bgmusic = new_from_file CFPlus::MixMusic CFPlus::find_rcfile "music/$bgmusic[0]"; - $bgmusic->play (0); + # default MUSIC_WANT, undef/0 == MUSIC_DEFAULT + @MUSIC_WANT = { path => CFPlus::find_rcfile "music/$MUSIC_DEFAULT" } unless @MUSIC_WANT; + + # if the currently playing song is acceptable, let it continue + return if grep $MUSIC_PLAYING eq $_->{path}, @MUSIC_WANT; + + if (defined $MUSIC_PLAYING) { + warn "fade out"; + CFPlus::MixMusic::fade_out 2000; + } else { + warn "new music\n"; + + my $music = $MUSIC_WANT [rand @MUSIC_WANT]; + + $MUSIC_PLAYING = $music->{path}; + + $MUSIC_PLAYER = new_from_file CFPlus::MixMusic $music->{path}; + $MUSIC_PLAYER->play (0); + } +} + +sub audio_music_finished { + $MUSIC_PLAYING = undef; + undef $MUSIC_PLAYER; - push @bgmusic, shift @bgmusic; + audio_music_changed; } sub audio_init {