2003-02-16 04:01:45 +00:00
|
|
|
#include "global.h"
|
2002-05-27 08:23:27 +00:00
|
|
|
#include "MenuTimer.h"
|
|
|
|
|
#include "RageUtil.h"
|
|
|
|
|
#include "GameConstantsAndTypes.h"
|
|
|
|
|
#include "ScreenManager.h"
|
2002-07-11 19:02:26 +00:00
|
|
|
#include "AnnouncerManager.h"
|
2002-11-11 04:53:31 +00:00
|
|
|
#include "ThemeManager.h"
|
2002-12-29 22:54:55 +00:00
|
|
|
#include "Font.h"
|
2004-07-08 00:10:34 +00:00
|
|
|
#include "GameSoundManager.h"
|
2004-11-06 23:13:47 +00:00
|
|
|
#include "ThemeMetric.h"
|
2005-05-04 02:30:55 +00:00
|
|
|
#include "ActorUtil.h"
|
2002-05-27 08:23:27 +00:00
|
|
|
|
2006-09-22 07:46:21 +00:00
|
|
|
RString WARNING_COMMAND_NAME( size_t i ) { return ssprintf("Warning%dCommand",int(i)); }
|
2005-04-24 05:58:58 +00:00
|
|
|
|
2005-05-04 03:46:59 +00:00
|
|
|
static const ThemeMetric<int> WARNING_START ("MenuTimer","WarningStart");
|
|
|
|
|
static const ThemeMetric<int> WARNING_BEEP_START ("MenuTimer","WarningBeepStart");
|
|
|
|
|
static const ThemeMetric<float> MAX_STALL_SECONDS ("MenuTimer","MaxStallSeconds");
|
2003-11-07 21:33:27 +00:00
|
|
|
|
2005-05-04 03:46:59 +00:00
|
|
|
static const float TIMER_PAUSE_SECONDS = 99.99f;
|
2002-05-27 08:23:27 +00:00
|
|
|
|
2005-04-24 05:58:58 +00:00
|
|
|
MenuTimer::MenuTimer() :
|
|
|
|
|
WARNING_COMMAND("MenuTimer", WARNING_COMMAND_NAME, WARNING_START+1)
|
2002-05-27 08:23:27 +00:00
|
|
|
{
|
2002-07-11 19:02:26 +00:00
|
|
|
m_fStallSeconds = 0;
|
2003-12-03 03:03:54 +00:00
|
|
|
m_fStallSecondsLeft = MAX_STALL_SECONDS;
|
2003-03-11 21:33:11 +00:00
|
|
|
m_bPaused = false;
|
2005-07-18 02:08:15 +00:00
|
|
|
}
|
2002-05-27 08:23:27 +00:00
|
|
|
|
2005-07-18 02:08:15 +00:00
|
|
|
void MenuTimer::Load()
|
|
|
|
|
{
|
2005-05-04 02:30:55 +00:00
|
|
|
for( int i=0; i<NUM_MENU_TIMER_TEXTS; i++ )
|
|
|
|
|
{
|
|
|
|
|
m_text[i].LoadFromFont( THEME->GetPathF("MenuTimer","numbers") );
|
|
|
|
|
m_text[i].SetName( ssprintf("Text%d",i+1) );
|
|
|
|
|
ActorUtil::OnCommand( m_text[i], "MenuTimer" );
|
|
|
|
|
this->AddChild( &m_text[i] );
|
|
|
|
|
}
|
2002-05-28 20:01:22 +00:00
|
|
|
|
2006-09-22 03:38:47 +00:00
|
|
|
m_exprFormatText[0] = THEME->GetMetricR("MenuTimer", "Text1FormatFunction");
|
|
|
|
|
m_exprFormatText[1] = THEME->GetMetricR("MenuTimer", "Text2FormatFunction");
|
|
|
|
|
|
2005-03-26 03:30:08 +00:00
|
|
|
SetSeconds( TIMER_PAUSE_SECONDS );
|
2003-11-07 21:33:27 +00:00
|
|
|
|
2005-02-06 03:28:22 +00:00
|
|
|
m_soundBeep.Load( THEME->GetPathS("MenuTimer","tick") );
|
2002-05-27 08:23:27 +00:00
|
|
|
}
|
|
|
|
|
|
2003-03-11 21:33:11 +00:00
|
|
|
void MenuTimer::EnableStealth( bool bStealth )
|
2002-09-13 18:06:36 +00:00
|
|
|
{
|
2003-03-11 21:33:11 +00:00
|
|
|
if( bStealth )
|
|
|
|
|
m_soundBeep.Unload(); // unload the sound
|
|
|
|
|
else
|
2005-02-06 03:28:22 +00:00
|
|
|
m_soundBeep.Load( THEME->GetPathS("MenuTimer","tick") ); // reload the sound
|
2003-11-07 21:33:27 +00:00
|
|
|
|
2005-05-04 02:30:55 +00:00
|
|
|
for( int i=0; i<NUM_MENU_TIMER_TEXTS; i++ )
|
|
|
|
|
{
|
|
|
|
|
m_text[i].SetHidden( bStealth );
|
|
|
|
|
}
|
2002-09-13 18:06:36 +00:00
|
|
|
}
|
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 )
|
2003-11-07 21:33:27 +00:00
|
|
|
m_fStallSeconds = max( m_fStallSeconds - fDeltaTime, 0 );
|
|
|
|
|
if( m_fStallSeconds > 0 )
|
2002-07-11 19:02:26 +00:00
|
|
|
return;
|
|
|
|
|
|
2003-11-07 21:33:27 +00:00
|
|
|
const float fOldSecondsLeft = m_fSecondsLeft;
|
2003-03-11 21:33:11 +00:00
|
|
|
m_fSecondsLeft -= fDeltaTime;
|
2005-05-04 04:00:00 +00:00
|
|
|
m_fSecondsLeft = max( 0, m_fSecondsLeft );
|
2003-11-07 21:33:27 +00:00
|
|
|
const float fNewSecondsLeft = m_fSecondsLeft;
|
2003-03-11 21:33:11 +00:00
|
|
|
|
2005-05-04 09:59:59 +00:00
|
|
|
SetText( fNewSecondsLeft );
|
|
|
|
|
|
2005-05-04 04:00:00 +00:00
|
|
|
if( fOldSecondsLeft == fNewSecondsLeft )
|
|
|
|
|
return;
|
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
|
|
|
|
2003-11-07 21:33:27 +00:00
|
|
|
|
2005-05-04 09:59:59 +00:00
|
|
|
int iCrossed = (int)floorf(fOldSecondsLeft);
|
|
|
|
|
if( fOldSecondsLeft > iCrossed && fNewSecondsLeft < iCrossed ) // crossed
|
2002-05-27 08:23:27 +00:00
|
|
|
{
|
2005-05-05 12:03:36 +00:00
|
|
|
if( iCrossed <= WARNING_START )
|
2005-05-04 04:00:00 +00:00
|
|
|
{
|
|
|
|
|
for( int i=0; i<NUM_MENU_TIMER_TEXTS; i++ )
|
2006-08-15 19:16:39 +00:00
|
|
|
m_text[i].RunCommands( WARNING_COMMAND.GetValue(iCrossed) );
|
2005-05-04 04:00:00 +00:00
|
|
|
}
|
2005-05-04 09:59:59 +00:00
|
|
|
|
|
|
|
|
if( iCrossed <= WARNING_BEEP_START && m_soundBeep.IsLoaded() )
|
|
|
|
|
m_soundBeep.Play();
|
2002-05-27 08:23:27 +00:00
|
|
|
}
|
2004-01-17 23:14:56 +00:00
|
|
|
|
2005-05-04 04:00:00 +00:00
|
|
|
if( fNewSecondsLeft == 0 )
|
2003-11-07 21:33:27 +00:00
|
|
|
{
|
|
|
|
|
Stop();
|
|
|
|
|
SCREENMAN->PostMessageToTopScreen( SM_MenuTimer, 0 );
|
2005-05-04 02:30:55 +00:00
|
|
|
for( int i=0; i<NUM_MENU_TIMER_TEXTS; i++ )
|
2005-07-24 03:11:03 +00:00
|
|
|
m_text[i].StopEffect();
|
2003-11-07 21:33:27 +00:00
|
|
|
}
|
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-11-07 21:33:27 +00:00
|
|
|
/* Don't call SetSeconds if we're already at 0: let the existing tweens finish. */
|
|
|
|
|
if( m_fSecondsLeft >= 1 )
|
|
|
|
|
SetSeconds( 0 );
|
2003-03-11 21:33:11 +00:00
|
|
|
Pause();
|
2002-05-27 08:23:27 +00:00
|
|
|
}
|
|
|
|
|
|
2003-03-11 21:33:11 +00:00
|
|
|
void MenuTimer::Disable()
|
|
|
|
|
{
|
2005-05-04 09:59:59 +00:00
|
|
|
SetSeconds( TIMER_PAUSE_SECONDS );
|
2003-03-11 21:33:11 +00:00
|
|
|
Pause();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MenuTimer::Stall()
|
2002-05-27 08:23:27 +00:00
|
|
|
{
|
2003-12-03 03:03:54 +00:00
|
|
|
/* Max amount of stall time we'll use: */
|
|
|
|
|
const float Amt = min( 0.5f, m_fStallSecondsLeft );
|
|
|
|
|
|
|
|
|
|
/* Amount of stall time to add: */
|
|
|
|
|
const float ToAdd = Amt - m_fStallSeconds;
|
|
|
|
|
|
|
|
|
|
m_fStallSeconds += ToAdd;
|
|
|
|
|
m_fStallSecondsLeft -= ToAdd;
|
2002-07-11 19:02:26 +00:00
|
|
|
}
|
2002-05-27 08:23:27 +00:00
|
|
|
|
2005-03-26 03:30:08 +00:00
|
|
|
void MenuTimer::SetSeconds( float fSeconds )
|
2002-07-11 19:02:26 +00:00
|
|
|
{
|
2005-03-26 03:30:08 +00:00
|
|
|
m_fSecondsLeft = fSeconds;
|
2002-08-20 21:00:56 +00:00
|
|
|
|
2005-05-04 02:30:55 +00:00
|
|
|
for( int i=0; i<NUM_MENU_TIMER_TEXTS; i++ )
|
|
|
|
|
m_text[i].PlayCommand( "On" );
|
2003-03-11 08:52:45 +00:00
|
|
|
|
2005-05-04 04:00:00 +00:00
|
|
|
SetText( fSeconds );
|
2002-05-27 08:23:27 +00:00
|
|
|
}
|
2002-08-27 23:31:41 +00:00
|
|
|
|
2003-03-11 21:33:11 +00:00
|
|
|
void MenuTimer::Start()
|
2002-08-27 23:31:41 +00:00
|
|
|
{
|
2003-03-11 21:33:11 +00:00
|
|
|
m_bPaused = false;
|
2002-08-27 23:31:41 +00:00
|
|
|
}
|
2003-03-11 21:33:11 +00:00
|
|
|
|
2005-05-04 02:30:55 +00:00
|
|
|
void MenuTimer::SetText( float fSeconds )
|
2003-03-11 21:33:11 +00:00
|
|
|
{
|
2005-06-16 06:55:34 +00:00
|
|
|
Lua *L = LUA->Get();
|
|
|
|
|
|
2005-05-04 02:30:55 +00:00
|
|
|
for( int i=0; i<NUM_MENU_TIMER_TEXTS; i++ )
|
|
|
|
|
{
|
|
|
|
|
// function
|
2005-06-16 06:55:34 +00:00
|
|
|
m_exprFormatText[i].PushSelf( L );
|
|
|
|
|
ASSERT( !lua_isnil(L, -1) );
|
2005-05-04 02:30:55 +00:00
|
|
|
|
|
|
|
|
// 1st parameter
|
2006-09-26 08:54:54 +00:00
|
|
|
LuaHelpers::Push( L, fSeconds );
|
2005-05-04 02:30:55 +00:00
|
|
|
|
|
|
|
|
// call function with 1 argument and 1 result
|
2005-06-16 06:55:34 +00:00
|
|
|
lua_call(L, 1, 1);
|
2005-05-04 02:30:55 +00:00
|
|
|
|
2006-01-22 01:00:06 +00:00
|
|
|
RString sText;
|
2006-09-22 08:48:49 +00:00
|
|
|
LuaHelpers::Pop( L, sText );
|
2005-05-04 02:30:55 +00:00
|
|
|
|
|
|
|
|
m_text[i].SetText( sText );
|
|
|
|
|
}
|
2005-06-16 06:55:34 +00:00
|
|
|
|
|
|
|
|
LUA->Release(L);
|
2003-03-17 23:24:00 +00:00
|
|
|
}
|
2004-06-07 21:14:03 +00:00
|
|
|
|
2006-09-01 23:21:19 +00:00
|
|
|
// lua start
|
|
|
|
|
#include "LuaBinding.h"
|
|
|
|
|
|
|
|
|
|
class LunaMenuTimer: public Luna<MenuTimer>
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
LunaMenuTimer() { LUA->Register( Register ); }
|
|
|
|
|
|
|
|
|
|
static int setseconds( T* p, lua_State *L ) { p->SetSeconds(FArg(1)); return 0; }
|
|
|
|
|
static int pause( T* p, lua_State *L ) { p->Pause(); return 0; }
|
|
|
|
|
static void Register(lua_State *L) {
|
|
|
|
|
ADD_METHOD( setseconds );
|
|
|
|
|
ADD_METHOD( pause );
|
|
|
|
|
|
|
|
|
|
Luna<T>::Register( L );
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
LUA_REGISTER_DERIVED_CLASS( MenuTimer, ActorFrame )
|
|
|
|
|
// lua end
|
|
|
|
|
|
2004-06-07 21:14:03 +00:00
|
|
|
/*
|
|
|
|
|
* (c) 2002-2004 Chris Danford
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
|
* copy of this software and associated documentation files (the
|
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
|
* distribute, and/or sell copies of the Software, and to permit persons to
|
|
|
|
|
* whom the Software is furnished to do so, provided that the above
|
|
|
|
|
* copyright notice(s) and this permission notice appear in all copies of
|
|
|
|
|
* the Software and that both the above copyright notice(s) and this
|
|
|
|
|
* permission notice appear in supporting documentation.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
|
|
|
|
|
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
|
|
|
|
|
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
|
|
|
|
|
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
|
|
|
|
|
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
|
|
|
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
|
|
|
* PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
|
*/
|