2003-02-16 04:01:45 +00:00
#include "global.h"
2003-01-08 23:43:54 +00:00
/*
-----------------------------------------------------------------------------
Class: ScreenDemonstration
Desc: See header.
Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved.
Chris Danford
-----------------------------------------------------------------------------
*/
2003-01-10 02:22:07 +00:00
#include "ScreenDemonstration.h"
#include "RageLog.h"
#include "ThemeManager.h"
#include "GameState.h"
#include "SongManager.h"
#include "StepMania.h"
2003-02-14 06:31:09 +00:00
#include "SDL_utils.h"
2003-01-10 02:22:07 +00:00
#define SECONDS_TO_SHOW THEME->GetMetricF("ScreenDemonstration","SecondsToShow")
#define NEXT_SCREEN THEME->GetMetric("ScreenDemonstration","NextScreen")
const ScreenMessage SM_NotesEnded = ScreenMessage ( SM_User + 101 ); // MUST be same as in ScreenGameplay
const ScreenMessage SM_BeginFadingToNextScreen = ScreenMessage ( SM_User + 1000 );
2003-01-19 04:44:22 +00:00
bool SetUpSongOptions () // always return true.
2003-01-10 02:22:07 +00:00
{
//
// Set the current song to prepare for a demonstration
//
switch ( GAMESTATE -> m_CurGame )
{
case GAME_DANCE : GAMESTATE -> m_CurStyle = STYLE_DANCE_VERSUS ; break ;
case GAME_PUMP : GAMESTATE -> m_CurStyle = STYLE_PUMP_VERSUS ; break ;
case GAME_EZ2 : GAMESTATE -> m_CurStyle = STYLE_EZ2_SINGLE_VERSUS ; break ;
case GAME_PARA : GAMESTATE -> m_CurStyle = STYLE_PARA_SINGLE ; break ;
case GAME_DS3DDX : GAMESTATE -> m_CurStyle = STYLE_DS3DDX_SINGLE ; break ;
case GAME_BM : GAMESTATE -> m_CurStyle = STYLE_BM_SINGLE ; break ;
default : ASSERT ( 0 );
}
GAMESTATE -> m_PlayMode = PLAY_MODE_ARCADE ;
//
// Search for a Song and Steps to play during the demo
//
for ( int i = 0 ; i < 600 ; i ++ ) // try 600 times
{
Song * pSong = SONGMAN -> GetRandomSong ();
if ( pSong == NULL ) // returns NULL there are no songs
2003-01-19 21:05:03 +00:00
return true ; // we need to detect this and abort demonstration later
2003-01-10 02:22:07 +00:00
if ( pSong -> m_apNotes . empty () )
continue ; // skip
if ( ! pSong -> HasMusic () )
continue ; // skip
vector < Notes *> apNotes ;
2003-02-10 05:30:12 +00:00
pSong -> GetNotes ( apNotes , GAMESTATE -> GetCurrentStyleDef () -> m_NotesType );
2003-01-10 02:22:07 +00:00
if ( apNotes . empty () )
continue ; // skip
// Found something we can use!
Notes * pNotes = apNotes [ rand () % apNotes . size () ];
GAMESTATE -> m_pCurSong = pSong ;
for ( int p = 0 ; p < NUM_PLAYERS ; p ++ )
GAMESTATE -> m_pCurNotes [ p ] = pNotes ;
break ; // done looking
}
ASSERT ( GAMESTATE -> m_pCurSong );
GAMESTATE -> m_MasterPlayerNumber = PLAYER_1 ;
// choose some cool options
2003-01-18 20:44:25 +00:00
int Benchmark = 0 ;
if ( Benchmark )
{
/* Note that you also need to make sure you benchmark with the
* same notes. I use a copy of MaxU with only heavy notes included. */
for ( int p = 0 ; p < NUM_PLAYERS ; p ++ )
{
if ( ! GAMESTATE -> IsPlayerEnabled ( p ) )
continue ;
/* Lots and lots of arrows. This might even bias to arrows a little
* too much. */
2003-02-26 23:26:57 +00:00
GAMESTATE -> m_PlayerOptions [ p ]. Init ();
2003-01-25 11:05:12 +00:00
GAMESTATE -> m_PlayerOptions [ p ]. m_fScrollSpeed = .25f ;
2003-02-26 23:26:57 +00:00
GAMESTATE -> m_PlayerOptions [ p ]. m_fEffects [ PlayerOptions :: EFFECT_SPACE ] = 1 ;
GAMESTATE -> m_PlayerOptions [ p ]. m_fEffects [ PlayerOptions :: EFFECT_MINI ] = 1 ;
2003-01-18 20:44:25 +00:00
}
GAMESTATE -> m_SongOptions . m_LifeType = SongOptions :: LIFE_BATTERY ;
2003-02-12 23:11:37 +00:00
GAMESTATE -> m_SongOptions . m_FailType = SongOptions :: FAIL_OFF ;
2003-01-18 20:44:25 +00:00
}
2003-01-10 02:22:07 +00:00
for ( int p = 0 ; p < NUM_PLAYERS ; p ++ )
{
if ( ! GAMESTATE -> IsPlayerEnabled ( p ) )
continue ;
2003-02-26 23:26:57 +00:00
GAMESTATE -> m_PlayerOptions [ p ]. Init ();
2003-02-11 02:20:38 +00:00
GAMESTATE -> m_PlayerOptions [ p ]. ChooseRandomMofifiers ();
2003-01-10 02:22:07 +00:00
}
GAMESTATE -> m_SongOptions = SongOptions ();
GAMESTATE -> m_SongOptions . m_LifeType = ( randomf ( 0 , 1 ) > 0.8f ) ? SongOptions :: LIFE_BATTERY : SongOptions :: LIFE_BAR ;
2003-02-12 23:11:37 +00:00
GAMESTATE -> m_SongOptions . m_FailType = SongOptions :: FAIL_OFF ;
2003-01-19 04:44:22 +00:00
2003-01-25 07:37:55 +00:00
GAMESTATE -> m_bDemonstration = true ;
2003-01-19 04:44:22 +00:00
return true ;
2003-01-10 02:22:07 +00:00
}
2003-01-19 04:44:22 +00:00
ScreenDemonstration :: ScreenDemonstration () : ScreenGameplay ( SetUpSongOptions ()) // this is a hack to get some code to execute before the ScreenGameplay constructor
2003-01-10 02:22:07 +00:00
{
2003-01-19 04:44:22 +00:00
LOG -> Trace ( "ScreenDemonstration::ScreenDemonstration()" );
2003-01-10 02:22:07 +00:00
2003-01-19 21:05:03 +00:00
if ( GAMESTATE -> m_pCurSong == NULL ) // we didn't find a song.
{
this -> SendScreenMessage ( SM_GoToNextScreen , 0 ); // Abort demonstration.
return ;
}
2003-01-10 02:22:07 +00:00
m_sprDemonstrationOverlay . Load ( THEME -> GetPathTo ( "Graphics" , "demonstration overlay" ) );
m_sprDemonstrationOverlay . SetXY ( CENTER_X , CENTER_Y );
this -> AddChild ( & m_sprDemonstrationOverlay );
m_sprDemonstrationBlink . Load ( THEME -> GetPathTo ( "Graphics" , "demonstration blink" ) );
m_sprDemonstrationBlink . SetXY ( CENTER_X , CENTER_Y );
2003-03-02 01:43:33 +00:00
m_sprDemonstrationBlink . SetEffectDiffuseBlink ();
2003-01-10 02:22:07 +00:00
this -> AddChild ( & m_sprDemonstrationBlink );
2003-02-02 09:09:29 +00:00
this -> MoveToTail ( & m_Fade );
2003-01-10 02:22:07 +00:00
m_Fade . OpenWipingRight ();
2003-01-19 04:44:22 +00:00
ClearMessageQueue (); // remove all of the messages set in ScreenGameplay that animate "ready", "here we go", etc.
2003-01-10 02:22:07 +00:00
2003-01-25 11:05:12 +00:00
GAMESTATE -> m_bPastHereWeGo = true ;
2003-01-10 02:22:07 +00:00
m_StarWipe . SetOpened ();
m_DancingState = STATE_DANCING ;
this -> SendScreenMessage ( SM_BeginFadingToNextScreen , SECONDS_TO_SHOW );
}
2003-01-19 04:44:22 +00:00
ScreenDemonstration ::~ ScreenDemonstration ()
{
GAMESTATE -> m_bDemonstration = false ;
GAMESTATE -> Reset ();
}
2003-01-10 02:22:07 +00:00
void ScreenDemonstration :: Update ( float fDeltaTime )
{
ScreenGameplay :: Update ( fDeltaTime );
2003-01-11 08:55:21 +00:00
// hide status icons
for ( int i = 0 ; i < NUM_STATUS_ICONS ; i ++ )
m_sprStatusIcons [ i ]. SetDiffuse ( RageColor ( 1 , 1 , 1 , 0 ) );
2003-01-10 02:22:07 +00:00
}
void ScreenDemonstration :: Input ( const DeviceInput & DeviceI , const InputEventType type , const GameInput & GameI , const MenuInput & MenuI , const StyleInput & StyleI )
{
//LOG->Trace( "ScreenDemonstration::Input()" );
2003-01-19 04:44:22 +00:00
//
// This should be the same as ScreenAttract::Input()
//
2003-01-10 02:22:07 +00:00
if ( type != IET_FIRST_PRESS ) return ; // don't care
2003-01-19 04:44:22 +00:00
if ( DeviceI . device == DEVICE_KEYBOARD && DeviceI . button == SDLK_F3 )
{
( int & ) PREFSMAN -> m_CoinMode = ( PREFSMAN -> m_CoinMode + 1 ) % PrefsManager :: NUM_COIN_MODES ;
2003-02-12 11:43:08 +00:00
/*ResetGame();
This causes problems on ScreenIntroMovie, which results in the
movie being restarted and/or becoming out-of-synch -- Miryokuteki */
2003-01-19 04:44:22 +00:00
CString sMessage = "Coin Mode: " ;
switch ( PREFSMAN -> m_CoinMode )
{
case PrefsManager :: COIN_HOME : sMessage += "HOME" ; break ;
case PrefsManager :: COIN_PAY : sMessage += "PAY" ; break ;
case PrefsManager :: COIN_FREE : sMessage += "FREE" ; break ;
}
2003-02-12 11:43:08 +00:00
SCREENMAN -> RefreshCreditsMessages ();
2003-01-19 04:44:22 +00:00
SCREENMAN -> SystemMessage ( sMessage );
2003-01-10 02:22:07 +00:00
return ;
2003-01-19 04:44:22 +00:00
}
2003-01-10 02:22:07 +00:00
if ( MenuI . IsValid () )
{
switch ( MenuI . button )
{
case MENU_BUTTON_LEFT :
case MENU_BUTTON_RIGHT :
2003-01-19 04:44:22 +00:00
if ( ! m_Fade . IsOpening () && ! m_Fade . IsClosing () )
m_Fade . CloseWipingRight ( SM_GoToNextScreen );
2003-01-10 02:22:07 +00:00
break ;
2003-01-19 04:44:22 +00:00
case MENU_BUTTON_COIN :
Screen :: MenuCoin ( MenuI . player ); // increment coins, play sound
2003-01-10 02:22:07 +00:00
m_soundMusic . Stop ();
2003-02-14 06:31:09 +00:00
SDL_Delay ( 800 ); // do a little pause, like the arcade does
2003-01-10 02:22:07 +00:00
SCREENMAN -> SetNewScreen ( "ScreenTitleMenu" );
break ;
2003-01-19 04:44:22 +00:00
case MENU_BUTTON_START :
2003-01-10 02:22:07 +00:00
case MENU_BUTTON_BACK :
2003-01-19 04:44:22 +00:00
switch ( PREFSMAN -> m_CoinMode )
{
case PrefsManager :: COIN_PAY :
if ( GAMESTATE -> m_iCoins < PREFSMAN -> m_iCoinsPerCredit )
break ; // don't fall through
// fall through
case PrefsManager :: COIN_FREE :
case PrefsManager :: COIN_HOME :
m_soundMusic . Stop ();
SOUNDMAN -> PlayOnce ( THEME -> GetPathTo ( "Sounds" , "insert coin" ) );
2003-02-14 06:31:09 +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 );
}
2003-01-10 02:22:07 +00:00
break ;
}
}
}
void ScreenDemonstration :: HandleScreenMessage ( const ScreenMessage SM )
{
switch ( SM )
{
case SM_NotesEnded :
this -> SendScreenMessage ( SM_BeginFadingToNextScreen , 0 );
return ;
case SM_BeginFadingToNextScreen :
m_Fade . CloseWipingRight ( SM_GoToNextScreen );
return ;
case SM_GoToNextScreen :
2003-02-03 05:53:59 +00:00
m_soundMusic . Stop ();
2003-01-10 02:22:07 +00:00
SCREENMAN -> SetNewScreen ( NEXT_SCREEN );
return ;
}
ScreenGameplay :: HandleScreenMessage ( SM );
2003-02-15 00:05:48 +00:00
}