Files
itgmania212121/src/GameInput.cpp
T

84 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"
2006-09-30 08:24:05 +00:00
#include "InputMapper.h"
2006-01-08 19:38:33 +00:00
#include "ThemeManager.h"
2002-07-27 19:29:51 +00:00
static const char *GameControllerNames[] = {
2009-03-22 20:14:56 +00:00
"1",
"2",
2005-04-24 02:15:41 +00:00
};
2006-10-15 00:09:18 +00:00
XToString( GameController );
2005-04-24 02:15:41 +00:00
StringToX( GameController );
2009-03-22 08:42:27 +00:00
LuaXType( GameController );
2005-04-24 02:15:41 +00:00
2006-09-30 08:24:05 +00:00
RString GameButtonToString( const InputScheme* pInputs, GameButton i )
2005-04-24 02:15:41 +00:00
{
return pInputs->GetGameButtonName(i);
2005-04-24 02:15:41 +00:00
}
2006-09-30 08:24:05 +00:00
RString GameButtonToLocalizedString( const InputScheme* pInputs, GameButton i )
2006-01-08 19:38:33 +00:00
{
2006-09-30 08:24:05 +00:00
return THEME->GetString( "GameButton", GameButtonToString(pInputs,i) );
2006-01-08 19:38:33 +00:00
}
2006-09-30 08:24:05 +00:00
GameButton StringToGameButton( const InputScheme* pInputs, const RString& s )
2005-04-24 02:15:41 +00:00
{
2006-11-21 05:39:56 +00:00
FOREACH_GameButtonInScheme( pInputs, i )
2005-04-24 02:15:41 +00:00
{
2006-11-21 05:39:56 +00:00
if( s == GameButtonToString(pInputs, i) )
return i;
2005-04-24 02:15:41 +00:00
}
2006-09-27 04:44:15 +00:00
return GameButton_Invalid;
2005-04-24 02:15:41 +00:00
}
2006-09-30 08:24:05 +00:00
RString GameInput::ToString( const InputScheme* pInputs ) const
2002-07-27 19:29:51 +00:00
{
2006-09-30 08:24:05 +00:00
return GameControllerToString(controller) + RString("_") + GameButtonToString(pInputs,button);
2002-07-27 19:29:51 +00:00
}
2006-09-30 08:24:05 +00:00
bool GameInput::FromString( const InputScheme* pInputs, const 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 ) )
{
2006-09-26 20:59:40 +00:00
controller = GameController_Invalid;
2002-07-27 19:29:51 +00:00
return false;
}
2005-04-24 02:15:41 +00:00
controller = StringToGameController( szController );
2006-09-30 08:24:05 +00:00
button = StringToGameButton( pInputs, 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.
*/