InputScheme

This commit is contained in:
Glenn Maynard
2006-09-30 08:24:05 +00:00
parent b6c3ea14d7
commit 3f315b0464
7 changed files with 26 additions and 28 deletions
+1 -2
View File
@@ -97,7 +97,6 @@ bool CodeItem::Load( RString sButtonsNames )
{ {
buttons.clear(); buttons.clear();
const Game* pGame = GAMESTATE->GetCurrentGame();
vector<RString> asButtonNames; vector<RString> asButtonNames;
bool bHasAPlus = sButtonsNames.find( '+' ) != string::npos; bool bHasAPlus = sButtonsNames.find( '+' ) != string::npos;
@@ -131,7 +130,7 @@ bool CodeItem::Load( RString sButtonsNames )
const RString sButtonName = asButtonNames[i]; const RString sButtonName = asButtonNames[i];
// Search for the corresponding GameButton // Search for the corresponding GameButton
const GameButton gb = pGame->ButtonNameToIndex( sButtonName ); const GameButton gb = INPUTMAPPER->GetInputScheme()->ButtonNameToIndex( sButtonName );
if( gb == GameButton_Invalid ) if( gb == GameButton_Invalid )
{ {
LOG->Trace( "The code '%s' contains an unrecognized button '%s'.", sButtonsNames.c_str(), sButtonName.c_str() ); LOG->Trace( "The code '%s' contains an unrecognized button '%s'.", sButtonsNames.c_str(), sButtonName.c_str() );
+12 -12
View File
@@ -2,7 +2,7 @@
#include "GameInput.h" #include "GameInput.h"
#include "RageLog.h" #include "RageLog.h"
#include "RageUtil.h" #include "RageUtil.h"
#include "Game.h" #include "InputMapper.h"
#include "ThemeManager.h" #include "ThemeManager.h"
@@ -14,33 +14,33 @@ XToString( GameController, NUM_GameController );
StringToX( GameController ); StringToX( GameController );
RString GameButtonToString( const Game* pGame, GameButton i ) RString GameButtonToString( const InputScheme* pInputs, GameButton i )
{ {
return pGame->m_szButtonNames[i]; return pInputs->m_szButtonNames[i];
} }
RString GameButtonToLocalizedString( const Game* pGame, GameButton i ) RString GameButtonToLocalizedString( const InputScheme* pInputs, GameButton i )
{ {
return THEME->GetString( "GameButton", GameButtonToString(pGame,i) ); return THEME->GetString( "GameButton", GameButtonToString(pInputs,i) );
} }
GameButton StringToGameButton( const Game* pGame, const RString& s ) GameButton StringToGameButton( const InputScheme* pInputs, const RString& s )
{ {
for( int i=0; i<pGame->m_iButtonsPerController; i++ ) for( int i=0; i<pInputs->m_iButtonsPerController; i++ )
{ {
if( s == GameButtonToString(pGame,(GameButton)i) ) if( s == GameButtonToString(pInputs,(GameButton)i) )
return (GameButton)i; return (GameButton)i;
} }
return GameButton_Invalid; return GameButton_Invalid;
} }
RString GameInput::ToString( const Game* pGame ) const RString GameInput::ToString( const InputScheme* pInputs ) const
{ {
return GameControllerToString(controller) + RString("_") + GameButtonToString(pGame,button); return GameControllerToString(controller) + RString("_") + GameButtonToString(pInputs,button);
} }
bool GameInput::FromString( const Game* pGame, const RString &s ) bool GameInput::FromString( const InputScheme* pInputs, const RString &s )
{ {
char szController[32] = ""; char szController[32] = "";
char szButton[32] = ""; char szButton[32] = "";
@@ -52,7 +52,7 @@ bool GameInput::FromString( const Game* pGame, const RString &s )
} }
controller = StringToGameController( szController ); controller = StringToGameController( szController );
button = StringToGameButton( pGame, szButton ); button = StringToGameButton( pInputs, szButton );
return true; return true;
}; };
+6 -6
View File
@@ -5,7 +5,7 @@
#include "EnumHelper.h" #include "EnumHelper.h"
class Game; class InputScheme;
enum GameController enum GameController
{ {
@@ -17,9 +17,9 @@ enum GameController
#define FOREACH_GameController( gc ) FOREACH_ENUM2( GameController, gc ) #define FOREACH_GameController( gc ) FOREACH_ENUM2( GameController, gc )
typedef int GameButton; typedef int GameButton;
RString GameButtonToString( const Game* pGame, GameButton i ); RString GameButtonToString( const InputScheme* pInputs, GameButton i );
RString GameButtonToLocalizedString( const Game* pGame, GameButton i ); RString GameButtonToLocalizedString( const InputScheme* pInputs, GameButton i );
GameButton StringToGameButton( const Game* pGame, const RString& s ); GameButton StringToGameButton( const InputScheme* pInputs, const RString& s );
const GameButton NUM_GameButton = 20; const GameButton NUM_GameButton = 20;
const GameButton GameButton_Invalid = NUM_GameButton+1; const GameButton GameButton_Invalid = NUM_GameButton+1;
@@ -260,8 +260,8 @@ struct GameInput
inline bool IsValid() const { return controller != GameController_Invalid; }; inline bool IsValid() const { return controller != GameController_Invalid; };
inline void MakeInvalid() { controller = GameController_Invalid; button = GameButton_Invalid; }; inline void MakeInvalid() { controller = GameController_Invalid; button = GameButton_Invalid; };
RString ToString( const Game* pGame ) const; RString ToString( const InputScheme* pInputs ) const;
bool FromString( const Game* pGame, const RString &s ); bool FromString( const InputScheme* pInputs, const RString &s );
}; };
#endif #endif
+3 -3
View File
@@ -48,7 +48,7 @@ void ScreenMapControllers::Init()
if( sButtons.empty() ) if( sButtons.empty() )
{ {
/* Map all buttons for this game. */ /* Map all buttons for this game. */
for( int b=0; b<GAMESTATE->GetCurrentGame()->m_iButtonsPerController; b++ ) for( int b=0; b<INPUTMAPPER->GetInputScheme()->m_iButtonsPerController; b++ )
{ {
KeyToMap k; KeyToMap k;
k.m_GameButton = (GameButton) b; k.m_GameButton = (GameButton) b;
@@ -63,7 +63,7 @@ void ScreenMapControllers::Init()
for( unsigned i=0; i<asBits.size(); ++i ) for( unsigned i=0; i<asBits.size(); ++i )
{ {
KeyToMap k; KeyToMap k;
k.m_GameButton = StringToGameButton( GAMESTATE->GetCurrentGame(), asBits[i] ); k.m_GameButton = StringToGameButton( INPUTMAPPER->GetInputScheme(), asBits[i] );
m_KeysToMap.push_back( k ); m_KeysToMap.push_back( k );
} }
} }
@@ -97,7 +97,7 @@ void ScreenMapControllers::Init()
BitmapText *pName = new BitmapText; BitmapText *pName = new BitmapText;
pName->SetName( "Primary" ); pName->SetName( "Primary" );
pName->LoadFromFont( THEME->GetPathF("Common","title") ); pName->LoadFromFont( THEME->GetPathF("Common","title") );
RString sText = GameButtonToLocalizedString( GAMESTATE->GetCurrentGame(), pKey->m_GameButton ); RString sText = GameButtonToLocalizedString( INPUTMAPPER->GetInputScheme(), pKey->m_GameButton );
pName->SetText( sText ); pName->SetText( sText );
ActorUtil::LoadAllCommands( *pName, m_sName ); ActorUtil::LoadAllCommands( *pName, m_sName );
m_Line[iRow].AddChild( pName ); m_Line[iRow].AddChild( pName );
+1 -1
View File
@@ -57,7 +57,7 @@ class InputList: public BitmapText
GameInput gi; GameInput gi;
if( INPUTMAPPER->DeviceToGame(*di,gi) ) if( INPUTMAPPER->DeviceToGame(*di,gi) )
{ {
RString sName = GameButtonToLocalizedString( GAMESTATE->GetCurrentGame(), gi.button ); RString sName = GameButtonToLocalizedString( INPUTMAPPER->GetInputScheme(), gi.button );
sTemp += ssprintf(" - "+CONTROLLER.GetValue()+" %d %s", gi.controller+1, sName.c_str() ); sTemp += ssprintf(" - "+CONTROLLER.GetValue()+" %d %s", gi.controller+1, sName.c_str() );
if( !PREFSMAN->m_bOnlyDedicatedMenuButtons ) if( !PREFSMAN->m_bOnlyDedicatedMenuButtons )
+1 -1
View File
@@ -79,7 +79,7 @@ void ScreenTestLights::Update( float fDeltaTime )
} }
else else
{ {
RString sGameButton = GameButtonToLocalizedString( GAMESTATE->GetCurrentGame(), gb ); RString sGameButton = GameButtonToLocalizedString( INPUTMAPPER->GetInputScheme(), gb );
PlayerNumber pn = (PlayerNumber)(gc+1); PlayerNumber pn = (PlayerNumber)(gc+1);
s += ssprintf( CONTROLLER_LIGHT.GetValue()+": %s %d %s\n", PlayerNumberToString(pn).c_str(), gb, sGameButton.c_str() ); s += ssprintf( CONTROLLER_LIGHT.GetValue()+": %s %d %s\n", PlayerNumberToString(pn).c_str(), gb, sGameButton.c_str() );
} }
@@ -1,8 +1,7 @@
#include "global.h" #include "global.h"
#include "LightsDriver_SystemMessage.h" #include "LightsDriver_SystemMessage.h"
#include "ScreenManager.h" #include "ScreenManager.h"
#include "GameState.h" #include "InputMapper.h"
#include "Game.h"
#include "PrefsManager.h" #include "PrefsManager.h"
@@ -30,7 +29,7 @@ void LightsDriver_SystemMessage::Set( const LightsState *ls )
} }
s += "\n"; s += "\n";
int iNumGameButtonsToShow = GAMESTATE->m_pCurGame->GetNumGameplayButtons(); int iNumGameButtonsToShow = INPUTMAPPER->GetInputScheme()->GetNumGameplayButtons();
FOREACH_GameController( gc ) FOREACH_GameController( gc )
{ {