diff --git a/stepmania/src/BGAnimation.cpp b/stepmania/src/BGAnimation.cpp index 9c3c9cb7f3..7de19e0f21 100644 --- a/stepmania/src/BGAnimation.cpp +++ b/stepmania/src/BGAnimation.cpp @@ -20,6 +20,7 @@ #include "song.h" #include "ThemeManager.h" #include "RageFile.h" +#include "ActorUtil.h" const int MAX_LAYERS = 1000; @@ -208,8 +209,35 @@ void BGAnimation::SetDiffuse( const RageColor &c ) m_Layers[i]->SetDiffuse(c); } -void BGAnimation::PlayOffCommand() +float BGAnimation::GetTweenTimeLeft() const +{ + float tot = 0; + + for( unsigned i=0; iGetMaxTweenTimeLeft(); + + return tot; +} + +void BGAnimation::PlayCommand( const CString &cmd ) { for( unsigned i=0; iPlayOffCommand(); + m_Layers[i]->PlayCommand( cmd ); } + +void BGAnimation::HandleCommand( const CStringArray &asTokens ) +{ + HandleParams; + + const CString& sName = asTokens[0]; + + if( sName=="playcommand" ) PlayCommand( sParam(1) ); + else + { + Actor::HandleCommand( asTokens ); + return; + } + + CheckHandledParams; +} + diff --git a/stepmania/src/BGAnimation.h b/stepmania/src/BGAnimation.h index a5c4a0b6ea..ac5c2074a4 100644 --- a/stepmania/src/BGAnimation.h +++ b/stepmania/src/BGAnimation.h @@ -41,7 +41,11 @@ public: float GetLengthSeconds() { return m_fLengthSeconds; } - void PlayOffCommand(); + virtual void HandleCommand( const CStringArray &asTokens ); + void PlayOffCommand() { PlayCommand("Off"); } + void PlayCommand( const CString &cmd ); + + float GetTweenTimeLeft() const; protected: vector m_Layers; diff --git a/stepmania/src/BGAnimationLayer.cpp b/stepmania/src/BGAnimationLayer.cpp index 2a0eb0bdad..dccfa731f6 100644 --- a/stepmania/src/BGAnimationLayer.cpp +++ b/stepmania/src/BGAnimationLayer.cpp @@ -41,7 +41,6 @@ const float SPIRAL_MIN_ZOOM = 0.3f; #define MAX_SPRITES (MAX_TILES_WIDE*MAX_TILES_HIGH) static const RectI FullScreenRectI(SCREEN_LEFT,SCREEN_TOP,SCREEN_RIGHT,SCREEN_BOTTOM); -// static const RectI FullScreenRectI(-SCREEN_WIDTH/2,-SCREEN_HEIGHT/2,+SCREEN_WIDTH/2,+SCREEN_HEIGHT/2); BGAnimationLayer::BGAnimationLayer() @@ -496,10 +495,31 @@ void BGAnimationLayer::LoadFromIni( CString sAniDir, CString sLayer ) sLayer.c_str(), sAniDir.c_str(), type.c_str() ); } - ini.GetValue( sLayer, "Command", m_sOnCommand ); + { + const IniFile::key *key = ini.GetKey( sLayer ); + for( IniFile::key::const_iterator i = key->begin(); + i != key->end(); ++i) + { + CString KeyName = i->first; /* "OnCommand" */ + KeyName.MakeLower(); + + if( KeyName.Right(7) != "command" ) + continue; /* not a command */ + + const CString &Data = i->second; + CString CmdName; + /* Special case: "Command=foo" -> "OnCommand=foo" */ + if( KeyName.size() == 7 ) + CmdName="on"; + else + CmdName = KeyName.Left( KeyName.size()-7 ); + m_asCommands[CmdName] = Data; + } + } + + ini.GetValue( sLayer, "CommandRepeatSeconds", m_fRepeatCommandEverySeconds ); m_fSecondsUntilNextCommand = m_fRepeatCommandEverySeconds; - ini.GetValue( sLayer, "OffCommand", m_sOffCommand ); ini.GetValue( sLayer, "FOV", m_fFOV ); ini.GetValue( sLayer, "Lighting", m_bLighting ); ini.GetValue( sLayer, "TexCoordVelocityX", m_fTexCoordVelocityX ); @@ -607,11 +627,7 @@ void BGAnimationLayer::LoadFromIni( CString sAniDir, CString sLayer ) m_pActors[i]->SetState( rand()%m_pActors[i]->GetNumStates() ); } - if( m_sOnCommand != "" ) - { - for( unsigned i=0; iCommand( m_sOnCommand ); - } + PlayCommand( "On" ); } float BGAnimationLayer::GetMaxTweenTimeLeft() const @@ -891,10 +907,7 @@ void BGAnimationLayer::Update( float fDeltaTime ) m_fSecondsUntilNextCommand -= fDeltaTime; if( m_fSecondsUntilNextCommand <= 0 ) { - for( unsigned i=0; iCommand( m_sOnCommand ); - } + PlayCommand( "On" ); m_fSecondsUntilNextCommand += m_fRepeatCommandEverySeconds; } } @@ -959,10 +972,7 @@ void BGAnimationLayer::GainingFocus( float fRate, bool bRewindMovie, bool bLoop m_pActors[0]->Command( ssprintf("rate,%f",fRate) ); if( m_fRepeatCommandEverySeconds == -1 ) // if not repeating - { - for( unsigned i=0; iCommand( m_sOnCommand ); - } + PlayCommand( "On" ); } void BGAnimationLayer::LosingFocus() @@ -970,12 +980,14 @@ void BGAnimationLayer::LosingFocus() m_pActors[0]->Command( "pause" ); } - -void BGAnimationLayer::PlayOffCommand() +void BGAnimationLayer::PlayCommand( CString cmd ) { - if( m_sOffCommand != "" ) - { - for( unsigned i=0; iCommand( m_sOffCommand ); - } + cmd.MakeLower(); + map::const_iterator it = m_asCommands.find( cmd ); + + if( it == m_asCommands.end() ) + return; + + for( unsigned i=0; iCommand( it->second ); } diff --git a/stepmania/src/BGAnimationLayer.h b/stepmania/src/BGAnimationLayer.h index d6c2ffe0cf..9b1d45f7ff 100644 --- a/stepmania/src/BGAnimationLayer.h +++ b/stepmania/src/BGAnimationLayer.h @@ -39,7 +39,8 @@ public: void GainingFocus( float fRate, bool bRewindMovie, bool bLoop ); void LosingFocus(); - void PlayOffCommand(); + void PlayCommand( CString cmd ); + void PlayOffCommand() { PlayCommand( "Off" ); } protected: vector m_pActors; @@ -90,8 +91,7 @@ protected: // // common stuff - CString m_sOnCommand; - CString m_sOffCommand; + map m_asCommands; float m_fRepeatCommandEverySeconds; // -1 = no repeat float m_fSecondsUntilNextCommand; float m_fUpdateRate; // set by GainingFocus