Files
itgmania212121/stepmania/src/GameInput.cpp
T

83 lines
2.6 KiB
C++
Raw Normal View History

2003-02-16 04:01:45 +00:00
#include "global.h"
2002-07-27 19:29:51 +00:00
#include "GameInput.h"
#include "RageLog.h"
#include "RageUtil.h"
2005-04-24 02:15:41 +00:00
#include "Game.h"
2006-01-08 19:38:33 +00:00
#include "ThemeManager.h"
2002-07-27 19:29:51 +00:00
static const char *GameControllerNames[] = {
2005-04-24 02:15:41 +00:00
"Controller1",
"Controller2",
};
XToString( GameController, MAX_GAME_CONTROLLERS );
StringToX( GameController );
2006-01-22 01:00:06 +00:00
RString GameButtonToString( const Game* pGame, GameButton i )
2005-04-24 02:15:41 +00:00
{
return pGame->m_szButtonNames[i];
}
2006-01-22 01:00:06 +00:00
RString GameButtonToLocalizedString( const Game* pGame, GameButton i )
2006-01-08 19:38:33 +00:00
{
return THEME->GetString( "GameButton", GameButtonToString(pGame,i) );
}
2006-01-22 01:00:06 +00:00
GameButton StringToGameButton( const Game* pGame, const RString& s )
2005-04-24 02:15:41 +00:00
{
for( int i=0; i<pGame->m_iButtonsPerController; i++ )
{
if( s == GameButtonToString(pGame,(GameButton)i) )
return (GameButton)i;
}
return GAME_BUTTON_INVALID;
}
2006-01-22 01:00:06 +00:00
RString GameInput::toString( const Game* pGame )
2002-07-27 19:29:51 +00:00
{
2006-01-22 01:00:06 +00:00
return GameControllerToString(controller) + RString("_") + GameButtonToString(pGame,button);
2002-07-27 19:29:51 +00:00
}
2006-01-22 01:00:06 +00:00
bool GameInput::fromString( const Game* pGame, RString s )
2002-07-27 19:29:51 +00:00
{
2005-04-24 02:15:41 +00:00
char szController[32] = "";
char szButton[32] = "";
2002-07-27 19:29:51 +00:00
2005-04-24 02:15:41 +00:00
if( 2 != sscanf( s, "%31[^_]_%31[^_]", szController, szButton ) )
{
controller = GAME_CONTROLLER_INVALID;
2002-07-27 19:29:51 +00:00
return false;
}
2005-04-24 02:15:41 +00:00
controller = StringToGameController( szController );
button = StringToGameButton( pGame, szButton );
2002-07-27 19:29:51 +00:00
return true;
};
2004-05-31 22:42:12 +00:00
/*
* (c) 2001-2004 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.
*/