From a71a6cc1be48ec1c2937349f25c12b1609a5d14b Mon Sep 17 00:00:00 2001 From: AJ Kelly Date: Tue, 8 Mar 2011 20:21:08 -0600 Subject: [PATCH] [MeterDisplay] Add Lua binding. "Allow setting and changing the width dynamically. Phase out the "StreamWidth" node property; set it with SetStreamWidth instead." [Glenn Maynard] --- Docs/Changelog_sm-ssc.txt | 3 +++ src/MeterDisplay.cpp | 35 ++++++++++++++++++++++++++++------- src/MeterDisplay.h | 5 ++--- 3 files changed, 33 insertions(+), 10 deletions(-) diff --git a/Docs/Changelog_sm-ssc.txt b/Docs/Changelog_sm-ssc.txt index b60bbd560c..0275ae24e7 100644 --- a/Docs/Changelog_sm-ssc.txt +++ b/Docs/Changelog_sm-ssc.txt @@ -18,6 +18,9 @@ sm-ssc v1.2.3 | 201103?? * [WheelBase] Add GetCurrentIndex and GetNumItems Lua bindings. [AJ] * [ScreenSelectMusic] Add GetMusicWheel Lua binding. [AJ] * Added custom MusicWheel items. [AJ] +* [MeterDisplay] Add Lua binding. "Allow setting and changing the width + dynamically. Phase out the "StreamWidth" node property; set it with + SetStreamWidth instead." [Glenn Maynard] 20110305 -------- diff --git a/src/MeterDisplay.cpp b/src/MeterDisplay.cpp index 8f04782eef..56a56773b7 100644 --- a/src/MeterDisplay.cpp +++ b/src/MeterDisplay.cpp @@ -17,15 +17,13 @@ MeterDisplay::MeterDisplay() void MeterDisplay::Load( RString sStreamPath, float fStreamWidth, RString sTipPath ) { - m_fStreamWidth = fStreamWidth; - m_sprStream.Load( sStreamPath ); - m_sprStream->SetZoomX( fStreamWidth / m_sprStream->GetUnzoomedWidth() ); this->AddChild( m_sprStream ); m_sprTip.Load( sTipPath ); this->AddChild( m_sprTip ); + SetStreamWidth( fStreamWidth ); SetPercent( 0.5f ); } @@ -33,14 +31,10 @@ void MeterDisplay::LoadFromNode( const XNode* pNode ) { LOG->Trace( "MeterDisplay::LoadFromNode(%s)", ActorUtil::GetWhere(pNode).c_str() ); - if( !pNode->GetAttrValue("StreamWidth", m_fStreamWidth) ) - RageException::Throw( "%s: MeterDisplay: missing the \"StreamWidth\" attribute", ActorUtil::GetWhere(pNode).c_str() ); - const XNode *pStream = pNode->GetChild( "Stream" ); if( pStream == NULL ) RageException::Throw( "%s: MeterDisplay: missing the \"Stream\" attribute", ActorUtil::GetWhere(pNode).c_str() ); m_sprStream.LoadActorFromNode( pStream, this ); - m_sprStream->SetZoomX( m_fStreamWidth / m_sprStream->GetUnzoomedWidth() ); this->AddChild( m_sprStream ); const XNode* pChild = pNode->GetChild( "Tip" ); @@ -50,6 +44,10 @@ void MeterDisplay::LoadFromNode( const XNode* pNode ) this->AddChild( m_sprTip ); } + float fStreamWidth = 0; + pNode->GetAttrValue( "StreamWidth", fStreamWidth ); + SetStreamWidth( fStreamWidth ); + SetPercent( 0.5f ); ActorFrame::LoadFromNode( pNode ); @@ -65,6 +63,12 @@ void MeterDisplay::SetPercent( float fPercent ) m_sprTip->SetX( SCALE(fPercent, 0.f, 1.f, -m_fStreamWidth/2, m_fStreamWidth/2) ); } +void MeterDisplay::SetStreamWidth( float fStreamWidth ) +{ + m_fStreamWidth = fStreamWidth; + m_sprStream->SetZoomX( m_fStreamWidth / m_sprStream->GetUnzoomedWidth() ); +} + void SongMeterDisplay::Update( float fDeltaTime ) { if( GAMESTATE->m_pCurSong ) @@ -80,6 +84,23 @@ void SongMeterDisplay::Update( float fDeltaTime ) MeterDisplay::Update( fDeltaTime ); } +// lua start +#include "LuaBinding.h" + +class LunaMeterDisplay: public Luna +{ +public: + static int SetStreamWidth( T* p, lua_State *L ) { p->SetStreamWidth(FArg(1)); return 0; } + + LunaMeterDisplay() + { + ADD_METHOD( SetStreamWidth ); + } +}; + +LUA_REGISTER_DERIVED_CLASS( MeterDisplay, ActorFrame ) +// lua end + /* * (c) 2003-2004 Chris Danford * All rights reserved. diff --git a/src/MeterDisplay.h b/src/MeterDisplay.h index cd22c8ea70..2d757e0be6 100644 --- a/src/MeterDisplay.h +++ b/src/MeterDisplay.h @@ -17,10 +17,9 @@ public: void SetPercent( float fPercent ); void SetStreamWidth( float fStreamWidth ); - + // Lua - // HACK: not linking right now. - // void PushSelf( lua_State *L ); + void PushSelf( lua_State *L ); private: float m_fStreamWidth;