From dc150962949dcdb16c16bcba12c951351567a459 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Thu, 2 Mar 2006 04:59:37 +0000 Subject: [PATCH] language filtering for XML-referenced files --- stepmania/src/ActorUtil.cpp | 5 ++- stepmania/src/ThemeManager.cpp | 60 ++++++++++++++++++---------------- stepmania/src/ThemeManager.h | 1 + 3 files changed, 36 insertions(+), 30 deletions(-) diff --git a/stepmania/src/ActorUtil.cpp b/stepmania/src/ActorUtil.cpp index 331cd1da14..890fa2e018 100644 --- a/stepmania/src/ActorUtil.cpp +++ b/stepmania/src/ActorUtil.cpp @@ -80,7 +80,10 @@ retry: ASSERT(0); } } - else if( asPaths.size() > 1 ) + + THEME->FilterFileLanguages( asPaths ); + + if( asPaths.size() > 1 ) { RString sError = ssprintf( "A file in '%s' references a file '%s' which has multiple matches.", sName.c_str(), sPath.c_str() ); switch( Dialog::AbortRetryIgnore( sError, "BROKEN_FILE_REFERENCE" ) ) diff --git a/stepmania/src/ThemeManager.cpp b/stepmania/src/ThemeManager.cpp index 74514224ac..ae7d747ef0 100644 --- a/stepmania/src/ThemeManager.cpp +++ b/stepmania/src/ThemeManager.cpp @@ -416,6 +416,36 @@ struct CompareLanguageTag } }; +/* + * If there's more than one result, check for language tags. For example, + * + * ScreenCompany graphic (lang English).png + * ScreenCompany graphic (lang French).png + * + * We still want to warn for ambiguous results. Use std::unique to filter + * files with the current language tag to the top, so choosing "ignore" from + * the multiple-match dialog will cause it to default to the first entry, so + * it'll still use a preferred language match if there were any. + */ +void ThemeManager::FilterFileLanguages( vector &asPaths ) +{ + if( asPaths.size() <= 1 ) + return; + vector::iterator it = + partition( asPaths.begin(), asPaths.end(), CompareLanguageTag(m_sCurLanguage) ); + + int iDist = distance( asPaths.begin(), it ); + if( iDist == 0 ) + { + /* We didn't find any for the current language. Try BASE_LANGUAGE. */ + it = partition( asPaths.begin(), asPaths.end(), CompareLanguageTag(SpecialFiles::BASE_LANGUAGE) ); + iDist = distance( asPaths.begin(), it ); + } + + if( iDist == 1 ) + asPaths.erase( it, asPaths.end() ); +} + RString ThemeManager::GetPathToRaw( const RString &sThemeName_, ElementCategory category, const RString &sClassName_, const RString &sElement_ ) { /* Ugly: the parameters to this function may be a reference into g_vThemes, or something @@ -490,35 +520,7 @@ try_element_again: if( asElementPaths.size() == 0 ) return NULL; // This isn't fatal. - /* - * If there's more than one result, check for language tags. For example, - * - * ScreenCompany graphic (lang English).png - * ScreenCompany graphic (lang French).png - * - * We still want to warn for ambiguous results. Use std::unique to filter - * files with the current language tag to the top. - */ - if( asElementPaths.size() > 1 ) - { - vector::iterator it = - partition( asElementPaths.begin(), asElementPaths.end(), CompareLanguageTag(m_sCurLanguage) ); - - int iDist = distance( asElementPaths.begin(), it ); - if( iDist == 0 ) - { - /* We didn't find any for the current language. Try BASE_LANGUAGE. */ - it = partition( asElementPaths.begin(), asElementPaths.end(), CompareLanguageTag(SpecialFiles::BASE_LANGUAGE) ); - iDist = distance( asElementPaths.begin(), it ); - } - - /* If there's more than one match (or no language matches), warn about it below. - * If "ignore" is picked, then it'll default to the first entry, so it'll still - * use a preferred language match if there were any (since partition() put them - * at the top). */ - if( iDist == 1 ) - asElementPaths.erase( it, asElementPaths.end() ); - } + FilterFileLanguages( asElementPaths ); if( asElementPaths.size() > 1 ) { diff --git a/stepmania/src/ThemeManager.h b/stepmania/src/ThemeManager.h index 447c4eb1f0..73de91950e 100644 --- a/stepmania/src/ThemeManager.h +++ b/stepmania/src/ThemeManager.h @@ -91,6 +91,7 @@ public: // Languages RString GetString( const RString &sClassName, const RString &sValueName ); void GetString( const RString &sClassName, const RString &sValueName, RString &valueOut ) { valueOut = GetString( sClassName, sValueName ); } + void FilterFileLanguages( vector &asElementPaths ); void GetMetricsThatBeginWith( const RString &sClassName, const RString &sValueName, set &vsValueNamesOut );