Cleanup, move commands into metrics.
This commit is contained in:
+44
-78
@@ -20,47 +20,42 @@
|
||||
#include "Font.h"
|
||||
#include "RageSounds.h"
|
||||
|
||||
const float TIMER_SECONDS = 99;
|
||||
#define WARNING_START THEME->GetMetricI("MenuTimer","WarningStart")
|
||||
#define WARNING_BEEP_START THEME->GetMetricI("MenuTimer","WarningBeepStart")
|
||||
#define WARNING_COMMAND(i) THEME->GetMetric ("MenuTimer", ssprintf("WarningCommand%i",i))
|
||||
#define ON_COMMAND THEME->GetMetric ("MenuTimer","OnCommand")
|
||||
|
||||
const int TIMER_SECONDS = 99;
|
||||
|
||||
MenuTimer::MenuTimer()
|
||||
{
|
||||
m_fSecondsLeft = TIMER_SECONDS;
|
||||
m_fStallSeconds = 0;
|
||||
m_bPaused = false;
|
||||
|
||||
m_textDigit1.LoadFromNumbers( THEME->GetPathToN("MenuTimer") );
|
||||
m_textDigit2.LoadFromNumbers( THEME->GetPathToN("MenuTimer") );
|
||||
|
||||
m_textDigit1.EnableShadow( false );
|
||||
m_textDigit2.EnableShadow( false );
|
||||
|
||||
const glyph &g = m_textDigit1.m_pFont->GetGlyph('0');
|
||||
float fCharWidth = (float)g.Texture->GetSourceFrameWidth();
|
||||
|
||||
m_textDigit1.SetXY( -fCharWidth/2, 0 );
|
||||
m_textDigit2.SetXY( +fCharWidth/2, 0 );
|
||||
const float fCharWidth = (float) m_textDigit1.m_pFont->GetLineWidthInSourcePixels(L"0");
|
||||
m_textDigit1.SetX( -fCharWidth/2 );
|
||||
m_textDigit2.SetX( +fCharWidth/2 );
|
||||
|
||||
this->AddChild( &m_textDigit1 );
|
||||
this->AddChild( &m_textDigit2 );
|
||||
|
||||
SetSeconds( TIMER_SECONDS );
|
||||
|
||||
m_soundBeep.Load( THEME->GetPathToS("MenuTimer tick") );
|
||||
}
|
||||
|
||||
void MenuTimer::EnableStealth( bool bStealth )
|
||||
{
|
||||
if( bStealth )
|
||||
{
|
||||
m_soundBeep.Unload(); // unload the sound
|
||||
// HACK: this is not a good way to keep the numbers from drawing...
|
||||
m_textDigit1.SetZoomY( 0 );
|
||||
m_textDigit2.SetZoomY( 0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_soundBeep.Load( THEME->GetPathToS("MenuTimer tick") ); // reload the sound
|
||||
m_textDigit1.SetZoomY( 1 );
|
||||
m_textDigit2.SetZoomY( 1 );
|
||||
}
|
||||
|
||||
m_textDigit1.SetHidden( bStealth );
|
||||
m_textDigit2.SetHidden( bStealth );
|
||||
}
|
||||
|
||||
void MenuTimer::Update( float fDeltaTime )
|
||||
@@ -72,67 +67,40 @@ void MenuTimer::Update( float fDeltaTime )
|
||||
|
||||
// run down the stall time if any
|
||||
if( m_fStallSeconds > 0 )
|
||||
{
|
||||
m_fStallSeconds -= fDeltaTime;
|
||||
m_fStallSeconds = max( m_fStallSeconds - fDeltaTime, 0 );
|
||||
if( m_fStallSeconds > 0 )
|
||||
return;
|
||||
}
|
||||
|
||||
float fOldSecondsLeft = m_fSecondsLeft;
|
||||
const float fOldSecondsLeft = m_fSecondsLeft;
|
||||
m_fSecondsLeft -= fDeltaTime;
|
||||
CLAMP( m_fSecondsLeft, 0, 99 );
|
||||
float fNewSecondsLeft = m_fSecondsLeft;
|
||||
const float fNewSecondsLeft = m_fSecondsLeft;
|
||||
|
||||
int iOldDisplay = (int)(fOldSecondsLeft + 0.99f);
|
||||
int iNewDisplay = (int)(fNewSecondsLeft + 0.99f);
|
||||
const int iOldDisplay = (int)(fOldSecondsLeft + 0.99f);
|
||||
const int iNewDisplay = (int)(fNewSecondsLeft + 0.99f);
|
||||
|
||||
if( fOldSecondsLeft > 5.5 && fNewSecondsLeft < 5.5 ) // transition to below 5.5
|
||||
SOUND->PlayOnceFromDir( ANNOUNCER->GetPathTo("hurry up") );
|
||||
|
||||
if( iOldDisplay != iNewDisplay )
|
||||
if( iOldDisplay == iNewDisplay )
|
||||
return;
|
||||
|
||||
SetText( iNewDisplay );
|
||||
|
||||
if( iNewDisplay <= WARNING_START )
|
||||
{
|
||||
SetText( iNewDisplay );
|
||||
|
||||
switch( iNewDisplay )
|
||||
{
|
||||
case 6: // transition to below 6
|
||||
m_textDigit1.StopTweening();
|
||||
m_textDigit1.BeginTweening( 0.8f ); // sleep
|
||||
m_textDigit1.BeginTweening( 0.2f );
|
||||
m_textDigit1.SetZoomX( 0 );
|
||||
m_textDigit2.StopTweening();
|
||||
m_textDigit2.BeginTweening( 0.8f ); // sleep
|
||||
m_textDigit2.BeginTweening( 0.2f );
|
||||
m_textDigit2.SetZoomX( 0 );
|
||||
break;
|
||||
case 5: // transition to below 5
|
||||
m_textDigit1.SetEffectGlowShift( 0.15f, RageColor(1,0,0,0), RageColor(1,0,0,1) );
|
||||
m_textDigit2.SetEffectGlowShift( 0.15f, RageColor(1,0,0,0), RageColor(1,0,0,1) );
|
||||
// fall through
|
||||
case 4:
|
||||
case 3:
|
||||
case 2:
|
||||
case 1:
|
||||
m_textDigit1.StopTweening();
|
||||
m_textDigit1.BeginTweening( 0.2f );
|
||||
m_textDigit1.SetZoomX( 1 );
|
||||
m_textDigit1.BeginTweening( 0.6f ); // sleep
|
||||
m_textDigit1.BeginTweening( 0.2f );
|
||||
m_textDigit1.SetZoomX( 0 );
|
||||
m_textDigit2.StopTweening();
|
||||
m_textDigit2.BeginTweening( 0.2f );
|
||||
m_textDigit2.SetZoomX( 1 );
|
||||
m_textDigit2.BeginTweening( 0.6f ); // sleep
|
||||
m_textDigit2.BeginTweening( 0.2f );
|
||||
m_textDigit2.SetZoomX( 0 );
|
||||
|
||||
m_soundBeep.Play();
|
||||
break;
|
||||
case 0:
|
||||
SCREENMAN->PostMessageToTopScreen( SM_MenuTimer, 0 );
|
||||
Stop();
|
||||
break;
|
||||
}
|
||||
m_textDigit1.Command( WARNING_COMMAND(iNewDisplay) );
|
||||
m_textDigit2.Command( WARNING_COMMAND(iNewDisplay) );
|
||||
}
|
||||
|
||||
if( iNewDisplay == 0 )
|
||||
{
|
||||
Stop();
|
||||
SCREENMAN->PostMessageToTopScreen( SM_MenuTimer, 0 );
|
||||
}
|
||||
|
||||
if( iNewDisplay <= WARNING_BEEP_START )
|
||||
m_soundBeep.Play();
|
||||
}
|
||||
|
||||
|
||||
@@ -143,7 +111,9 @@ void MenuTimer::Pause()
|
||||
|
||||
void MenuTimer::Stop()
|
||||
{
|
||||
SetSeconds( 0 );
|
||||
/* Don't call SetSeconds if we're already at 0: let the existing tweens finish. */
|
||||
if( m_fSecondsLeft >= 1 )
|
||||
SetSeconds( 0 );
|
||||
Pause();
|
||||
}
|
||||
|
||||
@@ -163,12 +133,8 @@ void MenuTimer::SetSeconds( int iSeconds )
|
||||
m_fSecondsLeft = (float)iSeconds;
|
||||
CLAMP( m_fSecondsLeft, 0, 99 );
|
||||
|
||||
m_textDigit1.StopTweening();
|
||||
m_textDigit2.StopTweening();
|
||||
m_textDigit1.SetZoomX( 1 );
|
||||
m_textDigit2.SetZoomX( 1 );
|
||||
m_textDigit1.SetEffectNone();
|
||||
m_textDigit2.SetEffectNone();
|
||||
m_textDigit1.Command( ON_COMMAND );
|
||||
m_textDigit2.Command( ON_COMMAND );
|
||||
|
||||
SetText( iSeconds );
|
||||
}
|
||||
@@ -180,8 +146,8 @@ void MenuTimer::Start()
|
||||
|
||||
void MenuTimer::SetText( int iSeconds )
|
||||
{
|
||||
int iDigit1 = (int)(iSeconds)/10;
|
||||
int iDigit2 = (int)(iSeconds)%10;
|
||||
const int iDigit1 = (int)(iSeconds)/10;
|
||||
const int iDigit2 = (int)(iSeconds)%10;
|
||||
|
||||
m_textDigit1.SetText( ssprintf("%d",iDigit1) );
|
||||
m_textDigit2.SetText( ssprintf("%d",iDigit2) );
|
||||
|
||||
Reference in New Issue
Block a user