From 555d5aa2fe98c690be6d9c98b5d1a45a9e80c9ab Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Wed, 23 Feb 2005 20:40:46 +0000 Subject: [PATCH] don't use Name/ID to load DifficultyMeter. We only need the Name at load time, so pass it into Load and don't save it in the Actor. --- stepmania/src/DifficultyList.cpp | 4 +-- stepmania/src/DifficultyMeter.cpp | 37 +++++++++++++++----------- stepmania/src/DifficultyMeter.h | 26 +++++++++++++++++- stepmania/src/EditMenu.cpp | 8 +++--- stepmania/src/ScreenEvaluation.cpp | 3 +-- stepmania/src/ScreenGameplay.cpp | 6 +---- stepmania/src/ScreenNetSelectMusic.cpp | 4 +-- stepmania/src/ScreenSelectMusic.cpp | 4 +-- 8 files changed, 58 insertions(+), 34 deletions(-) diff --git a/stepmania/src/DifficultyList.cpp b/stepmania/src/DifficultyList.cpp index 11bc1f6051..2fcd0109b4 100644 --- a/stepmania/src/DifficultyList.cpp +++ b/stepmania/src/DifficultyList.cpp @@ -58,8 +58,8 @@ void DifficultyList::Load() for( unsigned m = 0; m < m_Lines.size(); ++m ) { - m_Lines[m].m_Meter.SetName( "DifficultySummaryRow", "Row" ); - m_Lines[m].m_Meter.Load(); + m_Lines[m].m_Meter.SetName( "Row" ); + m_Lines[m].m_Meter.Load( "DifficultySummaryRow" ); this->AddChild( &m_Lines[m].m_Meter ); m_Lines[m].m_Description.SetName( "Description" ); diff --git a/stepmania/src/DifficultyMeter.cpp b/stepmania/src/DifficultyMeter.cpp index 4104cbb408..f356afe935 100644 --- a/stepmania/src/DifficultyMeter.cpp +++ b/stepmania/src/DifficultyMeter.cpp @@ -11,6 +11,11 @@ #include "ActorUtil.h" #include "Style.h" +// lua start +LUA_REGISTER_CLASS( DifficultyMeter ) +// lua end +REGISTER_ACTOR_CLASS( DifficultyMeter ); + DifficultyMeter::DifficultyMeter() { @@ -38,20 +43,20 @@ DifficultyMeter::DifficultyMeter() * so I'm trying it first in only this object. */ -void DifficultyMeter::Load() +void DifficultyMeter::Load( const CString &sType ) { - /* We can't use global ThemeMetrics, because we can have multiple - * DifficultyMeters on screen at once, with different names. */ - m_iNumFeetInMeter = THEME->GetMetricI(m_sName,"NumFeetInMeter"); - m_iMaxFeetInMeter = THEME->GetMetricI(m_sName,"MaxFeetInMeter"); - m_iGlowIfMeterGreaterThan = THEME->GetMetricI(m_sName,"GlowIfMeterGreaterThan"); - m_bShowFeet = THEME->GetMetricB(m_sName,"ShowFeet"); - /* "easy", "hard" */ - m_bShowDifficulty = THEME->GetMetricB(m_sName,"ShowDifficulty"); - /* 3, 9 */ - m_bShowMeter = THEME->GetMetricB(m_sName,"ShowMeter"); - m_bFeetIsDifficultyColor = THEME->GetMetricB(m_sName,"FeetIsDifficultyColor"); - m_bFeetPerDifficulty = THEME->GetMetricB(m_sName,"FeetPerDifficulty"); + /* We can't use global ThemeMetrics, because we can have multiple + * DifficultyMeters on screen at once, with different names. */ + m_iNumFeetInMeter = THEME->GetMetricI(sType,"NumFeetInMeter"); + m_iMaxFeetInMeter = THEME->GetMetricI(sType,"MaxFeetInMeter"); + m_iGlowIfMeterGreaterThan = THEME->GetMetricI(sType,"GlowIfMeterGreaterThan"); + m_bShowFeet = THEME->GetMetricB(sType,"ShowFeet"); + /* "easy", "hard" */ + m_bShowDifficulty = THEME->GetMetricB(sType,"ShowDifficulty"); + /* 3, 9 */ + m_bShowMeter = THEME->GetMetricB(sType,"ShowMeter"); + m_bFeetIsDifficultyColor = THEME->GetMetricB(sType,"FeetIsDifficultyColor"); + m_bFeetPerDifficulty = THEME->GetMetricB(sType,"FeetPerDifficulty"); if( m_bShowFeet ) { @@ -65,14 +70,14 @@ void DifficultyMeter::Load() } else Feet = "0X"; - m_textFeet.LoadFromTextureAndChars( THEME->GetPathG(m_sName,"bar"), Feet ); + m_textFeet.LoadFromTextureAndChars( THEME->GetPathG(sType,"bar"), Feet ); SET_XY_AND_ON_COMMAND( &m_textFeet ); this->AddChild( &m_textFeet ); } if( m_bShowDifficulty ) { - m_Difficulty.Load( THEME->GetPathG(m_sName,"difficulty") ); + m_Difficulty.Load( THEME->GetPathG(sType,"difficulty") ); m_Difficulty->SetName( "Difficulty" ); SET_XY_AND_ON_COMMAND( m_Difficulty ); this->AddChild( m_Difficulty ); @@ -81,7 +86,7 @@ void DifficultyMeter::Load() if( m_bShowMeter ) { m_textMeter.SetName( "Meter" ); - m_textMeter.LoadFromFont( THEME->GetPathF(m_sName,"meter") ); + m_textMeter.LoadFromFont( THEME->GetPathF(sType,"meter") ); SET_XY_AND_ON_COMMAND( m_textMeter ); this->AddChild( &m_textMeter ); } diff --git a/stepmania/src/DifficultyMeter.h b/stepmania/src/DifficultyMeter.h index c62f4de306..c64e0cb192 100644 --- a/stepmania/src/DifficultyMeter.h +++ b/stepmania/src/DifficultyMeter.h @@ -14,19 +14,43 @@ class Steps; class Trail; +template +class LunaDifficultyMeter : public LunaActorFrame +{ +public: + LunaDifficultyMeter() { LUA->Register( Register ); } + + static int Load( T* p, lua_State *L ) { p->Load( SArg(1) ); return 0; } + static int SetFromSteps( T* p, lua_State *L ) + { + if( lua_isnil(L,1) ) { p->SetFromSteps( NULL ); } + else { Steps *pS = Luna::check(L,1); p->SetFromSteps( pS ); } + return 0; + } + + static void Register(lua_State *L) + { + ADD_METHOD( Load ) + ADD_METHOD( SetFromSteps ) + LunaActor::Register( L ); + } +}; class DifficultyMeter: public ActorFrame { public: DifficultyMeter(); - void Load(); + void Load( const CString &sType ); void SetFromGameState( PlayerNumber pn ); void SetFromMeterAndDifficulty( int iMeter, Difficulty dc ); void SetFromSteps( const Steps* pSteps ); void SetFromTrail( const Trail* pTrail ); void Unset(); + // Lua + void PushSelf( lua_State *L ); + private: void SetFromDifficulty( Difficulty dc ); void SetFromCourseDifficulty( CourseDifficulty cd ); diff --git a/stepmania/src/EditMenu.cpp b/stepmania/src/EditMenu.cpp index d4566dcb53..e7eb29040c 100644 --- a/stepmania/src/EditMenu.cpp +++ b/stepmania/src/EditMenu.cpp @@ -79,14 +79,14 @@ EditMenu::EditMenu() m_SongTextBanner.SetXY( SONG_TEXT_BANNER_X, SONG_TEXT_BANNER_Y ); this->AddChild( &m_SongTextBanner ); - m_Meter.SetName( "EditDifficultyMeter", "DifficultyMeter" ); + m_Meter.SetName( "DifficultyMeter" ); m_Meter.SetXY( METER_X, METER_Y ); - m_Meter.Load(); + m_Meter.Load( "EditDifficultyMeter" ); this->AddChild( &m_Meter ); - m_SourceMeter.SetName( "EditDifficultyMeter", "DifficultyMeter" ); + m_SourceMeter.SetName( "DifficultyMeter" ); m_SourceMeter.SetXY( SOURCE_METER_X, SOURCE_METER_Y ); - m_SourceMeter.Load(); + m_SourceMeter.Load( "EditDifficultyMeter" ); this->AddChild( &m_SourceMeter ); diff --git a/stepmania/src/ScreenEvaluation.cpp b/stepmania/src/ScreenEvaluation.cpp index eab23b97ca..fd54abe475 100644 --- a/stepmania/src/ScreenEvaluation.cpp +++ b/stepmania/src/ScreenEvaluation.cpp @@ -391,8 +391,7 @@ void ScreenEvaluation::Init() SET_XY_AND_ON_COMMAND( m_DifficultyIcon[p] ); this->AddChild( &m_DifficultyIcon[p] ); - m_DifficultyMeter[p].SetName( ssprintf("ScreenEvaluation DifficultyMeterP%d",p+1) ); - m_DifficultyMeter[p].Load(); + m_DifficultyMeter[p].Load( ssprintf("ScreenEvaluation DifficultyMeterP%d",p+1) ); switch( m_Type ) { case stage: diff --git a/stepmania/src/ScreenGameplay.cpp b/stepmania/src/ScreenGameplay.cpp index 4b150b7c81..7ff32ffeca 100644 --- a/stepmania/src/ScreenGameplay.cpp +++ b/stepmania/src/ScreenGameplay.cpp @@ -574,11 +574,7 @@ void ScreenGameplay::Init() /* Position it in LoadNextSong. */ this->AddChild( &m_DifficultyIcon[p] ); - // FIXME: Find a better way to handle this than changing the name - CString sName = m_DifficultyMeter[p].GetName(); - m_DifficultyMeter[p].SetName( m_sName + ssprintf(" DifficultyMeterP%d",p+1) ); - m_DifficultyMeter[p].Load(); - m_DifficultyMeter[p].SetName( sName ); + m_DifficultyMeter[p].Load( m_sName + ssprintf(" DifficultyMeterP%d",p+1) ); /* Position it in LoadNextSong. */ this->AddChild( &m_DifficultyMeter[p] ); } diff --git a/stepmania/src/ScreenNetSelectMusic.cpp b/stepmania/src/ScreenNetSelectMusic.cpp index ee86d1ed95..f9a163f639 100644 --- a/stepmania/src/ScreenNetSelectMusic.cpp +++ b/stepmania/src/ScreenNetSelectMusic.cpp @@ -63,8 +63,8 @@ void ScreenNetSelectMusic::Init() ON_COMMAND( m_DifficultyIcon[p] ); m_DC[p] = GAMESTATE->m_PreferredDifficulty[p]; - m_DifficultyMeters[p].SetName( "DifficultyMeter", ssprintf("MeterP%d",p+1) ); - m_DifficultyMeters[p].Load(); + m_DifficultyMeters[p].SetName( ssprintf("MeterP%d",p+1) ); + m_DifficultyMeters[p].Load( "DifficultyMeter" ); SET_XY_AND_ON_COMMAND( m_DifficultyMeters[p] ); this->AddChild( &m_DifficultyMeters[p] ); } diff --git a/stepmania/src/ScreenSelectMusic.cpp b/stepmania/src/ScreenSelectMusic.cpp index 5b971079a0..74ebc20202 100644 --- a/stepmania/src/ScreenSelectMusic.cpp +++ b/stepmania/src/ScreenSelectMusic.cpp @@ -264,8 +264,8 @@ void ScreenSelectMusic::Init() this->AddChild( &m_PaneDisplay[p] ); } - m_DifficultyMeter[p].SetName( "DifficultyMeter", ssprintf("MeterP%d",p+1) ); - m_DifficultyMeter[p].Load(); + m_DifficultyMeter[p].SetName( ssprintf("MeterP%d",p+1) ); + m_DifficultyMeter[p].Load( "DifficultyMeter" ); SET_XY_AND_ON_COMMAND( m_DifficultyMeter[p] ); this->AddChild( &m_DifficultyMeter[p] );