diff --git a/stepmania/src/Background.cpp b/stepmania/src/Background.cpp index 017d10195b..320ea9b02b 100644 --- a/stepmania/src/Background.cpp +++ b/stepmania/src/Background.cpp @@ -238,8 +238,8 @@ bool Background::Layer::CreateBackground( const Song *pSong, const BackgroundDef if( vsPaths.empty() ) BackgroundUtil::GetSongBGAnimations( pSong, sToResolve, vsPaths, vsThrowAway ); if( vsPaths.empty() ) BackgroundUtil::GetSongMovies( pSong, sToResolve, vsPaths, vsThrowAway ); if( vsPaths.empty() ) BackgroundUtil::GetSongBitmaps( pSong, sToResolve, vsPaths, vsThrowAway ); - if( vsPaths.empty() ) BackgroundUtil::GetGlobalBGAnimations( sToResolve, vsPaths, vsThrowAway ); - if( vsPaths.empty() ) BackgroundUtil::GetGlobalRandomMovies( sToResolve, vsPaths, vsThrowAway ); + if( vsPaths.empty() ) BackgroundUtil::GetGlobalBGAnimations( pSong, sToResolve, vsPaths, vsThrowAway ); + if( vsPaths.empty() ) BackgroundUtil::GetGlobalRandomMovies( pSong, sToResolve, vsPaths, vsThrowAway ); CString &sResolved = vsResolved[i]; @@ -381,35 +381,20 @@ void Background::LoadFromSong( const Song* pSong ) // Choose a bunch of background that we'll use for the random file marker // { - CString sPreferredSubDir = m_pSong->m_sGroupName; - sPreferredSubDir += '/'; - CStringArray vsThrowAway, vsNames; - for( int i=0; i<2; i++ ) + switch( PREFSMAN->m_BackgroundMode ) { - switch( PREFSMAN->m_BackgroundMode ) - { - default: - FAIL_M( ssprintf("Invalid BackgroundMode: %i", (PrefsManager::BackgroundMode)PREFSMAN->m_BackgroundMode) ); - break; - - case PrefsManager::BGMODE_OFF: - break; - - case PrefsManager::BGMODE_ANIMATIONS: - BackgroundUtil::GetGlobalBGAnimations( sPreferredSubDir, vsThrowAway, vsNames ); - break; - - case PrefsManager::BGMODE_RANDOMMOVIES: - BackgroundUtil::GetGlobalRandomMovies( sPreferredSubDir, vsThrowAway, vsNames ); - break; - } - - if( !vsNames.empty() ) // found some - break; - - // now search without a subdir - sPreferredSubDir = ""; + default: + ASSERT_M( 0, ssprintf("Invalid BackgroundMode: %i", (PrefsManager::BackgroundMode)PREFSMAN->m_BackgroundMode) ); + break; + case PrefsManager::BGMODE_OFF: + break; + case PrefsManager::BGMODE_ANIMATIONS: + BackgroundUtil::GetGlobalBGAnimations( pSong, "", vsThrowAway, vsNames ); + break; + case PrefsManager::BGMODE_RANDOMMOVIES: + BackgroundUtil::GetGlobalRandomMovies( pSong, "", vsThrowAway, vsNames ); + break; } random_shuffle( vsNames.begin(), vsNames.end() ); diff --git a/stepmania/src/BackgroundUtil.cpp b/stepmania/src/BackgroundUtil.cpp index 0551bb350b..2c920cb228 100644 --- a/stepmania/src/BackgroundUtil.cpp +++ b/stepmania/src/BackgroundUtil.cpp @@ -3,6 +3,9 @@ #include "RageUtil.h" #include "song.h" #include "Foreach.h" +#include "IniFile.h" +#include "RageLog.h" +#include const CString BACKGROUND_EFFECTS_DIR = "BackgroundEffects/"; const CString BACKGROUND_TRANSITIONS_DIR = "BackgroundTransitions/"; @@ -68,7 +71,14 @@ void BackgroundUtil::GetBackgroundTransitions( const CString &_sName, vector &vsPathsOut, vector &vsNamesOut ) { vsPathsOut.clear(); - GetDirListing( pSong->GetSongDir()+sMatch+"*", vsPathsOut, true, true ); + if( sMatch.empty() ) + { + GetDirListing( pSong->GetSongDir()+sMatch+"*", vsPathsOut, true, true ); + } + else + { + GetDirListing( pSong->GetSongDir()+sMatch, vsPathsOut, true, true ); + } vsNamesOut.clear(); FOREACH_CONST( CString, vsPathsOut, s ) @@ -80,9 +90,16 @@ void BackgroundUtil::GetSongBGAnimations( const Song *pSong, const CString &sMat void BackgroundUtil::GetSongMovies( const Song *pSong, const CString &sMatch, vector &vsPathsOut, vector &vsNamesOut ) { vsPathsOut.clear(); - GetDirListing( pSong->GetSongDir()+sMatch+"*.avi", vsPathsOut, false, true ); - GetDirListing( pSong->GetSongDir()+sMatch+"*.mpg", vsPathsOut, false, true ); - GetDirListing( pSong->GetSongDir()+sMatch+"*.mpeg", vsPathsOut, false, true ); + if( sMatch.empty() ) + { + GetDirListing( pSong->GetSongDir()+sMatch+"*.avi", vsPathsOut, false, true ); + GetDirListing( pSong->GetSongDir()+sMatch+"*.mpg", vsPathsOut, false, true ); + GetDirListing( pSong->GetSongDir()+sMatch+"*.mpeg", vsPathsOut, false, true ); + } + else + { + GetDirListing( pSong->GetSongDir()+sMatch, vsPathsOut, false, true ); + } vsNamesOut.clear(); FOREACH_CONST( CString, vsPathsOut, s ) @@ -94,10 +111,17 @@ void BackgroundUtil::GetSongMovies( const Song *pSong, const CString &sMatch, ve void BackgroundUtil::GetSongBitmaps( const Song *pSong, const CString &sMatch, vector &vsPathsOut, vector &vsNamesOut ) { vsPathsOut.clear(); - GetDirListing( pSong->GetSongDir()+sMatch+"*.png", vsPathsOut, false, true ); - GetDirListing( pSong->GetSongDir()+sMatch+"*.jpg", vsPathsOut, false, true ); - GetDirListing( pSong->GetSongDir()+sMatch+"*.gif", vsPathsOut, false, true ); - GetDirListing( pSong->GetSongDir()+sMatch+"*.bmp", vsPathsOut, false, true ); + if( sMatch.empty() ) + { + GetDirListing( pSong->GetSongDir()+sMatch+"*.png", vsPathsOut, false, true ); + GetDirListing( pSong->GetSongDir()+sMatch+"*.jpg", vsPathsOut, false, true ); + GetDirListing( pSong->GetSongDir()+sMatch+"*.gif", vsPathsOut, false, true ); + GetDirListing( pSong->GetSongDir()+sMatch+"*.bmp", vsPathsOut, false, true ); + } + else + { + GetDirListing( pSong->GetSongDir()+sMatch, vsPathsOut, false, true ); + } vsNamesOut.clear(); FOREACH_CONST( CString, vsPathsOut, s ) @@ -106,7 +130,38 @@ void BackgroundUtil::GetSongBitmaps( const Song *pSong, const CString &sMatch, v StripCvs( vsPathsOut, vsNamesOut ); } -void BackgroundUtil::GetGlobalBGAnimations( const CString &sMatch, vector &vsPathsOut, vector &vsNamesOut ) +static void GetFilterToFileNames( const CString sBaseDir, const Song *pSong, set &vsPossibleFileNamesOut ) +{ + vsPossibleFileNamesOut.clear(); + + if( pSong->m_sGenre.empty() ) + return; + + ASSERT( !pSong->m_sGroupName.empty() ) + IniFile ini; + CString sPath = sBaseDir+pSong->m_sGroupName+"/"+"BackgroundMapping.ini"; + ini.ReadFile( sPath ); + + CString sSection; + bool bSuccess = ini.GetValue( "GenreToSection", pSong->m_sGenre, sSection ); + if( !bSuccess ) + { + LOG->Warn( "Genre '%s' isn't mapped", pSong->m_sGenre.c_str() ); + return; + } + + XNode *pSection = ini.GetChild( sSection ); + if( pSection == NULL ) + { + ASSERT_M( 0, ssprintf("File '%s' refers to a section '%s' that is missing.", sPath.c_str(), sSection.c_str()) ); + return; + } + + FOREACH_CONST_Attr( pSection, p ) + vsPossibleFileNamesOut.insert( p->m_sName ); +} + +void BackgroundUtil::GetGlobalBGAnimations( const Song *pSong, const CString &sMatch, vector &vsPathsOut, vector &vsNamesOut ) { vsPathsOut.clear(); GetDirListing( BG_ANIMS_DIR+sMatch+"*", vsPathsOut, true, true ); @@ -118,34 +173,56 @@ void BackgroundUtil::GetGlobalBGAnimations( const CString &sMatch, vector &vsPathsOut, vector &vsNamesOut ) +void BackgroundUtil::GetGlobalRandomMovies( const Song *pSong, const CString &sMatch, vector &vsPathsOut, vector &vsNamesOut ) { vsPathsOut.clear(); vsNamesOut.clear(); + CString sSongGroup; + set ssFilterToFileNames; + if( pSong && !pSong->m_sGenre.empty() ) + GetFilterToFileNames( RANDOMMOVIES_DIR, pSong, ssFilterToFileNames ); + + vector vsDirsToTry; + if( !sSongGroup.empty() ) + vsDirsToTry.push_back( RANDOMMOVIES_DIR+sSongGroup+"/" ); + vsDirsToTry.push_back( RANDOMMOVIES_DIR ); + + FOREACH_CONST( CString, vsDirsToTry, sDir ) { - GetDirListing( RANDOMMOVIES_DIR+sMatch+"*.avi", vsPathsOut, false, true ); - GetDirListing( RANDOMMOVIES_DIR+sMatch+"*.mpg", vsPathsOut, false, true ); - GetDirListing( RANDOMMOVIES_DIR+sMatch+"*.mpeg", vsPathsOut, false, true ); + if( sMatch.empty() ) + { + GetDirListingRecursive( *sDir, "*.avi", vsPathsOut ); + GetDirListingRecursive( *sDir, "*.mpg", vsPathsOut ); + GetDirListingRecursive( *sDir, "*.mpeg", vsPathsOut ); + } + else + { + GetDirListing( RANDOMMOVIES_DIR+sMatch, vsPathsOut, false, true ); + } + + if( !ssFilterToFileNames.empty() ) + { + for( int i=0; i vSubDirs; - GetDirListing( RANDOMMOVIES_DIR+"*", vSubDirs, true ); - FOREACH_CONST( CString, vSubDirs, sSubDir ) - { - vector v; - GetDirListing( RANDOMMOVIES_DIR+*sSubDir+"/"+sMatch+"*.avi", v, false, true ); - GetDirListing( RANDOMMOVIES_DIR+*sSubDir+"/"+sMatch+"*.mpg", v, false, true ); - GetDirListing( RANDOMMOVIES_DIR+*sSubDir+"/"+sMatch+"*.mpeg", v, false, true ); - - FOREACH_CONST( CString, v, s ) { - vsPathsOut.push_back( *s ); - vsNamesOut.push_back( *sSubDir+"/"+Basename(*s) ); + CString sName = s->Right( s->size() - RANDOMMOVIES_DIR.size() - 1 ); + vsNamesOut.push_back( sName ); } + + if( !vsPathsOut.empty() ) + break; } StripCvs( vsPathsOut, vsNamesOut ); diff --git a/stepmania/src/BackgroundUtil.h b/stepmania/src/BackgroundUtil.h index ecb8fa164c..e41dd83920 100644 --- a/stepmania/src/BackgroundUtil.h +++ b/stepmania/src/BackgroundUtil.h @@ -80,8 +80,8 @@ namespace BackgroundUtil void GetSongBGAnimations( const Song *pSong, const CString &sMatch, vector &vsPathsOut, vector &vsNamesOut ); void GetSongMovies( const Song *pSong, const CString &sMatch, vector &vsPathsOut, vector &vsNamesOut ); void GetSongBitmaps( const Song *pSong, const CString &sMatch, vector &vsPathsOut, vector &vsNamesOut ); - void GetGlobalBGAnimations( const CString &sMatch, vector &vsPathsOut, vector &vsNamesOut ); - void GetGlobalRandomMovies( const CString &sMatch, vector &vsPathsOut, vector &vsNamesOut ); + void GetGlobalBGAnimations( const Song *pSong, const CString &sMatch, vector &vsPathsOut, vector &vsNamesOut ); + void GetGlobalRandomMovies( const Song *pSong, const CString &sMatch, vector &vsPathsOut, vector &vsNamesOut ); }; diff --git a/stepmania/src/RageFileManager.cpp b/stepmania/src/RageFileManager.cpp index 9813d31dce..fd960021fd 100644 --- a/stepmania/src/RageFileManager.cpp +++ b/stepmania/src/RageFileManager.cpp @@ -878,6 +878,23 @@ void GetDirListing( const CString &sPath, CStringArray &AddTo, bool bOnlyDirs, b FILEMAN->GetDirListing( sPath, AddTo, bOnlyDirs, bReturnPathToo ); } +void GetDirListingRecursive( const CString &sDir, const CString &sMatch, CStringArray &AddTo ) +{ + ASSERT( sDir.Right(1) == "/" ); + GetDirListing( sDir+sMatch, AddTo, false, true ); + GetDirListing( sDir+"*", AddTo, true, true ); + for( unsigned i=0; iFlushDirCache( "" ); diff --git a/stepmania/src/RageUtil.h b/stepmania/src/RageUtil.h index 6c45caccb3..26dc5dda0c 100644 --- a/stepmania/src/RageUtil.h +++ b/stepmania/src/RageUtil.h @@ -387,6 +387,7 @@ typedef basic_string istring; /* Compatibility/convenience shortcuts. These are actually defined in RageFileManager.h, but * declared here since they're used in many places. */ void GetDirListing( const CString &sPath, CStringArray &AddTo, bool bOnlyDirs=false, bool bReturnPathToo=false ); +void GetDirListingRecursive( const CString &sDir, const CString &sMatch, CStringArray &AddTo ); /* returns path too */ bool DoesFileExist( const CString &sPath ); bool IsAFile( const CString &sPath ); bool IsADirectory( const CString &sPath ); diff --git a/stepmania/src/ScreenEdit.cpp b/stepmania/src/ScreenEdit.cpp index 5df20dd4fd..f285f2edb4 100644 --- a/stepmania/src/ScreenEdit.cpp +++ b/stepmania/src/ScreenEdit.cpp @@ -2066,8 +2066,8 @@ void ScreenEdit::HandleMainMenuChoice( MainMenuChoice c, const vector &iAns BackgroundUtil::GetSongBGAnimations( m_pSong, "", vThrowAway, g_BackgroundChange.rows[file1_song_bganimation].choices ); BackgroundUtil::GetSongMovies( m_pSong, "", vThrowAway, g_BackgroundChange.rows[file1_song_movie].choices ); BackgroundUtil::GetSongBitmaps( m_pSong, "", vThrowAway, g_BackgroundChange.rows[file1_song_still].choices ); - BackgroundUtil::GetGlobalBGAnimations( "", vThrowAway, g_BackgroundChange.rows[file1_global_bganimation].choices ); - BackgroundUtil::GetGlobalRandomMovies( "", vThrowAway, g_BackgroundChange.rows[file1_global_random_movie].choices ); + BackgroundUtil::GetGlobalBGAnimations( NULL, "", vThrowAway, g_BackgroundChange.rows[file1_global_bganimation].choices ); // NULL to get all background files + BackgroundUtil::GetGlobalRandomMovies( NULL, "", vThrowAway, g_BackgroundChange.rows[file1_global_random_movie].choices ); // NULL to get all background files g_BackgroundChange.rows[file2_type].choices = g_BackgroundChange.rows[file1_type].choices; g_BackgroundChange.rows[file2_song_bganimation].choices = g_BackgroundChange.rows[file1_song_bganimation].choices;