split strings and metrics

This commit is contained in:
Chris Danford
2006-06-24 05:13:54 +00:00
parent d27b40598e
commit 26ce4fa74d
8 changed files with 103 additions and 67 deletions
+35 -1
View File
@@ -1,4 +1,7 @@
[Arch]
[Common]
WindowTitle=StepMania
[Arch]
Couldn't create a movie driver.=Couldn't create a movie driver.
Input Handlers cannot be empty.=Input Handlers can not be empty.
Movie Drivers cannot be empty.=Movie Drivers can not be empty.
@@ -1387,6 +1390,8 @@ Jukebox=Jukebox
Select Game=Select Game
Theme=Theme
Credits=Credits
Options=Options
%d songs in %d groups, %d courses in %d groups=
[ScreenWithMenuElementsBlank]
HelpText=
@@ -1680,3 +1685,32 @@ Delete beat and shift up=Delete beat and shift up
Shift BPM changes and stops up one beat=Shift BPM changes and stops up one beat
Lay mine=Lay mine
Add to/remove from right half=Add to/remove from right half
[Grade]
Tier01=AAAA
Tier02=AAA
Tier03=AA
Tier04=A
Tier05=B
Tier06=C
Tier07=D
Failed=E
NoData=NO DATA
[ScreenPackages]
HelpText=
[ScreenOptionsTestMenu]
HelpText=
[ScreenMiniMenuContext]
HelpText=
[ScreenOptionsEditCoursesSimple]
HelpText=
[ScreenSMOnlineLogin]
HelpText=
[ScreenNetSelectMusic]
HelpText=Ctrl + Enter to enter room/select song
-28
View File
@@ -6,7 +6,6 @@ ColorP1Command=diffuse,PlayerColor(PLAYER_1)
ColorP2Command=diffuse,PlayerColor(PLAYER_2)
InitialScreen=ScreenCompany
FirstAttractScreen=ScreenCompany
WindowTitle=StepMania
DefaultModifiers=
DefaultCpuModifiers=
DifficultiesToShow=beginner,easy,medium,hard,challenge
@@ -113,17 +112,6 @@ IdleTimeoutSeconds=30
IdleTimeoutScreen=@THEME:GetMetric("Common","FirstAttractScreen")
PrevScreen=ScreenCompany
Game Start=
Select Game=
Options=Options
Edit/Sync Songs=
Edit Courses=
Jukebox=
Exit=
%d songs in %d groups, %d courses in %d groups=
[ScreenExit]
Class=ScreenExit
Fallback=Screen
@@ -691,7 +679,6 @@ Class=ScreenSMOnlineLogin
Fallback=ScreenOptionsServiceChild
NextScreen=@SMOnlineScreen()
PrevScreen=@ScreenTitleBranch()
HelpText=
StyleIcon=0
TimerSeconds=-1
@@ -818,7 +805,6 @@ NumSongsShow=4
NumGroupsShow=3
StyleIcon=
TimerSeconds=
HelpText=Ctrl + Enter to enter room/select song
PrevScreen=@ScreenTitleBranch()
NextScreen=ScreenStage
NoSongsScreen=@ScreenTitleBranch()
@@ -2754,7 +2740,6 @@ DownloadStatusOffCommand=diffusealpha,1.0;linear,0.6;diffusealpha,0.0
CanDL=1
StyleIcon=
TimerSeconds=
HelpText=
PrevScreen=@ScreenTitleBranch()
NextScreen=ScreenStage
NoSongsScreen=@ScreenTitleBranch()
@@ -3783,7 +3768,6 @@ NextScreen=ScreenOptionsService
PrevScreen=ScreenOptionsService
LineNames=1
Line1=lua,OptionsRowTest()
HelpText=
[TextBanner]
TitleX=-90
@@ -4220,16 +4204,6 @@ DeltaSecondsW1Command=shadowlength,4;diffusealpha,1;zoom,1.25;linear,0.3;zoomx,1
DeltaSecondsLetGoCommand=shadowlength,4;diffusealpha,1;zoom,1.25;linear,0.3;zoomx,1;zoomy,1;sleep,0.5;linear,0;diffusealpha,0
DeltaSecondsHeldCommand=shadowlength,4;diffusealpha,1;zoom,1.25;linear,0.3;zoomx,1;zoomy,1;sleep,0.5;linear,0;diffusealpha,0
DeltaSecondsGainLifeCommand=
[Grade]
Tier01=AAAA
Tier02=AAA
Tier03=AA
Tier04=A
Tier05=B
Tier06=C
Tier07=D
Failed=E
NoData=NO DATA
[PlayerStageStats]
GradePercentTier01=1.000000
@@ -4542,7 +4516,6 @@ TitleGainFocusCommand=diffuseshift;EffectColor1,0.3,0.3,0.3,1;EffectColor2,1.3,1
TitleLoseFocusCommand=stopeffect
ItemsStartX=0
LineHighlightX=0
HelpText=
ColorSelected=1,1,1,1
ColorNotSelected=0.7,0.7,0.7,1
@@ -4583,7 +4556,6 @@ InputMode=together
TitleOnCommand=zoom,0.5;horizalign,left;ShadowLength,0
TitleGainFocusCommand=diffuseshift;EffectColor1,1.3,1.3,1.3,1;EffectColor2,0.3,0.3,0.3,1
TitleLoseFocusCommand=stopeffect
HelpText=
BulletOnCommand=hidden,1
[ScreenOptionsManageCourses]
+2 -2
View File
@@ -35,8 +35,8 @@ protected:
ThemeMetric<RageColor> CHANGE_COLOR;
ThemeMetric<RageColor> EXTRA_COLOR;
ThemeMetric<bool> CYCLE;
LocalizedString SEPARATOR;
LocalizedString NO_BPM_TEXT;
ThemeMetric<RString> SEPARATOR;
ThemeMetric<RString> NO_BPM_TEXT;
BitmapText m_textBPM;
AutoActor m_sprLabel;
+3 -1
View File
@@ -6,6 +6,7 @@
#include "RageLog.h"
#include "GameState.h"
#include "ProductInfo.h"
#include "LuaFunctions.h"
static RString PLAYER_COLOR_NAME( size_t p ) { return ssprintf("ColorP%dCommand",int(p+1)); }
@@ -124,11 +125,12 @@ const vector<StepsType>& ThemeMetricStepsTypesToShow::GetValue() { return m_v; }
RString CommonMetrics::LocalizeOptionItem( const RString &s, bool bOptional )
{
if( bOptional && !THEME->HasMetric("OptionNames",s) )
if( bOptional && !THEME->HasString("OptionNames",s) )
return s;
return THEME->GetString( "OptionNames", s );
}
LuaFunction( LocalizeOptionItem, CommonMetrics::LocalizeOptionItem(SArg(1),true) );
/*
* (c) 2001-2004 Chris Danford
+2 -2
View File
@@ -2796,7 +2796,7 @@ RString GameManager::StepsTypeToString( StepsType st )
RString GameManager::StepsTypeToLocalizedString( StepsType st )
{
RString s = StepsTypeToString( st );
if( THEME->HasMetric( "StepsType", s ) )
if( THEME->HasString( "StepsType", s ) )
return THEME->GetString( "StepsType", s );
else
return s;
@@ -2806,7 +2806,7 @@ RString GameManager::StyleToLocalizedString( const Style* style )
{
RString s = style->m_szName;
s = Capitalize( s );
if( THEME->HasMetric( "Style", s ) )
if( THEME->HasString( "Style", s ) )
return THEME->GetString( "Style", s );
else
return s;
+1 -1
View File
@@ -12,7 +12,7 @@ LuaFunction( GradeToString, GradeToString((Grade)IArg(1)) )
RString GradeToLocalizedString( Grade g )
{
RString s = GradeToString(g);
if( !THEME->HasMetric("Grade",s) )
if( !THEME->HasString("Grade",s) )
return "???";
return THEME->GetString( "Grade",s );
}
+56 -29
View File
@@ -45,7 +45,18 @@ struct Theme
};
// When looking for a metric or an element, search these from head to tail.
static deque<Theme> g_vThemes;
static IniFile *g_pIniMetrics;
class LoadedThemeData
{
public:
IniFile iniMetrics;
IniFile iniStrings;
void ClearAll()
{
iniMetrics.Clear();
iniStrings.Clear();
}
};
LoadedThemeData *g_pLoadedThemeData = NULL;
//
@@ -148,7 +159,7 @@ ThemeManager::ThemeManager()
ThemeManager::~ThemeManager()
{
g_vThemes.clear();
SAFE_DELETE( g_pIniMetrics );
SAFE_DELETE( g_pLoadedThemeData );
}
void ThemeManager::GetThemeNames( vector<RString>& AddTo )
@@ -269,8 +280,12 @@ static void MergeIniUnder( XNode *pFrom, XNode *pTo )
void ThemeManager::LoadThemeMetrics( deque<Theme> &theme, const RString &sThemeName_, const RString &sLanguage_ )
{
delete g_pIniMetrics;
g_pIniMetrics = new IniFile;
if( g_pLoadedThemeData == NULL )
g_pLoadedThemeData = new LoadedThemeData;
// Don't delete and recreate LoadedThemeData. There are references iniMetrics and iniStrings
// on the stack, so Clear them instead.
g_pLoadedThemeData->ClearAll();
g_vThemes.clear();
RString sThemeName(sThemeName_);
@@ -288,14 +303,15 @@ void ThemeManager::LoadThemeMetrics( deque<Theme> &theme, const RString &sThemeN
Theme &t = g_vThemes.back();
t.sThemeName = sThemeName;
IniFile ini;
ini.ReadFile( GetMetricsIniPath(sThemeName) );
ini.ReadFile( GetLanguageIniPath(sThemeName,SpecialFiles::BASE_LANGUAGE) );
IniFile iniMetrics;
IniFile iniStrings;
iniMetrics.ReadFile( GetMetricsIniPath(sThemeName) );
iniStrings.ReadFile( GetLanguageIniPath(sThemeName,SpecialFiles::BASE_LANGUAGE) );
if( sLanguage.CompareNoCase(SpecialFiles::BASE_LANGUAGE) )
ini.ReadFile( GetLanguageIniPath(sThemeName,sLanguage) );
iniStrings.ReadFile( GetLanguageIniPath(sThemeName,sLanguage) );
bool bIsBaseTheme = !sThemeName.CompareNoCase(SpecialFiles::BASE_THEME_NAME);
ini.GetValue( "Global", "IsBaseTheme", bIsBaseTheme );
iniMetrics.GetValue( "Global", "IsBaseTheme", bIsBaseTheme );
if( bIsBaseTheme )
bLoadedBase = true;
@@ -303,7 +319,7 @@ void ThemeManager::LoadThemeMetrics( deque<Theme> &theme, const RString &sThemeN
* already loaded it, fall back on SpecialFiles::BASE_THEME_NAME. That way, default theme
* fallbacks can be disabled with "FallbackTheme=". */
RString sFallback;
if( !ini.GetValue("Global","FallbackTheme",sFallback) )
if( !iniMetrics.GetValue("Global","FallbackTheme",sFallback) )
{
if( sThemeName.CompareNoCase( SpecialFiles::BASE_THEME_NAME ) && !bLoadedBase )
sFallback = SpecialFiles::BASE_THEME_NAME;
@@ -314,7 +330,8 @@ void ThemeManager::LoadThemeMetrics( deque<Theme> &theme, const RString &sThemeN
* need to load the derived theme first, to find out the name of the fallback
* theme. Avoid having to load IniFile twice, merging the fallback theme
* into the derived theme that we've already loaded. */
MergeIniUnder( &ini, g_pIniMetrics );
MergeIniUnder( &iniMetrics, &g_pLoadedThemeData->iniMetrics );
MergeIniUnder( &iniStrings, &g_pLoadedThemeData->iniStrings );
if( sFallback.empty() )
break;
@@ -333,7 +350,7 @@ void ThemeManager::LoadThemeMetrics( deque<Theme> &theme, const RString &sThemeN
if( !re.Compare( sMetric, sBits ) )
RageException::Throw( "Invalid argument \"--metric=%s\"", sMetric.c_str() );
g_pIniMetrics->SetValue( sBits[0], sBits[1], sBits[2] );
g_pLoadedThemeData->iniMetrics.SetValue( sBits[0], sBits[1], sBits[2] );
}
LOG->MapLog( "theme", "Theme: %s", m_sCurThemeName.c_str() );
@@ -665,7 +682,7 @@ RString ThemeManager::GetPathToAndFallback( ElementCategory category, const RStr
// search fallback name (if any)
RString sFallback;
if( !GetMetricRawRecursive(sClassName, "Fallback", sFallback) )
if( !GetMetricRawRecursive( g_pLoadedThemeData->iniMetrics, sClassName, "Fallback", sFallback) )
return RString();
sClassName = sFallback;
}
@@ -758,7 +775,13 @@ RString ThemeManager::GetMetricsIniPath( const RString &sThemeName )
bool ThemeManager::HasMetric( const RString &sClassName, const RString &sValueName )
{
RString sThrowAway;
return GetMetricRawRecursive( sClassName, sValueName, sThrowAway );
return GetMetricRawRecursive( g_pLoadedThemeData->iniMetrics, sClassName, sValueName, sThrowAway );
}
bool ThemeManager::HasString( const RString &sClassName, const RString &sValueName )
{
RString sThrowAway;
return GetMetricRawRecursive( g_pLoadedThemeData->iniStrings, sClassName, sValueName, sThrowAway );
}
static LocalizedString RELOADED_METRICS( "ThemeManager", "Reloaded metrics" );
@@ -776,24 +799,25 @@ void ThemeManager::ReloadMetrics()
}
bool ThemeManager::GetMetricRawRecursive( const RString &sClassName_, const RString &sValueName, RString &sOut )
bool ThemeManager::GetMetricRawRecursive( const IniFile &ini, const RString &sClassName_, const RString &sValueName, RString &sOut )
{
ASSERT( sValueName != "" );
RString sClassName( sClassName_ );
ASSERT( g_pIniMetrics );
ASSERT( g_pLoadedThemeData );
int n = 100;
while( n-- )
{
if( g_pIniMetrics->GetValue(sClassName,sValueName,sOut) )
if( ini.GetValue(sClassName,sValueName,sOut) )
return true;
if( !sValueName.compare("Fallback") )
return false;
RString sFallback;
if( !GetMetricRawRecursive(sClassName,"Fallback",sFallback) )
// always look in iniMetrics for "Fallback"
if( !GetMetricRawRecursive(g_pLoadedThemeData->iniMetrics,sClassName,"Fallback",sFallback) )
return false;
sClassName = sFallback;
@@ -802,7 +826,7 @@ bool ThemeManager::GetMetricRawRecursive( const RString &sClassName_, const RStr
RageException::Throw( "Infinite recursion looking up theme metric \"%s::%s\"", sClassName.c_str(), sValueName.c_str() );
}
RString ThemeManager::GetMetricRaw( const RString &sClassName_, const RString &sValueName_ )
RString ThemeManager::GetMetricRaw( const IniFile &ini, const RString &sClassName_, const RString &sValueName_ )
{
/* Ugly: the parameters to this function may be a reference into g_vThemes, or something
* else that might suddenly go away when we call ReloadMetrics. */
@@ -812,7 +836,7 @@ RString ThemeManager::GetMetricRaw( const RString &sClassName_, const RString &s
while( true )
{
RString ret;
if( ThemeManager::GetMetricRawRecursive( sClassName, sValueName, ret ) )
if( ThemeManager::GetMetricRawRecursive( ini, sClassName, sValueName, ret ) )
return ret;
@@ -847,7 +871,7 @@ RString ThemeManager::GetMetricRaw( const RString &sClassName_, const RString &s
/* Get a string metric. */
RString ThemeManager::GetMetric( const RString &sClassName, const RString &sValueName )
{
RString sValue = GetMetricRaw(sClassName,sValueName);
RString sValue = GetMetricRaw(g_pLoadedThemeData->iniMetrics,sClassName,sValueName);
EvaluateString( sValue );
@@ -921,7 +945,7 @@ Commands ThemeManager::GetMetricM( const RString &sClassName, const RString &sVa
#if !defined(SMPACKAGE)
apActorCommands ThemeManager::GetMetricA( const RString &sClassName, const RString &sValueName )
{
RString sValue = GetMetricRaw( sClassName, sValueName );
RString sValue = GetMetricRaw( g_pLoadedThemeData->iniMetrics, sClassName, sValueName );
return apActorCommands( new ActorCommands( sValue ) );
}
#endif
@@ -963,7 +987,7 @@ RString ThemeManager::GetLanguageIniPath( const RString &sThemeName, const RStri
void ThemeManager::GetModifierNames( vector<RString>& AddTo )
{
const XNode *cur = g_pIniMetrics->GetChild( "OptionNames" );
const XNode *cur = g_pLoadedThemeData->iniStrings.GetChild( "OptionNames" );
if( cur )
{
FOREACH_CONST_Attr( cur, p )
@@ -980,7 +1004,7 @@ void ThemeManager::GetMetric( const RString &sClassName, const RString &sValueNa
void ThemeManager::GetMetric( const RString &sClassName, const RString &sValueName, LuaExpression &valueOut )
{
RString sValue = GetMetricRaw( sClassName, sValueName );
RString sValue = GetMetricRaw( g_pLoadedThemeData->iniMetrics, sClassName, sValueName );
valueOut.SetFromExpression( "function(self) " + sValue + "end" );
}
@@ -1019,9 +1043,13 @@ RString ThemeManager::GetString( const RString &sClassName, const RString &sValu
sValueName.Replace( "\r\n", "\\n" );
sValueName.Replace( "\n", "\\n" );
RString s = GetMetricRaw(g_pLoadedThemeData->iniStrings,sClassName,sValueName);
FontCharAliases::ReplaceMarkers( s );
// Don't EvalulateString. Strings are raw and shouldn't allow Lua.
//EvaluateString( s );
// Write stubs for missing strings into every language file.
RString s = ThemeManager::GetMetric( sClassName, sValueName );
/*
if( !ThemeManager::GetMetricRawRecursive( sClassName, sValueName, s ) )
{
@@ -1035,7 +1063,6 @@ RString ThemeManager::GetString( const RString &sClassName, const RString &sValu
LoadThemeMetrics( g_vThemes, m_sCurThemeName, m_sCurLanguage );
}
*/
EvaluateString( s );
s.Replace( "\\n", "\n" );
@@ -1075,7 +1102,7 @@ void ThemeManager::GetMetricsThatBeginWith( const RString &sClassName_, const RS
RString sClassName( sClassName_ );
while( !sClassName.empty() )
{
const XNode *cur = g_pIniMetrics->GetChild( sClassName );
const XNode *cur = g_pLoadedThemeData->iniMetrics.GetChild( sClassName );
if( cur != NULL )
{
// Iterate over all metrics that match.
@@ -1091,7 +1118,7 @@ void ThemeManager::GetMetricsThatBeginWith( const RString &sClassName_, const RS
// put the fallback (if any) in sClassName
RString sFallback;
if( GetMetricRawRecursive( sClassName, "Fallback", sFallback ) )
if( GetMetricRawRecursive( g_pLoadedThemeData->iniMetrics, sClassName, "Fallback", sFallback ) )
sClassName = sFallback;
else
sClassName = "";
+4 -3
View File
@@ -71,9 +71,9 @@ public:
// TODO: Make these return values const refs.
bool HasMetric( const RString &sClassName, const RString &sValueName );
RString GetMetricRaw( const RString &sClassName, const RString &sValueName );
RString GetMetricRaw( const IniFile &ini, const RString &sClassName, const RString &sValueName );
RString GetMetric( const RString &sClassName, const RString &sValueName );
int GetMetricI( const RString &sClassName, const RString &sValueName );
int GetMetricI( const RString &sClassName, const RString &sValueName );
float GetMetricF( const RString &sClassName, const RString &sValueName );
bool GetMetricB( const RString &sClassName, const RString &sValueName );
RageColor GetMetricC( const RString &sClassName, const RString &sValueName );
@@ -94,6 +94,7 @@ public:
#endif
// Languages
bool HasString( const RString &sClassName, const RString &sValueName );
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<RString> &asElementPaths );
@@ -114,7 +115,7 @@ public:
protected:
void RunLuaScripts( const RString &sMask );
void LoadThemeMetrics( deque<Theme> &theme, const RString &sThemeName, const RString &sLanguage_ );
bool GetMetricRawRecursive( const RString &sClassName, const RString &sValueName, RString &sRet );
bool GetMetricRawRecursive( const IniFile &ini, const RString &sClassName, const RString &sValueName, RString &sRet );
RString GetPathToAndFallback( ElementCategory category, const RString &sClassName, const RString &sFile );
RString GetPathToRaw( const RString &sThemeName, ElementCategory category, const RString &sClassName, const RString &sFile );
static RString GetThemeDirFromName( const RString &sThemeName );