Files
itgmania212121/stepmania/src/MenuTimer.cpp
T

119 lines
3.2 KiB
C++
Raw Normal View History

2002-05-27 08:23:27 +00:00
#include "stdafx.h"
/*
-----------------------------------------------------------------------------
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"
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
m_textDigit1.LoadFromFont( THEME->GetPathTo("Fonts","timer numbers") );
2002-05-27 08:23:27 +00:00
m_textDigit1.TurnShadowOff();
2002-05-28 20:01:22 +00:00
m_textDigit1.SetXY( -18, 0 );
2002-07-23 01:41:40 +00:00
this->AddSubActor( &m_textDigit1 );
2002-05-27 08:23:27 +00:00
m_textDigit2.LoadFromFont( THEME->GetPathTo("Fonts","timer numbers") );
2002-05-27 08:23:27 +00:00
m_textDigit2.TurnShadowOff();
2002-05-28 20:01:22 +00:00
m_textDigit2.SetXY( +18, 0 );
2002-07-23 01:41:40 +00:00
this->AddSubActor( &m_textDigit2 );
2002-05-28 20:01:22 +00:00
m_soundBeep.Load( THEME->GetPathTo("Sounds","menu timer") );
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
SOUND->PlayOnceStreamedFromDir( ANNOUNCER->GetPathTo(ANNOUNCER_MENU_HURRY_UP) );
else if( fOldSecondsLeft > 5 && fNewSecondsLeft < 5 ) // transition to below 5
2002-05-27 08:23:27 +00:00
{
m_textDigit1.SetEffectGlowing( 10, D3DXCOLOR(1,0,0,0), D3DXCOLOR(1,0,0,1) );
m_textDigit2.SetEffectGlowing( 10, D3DXCOLOR(1,0,0,0), D3DXCOLOR(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;
if( m_fSecondsLeft < 4.5f )
{
m_textDigit1.SetZoomX( min(1, fDistFromNearestNumber*8) );
m_textDigit2.SetZoomX( min(1, fDistFromNearestNumber*8) );
}
}
void MenuTimer::StopTimer()
{
2002-07-11 19:02:26 +00:00
m_bTimerStopped = true;
2002-05-27 08:23:27 +00:00
}
void MenuTimer::StallTimer()
{
2002-07-11 19:02:26 +00:00
m_fStallSeconds = 1;
}
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-05-27 08:23:27 +00:00
}