2004-03-14 06:39:39 +00:00
|
|
|
#include "global.h"
|
|
|
|
|
#include "ScreenSetTime.h"
|
|
|
|
|
#include "ScreenManager.h"
|
|
|
|
|
#include "RageLog.h"
|
|
|
|
|
#include "InputMapper.h"
|
|
|
|
|
#include "GameState.h"
|
2004-07-08 00:10:34 +00:00
|
|
|
#include "GameSoundManager.h"
|
2004-03-14 06:39:39 +00:00
|
|
|
#include "ThemeManager.h"
|
2004-09-28 05:51:10 +00:00
|
|
|
#include "DateTime.h"
|
2004-07-11 03:50:52 +00:00
|
|
|
#include "EnumHelper.h"
|
2004-03-14 06:39:39 +00:00
|
|
|
#include "arch/ArchHooks/ArchHooks.h"
|
|
|
|
|
|
2005-05-05 19:55:04 +00:00
|
|
|
static const CString SetTimeSelectionNames[] = {
|
2004-04-18 21:32:36 +00:00
|
|
|
"Year",
|
|
|
|
|
"Month",
|
|
|
|
|
"Day",
|
|
|
|
|
"Hour",
|
|
|
|
|
"Minute",
|
|
|
|
|
"Second",
|
|
|
|
|
};
|
2005-03-05 21:50:33 +00:00
|
|
|
XToString( SetTimeSelection, NUM_SET_TIME_SELECTIONS );
|
2004-04-18 21:32:36 +00:00
|
|
|
#define FOREACH_SetTimeSelection( s ) FOREACH_ENUM( SetTimeSelection, NUM_SET_TIME_SELECTIONS, s )
|
|
|
|
|
|
2004-04-18 22:07:26 +00:00
|
|
|
const float g_X[NUM_SET_TIME_SELECTIONS] =
|
2004-04-18 21:32:36 +00:00
|
|
|
{
|
|
|
|
|
320, 320, 320, 320, 320, 320
|
|
|
|
|
};
|
|
|
|
|
|
2004-04-18 22:07:26 +00:00
|
|
|
const float g_Y[NUM_SET_TIME_SELECTIONS] =
|
2004-04-18 21:32:36 +00:00
|
|
|
{
|
|
|
|
|
140, 180, 220, 260, 300, 340
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static float GetTitleX( SetTimeSelection s ) { return g_X[s] - 80; }
|
|
|
|
|
static float GetTitleY( SetTimeSelection s ) { return g_Y[s]; }
|
|
|
|
|
static float GetValueX( SetTimeSelection s ) { return g_X[s] + 80; }
|
|
|
|
|
static float GetValueY( SetTimeSelection s ) { return g_Y[s]; }
|
|
|
|
|
|
2004-11-26 17:28:47 +00:00
|
|
|
REGISTER_SCREEN_CLASS( ScreenSetTime );
|
2004-05-01 23:19:33 +00:00
|
|
|
ScreenSetTime::ScreenSetTime( CString sClassName ) : ScreenWithMenuElements( sClassName )
|
2004-03-14 06:39:39 +00:00
|
|
|
{
|
|
|
|
|
LOG->Trace( "ScreenSetTime::ScreenSetTime()" );
|
2005-02-23 06:29:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScreenSetTime::Init()
|
|
|
|
|
{
|
|
|
|
|
ScreenWithMenuElements::Init();
|
|
|
|
|
|
2004-03-14 06:39:39 +00:00
|
|
|
m_Selection = hour;
|
|
|
|
|
|
2004-05-27 00:48:34 +00:00
|
|
|
FOREACH_PlayerNumber( pn )
|
|
|
|
|
GAMESTATE->m_bSideIsJoined[pn] = true;
|
|
|
|
|
|
2004-04-18 21:32:36 +00:00
|
|
|
FOREACH_SetTimeSelection( s )
|
2004-03-14 06:39:39 +00:00
|
|
|
{
|
2004-04-18 21:32:36 +00:00
|
|
|
BitmapText &title = m_textTitle[s];
|
|
|
|
|
BitmapText &value = m_textValue[s];
|
|
|
|
|
|
2005-02-06 03:32:53 +00:00
|
|
|
title.LoadFromFont( THEME->GetPathF("Common","title") );
|
2004-04-18 21:32:36 +00:00
|
|
|
title.SetDiffuse( RageColor(1,1,1,1) );
|
|
|
|
|
title.SetText( SetTimeSelectionToString(s) );
|
|
|
|
|
title.SetXY( GetTitleX(s), GetTitleY(s) );
|
|
|
|
|
this->AddChild( &title );
|
|
|
|
|
|
2005-05-09 04:26:57 +00:00
|
|
|
title.SetDiffuse( RageColor(1,1,1,0) );
|
|
|
|
|
title.BeginTweening( 0.3f, TWEEN_LINEAR );
|
|
|
|
|
title.SetDiffuse( RageColor(1,1,1,1) );
|
|
|
|
|
|
2005-02-06 03:32:53 +00:00
|
|
|
value.LoadFromFont( THEME->GetPathF("Common","normal") );
|
2004-04-18 21:32:36 +00:00
|
|
|
value.SetDiffuse( RageColor(1,1,1,1) );
|
|
|
|
|
value.SetXY( GetValueX(s), GetValueY(s) );
|
|
|
|
|
this->AddChild( &value );
|
2005-05-09 04:26:57 +00:00
|
|
|
|
|
|
|
|
value.SetDiffuse( RageColor(1,1,1,0) );
|
|
|
|
|
value.BeginTweening( 0.3f, TWEEN_LINEAR );
|
|
|
|
|
value.SetDiffuse( RageColor(1,1,1,1) );
|
2004-03-14 06:39:39 +00:00
|
|
|
}
|
|
|
|
|
|
2004-05-27 01:05:14 +00:00
|
|
|
m_TimeOffset = 0;
|
2004-04-18 21:32:36 +00:00
|
|
|
m_Selection = (SetTimeSelection)0;
|
2004-03-14 06:39:39 +00:00
|
|
|
ChangeSelection( 0 );
|
|
|
|
|
|
|
|
|
|
SOUND->PlayMusic( THEME->GetPathS(m_sName,"music") );
|
2004-05-27 00:48:34 +00:00
|
|
|
|
|
|
|
|
this->SortByDrawOrder();
|
2004-03-14 06:39:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScreenSetTime::Update( float fDelta )
|
|
|
|
|
{
|
|
|
|
|
Screen::Update( fDelta );
|
|
|
|
|
|
2004-05-27 01:05:14 +00:00
|
|
|
time_t iNow = time(NULL);
|
|
|
|
|
iNow += m_TimeOffset;
|
|
|
|
|
|
|
|
|
|
tm now;
|
|
|
|
|
localtime_r( &iNow, &now );
|
|
|
|
|
|
2004-08-31 08:29:34 +00:00
|
|
|
int iPrettyHour = now.tm_hour%12;
|
|
|
|
|
if( iPrettyHour == 0 )
|
|
|
|
|
iPrettyHour = 12;
|
|
|
|
|
CString sPrettyHour = ssprintf( "%d %s", iPrettyHour, now.tm_hour>=12 ? "pm" : "am" );
|
|
|
|
|
|
|
|
|
|
m_textValue[hour].SetText( sPrettyHour );
|
2004-04-18 21:32:36 +00:00
|
|
|
m_textValue[minute].SetText( ssprintf("%02d",now.tm_min) );
|
|
|
|
|
m_textValue[second].SetText( ssprintf("%02d",now.tm_sec) );
|
|
|
|
|
m_textValue[year].SetText( ssprintf("%02d",now.tm_year+1900) );
|
2005-07-19 19:34:27 +00:00
|
|
|
m_textValue[month].SetText( MonthToString(now.tm_mon) );
|
2004-04-18 21:32:36 +00:00
|
|
|
m_textValue[day].SetText( ssprintf("%02d",now.tm_mday) );
|
2004-03-14 06:39:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScreenSetTime::Input( const DeviceInput& DeviceI, const InputEventType type, const GameInput &GameI, const MenuInput &MenuI, const StyleInput &StyleI )
|
|
|
|
|
{
|
|
|
|
|
if( type != IET_FIRST_PRESS && type != IET_SLOW_REPEAT )
|
|
|
|
|
return; // ignore
|
|
|
|
|
|
2004-05-01 23:19:33 +00:00
|
|
|
if( IsTransitioning() )
|
2004-03-14 06:39:39 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
Screen::Input( DeviceI, type, GameI, MenuI, StyleI ); // default handler
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScreenSetTime::ChangeValue( int iDirection )
|
|
|
|
|
{
|
2004-05-27 01:05:14 +00:00
|
|
|
time_t iNow = time(NULL);
|
|
|
|
|
time_t iAdjusted = iNow + m_TimeOffset;
|
|
|
|
|
|
|
|
|
|
tm adjusted;
|
|
|
|
|
localtime_r( &iAdjusted, &adjusted );
|
|
|
|
|
|
|
|
|
|
//tm now = GetLocalTime();
|
2004-03-14 06:39:39 +00:00
|
|
|
switch( m_Selection )
|
|
|
|
|
{
|
2004-05-27 01:05:14 +00:00
|
|
|
case hour: adjusted.tm_hour += iDirection; break;
|
|
|
|
|
case minute: adjusted.tm_min += iDirection; break;
|
|
|
|
|
case second: adjusted.tm_sec += iDirection; break;
|
|
|
|
|
case year: adjusted.tm_year += iDirection; break;
|
|
|
|
|
case month: adjusted.tm_mon += iDirection; break;
|
|
|
|
|
case day: adjusted.tm_mday += iDirection; break;
|
2004-03-14 06:39:39 +00:00
|
|
|
default: ASSERT(0);
|
|
|
|
|
}
|
|
|
|
|
|
2004-05-27 01:05:14 +00:00
|
|
|
/* Normalize: */
|
|
|
|
|
iAdjusted = mktime( &adjusted );
|
|
|
|
|
|
|
|
|
|
m_TimeOffset = iAdjusted - iNow;
|
2004-04-18 21:32:36 +00:00
|
|
|
|
|
|
|
|
SOUND->PlayOnce( THEME->GetPathS("ScreenSetTime","ChangeValue") );
|
2004-03-14 06:39:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScreenSetTime::ChangeSelection( int iDirection )
|
|
|
|
|
{
|
|
|
|
|
// set new value of m_Selection
|
2004-05-27 00:48:34 +00:00
|
|
|
SetTimeSelection OldSelection = m_Selection;
|
2004-05-27 05:35:10 +00:00
|
|
|
enum_add<SetTimeSelection>( m_Selection, iDirection );
|
2004-05-27 00:48:34 +00:00
|
|
|
|
2004-04-18 21:32:36 +00:00
|
|
|
CLAMP( (int&)m_Selection, 0, NUM_SET_TIME_SELECTIONS-1 );
|
2004-05-27 00:48:34 +00:00
|
|
|
if( iDirection != 0 && m_Selection == OldSelection )
|
|
|
|
|
return; // can't move any more
|
2004-04-18 21:32:36 +00:00
|
|
|
|
2004-05-27 00:48:34 +00:00
|
|
|
m_textValue[OldSelection].SetEffectNone();
|
2005-05-09 04:26:57 +00:00
|
|
|
m_textValue[m_Selection].SetEffectDiffuseShift( 1.f,
|
|
|
|
|
RageColor(0.3f,0.3f,0.3f,1),
|
|
|
|
|
RageColor(1,1,1,1) );
|
2004-03-14 06:39:39 +00:00
|
|
|
|
2005-05-09 04:21:25 +00:00
|
|
|
if( iDirection != 0 )
|
|
|
|
|
SOUND->PlayOnce( THEME->GetPathS("ScreenSetTime","ChangeSelection") );
|
2004-03-14 06:39:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScreenSetTime::MenuUp( PlayerNumber pn )
|
|
|
|
|
{
|
|
|
|
|
ChangeSelection( -1 );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScreenSetTime::MenuDown( PlayerNumber pn )
|
|
|
|
|
{
|
|
|
|
|
ChangeSelection( +1 );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScreenSetTime::MenuLeft( PlayerNumber pn )
|
|
|
|
|
{
|
|
|
|
|
ChangeValue( -1 );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScreenSetTime::MenuRight( PlayerNumber pn )
|
|
|
|
|
{
|
|
|
|
|
ChangeValue( +1 );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScreenSetTime::MenuStart( PlayerNumber pn )
|
|
|
|
|
{
|
2004-04-18 21:32:36 +00:00
|
|
|
bool bHoldingLeftAndRight =
|
|
|
|
|
INPUTMAPPER->IsButtonDown( MenuInput(pn, MENU_BUTTON_RIGHT) ) &&
|
|
|
|
|
INPUTMAPPER->IsButtonDown( MenuInput(pn, MENU_BUTTON_LEFT) );
|
|
|
|
|
|
|
|
|
|
if( bHoldingLeftAndRight )
|
|
|
|
|
ChangeSelection( -1 );
|
|
|
|
|
else if( m_Selection == NUM_SET_TIME_SELECTIONS -1 ) // last row
|
|
|
|
|
{
|
2004-05-27 01:05:14 +00:00
|
|
|
/* Save the new time. */
|
|
|
|
|
time_t iNow = time(NULL);
|
|
|
|
|
time_t iAdjusted = iNow + m_TimeOffset;
|
|
|
|
|
|
|
|
|
|
tm adjusted;
|
|
|
|
|
localtime_r( &iAdjusted, &adjusted );
|
|
|
|
|
|
|
|
|
|
HOOKS->SetTime( adjusted );
|
|
|
|
|
|
|
|
|
|
/* We're going to draw a little more while we transition out. We've already
|
|
|
|
|
* set the new time; don't over-adjust visually. */
|
|
|
|
|
m_TimeOffset = 0;
|
|
|
|
|
|
2005-05-09 04:26:57 +00:00
|
|
|
FOREACH_SetTimeSelection( s )
|
|
|
|
|
{
|
|
|
|
|
BitmapText &title = m_textTitle[s];
|
|
|
|
|
title.BeginTweening( 0.3f, TWEEN_LINEAR );
|
|
|
|
|
title.SetDiffuse( RageColor(1,1,1,0) );
|
|
|
|
|
|
|
|
|
|
BitmapText &value = m_textValue[s];
|
|
|
|
|
value.BeginTweening( 0.3f, TWEEN_LINEAR );
|
|
|
|
|
value.SetDiffuse( RageColor(1,1,1,0) );
|
|
|
|
|
}
|
|
|
|
|
|
2004-04-18 21:32:36 +00:00
|
|
|
SOUND->PlayOnce( THEME->GetPathS("Common","start") );
|
2004-05-01 23:19:33 +00:00
|
|
|
StartTransitioning( SM_GoToNextScreen );
|
2004-04-18 21:32:36 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
ChangeSelection( +1 );
|
2004-03-14 06:39:39 +00:00
|
|
|
}
|
|
|
|
|
|
2005-05-09 04:21:25 +00:00
|
|
|
void ScreenSetTime::MenuSelect( PlayerNumber pn )
|
|
|
|
|
{
|
|
|
|
|
ChangeSelection( -1 );
|
|
|
|
|
}
|
|
|
|
|
|
2004-03-14 06:39:39 +00:00
|
|
|
void ScreenSetTime::MenuBack( PlayerNumber pn )
|
|
|
|
|
{
|
2004-05-01 23:19:33 +00:00
|
|
|
StartTransitioning( SM_GoToPrevScreen );
|
2004-03-14 06:39:39 +00:00
|
|
|
}
|
2004-06-08 05:22:33 +00:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* (c) 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.
|
|
|
|
|
*/
|
|
|
|
|
|