Files
itgmania212121/stepmania/src/MenuTimer.cpp
T

189 lines
4.2 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"
2003-07-26 23:05:16 +00:00
#include "RageSounds.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;
2003-03-11 21:33:11 +00:00
m_bPaused = false;
2002-05-27 08:23:27 +00:00
m_textDigit1.LoadFromNumbers( THEME->GetPathToN("MenuTimer") );
m_textDigit2.LoadFromNumbers( THEME->GetPathToN("MenuTimer") );
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
m_soundBeep.Load( THEME->GetPathToS("MenuTimer tick") );
2002-05-27 08:23:27 +00:00
}
2003-03-11 21:33:11 +00:00
void MenuTimer::EnableStealth( bool bStealth )
{
2003-03-11 21:33:11 +00:00
if( bStealth )
{
2003-03-11 21:33:11 +00:00
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 );
}
2003-03-11 21:33:11 +00:00
else
{
m_soundBeep.Load( THEME->GetPathToS("MenuTimer tick") ); // reload the sound
2003-03-11 21:33:11 +00:00
m_textDigit1.SetZoomY( 1 );
m_textDigit2.SetZoomY( 1 );
}
}
2002-05-27 08:23:27 +00:00
void MenuTimer::Update( float fDeltaTime )
{
ActorFrame::Update( fDeltaTime );
2003-03-11 21:33:11 +00:00
if( m_bPaused )
2002-07-11 19:02:26 +00:00
return;
2003-03-11 21:33:11 +00:00
// run down the stall time if any
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;
2003-03-11 21:33:11 +00:00
m_fSecondsLeft -= fDeltaTime;
CLAMP( m_fSecondsLeft, 0, 99 );
float fNewSecondsLeft = m_fSecondsLeft;
int iOldDisplay = (int)(fOldSecondsLeft + 0.99f);
int iNewDisplay = (int)(fNewSecondsLeft + 0.99f);
2002-05-27 08:23:27 +00:00
2002-07-11 19:02:26 +00:00
if( fOldSecondsLeft > 5.5 && fNewSecondsLeft < 5.5 ) // transition to below 5.5
2003-07-26 23:05:16 +00:00
SOUND->PlayOnceFromDir( ANNOUNCER->GetPathTo("hurry up") );
2003-03-11 21:33:11 +00:00
if( iOldDisplay != iNewDisplay )
2002-05-27 08:23:27 +00:00
{
2003-03-11 21:33:11 +00:00
SetText( iNewDisplay );
switch( iNewDisplay )
{
case 6: // transition to below 6
m_textDigit1.StopTweening();
m_textDigit1.BeginTweening( 0.8f ); // sleep
m_textDigit1.BeginTweening( 0.2f );
2003-04-12 06:16:12 +00:00
m_textDigit1.SetZoomX( 0 );
2003-03-11 21:33:11 +00:00
m_textDigit2.StopTweening();
m_textDigit2.BeginTweening( 0.8f ); // sleep
m_textDigit2.BeginTweening( 0.2f );
2003-04-12 06:16:12 +00:00
m_textDigit2.SetZoomX( 0 );
2003-03-11 21:33:11 +00:00
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 );
2003-04-12 06:16:12 +00:00
m_textDigit1.SetZoomX( 1 );
2003-03-11 21:33:11 +00:00
m_textDigit1.BeginTweening( 0.6f ); // sleep
m_textDigit1.BeginTweening( 0.2f );
2003-04-12 06:16:12 +00:00
m_textDigit1.SetZoomX( 0 );
2003-03-11 21:33:11 +00:00
m_textDigit2.StopTweening();
m_textDigit2.BeginTweening( 0.2f );
2003-04-12 06:16:12 +00:00
m_textDigit2.SetZoomX( 1 );
2003-03-11 21:33:11 +00:00
m_textDigit2.BeginTweening( 0.6f ); // sleep
m_textDigit2.BeginTweening( 0.2f );
2003-04-12 06:16:12 +00:00
m_textDigit2.SetZoomX( 0 );
2003-03-11 21:33:11 +00:00
m_soundBeep.Play();
break;
case 0:
2003-03-25 21:17:29 +00:00
SCREENMAN->PostMessageToTopScreen( SM_MenuTimer, 0 );
2003-03-11 21:33:11 +00:00
Stop();
break;
}
2002-05-27 08:23:27 +00:00
}
}
2003-03-11 21:33:11 +00:00
void MenuTimer::Pause()
{
m_bPaused = true;
}
void MenuTimer::Stop()
2002-05-27 08:23:27 +00:00
{
2003-03-11 21:33:11 +00:00
SetSeconds( 0 );
Pause();
2002-05-27 08:23:27 +00:00
}
2003-03-11 21:33:11 +00:00
void MenuTimer::Disable()
{
SetSeconds( 99 );
Pause();
}
void MenuTimer::Stall()
2002-05-27 08:23:27 +00:00
{
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
2003-03-11 21:33:11 +00:00
void MenuTimer::SetSeconds( int iSeconds )
2002-07-11 19:02:26 +00:00
{
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
2003-03-11 21:33:11 +00:00
m_textDigit1.StopTweening();
m_textDigit2.StopTweening();
2002-08-20 21:00:56 +00:00
m_textDigit1.SetZoomX( 1 );
m_textDigit2.SetZoomX( 1 );
m_textDigit1.SetEffectNone();
m_textDigit2.SetEffectNone();
2003-03-11 08:52:45 +00:00
2003-03-11 21:33:11 +00:00
SetText( iSeconds );
2002-05-27 08:23:27 +00:00
}
2003-03-11 21:33:11 +00:00
void MenuTimer::Start()
{
2003-03-11 21:33:11 +00:00
m_bPaused = false;
}
2003-03-11 21:33:11 +00:00
void MenuTimer::SetText( int iSeconds )
{
int iDigit1 = (int)(iSeconds)/10;
int iDigit2 = (int)(iSeconds)%10;
m_textDigit1.SetText( ssprintf("%d",iDigit1) );
m_textDigit2.SetText( ssprintf("%d",iDigit2) );
2003-03-17 23:24:00 +00:00
}