From 9f2d17031730e6ea0c98ca2b9b00eba95ba6fcfa Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Wed, 16 Aug 2006 07:02:46 +0000 Subject: [PATCH] bind, add SetFromGameState --- stepmania/src/BPMDisplay.cpp | 55 ++++++++++++++++++++++++++++++++++-- stepmania/src/BPMDisplay.h | 6 ++++ 2 files changed, 59 insertions(+), 2 deletions(-) diff --git a/stepmania/src/BPMDisplay.cpp b/stepmania/src/BPMDisplay.cpp index 5aae6a7205..7529556960 100644 --- a/stepmania/src/BPMDisplay.cpp +++ b/stepmania/src/BPMDisplay.cpp @@ -11,6 +11,8 @@ #include +REGISTER_ACTOR_CLASS( BPMDisplay ) + BPMDisplay::BPMDisplay() { m_fBPMFrom = m_fBPMTo = 0; @@ -42,6 +44,12 @@ void BPMDisplay::Load() this->AddChild( m_sprLabel ); } +void BPMDisplay::LoadFromNode( const RString &sDir, const XNode *pNode ) +{ + ActorFrame::LoadFromNode( sDir, pNode ); + Load(); +} + float BPMDisplay::GetActiveBPM() const { return m_fBPMTo + (m_fBPMFrom-m_fBPMTo)*m_fPercentInState; @@ -206,11 +214,17 @@ void BPMDisplay::SetBpmFromCourse( const Course* pCourse ) Trail *pTrail = pCourse->GetTrail( st ); ASSERT( pTrail ); + m_fCycleTime = 0.2f; + + if( (int)pTrail->m_vEntries.size() > CommonMetrics::MAX_COURSE_ENTRIES_BEFORE_VARIOUS ) + { + SetVarious(); + return; + } + DisplayBpms bpms; pTrail->GetDisplayBpms( bpms ); - SetBPMRange( bpms ); - m_fCycleTime = 0.2f; } void BPMDisplay::SetConstantBpm( float fBPM ) @@ -227,6 +241,43 @@ void BPMDisplay::SetVarious() m_textBPM.SetText( "Various" ); } +void BPMDisplay::SetFromGameState() +{ + if( GAMESTATE->m_pCurSong.Get() ) + { + if( GAMESTATE->IsAnExtraStage() ) + CycleRandomly(); + else + SetBpmFromSong( GAMESTATE->m_pCurSong ); + return; + } + if( GAMESTATE->m_pCurCourse.Get() ) + { + SetBpmFromCourse( GAMESTATE->m_pCurCourse ); + + return; + } + + NoBPM(); +} + +#include "LuaBinding.h" +class LunaBPMDisplay: public Luna +{ +public: + LunaBPMDisplay() { LUA->Register( Register ); } + + static int SetFromGameState( T* p, lua_State *L ) { p->SetFromGameState(); return 0; } + static void Register(lua_State *L) + { + ADD_METHOD( SetFromGameState ); + + Luna::Register( L ); + } +}; + +LUA_REGISTER_DERIVED_CLASS( BPMDisplay, ActorFrame ) + /* * (c) 2001-2002 Chris Danford * All rights reserved. diff --git a/stepmania/src/BPMDisplay.h b/stepmania/src/BPMDisplay.h index 502240372a..c8c188fedc 100644 --- a/stepmania/src/BPMDisplay.h +++ b/stepmania/src/BPMDisplay.h @@ -17,8 +17,10 @@ class BPMDisplay : public ActorFrame { public: BPMDisplay(); + virtual Actor *Copy() const; void Load(); virtual void Update( float fDeltaTime ); + void LoadFromNode( const RString &sDir, const XNode *pNode ); void SetBpmFromSong( const Song* pSong ); void SetBpmFromCourse( const Course* pCourse ); @@ -26,6 +28,10 @@ public: void CycleRandomly(); void NoBPM(); void SetVarious(); + void SetFromGameState(); + + // Lua + virtual void PushSelf( lua_State *L ); protected: float GetActiveBPM() const;