2003-02-16 04:01:45 +00:00
#include "global.h"
2003-01-08 23:43:54 +00:00
#include "ScreenAttract.h"
#include "ScreenManager.h"
#include "RageUtil.h"
#include "StepMania.h"
#include "PrefsManager.h"
#include "RageLog.h"
#include "GameState.h"
#include "InputMapper.h"
#include "ThemeManager.h"
2004-07-08 00:10:34 +00:00
#include "GameSoundManager.h"
2005-09-05 02:26:50 +00:00
#include "InputEventPlus.h"
2005-10-04 06:51:06 +00:00
#include "RageSoundManager.h"
2003-01-08 23:43:54 +00:00
2005-03-17 07:23:59 +00:00
#define START_SCREEN(sScreenName) THEME->GetMetric (sScreenName,"StartScreen")
2003-01-08 23:43:54 +00:00
2005-04-05 03:27:42 +00:00
ThemeMetric < bool > BACK_GOES_TO_START_SCREEN ( "ScreenAttract" , "BackGoesToStartScreen" );
2006-01-15 20:46:15 +00:00
REGISTER_SCREEN_CLASS ( ScreenAttract );
2006-01-15 19:18:57 +00:00
ScreenAttract :: ScreenAttract ( bool bResetGameState )
2003-01-08 23:43:54 +00:00
{
2005-02-23 06:29:05 +00:00
if ( bResetGameState )
GAMESTATE -> Reset ();
}
2003-12-28 19:46:50 +00:00
2003-01-08 23:43:54 +00:00
2007-05-03 05:39:50 +00:00
void ScreenAttract :: BeginScreen ()
2006-01-15 19:18:57 +00:00
{
GAMESTATE -> VisitAttractScreen ( m_sName );
2007-05-03 05:48:01 +00:00
ScreenAttract :: SetAttractVolume ( ! GAMESTATE -> IsTimeToPlayAttractSounds () );
2006-01-15 19:18:57 +00:00
2007-05-03 05:39:50 +00:00
ScreenWithMenuElements :: BeginScreen ();
2006-01-15 19:18:57 +00:00
}
2005-09-05 02:26:50 +00:00
void ScreenAttract :: Input ( const InputEventPlus & input )
2003-01-08 23:43:54 +00:00
{
2003-04-22 07:42:50 +00:00
// LOG->Trace( "ScreenAttract::Input()" );
2003-01-08 23:43:54 +00:00
2005-09-05 02:26:50 +00:00
AttractInput ( input , this );
2003-03-09 00:55:49 +00:00
}
2003-01-10 02:22:07 +00:00
2007-05-03 05:28:46 +00:00
void ScreenAttract :: SetAttractVolume ( bool bInAttract )
{
if ( bInAttract )
SOUNDMAN -> SetVolumeOfNonCriticalSounds ( 0.0f ); // mute attract sounds
else
SOUNDMAN -> SetVolumeOfNonCriticalSounds ( 1.0f ); // unmute attract sounds
}
2005-09-05 02:26:50 +00:00
void ScreenAttract :: AttractInput ( const InputEventPlus & input , ScreenWithMenuElements * pScreen )
2003-03-09 00:55:49 +00:00
{
2005-09-05 02:26:50 +00:00
if ( input . type != IET_FIRST_PRESS )
2003-03-09 00:55:49 +00:00
return ; // don't care
2006-09-14 20:52:34 +00:00
switch ( input . MenuI )
2003-01-10 02:22:07 +00:00
{
2006-09-14 20:31:46 +00:00
case MENU_BUTTON_BACK :
if ( ! ( bool ) BACK_GOES_TO_START_SCREEN )
2003-01-10 02:22:07 +00:00
break ;
2006-09-14 20:31:46 +00:00
// fall through
case MENU_BUTTON_START :
case MENU_BUTTON_COIN :
switch ( GAMESTATE -> GetCoinMode () )
{
2007-02-26 09:40:14 +00:00
case CoinMode_Pay :
2006-09-14 20:31:46 +00:00
LOG -> Trace ( "ScreenAttract::AttractInput: COIN_PAY (%i/%i)" , GAMESTATE -> m_iCoins , PREFSMAN -> m_iCoinsPerCredit . Get () );
if ( GAMESTATE -> m_iCoins < PREFSMAN -> m_iCoinsPerCredit )
break ; // don't fall through
// fall through
2007-02-26 09:40:14 +00:00
case CoinMode_Home :
case CoinMode_Free :
2006-09-14 20:31:46 +00:00
if ( pScreen -> IsTransitioning () )
return ;
LOG -> Trace ( "ScreenAttract::AttractInput: begin fading to START_SCREEN" );
/* HandleGlobalInputs() already played the coin sound. Don't play it again. */
if ( input . MenuI != MENU_BUTTON_COIN )
SCREENMAN -> PlayCoinSound ();
2007-05-03 05:28:46 +00:00
SetAttractVolume ( false ); // unmute attract sounds
2006-09-14 20:31:46 +00:00
pScreen -> Cancel ( SM_GoToStartScreen );
break ;
default :
ASSERT ( 0 );
2003-01-10 02:22:07 +00:00
}
2006-09-14 20:31:46 +00:00
break ;
2003-01-10 02:22:07 +00:00
}
2005-04-01 12:35:49 +00:00
if ( pScreen -> IsTransitioning () )
2003-03-09 00:55:49 +00:00
return ;
2006-09-14 20:52:34 +00:00
switch ( input . MenuI )
2003-03-09 00:55:49 +00:00
{
2006-09-14 20:31:46 +00:00
case MENU_BUTTON_LEFT :
case MENU_BUTTON_RIGHT :
SCREENMAN -> PostMessageToTopScreen ( SM_BeginFadingOut , 0 );
break ;
}
2003-03-09 00:55:49 +00:00
2005-09-05 02:26:50 +00:00
// Screen::Input( input );
2003-01-10 02:22:07 +00:00
}
2005-03-22 22:53:39 +00:00
void ScreenAttract :: StartPlayingMusic ()
{
ScreenWithMenuElements :: StartPlayingMusic ();
}
2003-01-08 23:43:54 +00:00
void ScreenAttract :: HandleScreenMessage ( const ScreenMessage SM )
{
2005-04-01 12:35:49 +00:00
if ( SM == SM_MenuTimer ||
SM == SM_BeginFadingOut )
2003-01-08 23:43:54 +00:00
{
2005-02-28 06:08:55 +00:00
if ( ! IsTransitioning () )
2005-10-13 22:17:13 +00:00
StartTransitioningScreen ( SM_GoToNextScreen );
2005-04-01 12:35:49 +00:00
}
else if ( SM == SM_GoToStartScreen )
{
GoToStartScreen ( m_sName );
}
else if ( SM == SM_GoToNextScreen )
{
2004-02-14 01:29:09 +00:00
/* Look at the def of the screen we're going to; if it has a music theme element
* and it's the same as the one we're playing now, don't stop. However, if we're
* going to interrupt it when we fade in, stop the old music before we fade out. */
2005-03-21 01:14:30 +00:00
bool bMusicChanging = false ;
if ( PLAY_MUSIC )
2005-07-22 09:12:16 +00:00
bMusicChanging = THEME -> GetPathS ( m_sName , "music" ) != THEME -> GetPathS ( GetNextScreen (), "music" , true ); // GetPath optional on the next screen because it may not have music.
2005-03-21 01:14:30 +00:00
if ( bMusicChanging )
2005-07-22 23:07:49 +00:00
SOUND -> StopMusic ();
2003-01-08 23:43:54 +00:00
}
2007-05-03 05:42:36 +00:00
else if ( SM == SM_LoseFocus )
{
ScreenAttract :: SetAttractVolume ( false );
}
2005-07-22 09:12:16 +00:00
ScreenWithMenuElements :: HandleScreenMessage ( SM );
2003-01-08 23:43:54 +00:00
}
2004-06-09 04:28:27 +00:00
2006-01-22 01:00:06 +00:00
void ScreenAttract :: GoToStartScreen ( RString sScreenName )
2005-04-01 12:35:49 +00:00
{
SCREENMAN -> SetNewScreen ( START_SCREEN ( sScreenName ) );
}
2004-06-09 04:28:27 +00:00
/*
* (c) 2003-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.
*/