add Lua bindings for ControllerStateDisplay
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#include "InputMapper.h"
|
||||
#include "InputFilter.h"
|
||||
#include "RageLog.h"
|
||||
#include "LuaBinding.h"
|
||||
|
||||
static const char *ControllerStateButtonNames[] = {
|
||||
"Up",
|
||||
@@ -22,7 +23,15 @@ static const DeviceButton ControllerStateButtonToDeviceButton[] = {
|
||||
JOY_LEFT,
|
||||
JOY_RIGHT,
|
||||
};
|
||||
// TODO: Generalize for all game types
|
||||
static const GameButton ControllerStateButtonToGameButton[] = {
|
||||
DANCE_BUTTON_UP,
|
||||
DANCE_BUTTON_DOWN,
|
||||
DANCE_BUTTON_LEFT,
|
||||
DANCE_BUTTON_RIGHT,
|
||||
};
|
||||
|
||||
REGISTER_ACTOR_CLASS( ControllerStateDisplay )
|
||||
|
||||
ControllerStateDisplay::ControllerStateDisplay()
|
||||
{
|
||||
@@ -33,7 +42,7 @@ ControllerStateDisplay::ControllerStateDisplay()
|
||||
this->AddChild( &m_Buttons[b].spr );
|
||||
}
|
||||
|
||||
void ControllerStateDisplay::Load( MultiPlayer mp )
|
||||
void ControllerStateDisplay::LoadMultiPlayer( MultiPlayer mp )
|
||||
{
|
||||
m_bIsLoaded = true;
|
||||
|
||||
@@ -43,7 +52,7 @@ void ControllerStateDisplay::Load( MultiPlayer mp )
|
||||
{
|
||||
Button &button = m_Buttons[ b ];
|
||||
|
||||
LOG->Warn( "csd: %d %d", mp, b );
|
||||
//LOG->Warn( "csd: %d %d", mp, b );
|
||||
|
||||
RString sPath = THEME->GetPathG( "ControllerStateDisplay", ControllerStateButtonToString(b) );
|
||||
button.spr.Load( sPath );
|
||||
@@ -52,15 +61,58 @@ void ControllerStateDisplay::Load( MultiPlayer mp )
|
||||
}
|
||||
}
|
||||
|
||||
void ControllerStateDisplay::LoadGameController( GameController gc )
|
||||
{
|
||||
m_bIsLoaded = true;
|
||||
|
||||
m_sprFrame.Load( THEME->GetPathG("ControllerStateDisplay", "frame") );
|
||||
|
||||
FOREACH_ENUM2( ControllerStateButton, b )
|
||||
{
|
||||
Button &button = m_Buttons[ b ];
|
||||
|
||||
//LOG->Warn( "csd: %d %d", mp, b );
|
||||
|
||||
RString sPath = THEME->GetPathG( "ControllerStateDisplay", ControllerStateButtonToString(b) );
|
||||
button.spr.Load( sPath );
|
||||
|
||||
button.gi = GameInput( gc, ControllerStateButtonToGameButton[b] );
|
||||
}
|
||||
}
|
||||
|
||||
void ControllerStateDisplay::Update( float fDelta )
|
||||
{
|
||||
FOREACH_ENUM2( ControllerStateButton, b )
|
||||
{
|
||||
Button &button = m_Buttons[ b ];
|
||||
button.spr.SetVisible( INPUTFILTER->IsBeingPressed(button.di) );
|
||||
|
||||
bool bVisible = false;
|
||||
|
||||
if( button.gi.IsValid() )
|
||||
bVisible = INPUTMAPPER->IsButtonDown(button.gi);
|
||||
else if( button.di.IsValid() )
|
||||
bVisible = INPUTFILTER->IsBeingPressed(button.di);
|
||||
|
||||
button.spr.SetVisible( bVisible );
|
||||
}
|
||||
}
|
||||
|
||||
// lua start
|
||||
class LunaControllerStateDisplay: public Luna<ControllerStateDisplay>
|
||||
{
|
||||
public:
|
||||
LunaControllerStateDisplay() { LUA->Register( Register ); }
|
||||
|
||||
static int LoadGameController( T* p, lua_State *L ) { p->LoadGameController( (GameController)IArg(1) ); return 0; }
|
||||
|
||||
static void Register(lua_State *L)
|
||||
{
|
||||
ADD_METHOD( LoadGameController );
|
||||
Luna<T>::Register( L );
|
||||
}
|
||||
};
|
||||
|
||||
LUA_REGISTER_DERIVED_CLASS( ControllerStateDisplay, Actor )
|
||||
|
||||
/*
|
||||
* (c) 2001-2004 Chris Danford
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "PlayerNumber.h"
|
||||
#include "Sprite.h"
|
||||
#include "RageInput.h"
|
||||
#include "GameInput.h"
|
||||
|
||||
enum ControllerStateButton
|
||||
{
|
||||
@@ -23,17 +24,32 @@ class ControllerStateDisplay : public ActorFrame
|
||||
{
|
||||
public:
|
||||
ControllerStateDisplay();
|
||||
void Load( MultiPlayer mp );
|
||||
void LoadMultiPlayer( MultiPlayer mp );
|
||||
void LoadGameController( GameController gc );
|
||||
virtual void Update( float fDelta );
|
||||
bool IsLoaded() const { return m_bIsLoaded; }
|
||||
|
||||
virtual Actor *Copy() const;
|
||||
|
||||
//
|
||||
// Lua
|
||||
//
|
||||
virtual void PushSelf( lua_State *L );
|
||||
|
||||
protected:
|
||||
bool m_bIsLoaded;
|
||||
Sprite m_sprFrame;
|
||||
struct Button
|
||||
{
|
||||
Button()
|
||||
{
|
||||
di.MakeInvalid();
|
||||
gi.MakeInvalid();
|
||||
}
|
||||
|
||||
Sprite spr;
|
||||
DeviceInput di;
|
||||
GameInput gi;
|
||||
};
|
||||
Button m_Buttons[NUM_ControllerStateButton];
|
||||
};
|
||||
|
||||
@@ -242,7 +242,7 @@ void Player::Init(
|
||||
// Load CSD
|
||||
if( GAMESTATE->m_bMultiplayer && m_pControllerStateDisplay && !m_pControllerStateDisplay->IsLoaded() ) // only load the first time
|
||||
{
|
||||
m_pControllerStateDisplay->Load( pPlayerState->m_mp );
|
||||
m_pControllerStateDisplay->LoadMultiPlayer( pPlayerState->m_mp );
|
||||
this->AddChild( m_pControllerStateDisplay );
|
||||
}
|
||||
|
||||
|
||||
@@ -99,7 +99,7 @@ public:
|
||||
PositionItem( expr, &text, i, NUM_MultiplayerJudgeLine );
|
||||
}
|
||||
|
||||
m_ControllerStateDisplay.Load( mp );
|
||||
m_ControllerStateDisplay.LoadMultiPlayer( mp );
|
||||
this->AddChild( &m_ControllerStateDisplay );
|
||||
PositionItem( expr, &m_ControllerStateDisplay, NUM_MultiplayerJudgeLine, NUM_MultiplayerJudgeLine );
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ void ScreenJoinMultiplayer::Init()
|
||||
|
||||
LUA->UnsetGlobal( "ThisGameCommand" );
|
||||
|
||||
m_ControllerState[p].Load( p );
|
||||
m_ControllerState[p].LoadMultiPlayer( p );
|
||||
}
|
||||
|
||||
m_exprOnCommandFunction.SetFromExpression( THEME->GetMetric(m_sName,"TranformFunction") );
|
||||
|
||||
Reference in New Issue
Block a user