From 9a05977e52978d8c84469743626fc8acb8579ce8 Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Sun, 5 Feb 2006 20:30:37 +0000 Subject: [PATCH] localize SongOptions strings --- stepmania/src/PlayerOptions.cpp | 7 ++-- stepmania/src/PlayerOptions.h | 2 +- stepmania/src/ScreenGameplay.cpp | 2 +- stepmania/src/SongOptions.cpp | 65 +++++++++++++++++++++----------- stepmania/src/SongOptions.h | 5 ++- 5 files changed, 53 insertions(+), 28 deletions(-) diff --git a/stepmania/src/PlayerOptions.cpp b/stepmania/src/PlayerOptions.cpp index 05b94cb503..7e550746be 100644 --- a/stepmania/src/PlayerOptions.cpp +++ b/stepmania/src/PlayerOptions.cpp @@ -202,13 +202,14 @@ void PlayerOptions::GetMods( vector &AddTo ) const /* Options are added to the current settings; call Init() beforehand if * you don't want this. */ -void PlayerOptions::FromString( RString sOptions, bool bWarnOnInvalid ) +void PlayerOptions::FromString( const RString &sOptions, bool bWarnOnInvalid ) { ASSERT( NOTESKIN ); // Init(); - sOptions.MakeLower(); + RString sTemp = sOptions; + sTemp.MakeLower(); vector asBits; - split( sOptions, ",", asBits, true ); + split( sTemp, ",", asBits, true ); FOREACH( RString, asBits, bit ) { diff --git a/stepmania/src/PlayerOptions.h b/stepmania/src/PlayerOptions.h index 428ad2f4bb..5c04484a22 100644 --- a/stepmania/src/PlayerOptions.h +++ b/stepmania/src/PlayerOptions.h @@ -21,7 +21,7 @@ public: void ResetSavedPrefs(); void GetMods( vector &AddTo ) const; void GetLocalizedMods( vector &AddTo ) const; - void FromString( RString sOptions, bool bWarnOnInvalid = false ); + void FromString( const RString &sOptions, bool bWarnOnInvalid = false ); void ChooseRandomModifiers(); bool ContainsTransformOrTurn() const; diff --git a/stepmania/src/ScreenGameplay.cpp b/stepmania/src/ScreenGameplay.cpp index 4a1e656ce8..492a4d7aaa 100644 --- a/stepmania/src/ScreenGameplay.cpp +++ b/stepmania/src/ScreenGameplay.cpp @@ -722,7 +722,7 @@ void ScreenGameplay::Init( bool bUseSongBackgroundAndForeground ) m_textSongOptions.SetShadowLength( 0 ); m_textSongOptions.SetName( "SongOptions" ); SET_XY( m_textSongOptions ); - m_textSongOptions.SetText( GAMESTATE->m_SongOptions.GetString() ); + m_textSongOptions.SetText( GAMESTATE->m_SongOptions.GetLocalizedString() ); this->AddChild( &m_textSongOptions ); FOREACH_VisiblePlayerInfo( m_vPlayerInfo, pi ) diff --git a/stepmania/src/SongOptions.cpp b/stepmania/src/SongOptions.cpp index 8d84982f14..bb85a08caf 100644 --- a/stepmania/src/SongOptions.cpp +++ b/stepmania/src/SongOptions.cpp @@ -2,6 +2,7 @@ #include "SongOptions.h" #include "RageUtil.h" #include "GameState.h" +#include "CommonMetrics.h" void SongOptions::Init() { @@ -15,25 +16,23 @@ void SongOptions::Init() m_bSaveScore = true; } -RString SongOptions::GetString() const +void SongOptions::GetMods( vector &AddTo ) const { - RString sReturn; - switch( m_LifeType ) { case LIFE_BAR: switch( m_DrainType ) { - case DRAIN_NORMAL: break; - case DRAIN_NO_RECOVER: sReturn += "NoRecover, "; break; - case DRAIN_SUDDEN_DEATH: sReturn += "SuddenDeath, "; break; + case DRAIN_NORMAL: break; + case DRAIN_NO_RECOVER: AddTo.push_back("NoRecover"); break; + case DRAIN_SUDDEN_DEATH: AddTo.push_back("SuddenDeath"); break; } break; case LIFE_BATTERY: - sReturn += ssprintf( "%dLives, ", m_iBatteryLives ); + AddTo.push_back( ssprintf( "%dLives", m_iBatteryLives ) ); break; case LIFE_TIME: - sReturn += "LifeTime, "; + AddTo.push_back( "LifeTime" ); break; default: ASSERT(0); } @@ -41,9 +40,9 @@ RString SongOptions::GetString() const switch( m_FailType ) { - case FAIL_IMMEDIATE: break; - case FAIL_END_OF_SONG: sReturn += "FailEndOfSong, "; break; - case FAIL_OFF: sReturn += "FailOff, "; break; + case FAIL_IMMEDIATE: break; + case FAIL_END_OF_SONG: AddTo.push_back("FailEndOfSong"); break; + case FAIL_OFF: AddTo.push_back("FailOff"); break; default: ASSERT(0); } @@ -52,30 +51,52 @@ RString SongOptions::GetString() const RString s = ssprintf( "%2.2f", m_fMusicRate ); if( s[s.size()-1] == '0' ) s.erase( s.size()-1 ); - sReturn += s + "xMusic, "; + AddTo.push_back( s + "xMusic" ); } switch( m_AutosyncType ) { - case AUTOSYNC_OFF: break; - case AUTOSYNC_SONG: sReturn += "AutosyncSong, "; break; - case AUTOSYNC_MACHINE: sReturn += "AutosyncMachine, "; break; + case AUTOSYNC_OFF: break; + case AUTOSYNC_SONG: AddTo.push_back("AutosyncSong"); break; + case AUTOSYNC_MACHINE: AddTo.push_back("AutosyncMachine"); break; default: ASSERT(0); } - - if( sReturn.size() > 2 ) - sReturn.erase( sReturn.size()-2 ); // delete the trailing ", " - return sReturn; } +void SongOptions::GetLocalizedMods( vector &AddTo ) const +{ + vector vMods; + GetMods( vMods ); + FOREACH( RString, vMods, s ) + { + *s = CommonMetrics::LocalizeOptionItem( *s, true ); + } +} + +RString SongOptions::GetString() const +{ + vector v; + GetMods( v ); + return join( ", ", v ); +} + +RString SongOptions::GetLocalizedString() const +{ + vector v; + GetLocalizedMods( v ); + return join( ", ", v ); +} + + /* Options are added to the current settings; call Init() beforehand if * you don't want this. */ -void SongOptions::FromString( RString sOptions ) +void SongOptions::FromString( const RString &sOptions ) { // Init(); - sOptions.MakeLower(); + RString sTemp = sOptions; + sTemp.MakeLower(); vector asBits; - split( sOptions, ",", asBits, true ); + split( sTemp, ",", asBits, true ); for( unsigned i=0; i &AddTo ) const; + void GetLocalizedMods( vector &AddTo ) const; RString GetString() const; - void FromString( RString sOptions ); + RString GetLocalizedString() const; + void FromString( const RString &sOptions ); bool operator==( const SongOptions &other ) const; bool operator!=( const SongOptions &other ) const { return !operator==(other); }