Files
itgmania212121/stepmania/src/MenuTimer.cpp
T

154 lines
4.1 KiB
C++
Raw Normal View History

2003-02-16 04:01:45 +00:00
#include "global.h"
2002-05-27 08:23:27 +00:00
/*
-----------------------------------------------------------------------------
Class: MenuTimer
Desc: See header.
Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved.
Chris Danford
-----------------------------------------------------------------------------
*/
#include "MenuTimer.h"
#include "RageUtil.h"
#include "GameConstantsAndTypes.h"
2002-07-23 01:41:40 +00:00
#include "PrefsManager.h"
2002-05-27 08:23:27 +00:00
#include "ScreenManager.h"
2002-07-11 19:02:26 +00:00
#include "AnnouncerManager.h"
#include "ThemeManager.h"
2002-12-29 22:54:55 +00:00
#include "Font.h"
2002-05-27 08:23:27 +00:00
2002-06-14 22:25:22 +00:00
const float TIMER_SECONDS = 99;
2002-05-27 08:23:27 +00:00
MenuTimer::MenuTimer()
{
m_fSecondsLeft = TIMER_SECONDS;
2002-07-11 19:02:26 +00:00
m_fStallSeconds = 0;
m_bTimerStopped = false;
2002-05-27 08:23:27 +00:00
2003-03-09 00:55:49 +00:00
m_textDigit1.LoadFromNumbers( THEME->GetPathTo("Numbers","MenuTimer numbers") );
m_textDigit2.LoadFromNumbers( THEME->GetPathTo("Numbers","MenuTimer numbers") );
2002-09-29 05:06:18 +00:00
2003-03-02 01:43:33 +00:00
m_textDigit1.EnableShadow( false );
m_textDigit2.EnableShadow( false );
2002-09-29 05:06:18 +00:00
2003-01-04 05:20:40 +00:00
const glyph &g = m_textDigit1.m_pFont->GetGlyph('0');
float fCharWidth = (float)g.Texture->GetSourceFrameWidth();
2002-09-29 05:06:18 +00:00
m_textDigit1.SetXY( -fCharWidth/2, 0 );
m_textDigit2.SetXY( +fCharWidth/2, 0 );
this->AddChild( &m_textDigit1 );
this->AddChild( &m_textDigit2 );
2002-05-28 20:01:22 +00:00
2003-03-09 00:55:49 +00:00
m_soundBeep.Load( THEME->GetPathTo("Sounds","MenuTimer tick") );
2002-05-27 08:23:27 +00:00
}
void MenuTimer::StealthTimer( int iActive )
{
if ( iActive == 0 ) // we wanna keep everything as it is...
{
m_soundBeep.Load( THEME->GetPathTo("Sounds","menu timer") ); // reload the sound
}
else if ( iActive == 1 ) // otherwise we wanna make the timer invisible and silent....
{
m_soundBeep.Unload(); // unload the sound
}
// else take no action
}
2002-05-27 08:23:27 +00:00
void MenuTimer::Update( float fDeltaTime )
{
ActorFrame::Update( fDeltaTime );
2002-07-11 19:02:26 +00:00
if( m_bTimerStopped )
2002-07-27 19:29:51 +00:00
{
m_textDigit1.SetText( ssprintf("%d", ((int)m_fSecondsLeft)/10) );
m_textDigit2.SetText( ssprintf("%d", ((int)m_fSecondsLeft)%10) );
m_textDigit1.SetZoomX( 1 );
m_textDigit2.SetZoomX( 1 );
2002-07-11 19:02:26 +00:00
return;
2002-07-27 19:29:51 +00:00
}
2002-07-11 19:02:26 +00:00
if( m_fStallSeconds > 0 )
{
m_fStallSeconds -= fDeltaTime;
return;
}
2002-05-27 08:23:27 +00:00
float fOldSecondsLeft = m_fSecondsLeft;
float fNewSecondsLeft = fOldSecondsLeft - fDeltaTime;
2002-07-11 19:02:26 +00:00
if( fOldSecondsLeft > 5.5 && fNewSecondsLeft < 5.5 ) // transition to below 5.5
2003-01-02 08:13:34 +00:00
SOUNDMAN->PlayOnceFromDir( ANNOUNCER->GetPathTo("hurry up") );
2002-07-11 19:02:26 +00:00
else if( fOldSecondsLeft > 5 && fNewSecondsLeft < 5 ) // transition to below 5
2002-05-27 08:23:27 +00:00
{
2003-02-18 23:15:38 +00:00
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) );
2002-05-28 20:01:22 +00:00
m_soundBeep.Play();
2002-05-27 08:23:27 +00:00
}
2002-05-28 20:01:22 +00:00
else if( fOldSecondsLeft > 4 && fNewSecondsLeft < 4 ) // transition to below 4
m_soundBeep.Play();
else if( fOldSecondsLeft > 3 && fNewSecondsLeft < 3 ) // transition to below 3
m_soundBeep.Play();
else if( fOldSecondsLeft > 2 && fNewSecondsLeft < 2 ) // transition to below 2
m_soundBeep.Play();
else if( fOldSecondsLeft > 1 && fNewSecondsLeft < 1 ) // transition to below 1
m_soundBeep.Play();
2002-05-27 08:23:27 +00:00
else if( fOldSecondsLeft > 0 && fNewSecondsLeft < 0 ) // transition to below 0
SCREENMAN->SendMessageToTopScreen( SM_MenuTimer, 0 );
m_fSecondsLeft = fNewSecondsLeft;
m_fSecondsLeft = max( 0, m_fSecondsLeft );
2002-05-28 20:01:22 +00:00
m_textDigit1.SetText( ssprintf("%d", ((int)m_fSecondsLeft+1)/10) );
m_textDigit2.SetText( ssprintf("%d", ((int)m_fSecondsLeft+1)%10) );
2002-05-27 08:23:27 +00:00
// "flip" the numbers
float fRemainder = m_fSecondsLeft - (int)m_fSecondsLeft;
float fDistFromNearestNumber = min( fRemainder, 1-fRemainder ); // this is between 0 and 0.5;
2003-03-09 00:55:49 +00:00
if( m_fSecondsLeft == 0 )
{
m_textDigit1.SetZoomX( 1 );
m_textDigit2.SetZoomX( 1 );
}
else if( m_fSecondsLeft < 4.5f )
2002-05-27 08:23:27 +00:00
{
m_textDigit1.SetZoomX( min(1, fDistFromNearestNumber*8) );
m_textDigit2.SetZoomX( min(1, fDistFromNearestNumber*8) );
}
}
void MenuTimer::StopTimer()
{
2002-10-20 19:38:07 +00:00
SetTimer( 0 );
2002-07-11 19:02:26 +00:00
m_bTimerStopped = true;
2002-05-27 08:23:27 +00:00
}
void MenuTimer::StallTimer()
{
2002-08-20 21:00:56 +00:00
m_fStallSeconds = 0.5f;
2002-07-11 19:02:26 +00:00
}
2002-05-27 08:23:27 +00:00
2002-07-11 19:02:26 +00:00
void MenuTimer::SetTimer( int iSeconds )
{
m_fSecondsLeft = (float)iSeconds;
2002-07-27 19:29:51 +00:00
CLAMP( m_fSecondsLeft, 0, 99 );
2002-08-20 21:00:56 +00:00
m_textDigit1.SetZoomX( 1 );
m_textDigit2.SetZoomX( 1 );
m_textDigit1.SetEffectNone();
m_textDigit2.SetEffectNone();
2002-05-27 08:23:27 +00:00
}
void MenuTimer::StartTimer()
{
m_bTimerStopped = false;
}