From 9122e2f935c0b5b1b822c08945ebd04504dde0c3 Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Sun, 8 Jan 2006 19:38:33 +0000 Subject: [PATCH] localize more strings --- stepmania/src/Game.h | 4 +-- stepmania/src/GameInput.cpp | 6 ++++ stepmania/src/GameInput.h | 3 +- stepmania/src/GameManager.cpp | 20 +++-------- stepmania/src/GameManager.h | 3 +- stepmania/src/Makefile.am | 3 +- stepmania/src/MenuInput.cpp | 46 ++++++++++++++++++++++++++ stepmania/src/MenuInput.h | 11 +++--- stepmania/src/ScreenMapControllers.cpp | 16 ++++----- stepmania/src/ScreenTestInput.cpp | 17 ++++++---- stepmania/src/ScreenTestLights.cpp | 2 +- 11 files changed, 90 insertions(+), 41 deletions(-) create mode 100644 stepmania/src/MenuInput.cpp diff --git a/stepmania/src/Game.h b/stepmania/src/Game.h index 91ed283386..49f9fc71f3 100644 --- a/stepmania/src/Game.h +++ b/stepmania/src/Game.h @@ -48,8 +48,8 @@ public: int m_iButtonsPerController; int GetNumGameplayButtons() const; char m_szButtonNames[MAX_GAME_BUTTONS][60]; // The name used by the button graphics system. e.g. "left", "right", "middle C", "snare" - GameButton m_DedicatedMenuButton[NUM_MENU_BUTTONS]; - GameButton m_SecondaryMenuButton[NUM_MENU_BUTTONS]; + GameButton m_DedicatedMenuButton[NUM_MenuButton]; + GameButton m_SecondaryMenuButton[NUM_MenuButton]; DeviceButton m_iDefaultKeyboardKey[MAX_GAME_CONTROLLERS][MAX_GAME_BUTTONS]; // default keyboard keys only have an effect the current game is this game GameButton ButtonNameToIndex( const CString &sButtonName ) const; diff --git a/stepmania/src/GameInput.cpp b/stepmania/src/GameInput.cpp index ed28ebe561..5761a01b62 100644 --- a/stepmania/src/GameInput.cpp +++ b/stepmania/src/GameInput.cpp @@ -3,6 +3,7 @@ #include "RageLog.h" #include "RageUtil.h" #include "Game.h" +#include "ThemeManager.h" static const char *GameControllerNames[] = { @@ -18,6 +19,11 @@ CString GameButtonToString( const Game* pGame, GameButton i ) return pGame->m_szButtonNames[i]; } +CString GameButtonToLocalizedString( const Game* pGame, GameButton i ) +{ + return THEME->GetString( "GameButton", GameButtonToString(pGame,i) ); +} + GameButton StringToGameButton( const Game* pGame, const CString& s ) { for( int i=0; im_iButtonsPerController; i++ ) diff --git a/stepmania/src/GameInput.h b/stepmania/src/GameInput.h index 6c0aca7024..dbbb29fc18 100644 --- a/stepmania/src/GameInput.h +++ b/stepmania/src/GameInput.h @@ -17,7 +17,8 @@ enum GameController #define FOREACH_GameController( gc ) FOREACH_ENUM( GameController, MAX_GAME_CONTROLLERS, gc ) typedef int GameButton; -CString GameButtonToString( GameButton i ); +CString GameButtonToString( const Game* pGame, GameButton i ); +CString GameButtonToLocalizedString( const Game* pGame, GameButton i ); GameButton StringToGameButton( const Game* pGame, const CString& s ); const GameButton MAX_GAME_BUTTONS = 20; diff --git a/stepmania/src/GameManager.cpp b/stepmania/src/GameManager.cpp index 60d3dfd2d3..46cbaf0200 100644 --- a/stepmania/src/GameManager.cpp +++ b/stepmania/src/GameManager.cpp @@ -2794,7 +2794,7 @@ const Style* GameManager::GameAndStringToStyle( const Game *game, CString sStyle } -CString GameManager::GetMenuButtonSecondaryFunction( const Game *pGame, GameButton gb ) const +MenuButton GameManager::GetMenuButtonSecondaryFunction( const Game *pGame, GameButton gb ) const { /* * Each GameButton can be used in gameplay (if any gameplay style maps to @@ -2821,28 +2821,16 @@ CString GameManager::GetMenuButtonSecondaryFunction( const Game *pGame, GameButt } } - static const char *szSecondaryNames[] = - { - "MenuLeft", - "MenuRight", - "MenuUp", - "MenuDown", - "MenuStart", - "MenuSelect", - "MenuBack", - "Coin", - "Operator" - }; FOREACH_MenuButton(m) { if( !bUsedInGameplay && pGame->m_DedicatedMenuButton[m] == gb ) - return CString(); + return MenuButton_INVALID; else if( bUsedInGameplay && pGame->m_SecondaryMenuButton[m] == gb ) - return szSecondaryNames[m]; + return m; } - return CString(); // only used in gameplay + return MenuButton_INVALID; // only used in gameplay } diff --git a/stepmania/src/GameManager.h b/stepmania/src/GameManager.h index a3c730886b..e7252473e9 100644 --- a/stepmania/src/GameManager.h +++ b/stepmania/src/GameManager.h @@ -9,6 +9,7 @@ struct lua_State; #include "GameConstantsAndTypes.h" #include "GameInput.h" +#include "MenuInput.h" class GameManager { @@ -35,7 +36,7 @@ public: static const Game* StringToGameType( CString sGameType ); const Style* GameAndStringToStyle( const Game* pGame, CString sStyle ); static CString StyleToLocalizedString( const Style* s ); - CString GetMenuButtonSecondaryFunction( const Game *pGame, GameButton gb ) const; + MenuButton GetMenuButtonSecondaryFunction( const Game *pGame, GameButton gb ) const; // Lua void PushSelf( lua_State *L ); diff --git a/stepmania/src/Makefile.am b/stepmania/src/Makefile.am index 759e6c6b9c..3d5caa47af 100644 --- a/stepmania/src/Makefile.am +++ b/stepmania/src/Makefile.am @@ -108,7 +108,8 @@ LocalizedString.cpp LocalizedString.h \ LuaFunctions.h \ LuaReference.cpp LuaReference.h \ LuaExpressionTransform.cpp LuaExpressionTransform.h \ -LyricsLoader.cpp LyricsLoader.h MenuInput.h \ +LyricsLoader.cpp LyricsLoader.h +MenuInput.cpp MenuInput.h \ NoteData.cpp NoteData.h NoteDataUtil.cpp NoteDataUtil.h NoteDataWithScoring.cpp NoteDataWithScoring.h \ NoteFieldPositioning.cpp NoteFieldPositioning.h NoteTypes.cpp NoteTypes.h NotesLoader.cpp NotesLoader.h \ NotesLoaderBMS.cpp NotesLoaderBMS.h NotesLoaderDWI.cpp NotesLoaderDWI.h NotesLoaderKSF.cpp NotesLoaderKSF.h \ diff --git a/stepmania/src/MenuInput.cpp b/stepmania/src/MenuInput.cpp new file mode 100644 index 0000000000..6f4ae6592e --- /dev/null +++ b/stepmania/src/MenuInput.cpp @@ -0,0 +1,46 @@ +#include "global.h" +#include "MenuInput.h" +#include "EnumHelper.h" +#include "RageUtil.h" +#include "LocalizedString.h" + +static const char *MenuButtonNames[] = +{ + "MenuLeft", + "MenuRight", + "MenuUp", + "MenuDown", + "MenuStart", + "MenuSelect", + "MenuBack", + "Coin", + "Operator" +}; +XToString( MenuButton, NUM_MenuButton ); +XToLocalizedString( MenuButton ); + + +/* + * (c) 2006 Chris Danford + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, and/or sell copies of the Software, and to permit persons to + * whom the Software is furnished to do so, provided that the above + * copyright notice(s) and this permission notice appear in all copies of + * the Software and that both the above copyright notice(s) and this + * permission notice appear in supporting documentation. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF + * THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS + * INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT + * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR + * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ diff --git a/stepmania/src/MenuInput.h b/stepmania/src/MenuInput.h index e44e7eadbe..4802ed419c 100644 --- a/stepmania/src/MenuInput.h +++ b/stepmania/src/MenuInput.h @@ -16,10 +16,13 @@ enum MenuButton MENU_BUTTON_BACK, MENU_BUTTON_COIN, MENU_BUTTON_OPERATOR, - NUM_MENU_BUTTONS, // leave this at the end - MENU_BUTTON_INVALID + NUM_MenuButton, // leave this at the end + MenuButton_INVALID }; -#define FOREACH_MenuButton( m ) FOREACH_ENUM( MenuButton, NUM_MENU_BUTTONS, m ) +#define FOREACH_MenuButton( m ) FOREACH_ENUM( MenuButton, NUM_MenuButton, m ) + +const CString &MenuButtonToString( MenuButton mb ); +const CString &MenuButtonToLocalizedString( MenuButton mb ); struct MenuInput { @@ -33,7 +36,7 @@ struct MenuInput bool operator!=( const MenuInput &other ) { return !operator==(other); }; inline bool IsValid() const { return player != PLAYER_INVALID; }; - inline void MakeInvalid() { player = PLAYER_INVALID; button = MENU_BUTTON_INVALID; }; + inline void MakeInvalid() { player = PLAYER_INVALID; button = MenuButton_INVALID; }; }; #endif diff --git a/stepmania/src/ScreenMapControllers.cpp b/stepmania/src/ScreenMapControllers.cpp index c95607abfe..1c12976285 100644 --- a/stepmania/src/ScreenMapControllers.cpp +++ b/stepmania/src/ScreenMapControllers.cpp @@ -12,11 +12,11 @@ #include "ScreenDimensions.h" #include "Command.h" #include "InputEventPlus.h" +#include "LocalizedString.h" -#define BUTTONS_TO_MAP THEME->GetMetric ( m_sName, "ButtonsToMap" ) -#define INVALID_BUTTON THEME->GetMetric ( m_sName, "InvalidButton" ) -#define MAPPED_TO_COMMAND(gc,slot) THEME->GetMetricA( m_sName, ssprintf("MappedToP%iS%iCommand", gc+1, slot+1) ) -#define BUTTON_NAME(s) THEME->GetString ( m_sName, s ) +#define BUTTONS_TO_MAP THEME->GetMetric ( m_sName, "ButtonsToMap" ) +static LocalizedString INVALID_BUTTON ( "ScreenMapControllers", "InvalidButton" ); +#define MAPPED_TO_COMMAND(gc,slot) THEME->GetMetricA( m_sName, ssprintf("MappedToP%iS%iCommand", gc+1, slot+1) ) static const float g_fSecondsToWaitForInput = 0.05f; @@ -67,8 +67,7 @@ void ScreenMapControllers::Init() BitmapText *pName = new BitmapText; pName->SetName( "Title" ); pName->LoadFromFont( THEME->GetPathF("Common","title") ); - CString sText = GAMESTATE->GetCurrentGame()->m_szButtonNames[pKey->m_GameButton]; - sText = BUTTON_NAME(sText.c_str()); + CString sText = GameButtonToLocalizedString( GAMESTATE->GetCurrentGame(), pKey->m_GameButton ); pName->SetText( sText ); ActorUtil::LoadAllCommands( *pName, m_sName ); m_Line[b].AddChild( pName ); @@ -76,8 +75,9 @@ void ScreenMapControllers::Init() BitmapText *pSecondary = new BitmapText; pSecondary->SetName( "Secondary" ); pSecondary->LoadFromFont( THEME->GetPathF("Common","title") ); - sText = GAMEMAN->GetMenuButtonSecondaryFunction( GAMESTATE->GetCurrentGame(), pKey->m_GameButton ); - sText = BUTTON_NAME(sText.c_str()); + MenuButton mb = GAMEMAN->GetMenuButtonSecondaryFunction( GAMESTATE->GetCurrentGame(), pKey->m_GameButton ); + if( mb != MenuButton_INVALID ) + sText = MenuButtonToLocalizedString( mb ); ActorUtil::LoadAllCommands( *pSecondary, m_sName ); pSecondary->SetText( sText ); m_Line[b].AddChild( pSecondary ); diff --git a/stepmania/src/ScreenTestInput.cpp b/stepmania/src/ScreenTestInput.cpp index 887ad0b56b..4bea2e63db 100644 --- a/stepmania/src/ScreenTestInput.cpp +++ b/stepmania/src/ScreenTestInput.cpp @@ -11,6 +11,7 @@ #include "PrefsManager.h" #include "RageInput.h" #include "InputEventPlus.h" +#include "LocalizedString.h" REGISTER_SCREEN_CLASS( ScreenTestInput ); @@ -47,7 +48,9 @@ ScreenTestInput::~ScreenTestInput() LOG->Trace( "ScreenTestInput::~ScreenTestInput()" ); } - +static LocalizedString CONTROLLER ( "ScreenTestInput", "Controller" ); +static LocalizedString SECONDARY ( "ScreenTestInput", "secondary" ); +static LocalizedString NOT_MAPPED ( "ScreenTestInput", "not mapped" ); void ScreenTestInput::Update( float fDeltaTime ) { Screen::Update( fDeltaTime ); @@ -88,19 +91,19 @@ void ScreenTestInput::Update( float fDeltaTime ) GameInput gi; if( INPUTMAPPER->DeviceToGame(*di,gi) ) { - CString sName = GAMESTATE->GetCurrentGame()->m_szButtonNames[gi.button]; - sTemp += ssprintf(" - Controller %d %s", gi.controller+1, sName.c_str() ); + CString sName = GameButtonToLocalizedString( GAMESTATE->GetCurrentGame(), gi.button ); + sTemp += ssprintf(" - "+CONTROLLER.GetValue()+" %d %s", gi.controller+1, sName.c_str() ); if( !PREFSMAN->m_bOnlyDedicatedMenuButtons ) { - CString sSecondary = GAMEMAN->GetMenuButtonSecondaryFunction( GAMESTATE->GetCurrentGame(), gi.button ); - if( !sSecondary.empty() ) - sTemp += ssprintf(" - (%s secondary)", sSecondary.c_str() ); + MenuButton mb = GAMEMAN->GetMenuButtonSecondaryFunction( GAMESTATE->GetCurrentGame(), gi.button ); + if( mb != MenuButton_INVALID ) + sTemp += ssprintf( " - (%s %s)", MenuButtonToLocalizedString(mb).c_str(), SECONDARY.GetValue().c_str() ); } } else { - sTemp += " - not mapped"; + sTemp += " - "+NOT_MAPPED.GetValue(); } CString sComment = INPUTFILTER->GetButtonComment( *di ); diff --git a/stepmania/src/ScreenTestLights.cpp b/stepmania/src/ScreenTestLights.cpp index b9ff2b5dea..2895db34f1 100644 --- a/stepmania/src/ScreenTestLights.cpp +++ b/stepmania/src/ScreenTestLights.cpp @@ -80,7 +80,7 @@ void ScreenTestLights::Update( float fDeltaTime ) } else { - CString sGameButton = GAMESTATE->GetCurrentGame()->m_szButtonNames[gb]; + CString sGameButton = GameButtonToLocalizedString( GAMESTATE->GetCurrentGame(), gb ); s += ssprintf( "controller light: P%d %d %s\n", gc+1, gb, sGameButton.c_str() ); }