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.
This commit is contained in:
@@ -9,6 +9,7 @@
|
|||||||
#include "GameState.h"
|
#include "GameState.h"
|
||||||
#include "StatsManager.h"
|
#include "StatsManager.h"
|
||||||
#include "PlayerState.h"
|
#include "PlayerState.h"
|
||||||
|
#include "MessageManager.h"
|
||||||
|
|
||||||
const float FULL_LIFE_SECONDS = 1.5f*60;
|
const float FULL_LIFE_SECONDS = 1.5f*60;
|
||||||
|
|
||||||
@@ -76,9 +77,14 @@ void LifeMeterTime::OnLoadSong()
|
|||||||
|
|
||||||
Course* pCourse = GAMESTATE->m_pCurCourse;
|
Course* pCourse = GAMESTATE->m_pCurCourse;
|
||||||
ASSERT( pCourse );
|
ASSERT( pCourse );
|
||||||
|
|
||||||
|
float fOldLife = m_fLifeTotalLostSeconds;
|
||||||
|
|
||||||
m_fLifeTotalGainedSeconds += pCourse->m_vEntries[GAMESTATE->GetCourseSongIndex()].fGainSeconds;
|
m_fLifeTotalGainedSeconds += pCourse->m_vEntries[GAMESTATE->GetCourseSongIndex()].fGainSeconds;
|
||||||
|
|
||||||
m_soundGainLife.Play();
|
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;
|
case TNS_HitMine: fMeterChange = PREFSMAN->m_fTimeMeterSecondsChange[SE_HitMine]; break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float fOldLife = m_fLifeTotalLostSeconds;
|
||||||
|
|
||||||
m_fLifeTotalLostSeconds -= fMeterChange;
|
m_fLifeTotalLostSeconds -= fMeterChange;
|
||||||
|
|
||||||
|
SendLifeChangedMessage( fOldLife, tns, HoldNoteScore_Invalid );
|
||||||
}
|
}
|
||||||
|
|
||||||
void LifeMeterTime::ChangeLife( HoldNoteScore hns, TapNoteScore tns )
|
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;
|
case HNS_LetGo: fMeterChange = PREFSMAN->m_fTimeMeterSecondsChange[SE_LetGo]; break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float fOldLife = m_fLifeTotalLostSeconds;
|
||||||
|
|
||||||
m_fLifeTotalLostSeconds -= fMeterChange;
|
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
|
bool LifeMeterTime::IsInDanger() const
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
float GetLifeSeconds() const;
|
float GetLifeSeconds() const;
|
||||||
|
void SendLifeChangedMessage( float fOldLife, TapNoteScore tns, HoldNoteScore hns );
|
||||||
|
|
||||||
AutoActor m_sprBackground;
|
AutoActor m_sprBackground;
|
||||||
Quad m_quadDangerGlow;
|
Quad m_quadDangerGlow;
|
||||||
|
|||||||
@@ -3,15 +3,11 @@
|
|||||||
#include "RageUtil.h"
|
#include "RageUtil.h"
|
||||||
#include "RageLog.h"
|
#include "RageLog.h"
|
||||||
#include "PrefsManager.h"
|
#include "PrefsManager.h"
|
||||||
#include "GameState.h"
|
|
||||||
#include "ThemeManager.h"
|
#include "ThemeManager.h"
|
||||||
#include "PlayerState.h"
|
#include "PlayerState.h"
|
||||||
#include "StatsManager.h"
|
#include "PlayerStageStats.h"
|
||||||
#include "CommonMetrics.h"
|
#include "CommonMetrics.h"
|
||||||
#include "ActorUtil.h"
|
#include "ActorUtil.h"
|
||||||
#include "Course.h"
|
|
||||||
|
|
||||||
static const RString GAIN_LIFE_COMMAND_NAME = "GainLife";
|
|
||||||
|
|
||||||
ScoreDisplayLifeTime::ScoreDisplayLifeTime()
|
ScoreDisplayLifeTime::ScoreDisplayLifeTime()
|
||||||
{
|
{
|
||||||
@@ -55,10 +51,6 @@ void ScoreDisplayLifeTime::Init( const PlayerState* pPlayerState, const PlayerSt
|
|||||||
if( !m_textDeltaSeconds.HasCommand( sCommand ) )
|
if( !m_textDeltaSeconds.HasCommand( sCommand ) )
|
||||||
ActorUtil::LoadCommand( m_textDeltaSeconds, sType, 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 )
|
void ScoreDisplayLifeTime::Update( float fDelta )
|
||||||
@@ -73,64 +65,16 @@ void ScoreDisplayLifeTime::Update( float fDelta )
|
|||||||
|
|
||||||
void ScoreDisplayLifeTime::OnLoadSong()
|
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 )
|
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 )
|
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
|
* (c) 2001-2004 Chris Danford
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
|
|||||||
@@ -21,8 +21,6 @@ public:
|
|||||||
virtual void OnJudgment( HoldNoteScore score, TapNoteScore tscore );
|
virtual void OnJudgment( HoldNoteScore score, TapNoteScore tscore );
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void PlayGainLoss( const RString &sCommand, float fDeltaLifeSecs );
|
|
||||||
|
|
||||||
AutoActor m_sprFrame;
|
AutoActor m_sprFrame;
|
||||||
BitmapText m_textTimeRemaining;
|
BitmapText m_textTimeRemaining;
|
||||||
BitmapText m_textDeltaSeconds;
|
BitmapText m_textDeltaSeconds;
|
||||||
|
|||||||
Reference in New Issue
Block a user