add support for random background sets using Song genre

This commit is contained in:
Chris Danford
2005-06-02 10:09:46 +00:00
parent 882f1d7447
commit c80d0c4a53
6 changed files with 141 additions and 61 deletions
+14 -29
View File
@@ -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() );
+105 -28
View File
@@ -3,6 +3,9 @@
#include "RageUtil.h"
#include "song.h"
#include "Foreach.h"
#include "IniFile.h"
#include "RageLog.h"
#include <set>
const CString BACKGROUND_EFFECTS_DIR = "BackgroundEffects/";
const CString BACKGROUND_TRANSITIONS_DIR = "BackgroundTransitions/";
@@ -68,7 +71,14 @@ void BackgroundUtil::GetBackgroundTransitions( const CString &_sName, vector<CSt
void BackgroundUtil::GetSongBGAnimations( const Song *pSong, const CString &sMatch, vector<CString> &vsPathsOut, vector<CString> &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<CString> &vsPathsOut, vector<CString> &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<CString> &vsPathsOut, vector<CString> &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<CString> &vsPathsOut, vector<CString> &vsNamesOut )
static void GetFilterToFileNames( const CString sBaseDir, const Song *pSong, set<CString> &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<CString> &vsPathsOut, vector<CString> &vsNamesOut )
{
vsPathsOut.clear();
GetDirListing( BG_ANIMS_DIR+sMatch+"*", vsPathsOut, true, true );
@@ -118,34 +173,56 @@ void BackgroundUtil::GetGlobalBGAnimations( const CString &sMatch, vector<CStrin
StripCvs( vsPathsOut, vsNamesOut );
}
void BackgroundUtil::GetGlobalRandomMovies( const CString &sMatch, vector<CString> &vsPathsOut, vector<CString> &vsNamesOut )
void BackgroundUtil::GetGlobalRandomMovies( const Song *pSong, const CString &sMatch, vector<CString> &vsPathsOut, vector<CString> &vsNamesOut )
{
vsPathsOut.clear();
vsNamesOut.clear();
CString sSongGroup;
set<CString> ssFilterToFileNames;
if( pSong && !pSong->m_sGenre.empty() )
GetFilterToFileNames( RANDOMMOVIES_DIR, pSong, ssFilterToFileNames );
vector<CString> 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<vsPathsOut.size(); i++ )
{
CString sBasename = Basename( vsPathsOut[i] );
bool bFound = ssFilterToFileNames.find(sBasename) != ssFilterToFileNames.end();
if( !bFound )
{
vsPathsOut.erase( vsPathsOut.begin()+i );
i--;
}
}
}
FOREACH_CONST( CString, vsPathsOut, s )
vsNamesOut.push_back( Basename(*s) );
}
vector<CString> vSubDirs;
GetDirListing( RANDOMMOVIES_DIR+"*", vSubDirs, true );
FOREACH_CONST( CString, vSubDirs, sSubDir )
{
vector<CString> 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 );
+2 -2
View File
@@ -80,8 +80,8 @@ namespace BackgroundUtil
void GetSongBGAnimations( const Song *pSong, const CString &sMatch, vector<CString> &vsPathsOut, vector<CString> &vsNamesOut );
void GetSongMovies( const Song *pSong, const CString &sMatch, vector<CString> &vsPathsOut, vector<CString> &vsNamesOut );
void GetSongBitmaps( const Song *pSong, const CString &sMatch, vector<CString> &vsPathsOut, vector<CString> &vsNamesOut );
void GetGlobalBGAnimations( const CString &sMatch, vector<CString> &vsPathsOut, vector<CString> &vsNamesOut );
void GetGlobalRandomMovies( const CString &sMatch, vector<CString> &vsPathsOut, vector<CString> &vsNamesOut );
void GetGlobalBGAnimations( const Song *pSong, const CString &sMatch, vector<CString> &vsPathsOut, vector<CString> &vsNamesOut );
void GetGlobalRandomMovies( const Song *pSong, const CString &sMatch, vector<CString> &vsPathsOut, vector<CString> &vsNamesOut );
};
+17
View File
@@ -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; i<AddTo.size(); i++ )
{
if( IsADirectory( AddTo[i] ) )
{
GetDirListing( AddTo[i]+"/"+sMatch, AddTo, false, true );
GetDirListing( AddTo[i]+"/*", AddTo, true, true );
AddTo.erase( AddTo.begin()+i );
i--;
}
}
}
void FlushDirCache()
{
FILEMAN->FlushDirCache( "" );
+1
View File
@@ -387,6 +387,7 @@ typedef basic_string<char,char_traits_char_nocase> 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 );
+2 -2
View File
@@ -2066,8 +2066,8 @@ void ScreenEdit::HandleMainMenuChoice( MainMenuChoice c, const vector<int> &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;