Most of Game is generic, but not all. Split the InputMapper-
specific stuff apart into InputScheme.
This commit is contained in:
@@ -4,14 +4,14 @@
|
||||
#include "RageUtil.h"
|
||||
#include "PrefsManager.h"
|
||||
|
||||
int Game::GetNumGameplayButtons() const
|
||||
int InputScheme::GetNumGameplayButtons() const
|
||||
{
|
||||
int iIndexOfStart = ButtonNameToIndex( "Start" );
|
||||
ASSERT( iIndexOfStart != GameButton_Invalid );
|
||||
return iIndexOfStart;
|
||||
}
|
||||
|
||||
GameButton Game::ButtonNameToIndex( const RString &sButtonName ) const
|
||||
GameButton InputScheme::ButtonNameToIndex( const RString &sButtonName ) const
|
||||
{
|
||||
for( int i=0; i<m_iButtonsPerController; i++ )
|
||||
if( stricmp(m_szButtonNames[i], sButtonName) == 0 )
|
||||
@@ -20,7 +20,7 @@ GameButton Game::ButtonNameToIndex( const RString &sButtonName ) const
|
||||
return GameButton_Invalid;
|
||||
}
|
||||
|
||||
MenuButton Game::GameInputToMenuButton( GameInput GameI ) const
|
||||
MenuButton InputScheme::GameInputToMenuButton( GameInput GameI ) const
|
||||
{
|
||||
FOREACH_MenuButton(i)
|
||||
if( m_DedicatedMenuButton[i] == GameI.button )
|
||||
@@ -36,7 +36,7 @@ MenuButton Game::GameInputToMenuButton( GameInput GameI ) const
|
||||
return MenuButton_INVALID; // invalid GameInput
|
||||
}
|
||||
|
||||
void Game::MenuButtonToGameInputs( MenuButton MenuI, PlayerNumber pn, GameInput GameIout[4] ) const
|
||||
void InputScheme::MenuButtonToGameInputs( MenuButton MenuI, PlayerNumber pn, GameInput GameIout[4] ) const
|
||||
{
|
||||
ASSERT( MenuI != MenuButton_INVALID );
|
||||
|
||||
|
||||
+2
-10
@@ -7,6 +7,7 @@
|
||||
#include "MenuInput.h"
|
||||
#include "GameConstantsAndTypes.h"
|
||||
#include "RageInputDevice.h"
|
||||
#include "InputMapper.h"
|
||||
|
||||
struct lua_State;
|
||||
|
||||
@@ -37,16 +38,7 @@ public:
|
||||
const char *m_szName;
|
||||
|
||||
bool m_bCountNotesSeparately; // Count multiple notes in a row as separate notes or as one note
|
||||
int m_iButtonsPerController;
|
||||
int GetNumGameplayButtons() const;
|
||||
char m_szButtonNames[NUM_GameButton][60]; // The name used by the button graphics system. e.g. "left", "right", "middle C", "snare"
|
||||
GameButton m_DedicatedMenuButton[NUM_MenuButton];
|
||||
GameButton m_SecondaryMenuButton[NUM_MenuButton];
|
||||
DeviceButton m_iDefaultKeyboardKey[NUM_GameController][NUM_GameButton]; // default keyboard keys only have an effect the current game is this game
|
||||
|
||||
GameButton ButtonNameToIndex( const RString &sButtonName ) const;
|
||||
MenuButton GameInputToMenuButton( GameInput GameI ) const;
|
||||
void MenuButtonToGameInputs( MenuButton MenuI, PlayerNumber pn, GameInput GameIout[4] ) const;
|
||||
InputScheme m_InputScheme;
|
||||
|
||||
TapNoteScore MapTapNoteScore( TapNoteScore tns ) const;
|
||||
TapNoteScore m_mapW1To;
|
||||
|
||||
@@ -27,7 +27,6 @@ InputMapper* INPUTMAPPER = NULL; // global and accessable from anywhere in our p
|
||||
|
||||
InputMapper::InputMapper()
|
||||
{
|
||||
ReadMappingsFromDisk();
|
||||
}
|
||||
|
||||
|
||||
@@ -52,12 +51,11 @@ void InputMapper::AddDefaultMappingsForCurrentGameIfUnmapped()
|
||||
FOREACH_GameButton(j)
|
||||
ClearFromInputMap( GameInput(i, j), 2 );
|
||||
|
||||
const Game* pGame = GAMESTATE->GetCurrentGame();
|
||||
FOREACH_GameController( c )
|
||||
{
|
||||
for( int b=0; b<pGame->m_iButtonsPerController; b++ )
|
||||
for( int b=0; b<m_pInputScheme->m_iButtonsPerController; b++ )
|
||||
{
|
||||
DeviceButton key = pGame->m_iDefaultKeyboardKey[c][b];
|
||||
DeviceButton key = m_pInputScheme->m_iDefaultKeyboardKey[c][b];
|
||||
if( key == NO_DEFAULT_KEY )
|
||||
continue;
|
||||
DeviceInput DeviceI( DEVICE_KEYBOARD, key );
|
||||
@@ -498,8 +496,6 @@ void InputMapper::AutoMapJoysticksForCurrentGame()
|
||||
|
||||
int iNumJoysticksMapped = 0;
|
||||
|
||||
const Game* pGame = GAMESTATE->m_pCurGame;
|
||||
|
||||
for( unsigned i=0; i<vDevices.size(); i++ )
|
||||
{
|
||||
InputDevice id = vDevices[i].id;
|
||||
@@ -508,7 +504,7 @@ void InputMapper::AutoMapJoysticksForCurrentGame()
|
||||
{
|
||||
const AutoJoyMapping& mapping = g_AutoJoyMappings[j];
|
||||
|
||||
if( pGame != GAMEMAN->StringToGameType(mapping.szGame) )
|
||||
if( RString(m_pInputScheme->m_szName).CompareNoCase(mapping.szGame) )
|
||||
continue; // games don't match
|
||||
|
||||
RString sDriverRegex = mapping.szDriverRegex;
|
||||
@@ -534,6 +530,18 @@ void InputMapper::AutoMapJoysticksForCurrentGame()
|
||||
}
|
||||
}
|
||||
|
||||
void InputMapper::SetInputScheme( const InputScheme *pInputScheme )
|
||||
{
|
||||
m_pInputScheme = pInputScheme;
|
||||
|
||||
ReadMappingsFromDisk();
|
||||
}
|
||||
|
||||
const InputScheme *InputMapper::GetInputScheme() const
|
||||
{
|
||||
return m_pInputScheme;
|
||||
}
|
||||
|
||||
static const RString DEVICE_INPUT_SEPARATOR = ":"; // this isn't used in any key names
|
||||
|
||||
void InputMapper::ReadMappingsFromDisk()
|
||||
@@ -547,9 +555,7 @@ void InputMapper::ReadMappingsFromDisk()
|
||||
LOG->Trace( "Couldn't open mapping file \"%s\": %s.",
|
||||
SpecialFiles::KEYMAPS_PATH.c_str(), ini.GetError().c_str() );
|
||||
|
||||
const Game *pGame = GAMESTATE->GetCurrentGame();
|
||||
|
||||
const XNode *Key = ini.GetChild( pGame->m_szName );
|
||||
const XNode *Key = ini.GetChild( m_pInputScheme->m_szName );
|
||||
|
||||
if( Key )
|
||||
{
|
||||
@@ -559,7 +565,7 @@ void InputMapper::ReadMappingsFromDisk()
|
||||
const RString &value = i->second;
|
||||
|
||||
GameInput GameI;
|
||||
GameI.FromString( pGame, name );
|
||||
GameI.FromString( m_pInputScheme, name );
|
||||
|
||||
vector<RString> sDeviceInputStrings;
|
||||
split( value, DEVICE_INPUT_SEPARATOR, sDeviceInputStrings, false );
|
||||
@@ -582,18 +588,21 @@ void InputMapper::SaveMappingsToDisk()
|
||||
IniFile ini;
|
||||
ini.ReadFile( SpecialFiles::KEYMAPS_PATH );
|
||||
|
||||
const Game* pGame = GAMESTATE->GetCurrentGame();
|
||||
|
||||
// erase the key so that we overwrite everything for this game
|
||||
ini.DeleteKey( pGame->m_szName );
|
||||
ini.DeleteKey( m_pInputScheme->m_szName );
|
||||
|
||||
XNode *pKey = ini.GetChild( m_pInputScheme->m_szName );
|
||||
if( pKey != NULL )
|
||||
ini.RemoveChild( pKey );
|
||||
pKey = ini.AppendChild( m_pInputScheme->m_szName );
|
||||
|
||||
// iterate over our input map and write all mappings to the ini file
|
||||
FOREACH_GameController( i )
|
||||
{
|
||||
for( int j=0; j<pGame->m_iButtonsPerController; j++ )
|
||||
for( int j=0; j<m_pInputScheme->m_iButtonsPerController; j++ )
|
||||
{
|
||||
GameInput GameI( i, (GameButton)j );
|
||||
RString sNameString = GameI.ToString( pGame );
|
||||
RString sNameString = GameI.ToString( m_pInputScheme );
|
||||
|
||||
vector<RString> asValues;
|
||||
for( int slot = 0; slot < NUM_USER_GAME_TO_DEVICE_SLOTS; ++slot ) // don't save data from the last (keyboard automap) slot
|
||||
@@ -604,7 +613,7 @@ void InputMapper::SaveMappingsToDisk()
|
||||
|
||||
RString sValueString = join( DEVICE_INPUT_SEPARATOR, asValues );
|
||||
|
||||
ini.SetValue( pGame->m_szName, sNameString, sValueString );
|
||||
pKey->AppendAttr( sNameString, sValueString );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -771,8 +780,7 @@ PlayerNumber InputMapper::ControllerToPlayerNumber( GameController controller )
|
||||
|
||||
MenuButton InputMapper::GameToMenu( const GameInput &GameI )
|
||||
{
|
||||
const Game* pGame = GAMESTATE->GetCurrentGame();
|
||||
return pGame->GameInputToMenuButton( GameI );
|
||||
return m_pInputScheme->GameInputToMenuButton( GameI );
|
||||
}
|
||||
|
||||
void InputMapper::MenuToGame( MenuButton MenuI, PlayerNumber pn, GameInput GameIout[4] )
|
||||
@@ -783,8 +791,7 @@ void InputMapper::MenuToGame( MenuButton MenuI, PlayerNumber pn, GameInput GameI
|
||||
pn = PLAYER_INVALID;
|
||||
}
|
||||
|
||||
const Game* pGame = GAMESTATE->GetCurrentGame();
|
||||
pGame->MenuButtonToGameInputs( MenuI, pn, GameIout );
|
||||
m_pInputScheme->MenuButtonToGameInputs( MenuI, pn, GameIout );
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -12,12 +12,30 @@ const int NUM_GAME_TO_DEVICE_SLOTS = 5; // five device inputs may map to one gam
|
||||
const int NUM_SHOWN_GAME_TO_DEVICE_SLOTS = 3;
|
||||
const int NUM_USER_GAME_TO_DEVICE_SLOTS = 2;
|
||||
|
||||
class InputScheme
|
||||
{
|
||||
public:
|
||||
const char *m_szName;
|
||||
int m_iButtonsPerController;
|
||||
char m_szButtonNames[NUM_GameButton][60]; // The name used by the button graphics system. e.g. "left", "right", "middle C", "snare"
|
||||
GameButton m_DedicatedMenuButton[NUM_MenuButton];
|
||||
GameButton m_SecondaryMenuButton[NUM_MenuButton];
|
||||
DeviceButton m_iDefaultKeyboardKey[NUM_GameController][NUM_GameButton]; // default keyboard keys only have an effect the current game is this game
|
||||
|
||||
int GetNumGameplayButtons() const;
|
||||
GameButton ButtonNameToIndex( const RString &sButtonName ) const;
|
||||
MenuButton GameInputToMenuButton( GameInput GameI ) const;
|
||||
void MenuButtonToGameInputs( MenuButton MenuI, PlayerNumber pn, GameInput GameIout[4] ) const;
|
||||
};
|
||||
|
||||
class InputMapper
|
||||
{
|
||||
public:
|
||||
InputMapper();
|
||||
~InputMapper();
|
||||
|
||||
void SetInputScheme( const InputScheme *pInputScheme );
|
||||
const InputScheme *GetInputScheme() const;
|
||||
void ReadMappingsFromDisk();
|
||||
void SaveMappingsToDisk();
|
||||
|
||||
@@ -82,6 +100,7 @@ protected:
|
||||
DeviceInput m_GItoDI[NUM_GameController][NUM_GameButton][NUM_GAME_TO_DEVICE_SLOTS];
|
||||
|
||||
void UpdateTempDItoGI();
|
||||
const InputScheme *m_pInputScheme;
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user