Files
itgmania212121/src/ControllerStateDisplay.cpp
T

138 lines
4.0 KiB
C++
Raw Normal View History

2006-09-29 21:58:00 +00:00
#include "global.h"
#include "ControllerStateDisplay.h"
#include "EnumHelper.h"
#include "RageUtil.h"
#include "RageInputDevice.h"
#include "ThemeManager.h"
#include "InputMapper.h"
#include "InputFilter.h"
#include "RageLog.h"
#include "LuaBinding.h"
static const char *ControllerStateButtonNames[] = {
2007-07-12 11:03:16 +00:00
"UpLeft",
"UpRight",
"Center",
"DownLeft",
"DownRight",
2006-09-29 21:58:00 +00:00
};
2006-10-15 00:09:18 +00:00
XToString( ControllerStateButton );
2006-09-29 21:58:00 +00:00
// TODO: Generalize for all game types
static const GameButton ControllerStateButtonToGameButton[] = {
2007-07-12 11:03:16 +00:00
PUMP_BUTTON_UPLEFT,
PUMP_BUTTON_UPRIGHT,
PUMP_BUTTON_CENTER,
PUMP_BUTTON_DOWNLEFT,
PUMP_BUTTON_DOWNRIGHT,
2006-09-29 21:58:00 +00:00
};
REGISTER_ACTOR_CLASS( ControllerStateDisplay )
ControllerStateDisplay::ControllerStateDisplay()
{
m_bIsLoaded = false;
2006-10-07 04:02:10 +00:00
m_mp = MultiPlayer_Invalid;
2007-07-12 11:03:16 +00:00
m_idsLast = InputDeviceState_Invalid;
2006-09-29 21:58:00 +00:00
}
2007-07-13 10:42:42 +00:00
void ControllerStateDisplay::LoadMultiPlayer( RString sType, MultiPlayer mp )
2006-09-29 21:58:00 +00:00
{
2009-03-22 20:14:56 +00:00
LoadInternal( sType, mp, GameController_1 );
2006-09-29 21:58:00 +00:00
}
2007-07-13 10:42:42 +00:00
void ControllerStateDisplay::LoadGameController( RString sType, GameController gc )
2006-09-29 21:58:00 +00:00
{
2007-07-13 10:42:42 +00:00
LoadInternal( sType, MultiPlayer_Invalid, gc );
2006-09-29 21:58:00 +00:00
}
2007-07-13 10:42:42 +00:00
void ControllerStateDisplay::LoadInternal( RString sType, MultiPlayer mp, GameController gc )
2006-09-29 21:58:00 +00:00
{
ASSERT( !m_bIsLoaded );
m_bIsLoaded = true;
2007-07-12 11:03:16 +00:00
m_mp = mp;
2006-09-29 21:58:00 +00:00
2007-07-12 11:03:16 +00:00
LuaThreadVariable varElement( "MultiPlayer", LuaReference::Create(m_mp) );
2007-07-13 10:42:42 +00:00
m_sprFrame.Load( THEME->GetPathG(sType, "frame") );
2006-09-29 21:58:00 +00:00
this->AddChild( m_sprFrame );
2006-10-07 08:56:58 +00:00
FOREACH_ENUM( ControllerStateButton, b )
2006-09-29 21:58:00 +00:00
{
Button &button = m_Buttons[ b ];
2007-07-13 10:42:42 +00:00
RString sPath = THEME->GetPathG( sType, ControllerStateButtonToString(b) );
2006-09-29 21:58:00 +00:00
button.spr.Load( sPath );
this->AddChild( m_Buttons[b].spr );
button.gi = GameInput( gc, ControllerStateButtonToGameButton[b] );
}
}
void ControllerStateDisplay::Update( float fDelta )
{
ActorFrame::Update( fDelta );
2007-07-12 11:03:16 +00:00
if( m_mp != MultiPlayer_Invalid )
{
InputDevice id = InputMapper::MultiPlayerToInputDevice( m_mp );
InputDeviceState ids = INPUTMAN->GetInputDeviceState(id);
if( ids != m_idsLast )
{
PlayCommand( InputDeviceStateToString(ids) );
}
m_idsLast = ids;
}
2006-10-07 08:56:58 +00:00
FOREACH_ENUM( ControllerStateButton, b )
2006-09-29 21:58:00 +00:00
{
Button &button = m_Buttons[ b ];
2007-08-25 22:33:34 +00:00
if( !button.spr.IsLoaded() )
continue;
2006-09-29 21:58:00 +00:00
2006-09-30 04:01:34 +00:00
bool bVisible = INPUTMAPPER->IsBeingPressed( button.gi, m_mp );
2006-09-29 21:58:00 +00:00
button.spr->SetVisible( bVisible );
}
}
// lua start
class LunaControllerStateDisplay: public Luna<ControllerStateDisplay>
{
public:
2009-03-22 08:42:27 +00:00
static int LoadGameController( T* p, lua_State *L ) { p->LoadGameController( SArg(1), Enum::Check<GameController>(L, 2) ); return 0; }
2007-08-25 22:32:38 +00:00
static int LoadMultiPlayer( T* p, lua_State *L ) { p->LoadMultiPlayer( SArg(1), Enum::Check<MultiPlayer>(L, 2) ); return 0; }
2006-09-29 21:58:00 +00:00
2006-09-30 04:01:34 +00:00
LunaControllerStateDisplay()
2006-09-29 21:58:00 +00:00
{
ADD_METHOD( LoadGameController );
ADD_METHOD( LoadMultiPlayer );
}
};
2007-07-12 11:03:16 +00:00
LUA_REGISTER_DERIVED_CLASS( ControllerStateDisplay, ActorFrame )
2006-09-29 21:58:00 +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.
*/