Files
itgmania212121/stepmania/src/ScreenAttract.cpp
T

168 lines
4.7 KiB
C++
Raw Normal View History

2003-02-16 04:01:45 +00:00
#include "global.h"
/*
-----------------------------------------------------------------------------
Class: ScreenAttract
Desc: See header.
Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved.
Chris Danford
-----------------------------------------------------------------------------
*/
#include "ScreenAttract.h"
#include "ScreenManager.h"
#include "GameConstantsAndTypes.h"
#include "RageUtil.h"
#include "StepMania.h"
#include "PrefsManager.h"
#include "RageLog.h"
#include "SongManager.h"
#include "AnnouncerManager.h"
#include "GameState.h"
#include "GameManager.h"
#include "InputMapper.h"
#include "ThemeManager.h"
2003-02-14 06:43:23 +00:00
#include "SDL_utils.h"
2003-07-26 22:53:22 +00:00
#include "RageSounds.h"
2003-04-12 06:16:12 +00:00
#define NEXT_SCREEN THEME->GetMetric(m_sName,"NextScreen")
2003-04-12 06:16:12 +00:00
ScreenAttract::ScreenAttract( CString sClassName ) : Screen( sClassName )
{
2003-03-09 00:55:49 +00:00
LOG->Trace( "ScreenAttract::ScreenAttract(%s)", sClassName.c_str() );
2003-01-19 04:44:22 +00:00
2003-01-20 04:33:45 +00:00
GAMESTATE->Reset();
2003-01-19 04:44:22 +00:00
// We have to do initialization in the first update because this->GetElementName() won't
// work until the object has been fully constructed.
m_Background.LoadFromAniDir( THEME->GetPathToB(m_sName+" background") );
2003-01-19 04:44:22 +00:00
this->AddChild( &m_Background );
m_In.Load( THEME->GetPathToB("ScreenAttract in") );
2003-03-09 00:55:49 +00:00
m_In.StartTransitioning();
this->AddChild( &m_In );
2003-01-19 04:44:22 +00:00
m_Out.Load( THEME->GetPathToB("ScreenAttract out") );
2003-03-09 00:55:49 +00:00
this->AddChild( &m_Out );
2003-01-19 04:44:22 +00:00
2003-07-26 22:53:22 +00:00
SOUND->PlayOnceFromDir( ANNOUNCER->GetPathTo(m_sName) );
2003-01-19 04:44:22 +00:00
m_soundStart.Load( THEME->GetPathToS("Common start") );
2003-03-09 00:55:49 +00:00
2003-10-12 19:45:28 +00:00
if( PREFSMAN->m_bAttractSound )
SOUND->PlayMusic( THEME->GetPathToS(m_sName + " music") );
2003-01-19 04:44:22 +00:00
GAMESTATE->m_bPlayersCanJoin = true;
2003-03-09 00:55:49 +00:00
float fTimeUntilBeginFadingOut = m_Background.GetLengthSeconds() - m_Out.GetLengthSeconds();
2003-10-10 03:47:45 +00:00
if( fTimeUntilBeginFadingOut < 0 )
{
LOG->Warn( "Screen '%s' Out BGAnimation (%f seconds) is longer than Background BGAnimation (%f seconds); background BGA will be truncated",
m_sName.c_str(), m_Out.GetLengthSeconds(), m_Background.GetLengthSeconds() );
fTimeUntilBeginFadingOut = 0;
}
2003-03-25 21:17:29 +00:00
this->PostScreenMessage( SM_BeginFadingOut, fTimeUntilBeginFadingOut );
}
ScreenAttract::~ScreenAttract()
{
LOG->Trace( "ScreenAttract::~ScreenAttract()" );
}
void ScreenAttract::Input( const DeviceInput& DeviceI, const InputEventType type, const GameInput &GameI, const MenuInput &MenuI, const StyleInput &StyleI )
{
2003-04-22 07:42:50 +00:00
// LOG->Trace( "ScreenAttract::Input()" );
2003-03-09 00:55:49 +00:00
AttractInput( DeviceI, type, GameI, MenuI, StyleI, m_In.IsTransitioning() || m_Out.IsTransitioning() );
}
2003-03-09 00:55:49 +00:00
void ScreenAttract::AttractInput( const DeviceInput& DeviceI, const InputEventType type, const GameInput &GameI, const MenuInput &MenuI, const StyleInput &StyleI, bool bTransitioning )
{
if(type != IET_FIRST_PRESS)
return; // don't care
ChangeCoinModeInput( DeviceI, type, GameI, MenuI, StyleI );
if( MenuI.IsValid() )
{
switch( MenuI.button )
{
2003-01-19 04:44:22 +00:00
case MENU_BUTTON_START:
case MENU_BUTTON_BACK:
2003-03-09 00:55:49 +00:00
case MENU_BUTTON_COIN:
switch( PREFSMAN->m_iCoinMode )
2003-01-19 04:44:22 +00:00
{
case COIN_PAY:
2003-01-19 04:44:22 +00:00
if( GAMESTATE->m_iCoins < PREFSMAN->m_iCoinsPerCredit )
break; // don't fall through
// fall through
case COIN_HOME:
case COIN_FREE:
2003-07-26 22:53:22 +00:00
SOUND->StopMusic();
2003-03-09 03:28:34 +00:00
/* We already played the it was a coin was inserted. Don't play it again. */
if( MenuI.button != MENU_BUTTON_COIN )
2003-07-26 22:53:22 +00:00
SOUND->PlayOnce( THEME->GetPathToS("Common coin") );
2003-02-14 06:43:23 +00:00
SDL_Delay( 800 ); // do a little pause, like the arcade does
2003-01-19 04:44:22 +00:00
SCREENMAN->SetNewScreen( "ScreenTitleMenu" );
break;
default:
ASSERT(0);
}
break;
}
}
2003-03-09 00:55:49 +00:00
if( bTransitioning )
return;
if( MenuI.IsValid() )
{
switch( MenuI.button )
{
case MENU_BUTTON_LEFT:
case MENU_BUTTON_RIGHT:
2003-03-25 21:17:29 +00:00
SCREENMAN->PostMessageToTopScreen( SM_BeginFadingOut, 0 );
2003-03-09 00:55:49 +00:00
break;
}
}
// Screen::Input( DeviceI, type, GameI, MenuI, StyleI );
}
void ScreenAttract::Update( float fDelta )
{
Screen::Update(fDelta);
}
void ScreenAttract::HandleScreenMessage( const ScreenMessage SM )
{
switch( SM )
{
case SM_BeginFadingOut:
2003-03-09 00:55:49 +00:00
if( !m_Out.IsTransitioning() )
m_Out.StartTransitioning( SM_GoToNextScreen );
break;
case SM_GoToNextScreen:
/* XXX: 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, it's cleaner to stop it before we fade out.) */
2003-02-18 09:36:59 +00:00
2003-01-26 20:49:05 +00:00
/* Don't stop the music, or else the music will start over from the
* beginning for consecutive screens with the same music. -Chris */
2003-02-18 09:36:59 +00:00
/* But if you don't stop it, for screens that have their own unique
* music, it will constantly loop even after the screen has gone on
* to the next attract screen. -- Miryokuteki */
2003-07-26 22:53:22 +00:00
SOUND->PlayMusic( "" );
SCREENMAN->SetNewScreen( NEXT_SCREEN );
break;
}
}