From f9f485debf40bf7887a0f618c2ad8de631833d6f Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Tue, 21 Nov 2006 03:11:58 +0000 Subject: [PATCH] On life change, send a message. Remove the duplicate code from ScoreDisplayLifeTime; actors can catch the message if they want to do things like this. --- stepmania/src/LifeMeterTime.cpp | 25 +++++++++++ stepmania/src/LifeMeterTime.h | 1 + stepmania/src/ScoreDisplayLifeTime.cpp | 58 +------------------------- stepmania/src/ScoreDisplayLifeTime.h | 2 - 4 files changed, 27 insertions(+), 59 deletions(-) diff --git a/stepmania/src/LifeMeterTime.cpp b/stepmania/src/LifeMeterTime.cpp index 9315e69ca0..67da886720 100644 --- a/stepmania/src/LifeMeterTime.cpp +++ b/stepmania/src/LifeMeterTime.cpp @@ -9,6 +9,7 @@ #include "GameState.h" #include "StatsManager.h" #include "PlayerState.h" +#include "MessageManager.h" const float FULL_LIFE_SECONDS = 1.5f*60; @@ -76,9 +77,14 @@ void LifeMeterTime::OnLoadSong() Course* pCourse = GAMESTATE->m_pCurCourse; ASSERT( pCourse ); + + float fOldLife = m_fLifeTotalLostSeconds; + m_fLifeTotalGainedSeconds += pCourse->m_vEntries[GAMESTATE->GetCourseSongIndex()].fGainSeconds; m_soundGainLife.Play(); + + SendLifeChangedMessage( fOldLife, TapNoteScore_Invalid, HoldNoteScore_Invalid ); } @@ -100,7 +106,11 @@ void LifeMeterTime::ChangeLife( TapNoteScore tns ) case TNS_HitMine: fMeterChange = PREFSMAN->m_fTimeMeterSecondsChange[SE_HitMine]; break; } + float fOldLife = m_fLifeTotalLostSeconds; + m_fLifeTotalLostSeconds -= fMeterChange; + + SendLifeChangedMessage( fOldLife, tns, HoldNoteScore_Invalid ); } void LifeMeterTime::ChangeLife( HoldNoteScore hns, TapNoteScore tns ) @@ -116,7 +126,22 @@ void LifeMeterTime::ChangeLife( HoldNoteScore hns, TapNoteScore tns ) case HNS_LetGo: fMeterChange = PREFSMAN->m_fTimeMeterSecondsChange[SE_LetGo]; break; } + float fOldLife = m_fLifeTotalLostSeconds; + m_fLifeTotalLostSeconds -= fMeterChange; + + SendLifeChangedMessage( fOldLife, tns, hns ); +} + +void LifeMeterTime::SendLifeChangedMessage( float fOldLife, TapNoteScore tns, HoldNoteScore hns ) +{ + Message msg( "LifeChanged" ); + msg.SetParam( "Player", m_pPlayerState->m_PlayerNumber ); + msg.SetParam( "TapNoteScore", LuaReference::Create(tns) ); + msg.SetParam( "HoldNoteScore", LuaReference::Create(hns) ); + msg.SetParam( "OldLife", fOldLife ); + msg.SetParam( "LifeMeter", LuaReference::CreateFromPush(*this) ); + MESSAGEMAN->Broadcast( msg ); } bool LifeMeterTime::IsInDanger() const diff --git a/stepmania/src/LifeMeterTime.h b/stepmania/src/LifeMeterTime.h index 07be6e5a5c..e3a800aa41 100644 --- a/stepmania/src/LifeMeterTime.h +++ b/stepmania/src/LifeMeterTime.h @@ -32,6 +32,7 @@ public: private: float GetLifeSeconds() const; + void SendLifeChangedMessage( float fOldLife, TapNoteScore tns, HoldNoteScore hns ); AutoActor m_sprBackground; Quad m_quadDangerGlow; diff --git a/stepmania/src/ScoreDisplayLifeTime.cpp b/stepmania/src/ScoreDisplayLifeTime.cpp index ef7db529c0..35da3918e0 100644 --- a/stepmania/src/ScoreDisplayLifeTime.cpp +++ b/stepmania/src/ScoreDisplayLifeTime.cpp @@ -3,15 +3,11 @@ #include "RageUtil.h" #include "RageLog.h" #include "PrefsManager.h" -#include "GameState.h" #include "ThemeManager.h" #include "PlayerState.h" -#include "StatsManager.h" +#include "PlayerStageStats.h" #include "CommonMetrics.h" #include "ActorUtil.h" -#include "Course.h" - -static const RString GAIN_LIFE_COMMAND_NAME = "GainLife"; ScoreDisplayLifeTime::ScoreDisplayLifeTime() { @@ -55,10 +51,6 @@ void ScoreDisplayLifeTime::Init( const PlayerState* pPlayerState, const PlayerSt if( !m_textDeltaSeconds.HasCommand( sCommand ) ) ActorUtil::LoadCommand( m_textDeltaSeconds, sType, sCommand ); } - { - if( !m_textDeltaSeconds.HasCommand( GAIN_LIFE_COMMAND_NAME ) ) - ActorUtil::LoadCommand( m_textDeltaSeconds, sType, GAIN_LIFE_COMMAND_NAME ); - } } void ScoreDisplayLifeTime::Update( float fDelta ) @@ -73,64 +65,16 @@ void ScoreDisplayLifeTime::Update( float fDelta ) void ScoreDisplayLifeTime::OnLoadSong() { - if( STATSMAN->m_CurStageStats.m_player[m_pPlayerState->m_PlayerNumber].m_bFailed ) - return; - - Course* pCourse = GAMESTATE->m_pCurCourse; - ASSERT( pCourse ); - const CourseEntry *pEntry = &pCourse->m_vEntries[GAMESTATE->GetCourseSongIndex()]; - - PlayGainLoss( GAIN_LIFE_COMMAND_NAME, pEntry->fGainSeconds ); } void ScoreDisplayLifeTime::OnJudgment( TapNoteScore tns ) { - if( STATSMAN->m_CurStageStats.m_player[m_pPlayerState->m_PlayerNumber].m_bFailed ) - return; - - float fMeterChange = 0; - switch( tns ) - { - case TNS_W1: fMeterChange = PREFSMAN->m_fTimeMeterSecondsChange[SE_W1]; break; - case TNS_W2: fMeterChange = PREFSMAN->m_fTimeMeterSecondsChange[SE_W2]; break; - case TNS_W3: fMeterChange = PREFSMAN->m_fTimeMeterSecondsChange[SE_W3]; break; - case TNS_W4: fMeterChange = PREFSMAN->m_fTimeMeterSecondsChange[SE_W4]; break; - case TNS_W5: fMeterChange = PREFSMAN->m_fTimeMeterSecondsChange[SE_W5]; break; - case TNS_Miss: fMeterChange = PREFSMAN->m_fTimeMeterSecondsChange[SE_Miss]; break; - case TNS_HitMine: fMeterChange = PREFSMAN->m_fTimeMeterSecondsChange[SE_HitMine]; break; - default: ASSERT(0); - } - - PlayGainLoss( TapNoteScoreToString(tns), fMeterChange ); } void ScoreDisplayLifeTime::OnJudgment( HoldNoteScore hns, TapNoteScore tns ) { - if( STATSMAN->m_CurStageStats.m_player[m_pPlayerState->m_PlayerNumber].m_bFailed ) - return; - - float fMeterChange = 0; - switch( hns ) - { - case HNS_Held: fMeterChange = PREFSMAN->m_fTimeMeterSecondsChange[SE_Held]; break; - case HNS_LetGo: fMeterChange = PREFSMAN->m_fTimeMeterSecondsChange[SE_LetGo]; break; - default: ASSERT(0); - } - - PlayGainLoss( HoldNoteScoreToString(hns), fMeterChange ); } -void ScoreDisplayLifeTime::PlayGainLoss( const RString &sCommand, float fDeltaLifeSecs ) -{ - if( fDeltaLifeSecs == 0 ) - return; // don't animate if no change - RString s = ssprintf( "%+1.1fs", fDeltaLifeSecs); - m_textDeltaSeconds.SetText( s ); - m_textDeltaSeconds.FinishTweening(); - m_textDeltaSeconds.PlayCommand( sCommand ); -} - - /* * (c) 2001-2004 Chris Danford * All rights reserved. diff --git a/stepmania/src/ScoreDisplayLifeTime.h b/stepmania/src/ScoreDisplayLifeTime.h index 466af6afc6..165373678d 100644 --- a/stepmania/src/ScoreDisplayLifeTime.h +++ b/stepmania/src/ScoreDisplayLifeTime.h @@ -21,8 +21,6 @@ public: virtual void OnJudgment( HoldNoteScore score, TapNoteScore tscore ); protected: - void PlayGainLoss( const RString &sCommand, float fDeltaLifeSecs ); - AutoActor m_sprFrame; BitmapText m_textTimeRemaining; BitmapText m_textDeltaSeconds;