cleaner, more consistent SecondaryFunction handling

This commit is contained in:
Glenn Maynard
2007-01-13 05:41:40 +00:00
parent b0b68212c7
commit 8b279db97f
2 changed files with 43 additions and 52 deletions
+33 -43
View File
@@ -828,7 +828,7 @@ void InputMapper::SetJoinControllers( PlayerNumber pn )
} }
void InputMapper::MenuToGame( GameButton MenuI, PlayerNumber pn, GameInput GameIout[4] ) void InputMapper::MenuToGame( GameButton MenuI, PlayerNumber pn, vector<GameInput> &GameIout )
{ {
if( g_JoinControllers != PLAYER_INVALID ) if( g_JoinControllers != PLAYER_INVALID )
pn = PLAYER_INVALID; pn = PLAYER_INVALID;
@@ -857,10 +857,10 @@ bool InputMapper::IsBeingPressed( const GameInput &GameI, MultiPlayer mp, const
bool InputMapper::IsBeingPressed( GameButton MenuI, PlayerNumber pn ) bool InputMapper::IsBeingPressed( GameButton MenuI, PlayerNumber pn )
{ {
GameInput GameI[4]; vector<GameInput> GameI;
MenuToGame( MenuI, pn, GameI ); MenuToGame( MenuI, pn, GameI );
for( int i=0; i<4; i++ ) for( size_t i=0; i<GameI.size(); i++ )
if( GameI[i].IsValid() && IsBeingPressed(GameI[i]) ) if( IsBeingPressed(GameI[i]) )
return true; return true;
return false; return false;
@@ -879,10 +879,9 @@ void InputMapper::RepeatStopKey( const GameInput &GameI )
void InputMapper::RepeatStopKey( GameButton MenuI, PlayerNumber pn ) void InputMapper::RepeatStopKey( GameButton MenuI, PlayerNumber pn )
{ {
GameInput GameI[4]; vector<GameInput> GameI;
MenuToGame( MenuI, pn, GameI ); MenuToGame( MenuI, pn, GameI );
for( int i=0; i<4; i++ ) for( size_t i=0; i<GameI.size(); i++ )
if( GameI[i].IsValid() )
RepeatStopKey( GameI[i] ); RepeatStopKey( GameI[i] );
} }
@@ -908,10 +907,9 @@ float InputMapper::GetSecsHeld( GameButton MenuI, PlayerNumber pn )
{ {
float fMaxSecsHeld = 0; float fMaxSecsHeld = 0;
GameInput GameI[4]; vector<GameInput> GameI;
MenuToGame( MenuI, pn, GameI ); MenuToGame( MenuI, pn, GameI );
for( int i=0; i<4; i++ ) for( size_t i=0; i<GameI.size(); i++ )
if( GameI[i].IsValid() )
fMaxSecsHeld = max( fMaxSecsHeld, GetSecsHeld(GameI[i]) ); fMaxSecsHeld = max( fMaxSecsHeld, GetSecsHeld(GameI[i]) );
return fMaxSecsHeld; return fMaxSecsHeld;
@@ -929,10 +927,9 @@ void InputMapper::ResetKeyRepeat( const GameInput &GameI )
void InputMapper::ResetKeyRepeat( GameButton MenuI, PlayerNumber pn ) void InputMapper::ResetKeyRepeat( GameButton MenuI, PlayerNumber pn )
{ {
GameInput GameI[4]; vector<GameInput> GameI;
MenuToGame( MenuI, pn, GameI ); MenuToGame( MenuI, pn, GameI );
for( int i=0; i<4; i++ ) for( size_t i=0; i<GameI.size(); i++ )
if( GameI[i].IsValid() )
ResetKeyRepeat( GameI[i] ); ResetKeyRepeat( GameI[i] );
} }
@@ -970,50 +967,43 @@ GameButton InputScheme::GameButtonToMenuButton( GameButton gb ) const
return GameButton_Invalid; // no GameButton for this GameButton return GameButton_Invalid; // no GameButton for this GameButton
} }
void InputScheme::MenuButtonToGameInputs( GameButton MenuI, PlayerNumber pn, GameInput GameIout[4] ) const void InputScheme::MenuButtonToGameInputs( GameButton MenuI, PlayerNumber pn, vector<GameInput> &GameIout ) const
{ {
ASSERT( MenuI != GameButton_Invalid ); ASSERT( MenuI != GameButton_Invalid );
GameIout[0].MakeInvalid(); // initialize vector<GameButton> aGameButtons;
GameIout[1].MakeInvalid(); MenuButtonToGameButtons( MenuI, aGameButtons );
GameIout[2].MakeInvalid(); FOREACH( GameButton, aGameButtons, gb )
GameIout[3].MakeInvalid(); {
vector<GameController> controller;
if( pn == PLAYER_INVALID ) if( pn == PLAYER_INVALID )
{ {
controller.push_back( GAME_CONTROLLER_1 ); GameIout.push_back( GameInput(GAME_CONTROLLER_1, *gb) );
controller.push_back( GAME_CONTROLLER_2 ); GameIout.push_back( GameInput(GAME_CONTROLLER_2, *gb) );
} }
else else
{ {
controller.push_back( (GameController)pn ); GameIout.push_back( GameInput((GameController)pn, *gb) );
}
GameButton SecondaryGameButton = GameButton_Invalid;
for( GameButton gb=GAME_BUTTON_NEXT; gb<m_iButtonsPerController; gb=(GameButton)(gb+1) )
{
if( m_GameButtonInfo[gb-GAME_BUTTON_NEXT].m_SecondaryMenuButton == MenuI )
{
SecondaryGameButton = gb;
break;
} }
} }
}
GameButton button[2] = { MenuI, SecondaryGameButton }; void InputScheme::MenuButtonToGameButtons( GameButton MenuI, vector<GameButton> &aGameButtons ) const
int iNumButtonsUsing = PREFSMAN->m_bOnlyDedicatedMenuButtons ? 1 : 2; {
ASSERT( MenuI != GameButton_Invalid );
int iOut = 0; if( MenuI == GameButton_Invalid )
for( size_t i=0; i<controller.size(); i++ ) return;
aGameButtons.push_back( MenuI );
if( PREFSMAN->m_bOnlyDedicatedMenuButtons )
return;
for( GameButton gb=GAME_BUTTON_NEXT; gb<m_iButtonsPerController; enum_add(gb, +1) )
{ {
for( int j=0; j<iNumButtonsUsing; j++ ) if( m_GameButtonInfo[gb-GAME_BUTTON_NEXT].m_SecondaryMenuButton != MenuI )
{
if( button[j] == GameButton_Invalid )
continue; continue;
GameIout[iOut].controller = controller[i]; aGameButtons.push_back( gb );
GameIout[iOut].button = button[j];
++iOut;
}
} }
} }
+3 -2
View File
@@ -47,7 +47,8 @@ public:
GameButton ButtonNameToIndex( const RString &sButtonName ) const; GameButton ButtonNameToIndex( const RString &sButtonName ) const;
GameButton GameButtonToMenuButton( GameButton gb ) const; GameButton GameButtonToMenuButton( GameButton gb ) const;
void MenuButtonToGameInputs( GameButton MenuI, PlayerNumber pn, GameInput GameIout[4] ) const; void MenuButtonToGameInputs( GameButton MenuI, PlayerNumber pn, vector<GameInput> &GameIout ) const;
void MenuButtonToGameButtons( GameButton MenuI, vector<GameButton> &aGameButtons ) const;
GameButton GetMenuButtonSecondaryFunction( GameButton gb ) const; GameButton GetMenuButtonSecondaryFunction( GameButton gb ) const;
const GameButtonInfo *GetGameButtonInfo( GameButton gb ) const; const GameButtonInfo *GetGameButtonInfo( GameButton gb ) const;
const char *GetGameButtonName( GameButton gb ) const; const char *GetGameButtonName( GameButton gb ) const;
@@ -83,7 +84,7 @@ public:
bool GameToDevice( const GameInput &GameI, int iSlotNum, DeviceInput& DeviceI ); // return true if there is a mapping from pad to device bool GameToDevice( const GameInput &GameI, int iSlotNum, DeviceInput& DeviceI ); // return true if there is a mapping from pad to device
GameButton GameButtonToMenuButton( GameButton gb ); GameButton GameButtonToMenuButton( GameButton gb );
void MenuToGame( GameButton MenuI, PlayerNumber pn, GameInput GameIout[4] ); void MenuToGame( GameButton MenuI, PlayerNumber pn, vector<GameInput> &GameIout );
PlayerNumber ControllerToPlayerNumber( GameController controller ); PlayerNumber ControllerToPlayerNumber( GameController controller );
float GetSecsHeld( const GameInput &GameI, MultiPlayer mp = MultiPlayer_Invalid ); float GetSecsHeld( const GameInput &GameI, MultiPlayer mp = MultiPlayer_Invalid );