diff --git a/stepmania/src/Difficulty.h b/stepmania/src/Difficulty.h index 0bab3017a5..243f1f2ce4 100644 --- a/stepmania/src/Difficulty.h +++ b/stepmania/src/Difficulty.h @@ -31,7 +31,7 @@ const RString& CourseDifficultyToLocalizedString( Difficulty dc ); Difficulty GetNextShownCourseDifficulty( Difficulty pn ); -enum DifficultyDisplayType // ID for coloring and localized strings in DifficultyDisplay +enum DifficultyDisplayType // ID for coloring and localized strings in StepsDisplay { DifficultyDisplayType_Single_Beginner, DifficultyDisplayType_Single_Easy, diff --git a/stepmania/src/DifficultyDisplay.cpp b/stepmania/src/DifficultyDisplay.cpp index 1e70611939..b1498a62b9 100644 --- a/stepmania/src/DifficultyDisplay.cpp +++ b/stepmania/src/DifficultyDisplay.cpp @@ -1,5 +1,5 @@ #include "global.h" -#include "DifficultyDisplay.h" +#include "StepsDisplay.h" #include "RageUtil.h" #include "GameConstantsAndTypes.h" #include "GameState.h" @@ -14,10 +14,10 @@ #include "GameManager.h" #include "PlayerState.h" -REGISTER_ACTOR_CLASS( DifficultyDisplay ); +REGISTER_ACTOR_CLASS( StepsDisplay ); -DifficultyDisplay::DifficultyDisplay() +StepsDisplay::StepsDisplay() { } @@ -43,12 +43,12 @@ DifficultyDisplay::DifficultyDisplay() * so I'm trying it first in only this object. */ -void DifficultyDisplay::Load( const RString &sMetricsGroup, const PlayerState *pPlayerState ) +void StepsDisplay::Load( const RString &sMetricsGroup, const PlayerState *pPlayerState ) { m_sMetricsGroup = sMetricsGroup; /* We can't use global ThemeMetrics, because we can have multiple - * DifficultyDisplays on screen at once, with different names. */ + * StepsDisplays on screen at once, with different names. */ m_iNumTicks.Load(m_sMetricsGroup,"NumTicks"); m_iMaxTicks.Load(m_sMetricsGroup,"MaxTicks"); m_bShowTicks.Load(m_sMetricsGroup,"ShowTicks"); @@ -117,7 +117,7 @@ void DifficultyDisplay::Load( const RString &sMetricsGroup, const PlayerState *p Unset(); } -void DifficultyDisplay::SetFromGameState( PlayerNumber pn ) +void StepsDisplay::SetFromGameState( PlayerNumber pn ) { if( GAMESTATE->IsCourseMode() ) { @@ -137,7 +137,7 @@ void DifficultyDisplay::SetFromGameState( PlayerNumber pn ) } } -void DifficultyDisplay::SetFromSteps( const Steps* pSteps ) +void StepsDisplay::SetFromSteps( const Steps* pSteps ) { if( pSteps == NULL ) { @@ -149,7 +149,7 @@ void DifficultyDisplay::SetFromSteps( const Steps* pSteps ) SetInternal( params ); } -void DifficultyDisplay::SetFromTrail( const Trail* pTrail ) +void StepsDisplay::SetFromTrail( const Trail* pTrail ) { if( pTrail == NULL ) { @@ -161,25 +161,25 @@ void DifficultyDisplay::SetFromTrail( const Trail* pTrail ) SetInternal( params ); } -void DifficultyDisplay::Unset() +void StepsDisplay::Unset() { SetParams params = { NULL, NULL, 0, StepsType_Invalid, Difficulty_Invalid, false, RString() }; SetInternal( params ); } -void DifficultyDisplay::SetFromStepsTypeAndMeterAndDifficulty( StepsType st, int iMeter, Difficulty dc ) +void StepsDisplay::SetFromStepsTypeAndMeterAndDifficulty( StepsType st, int iMeter, Difficulty dc ) { SetParams params = { NULL, NULL, iMeter, st, dc, false, RString() }; SetInternal( params ); } -void DifficultyDisplay::SetFromStepsTypeAndMeterAndCourseDifficulty( StepsType st, int iMeter, CourseDifficulty cd ) +void StepsDisplay::SetFromStepsTypeAndMeterAndCourseDifficulty( StepsType st, int iMeter, CourseDifficulty cd ) { SetParams params = { NULL, NULL, 0, st, cd, true, RString() }; SetInternal( params ); } -void DifficultyDisplay::SetInternal( const SetParams ¶ms ) +void StepsDisplay::SetInternal( const SetParams ¶ms ) { DifficultyDisplayType ddt = DifficultyDisplayType_Invalid; if( params.st != StepsType_Invalid ) @@ -273,7 +273,7 @@ void DifficultyDisplay::SetInternal( const SetParams ¶ms ) // lua start #include "LuaBinding.h" -class LunaDifficultyDisplay: public Luna +class LunaStepsDisplay: public Luna { public: static int Load( T* p, lua_State *L ) { p->Load( SArg(1), NULL ); return 0; } @@ -311,7 +311,7 @@ public: return 0; } - LunaDifficultyDisplay() + LunaStepsDisplay() { ADD_METHOD( Load ); ADD_METHOD( SetFromStepsTypeAndMeterAndDifficulty ); @@ -321,7 +321,7 @@ public: } }; -LUA_REGISTER_DERIVED_CLASS( DifficultyDisplay, ActorFrame ) +LUA_REGISTER_DERIVED_CLASS( StepsDisplay, ActorFrame ) // lua end /* diff --git a/stepmania/src/DifficultyDisplay.h b/stepmania/src/DifficultyDisplay.h index 3d26813b02..6adcf0f8e6 100644 --- a/stepmania/src/DifficultyDisplay.h +++ b/stepmania/src/DifficultyDisplay.h @@ -1,7 +1,7 @@ -/* DifficultyDisplay - A graphical representation of a Steps or a Trail - has a difficulty number, meter, text, edit description. */ +/* StepsDisplay - A graphical representation of a Steps or a Trail - has a difficulty number, meter, text, edit description. */ -#ifndef DIFFICULTY_METER_H -#define DIFFICULTY_METER_H +#ifndef StepsDisplay_H +#define StepsDisplay_H #include "BitmapText.h" #include "PlayerNumber.h" @@ -17,14 +17,14 @@ class Steps; class Trail; class PlayerState; -class DifficultyDisplay : public ActorFrame +class StepsDisplay : public ActorFrame { public: - DifficultyDisplay(); + StepsDisplay(); void Load( const RString &sMetricsGroup, const PlayerState *pPlayerState ); - virtual DifficultyDisplay *Copy() const; + virtual StepsDisplay *Copy() const; void SetFromGameState( PlayerNumber pn ); void SetFromStepsTypeAndMeterAndDifficulty( StepsType st, int iMeter, Difficulty dc ); diff --git a/stepmania/src/DifficultyList.cpp b/stepmania/src/DifficultyList.cpp index e77f484cda..f7e029032f 100644 --- a/stepmania/src/DifficultyList.cpp +++ b/stepmania/src/DifficultyList.cpp @@ -4,7 +4,7 @@ #include "Song.h" #include "Steps.h" #include "Style.h" -#include "DifficultyDisplay.h" +#include "StepsDisplay.h" #include "StepsUtil.h" #include "CommonMetrics.h" #include "Foreach.h" @@ -68,7 +68,7 @@ void DifficultyList::LoadFromNode( const XNode* pNode ) for( unsigned m = 0; m < m_Lines.size(); ++m ) { m_Lines[m].m_Meter.SetName( "Row" ); - m_Lines[m].m_Meter.Load( "DifficultyDisplayListRow", NULL ); + m_Lines[m].m_Meter.Load( "StepsDisplayListRow", NULL ); this->AddChild( &m_Lines[m].m_Meter ); } diff --git a/stepmania/src/DifficultyList.h b/stepmania/src/DifficultyList.h index e072b8ed7f..92a92d0bf1 100644 --- a/stepmania/src/DifficultyList.h +++ b/stepmania/src/DifficultyList.h @@ -3,7 +3,7 @@ #include "ActorFrame.h" #include "PlayerNumber.h" -#include "DifficultyDisplay.h" +#include "StepsDisplay.h" #include "ThemeMetric.h" class Song; @@ -44,7 +44,7 @@ private: struct Line { - DifficultyDisplay m_Meter; + StepsDisplay m_Meter; }; vector m_Lines; diff --git a/stepmania/src/EditMenu.cpp b/stepmania/src/EditMenu.cpp index 3328c6ec7d..6ae155d6b4 100644 --- a/stepmania/src/EditMenu.cpp +++ b/stepmania/src/EditMenu.cpp @@ -174,12 +174,12 @@ void EditMenu::Load( const RString &sType ) this->AddChild( &m_SongTextBanner ); m_Meter.SetName( "Meter" ); - m_Meter.Load( "DifficultyDisplayEdit", NULL ); + m_Meter.Load( "StepsDisplayEdit", NULL ); ActorUtil::SetXY( m_Meter, sType ); this->AddChild( &m_Meter ); m_SourceMeter.SetName( "SourceMeter" ); - m_SourceMeter.Load( "DifficultyDisplayEdit", NULL ); + m_SourceMeter.Load( "StepsDisplayEdit", NULL ); ActorUtil::SetXY( m_SourceMeter, sType ); this->AddChild( &m_SourceMeter ); diff --git a/stepmania/src/EditMenu.h b/stepmania/src/EditMenu.h index fae953f84c..2da1fb2080 100644 --- a/stepmania/src/EditMenu.h +++ b/stepmania/src/EditMenu.h @@ -7,7 +7,7 @@ #include "FadingBanner.h" #include "TextBanner.h" #include "GameConstantsAndTypes.h" -#include "DifficultyDisplay.h" +#include "StepsDisplay.h" #include "RageSound.h" #include "EnumHelper.h" #include "ThemeMetric.h" @@ -94,8 +94,8 @@ private: FadingBanner m_GroupBanner; FadingBanner m_SongBanner; TextBanner m_SongTextBanner; - DifficultyDisplay m_Meter; - DifficultyDisplay m_SourceMeter; + StepsDisplay m_Meter; + StepsDisplay m_SourceMeter; struct StepsAndDifficulty diff --git a/stepmania/src/ScreenGameplay.cpp b/stepmania/src/ScreenGameplay.cpp index a6f19cc8df..bf36d2c22c 100644 --- a/stepmania/src/ScreenGameplay.cpp +++ b/stepmania/src/ScreenGameplay.cpp @@ -49,7 +49,7 @@ #include "Game.h" #include "ActiveAttackList.h" #include "Player.h" -#include "DifficultyDisplay.h" +#include "StepsDisplay.h" #include "XmlFile.h" #include "Background.h" #include "Foreground.h" @@ -115,7 +115,7 @@ PlayerInfo::PlayerInfo() m_pActiveAttackList = NULL; m_pPlayer = NULL; m_pInventory = NULL; - m_pDifficultyDisplay = NULL; + m_pStepsDisplay = NULL; } void PlayerInfo::Load( PlayerNumber pn, MultiPlayer mp, bool bShowNoteField, int iAddToDifficulty ) @@ -184,7 +184,7 @@ void PlayerInfo::Load( PlayerNumber pn, MultiPlayer mp, bool bShowNoteField, int m_pActiveAttackList = NULL; m_pPlayer = new Player( m_NoteData, bShowNoteField ); m_pInventory = NULL; - m_pDifficultyDisplay = NULL; + m_pStepsDisplay = NULL; if( IsMultiPlayer() ) { @@ -220,7 +220,7 @@ PlayerInfo::~PlayerInfo() SAFE_DELETE( m_pActiveAttackList ); SAFE_DELETE( m_pPlayer ); SAFE_DELETE( m_pInventory ); - SAFE_DELETE( m_pDifficultyDisplay ); + SAFE_DELETE( m_pStepsDisplay ); } void PlayerInfo::ShowOniGameOver() @@ -626,15 +626,15 @@ void ScreenGameplay::Init() // // Difficulty icon and meter // - ASSERT( pi->m_pDifficultyDisplay == NULL ); - pi->m_pDifficultyDisplay = new DifficultyDisplay; - pi->m_pDifficultyDisplay->Load("DifficultyDisplayGameplay", pi->GetPlayerState() ); - pi->m_pDifficultyDisplay->SetName( ssprintf("DifficultyDisplay%s",pi->GetName().c_str()) ); + ASSERT( pi->m_pStepsDisplay == NULL ); + pi->m_pStepsDisplay = new StepsDisplay; + pi->m_pStepsDisplay->Load("StepsDisplayGameplay", pi->GetPlayerState() ); + pi->m_pStepsDisplay->SetName( ssprintf("StepsDisplay%s",pi->GetName().c_str()) ); PlayerNumber pn = pi->GetStepsAndTrailIndex(); if( pn != PlayerNumber_Invalid ) - pi->m_pDifficultyDisplay->PlayCommand( "Set" + pi->GetName() ); - LOAD_ALL_COMMANDS_AND_SET_XY( pi->m_pDifficultyDisplay ); - this->AddChild( pi->m_pDifficultyDisplay ); + pi->m_pStepsDisplay->PlayCommand( "Set" + pi->GetName() ); + LOAD_ALL_COMMANDS_AND_SET_XY( pi->m_pStepsDisplay ); + this->AddChild( pi->m_pStepsDisplay ); // switch( GAMESTATE->m_PlayMode ) // { @@ -1087,8 +1087,8 @@ void ScreenGameplay::LoadNextSong() if( GAMESTATE->m_SongOptions.GetCurrent().m_LifeType==SongOptions::LIFE_BAR && pi->m_pLifeMeter ) pi->m_pLifeMeter->UpdateNonstopLifebar(); - if( pi->m_pDifficultyDisplay ) - pi->m_pDifficultyDisplay->SetFromSteps( pSteps ); + if( pi->m_pStepsDisplay ) + pi->m_pStepsDisplay->SetFromSteps( pSteps ); /* The actual note data for scoring is the base class of Player. This includes * transforms, like Wide. Otherwise, the scoring will operate on the wrong data. */ @@ -1138,8 +1138,8 @@ void ScreenGameplay::LoadNextSong() { bool bReverse = pi->GetPlayerState()->m_PlayerOptions.GetCurrent().m_fScrolls[PlayerOptions::SCROLL_REVERSE] == 1; - if( pi->m_pDifficultyDisplay ) - pi->m_pDifficultyDisplay->PlayCommand( bReverse? "SetReverse":"SetNoReverse" ); + if( pi->m_pStepsDisplay ) + pi->m_pStepsDisplay->PlayCommand( bReverse? "SetReverse":"SetNoReverse" ); } m_LyricDisplay.PlayCommand( bAllReverse? "SetReverse": bAtLeastOneReverse? "SetOneReverse": "SetNoReverse" ); diff --git a/stepmania/src/ScreenGameplay.h b/stepmania/src/ScreenGameplay.h index 34a0c6c9ef..931ff77f6c 100644 --- a/stepmania/src/ScreenGameplay.h +++ b/stepmania/src/ScreenGameplay.h @@ -27,7 +27,7 @@ class CombinedLifeMeter; class Player; class LifeMeter; class ScoreDisplay; -class DifficultyDisplay; +class StepsDisplay; class Inventory; class ScoreKeeper; class Background; @@ -98,7 +98,7 @@ public: // used in PLAY_MODE_BATTLE Inventory *m_pInventory; - DifficultyDisplay *m_pDifficultyDisplay; + StepsDisplay *m_pStepsDisplay; AutoActor m_sprOniGameOver; }; diff --git a/stepmania/src/ScreenNetSelectMusic.cpp b/stepmania/src/ScreenNetSelectMusic.cpp index 8ed493cbfc..91ee7389d9 100644 --- a/stepmania/src/ScreenNetSelectMusic.cpp +++ b/stepmania/src/ScreenNetSelectMusic.cpp @@ -67,10 +67,10 @@ void ScreenNetSelectMusic::Init() ON_COMMAND( m_DifficultyIcon[p] ); m_DC[p] = GAMESTATE->m_PreferredDifficulty[p]; - m_DifficultyDisplays[p].SetName( ssprintf("MeterP%d",p+1) ); - m_DifficultyDisplays[p].Load( "DifficultyDisplay", NULL ); - LOAD_ALL_COMMANDS_AND_SET_XY_AND_ON_COMMAND( m_DifficultyDisplays[p] ); - this->AddChild( &m_DifficultyDisplays[p] ); + m_StepsDisplays[p].SetName( ssprintf("MeterP%d",p+1) ); + m_StepsDisplays[p].Load( "StepsDisplay", NULL ); + LOAD_ALL_COMMANDS_AND_SET_XY_AND_ON_COMMAND( m_StepsDisplays[p] ); + this->AddChild( &m_StepsDisplays[p] ); } m_MusicWheel.SetName( "MusicWheel" ); @@ -452,7 +452,7 @@ void ScreenNetSelectMusic::TweenOffScreen() FOREACH_EnabledPlayer (pn) { - OFF_COMMAND( m_DifficultyDisplays[pn] ); + OFF_COMMAND( m_StepsDisplays[pn] ); OFF_COMMAND( m_DifficultyIcon[pn] ); OFF_COMMAND( m_ModIconRow[pn] ); } @@ -488,7 +488,7 @@ void ScreenNetSelectMusic::UpdateDifficulties( PlayerNumber pn ) { if ( GAMESTATE->m_pCurSong == NULL ) { - m_DifficultyDisplays[pn].SetFromStepsTypeAndMeterAndDifficulty( StepsType_Invalid, 0, Difficulty_Beginner ); + m_StepsDisplays[pn].SetFromStepsTypeAndMeterAndDifficulty( StepsType_Invalid, 0, Difficulty_Beginner ); m_DifficultyIcon[pn].SetFromSteps( pn, NULL ); //It will blank it out return; } @@ -506,9 +506,9 @@ void ScreenNetSelectMusic::UpdateDifficulties( PlayerNumber pn ) GAMESTATE->m_pCurSteps[pn].Set( pSteps ); if ( ( m_DC[pn] < NUM_Difficulty ) && ( m_DC[pn] >= Difficulty_Beginner ) ) - m_DifficultyDisplays[pn].SetFromSteps( pSteps ); + m_StepsDisplays[pn].SetFromSteps( pSteps ); else - m_DifficultyDisplays[pn].SetFromStepsTypeAndMeterAndDifficulty( StepsType_Invalid, 0, Difficulty_Beginner ); + m_StepsDisplays[pn].SetFromStepsTypeAndMeterAndDifficulty( StepsType_Invalid, 0, Difficulty_Beginner ); } void ScreenNetSelectMusic::MusicChanged() diff --git a/stepmania/src/ScreenNetSelectMusic.h b/stepmania/src/ScreenNetSelectMusic.h index ecb3e46dc3..5f2ca19ffe 100644 --- a/stepmania/src/ScreenNetSelectMusic.h +++ b/stepmania/src/ScreenNetSelectMusic.h @@ -8,7 +8,7 @@ #include "Sprite.h" #include "DifficultyIcon.h" #include "Difficulty.h" -#include "DifficultyDisplay.h" +#include "StepsDisplay.h" #include "MusicWheel.h" #include "ModIconRow.h" #include "BPMDisplay.h" @@ -68,7 +68,7 @@ private: Difficulty m_DC[NUM_PLAYERS]; void UpdateDifficulties( PlayerNumber pn ); - DifficultyDisplay m_DifficultyDisplays[NUM_PLAYERS]; + StepsDisplay m_StepsDisplays[NUM_PLAYERS]; RageSound m_soundChangeOpt; RageSound m_soundChangeSel; diff --git a/stepmania/src/StepsDisplay.cpp b/stepmania/src/StepsDisplay.cpp new file mode 100644 index 0000000000..b1498a62b9 --- /dev/null +++ b/stepmania/src/StepsDisplay.cpp @@ -0,0 +1,350 @@ +#include "global.h" +#include "StepsDisplay.h" +#include "RageUtil.h" +#include "GameConstantsAndTypes.h" +#include "GameState.h" +#include "ThemeManager.h" +#include "Steps.h" +#include "Course.h" +#include "SongManager.h" +#include "ActorUtil.h" +#include "Style.h" +#include "XmlFile.h" +#include "LuaBinding.h" +#include "GameManager.h" +#include "PlayerState.h" + +REGISTER_ACTOR_CLASS( StepsDisplay ); + + +StepsDisplay::StepsDisplay() +{ +} + +/* sID experiment: + * + * Names of an actor, "Foo": + * [Foo] + * Metric=abc + * + * [ScreenSomething] + * FooP1X=20 + * FooP2Y=30 + * + * Graphics\Foo under p1 + * + * We want to call it different things in different contexts: we may only want one + * set of internal metrics for a given use, but separate metrics for each player at + * the screen level, and we may or may not want separate names at the asset level. + * + * As is, we tend to end up having to either duplicate [Foo] to [FooP1] and [FooP2] + * or not use m_sName for [Foo], which limits its use. Let's try using a separate + * name for internal metrics. I'm not sure if this will cause more confusion than good, + * so I'm trying it first in only this object. + */ + +void StepsDisplay::Load( const RString &sMetricsGroup, const PlayerState *pPlayerState ) +{ + m_sMetricsGroup = sMetricsGroup; + + /* We can't use global ThemeMetrics, because we can have multiple + * StepsDisplays on screen at once, with different names. */ + m_iNumTicks.Load(m_sMetricsGroup,"NumTicks"); + m_iMaxTicks.Load(m_sMetricsGroup,"MaxTicks"); + m_bShowTicks.Load(m_sMetricsGroup,"ShowTicks"); + m_bShowMeter.Load(m_sMetricsGroup,"ShowMeter"); + m_bShowDescription.Load(m_sMetricsGroup,"ShowDescription"); + m_bShowAutogen.Load(m_sMetricsGroup,"ShowAutogen"); + m_bShowStepsType.Load(m_sMetricsGroup,"ShowStepsType"); + m_sZeroMeterString.Load(m_sMetricsGroup,"ZeroMeterString"); + + + m_sprFrame.Load( THEME->GetPathG(m_sMetricsGroup,"frame") ); + m_sprFrame->SetName( "Frame" ); + ActorUtil::LoadAllCommandsAndSetXYAndOnCommand( m_sprFrame, m_sMetricsGroup ); + this->AddChild( m_sprFrame ); + + if( m_bShowTicks ) + { + RString sChars = "10"; // on, off + m_textTicks.SetName( "Ticks" ); + m_textTicks.LoadFromTextureAndChars( THEME->GetPathF(m_sMetricsGroup,"ticks"), sChars ); + ActorUtil::LoadAllCommandsAndSetXYAndOnCommand( m_textTicks, m_sMetricsGroup ); + this->AddChild( &m_textTicks ); + } + + if( m_bShowMeter ) + { + m_textMeter.SetName( "Meter" ); + m_textMeter.LoadFromFont( THEME->GetPathF(m_sMetricsGroup,"meter") ); + ActorUtil::LoadAllCommandsAndSetXYAndOnCommand( m_textMeter, m_sMetricsGroup ); + this->AddChild( &m_textMeter ); + + // These commands should have been loaded by SetXYAndOnCommand above. + ASSERT( m_textMeter.HasCommand("Set") ); + } + + if( m_bShowDescription ) + { + m_textDescription.SetName( "Description" ); + m_textDescription.LoadFromFont( THEME->GetPathF(m_sMetricsGroup,"Description") ); + ActorUtil::LoadAllCommandsAndSetXYAndOnCommand( m_textDescription, m_sMetricsGroup ); + this->AddChild( &m_textDescription ); + } + + if( m_bShowAutogen ) + { + m_sprAutogen.Load( THEME->GetPathG(m_sMetricsGroup,"Autogen") ); + m_sprAutogen->SetName( "Autogen" ); + ActorUtil::LoadAllCommandsAndSetXYAndOnCommand( m_sprAutogen, m_sMetricsGroup ); + this->AddChild( m_sprAutogen ); + } + + if( m_bShowStepsType ) + { + m_sprStepsType.SetName( "StepsType" ); + ActorUtil::LoadAllCommandsAndSetXYAndOnCommand( m_sprStepsType, m_sMetricsGroup ); + this->AddChild( &m_sprStepsType ); + } + + // Play Load Command + PlayerState* pPlayerState_ = const_cast(pPlayerState); + Message msg("Load"); + if( pPlayerState_ ) + msg.SetParam( "PlayerState", LuaReference::CreateFromPush(*pPlayerState_) ); + this->HandleMessage( msg ); + + Unset(); +} + +void StepsDisplay::SetFromGameState( PlayerNumber pn ) +{ + if( GAMESTATE->IsCourseMode() ) + { + const Trail* pTrail = GAMESTATE->m_pCurTrail[pn]; + if( pTrail ) + SetFromTrail( pTrail ); + else + SetFromStepsTypeAndMeterAndCourseDifficulty( StepsType_Invalid, 0, GAMESTATE->m_PreferredCourseDifficulty[pn] ); + } + else + { + const Steps* pSteps = GAMESTATE->m_pCurSteps[pn]; + if( pSteps ) + SetFromSteps( pSteps ); + else + SetFromStepsTypeAndMeterAndDifficulty( StepsType_Invalid, 0, GAMESTATE->m_PreferredDifficulty[pn] ); + } +} + +void StepsDisplay::SetFromSteps( const Steps* pSteps ) +{ + if( pSteps == NULL ) + { + Unset(); + return; + } + + SetParams params = { pSteps, NULL, pSteps->GetMeter(), pSteps->m_StepsType, pSteps->GetDifficulty(), false, pSteps->GetDescription() }; + SetInternal( params ); +} + +void StepsDisplay::SetFromTrail( const Trail* pTrail ) +{ + if( pTrail == NULL ) + { + Unset(); + return; + } + + SetParams params = { NULL, pTrail, pTrail->GetMeter(), pTrail->m_StepsType, pTrail->m_CourseDifficulty, true, RString() }; + SetInternal( params ); +} + +void StepsDisplay::Unset() +{ + SetParams params = { NULL, NULL, 0, StepsType_Invalid, Difficulty_Invalid, false, RString() }; + SetInternal( params ); +} + +void StepsDisplay::SetFromStepsTypeAndMeterAndDifficulty( StepsType st, int iMeter, Difficulty dc ) +{ + SetParams params = { NULL, NULL, iMeter, st, dc, false, RString() }; + SetInternal( params ); +} + +void StepsDisplay::SetFromStepsTypeAndMeterAndCourseDifficulty( StepsType st, int iMeter, CourseDifficulty cd ) +{ + SetParams params = { NULL, NULL, 0, st, cd, true, RString() }; + SetInternal( params ); +} + +void StepsDisplay::SetInternal( const SetParams ¶ms ) +{ + DifficultyDisplayType ddt = DifficultyDisplayType_Invalid; + if( params.st != StepsType_Invalid ) + ddt = MakeDifficultyDisplayType( params.dc, GameManager::GetStepsTypeInfo(params.st).m_StepsTypeCategory ); + + Message msg( "Set" ); + if( params.pSteps ) + msg.SetParam( "Steps", LuaReference::CreateFromPush(*(Steps*)params.pSteps) ); + if( params.pTrail ) + msg.SetParam( "Trail", LuaReference::CreateFromPush(*(Trail*)params.pTrail) ); + msg.SetParam( "Meter", params.iMeter ); + msg.SetParam( "StepsType", params.st ); + msg.SetParam( "Difficulty", params.dc ); + msg.SetParam( "IsCourseDifficulty", params.bIsCourseDifficulty ); + msg.SetParam( "Description", params.sDescription ); + msg.SetParam( "DifficultyDisplayType", ddt ); + + m_sprFrame->HandleMessage( msg ); + + if( m_bShowTicks ) + { + char on = char('1'); + char off = '0'; + + RString sNewText; + int iNumOn = min( (int)m_iMaxTicks, params.iMeter ); + sNewText.insert( sNewText.end(), iNumOn, on ); + int iNumOff = max( 0, m_iNumTicks-iNumOn ); + sNewText.insert( sNewText.end(), iNumOff, off ); + m_textTicks.SetText( sNewText ); + } + + if( m_bShowMeter ) + { + if( params.iMeter == 0 ) // Unset calls with this + { + m_textMeter.SetText( m_sZeroMeterString ); + } + else + { + const RString sMeter = ssprintf( "%i", params.iMeter ); + m_textMeter.SetText( sMeter ); + } + } + + if( m_bShowDescription ) + { + RString s; + if( params.bIsCourseDifficulty ) + { + s = CourseDifficultyToLocalizedString(params.dc); + } + else + { + switch( ddt ) + { + case DifficultyDisplayType_Invalid: + // empty string + break; + case DifficultyDisplayType_Edit: + s = params.sDescription; + break; + default: + s = DifficultyDisplayTypeToLocalizedString( ddt ); + break; + } + } + + m_textDescription.SetText( s ); + } + + if( m_bShowAutogen ) + { + bool b = params.pSteps && params.pSteps->IsAutogen(); + m_sprAutogen->SetVisible( b ); + } + + if( m_bShowStepsType ) + { + // TODO: Make this an AutoActor, optimize graphic loading + if( params.st != StepsType_Invalid ) + { + RString sStepsType = GameManager::GetStepsTypeInfo(params.st).szName; + m_sprStepsType.Load( THEME->GetPathG(m_sMetricsGroup,"StepsType "+sStepsType) ); + } + } + + this->HandleMessage( msg ); +} + +// lua start +#include "LuaBinding.h" + +class LunaStepsDisplay: public Luna +{ +public: + static int Load( T* p, lua_State *L ) { p->Load( SArg(1), NULL ); return 0; } + static int SetFromStepsTypeAndMeterAndDifficulty( T* p, lua_State *L ) { p->SetFromStepsTypeAndMeterAndDifficulty( Enum::Check(L, 1), IArg(2), Enum::Check(L, 3) ); 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 int SetFromTrail( T* p, lua_State *L ) + { + if( lua_isnil(L,1) ) + { + p->SetFromTrail( NULL ); + } + else + { + Trail *pT = Luna::check(L,1); + p->SetFromTrail( pT ); + } + return 0; + } + static int SetFromGameState( T* p, lua_State *L ) + { + PlayerNumber pn = Enum::Check(L, 1); + p->SetFromGameState( pn ); + return 0; + } + + LunaStepsDisplay() + { + ADD_METHOD( Load ); + ADD_METHOD( SetFromStepsTypeAndMeterAndDifficulty ); + ADD_METHOD( SetFromSteps ); + ADD_METHOD( SetFromTrail ); + ADD_METHOD( SetFromGameState ); + } +}; + +LUA_REGISTER_DERIVED_CLASS( StepsDisplay, ActorFrame ) +// lua end + +/* + * (c) 2001-2004 Chris Danford, Glenn Maynard + * 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. + */ diff --git a/stepmania/src/StepsDisplay.h b/stepmania/src/StepsDisplay.h new file mode 100644 index 0000000000..6adcf0f8e6 --- /dev/null +++ b/stepmania/src/StepsDisplay.h @@ -0,0 +1,96 @@ +/* StepsDisplay - A graphical representation of a Steps or a Trail - has a difficulty number, meter, text, edit description. */ + +#ifndef StepsDisplay_H +#define StepsDisplay_H + +#include "BitmapText.h" +#include "PlayerNumber.h" +#include "AutoActor.h" +#include "GameConstantsAndTypes.h" +#include "ActorUtil.h" +#include "Difficulty.h" +#include "ActorFrame.h" +#include "ThemeMetric.h" +#include "Sprite.h" + +class Steps; +class Trail; +class PlayerState; + +class StepsDisplay : public ActorFrame +{ +public: + StepsDisplay(); + + void Load( const RString &sMetricsGroup, const PlayerState *pPlayerState ); + + virtual StepsDisplay *Copy() const; + + void SetFromGameState( PlayerNumber pn ); + void SetFromStepsTypeAndMeterAndDifficulty( StepsType st, int iMeter, Difficulty dc ); + void SetFromStepsTypeAndMeterAndCourseDifficulty( StepsType st, int iMeter, CourseDifficulty cd ); + void SetFromSteps( const Steps* pSteps ); + void SetFromTrail( const Trail* pTrail ); + void Unset(); + + // Lua + void PushSelf( lua_State *L ); + +private: + struct SetParams + { + const Steps *pSteps; + const Trail *pTrail; + int iMeter; + StepsType st; + Difficulty dc; + bool bIsCourseDifficulty; + RString sDescription; + }; + void SetInternal( const SetParams ¶ms ); + + RString m_sMetricsGroup; + + AutoActor m_sprFrame; + BitmapText m_textTicks; /* 111100000 */ + BitmapText m_textMeter; /* 3, 9 */ + BitmapText m_textDescription; /* Easy, Medium, SuperCoolEdit */ + AutoActor m_sprAutogen; // visible if Steps and is autogen'd + Sprite m_sprStepsType; // TODO: Make this an AutoActor + + ThemeMetric m_iNumTicks; + ThemeMetric m_iMaxTicks; + ThemeMetric m_bShowTicks; + ThemeMetric m_bShowMeter; + ThemeMetric m_bShowDescription; + ThemeMetric m_bShowAutogen; + ThemeMetric m_bShowStepsType; + ThemeMetric m_sZeroMeterString; +}; + +#endif + +/* + * (c) 2001-2004 Chris Danford, Glenn Maynard + * 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. + */