2003-02-16 04:01:45 +00:00
# include "global.h"
2004-06-09 02:48:38 +00:00
2003-01-31 21:34:34 +00:00
# include "ScreenJukebox.h"
# include "RageLog.h"
# include "ThemeManager.h"
# include "GameState.h"
# include "SongManager.h"
# include "StepMania.h"
2003-04-13 00:44:50 +00:00
# include "ScreenManager.h"
2004-07-08 00:10:34 +00:00
# include "GameSoundManager.h"
2003-08-25 15:08:03 +00:00
# include "Steps.h"
2004-03-23 21:02:58 +00:00
# include "ScreenAttract.h"
2004-04-07 23:55:44 +00:00
# include "RageUtil.h"
2003-01-31 21:34:34 +00:00
2004-04-07 23:55:44 +00:00
// HACK: This belongs in ScreenDemonstration
# define DIFFICULTIES_TO_SHOW THEME->GetMetric ("ScreenDemonstration","DifficultiesToShow")
2003-01-31 21:34:34 +00:00
2003-03-17 04:56:47 +00:00
const ScreenMessage SM_NotesEnded = ScreenMessage ( SM_User + 10 ) ; // MUST be same as in ScreenGameplay
2003-01-31 21:34:34 +00:00
2004-04-07 23:55:44 +00:00
bool ScreenJukebox : : SetSong ( bool bDemonstration )
2003-01-31 21:34:34 +00:00
{
2003-02-11 02:20:38 +00:00
vector < Song * > vSongs ;
2003-02-25 00:33:42 +00:00
if ( GAMESTATE - > m_sPreferredGroup = = GROUP_ALL_MUSIC )
2003-02-11 02:20:38 +00:00
SONGMAN - > GetSongs ( vSongs ) ;
else
SONGMAN - > GetSongs ( vSongs , GAMESTATE - > m_sPreferredGroup ) ;
2003-01-31 21:34:34 +00:00
2004-04-07 23:55:44 +00:00
//
// Calculate what difficulties to show
//
CStringArray asBits ;
vector < Difficulty > vDifficultiesToShow ;
if ( bDemonstration )
{
split ( DIFFICULTIES_TO_SHOW , " , " , asBits ) ;
2004-04-08 00:13:29 +00:00
for ( unsigned i = 0 ; i < asBits . size ( ) ; i + + )
2004-04-07 23:55:44 +00:00
{
Difficulty dc = StringToDifficulty ( asBits [ i ] ) ;
if ( dc ! = DIFFICULTY_INVALID )
vDifficultiesToShow . push_back ( dc ) ;
}
}
else
{
if ( GAMESTATE - > m_PreferredDifficulty [ PLAYER_1 ] ! = DIFFICULTY_INVALID )
{
vDifficultiesToShow . push_back ( GAMESTATE - > m_PreferredDifficulty [ PLAYER_1 ] ) ;
}
else
{
FOREACH_Difficulty ( dc )
vDifficultiesToShow . push_back ( dc ) ;
}
}
2004-04-14 06:00:32 +00:00
if ( vDifficultiesToShow . empty ( ) )
vDifficultiesToShow . push_back ( DIFFICULTY_EASY ) ;
2003-01-31 21:34:34 +00:00
//
2003-08-03 00:13:55 +00:00
// Search for a Song and Steps to play during the demo
2003-01-31 21:34:34 +00:00
//
2004-04-07 23:55:44 +00:00
for ( int i = 0 ; i < 1000 ; i + + )
2003-01-31 21:34:34 +00:00
{
2003-02-11 02:20:38 +00:00
if ( vSongs . size ( ) = = 0 )
return true ;
Song * pSong = vSongs [ rand ( ) % vSongs . size ( ) ] ;
2003-01-31 21:34:34 +00:00
if ( ! pSong - > HasMusic ( ) )
continue ; // skip
2004-02-26 20:29:37 +00:00
if ( pSong - > NeverDisplayed ( ) )
2004-02-21 01:11:41 +00:00
continue ; // skip
2004-04-07 23:55:44 +00:00
Difficulty dc = vDifficultiesToShow [ rand ( ) % vDifficultiesToShow . size ( ) ] ;
2004-06-28 07:26:00 +00:00
Steps * pSteps = pSong - > GetStepsByDifficulty ( GAMESTATE - > GetCurrentStyle ( ) - > m_StepsType , dc ) ;
2003-01-31 21:34:34 +00:00
2004-05-24 03:41:39 +00:00
if ( pSteps = = NULL )
2003-01-31 21:34:34 +00:00
continue ; // skip
2004-05-24 03:41:39 +00:00
if ( ! PREFSMAN - > m_bAutogenSteps & & pSteps - > IsAutogen ( ) )
2003-08-25 15:08:03 +00:00
continue ; // skip
2003-01-31 21:34:34 +00:00
// Found something we can use!
GAMESTATE - > m_pCurSong = pSong ;
2004-05-24 06:10:11 +00:00
FOREACH_PlayerNumber ( p )
2004-05-24 06:12:17 +00:00
GAMESTATE - > m_pCurSteps [ p ] = pSteps ;
2003-01-31 21:34:34 +00:00
2003-03-23 18:47:13 +00:00
return true ; // done looking
2003-01-31 21:34:34 +00:00
}
2003-03-23 18:47:13 +00:00
return false ;
}
2004-04-07 23:55:44 +00:00
bool ScreenJukebox : : PrepareForJukebox ( bool bDemonstration ) // always return true.
2003-03-23 18:47:13 +00:00
{
// ScreeJukeboxMenu must set this
2004-06-28 07:26:00 +00:00
ASSERT ( GAMESTATE - > m_pCurStyle ) ;
2004-06-11 06:05:35 +00:00
GAMESTATE - > m_PlayMode = PLAY_MODE_REGULAR ;
2003-03-23 18:47:13 +00:00
2004-04-07 23:55:44 +00:00
SetSong ( bDemonstration ) ;
2003-03-23 18:47:13 +00:00
2003-03-24 21:26:12 +00:00
// ASSERT( GAMESTATE->m_pCurSong );
2003-01-31 21:34:34 +00:00
GAMESTATE - > m_MasterPlayerNumber = PLAYER_1 ;
// choose some cool options
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. */
2004-05-24 06:10:11 +00:00
FOREACH_PlayerNumber ( p )
2003-01-31 21:34:34 +00:00
{
if ( ! GAMESTATE - > IsPlayerEnabled ( p ) )
continue ;
/* Lots and lots of arrows. This might even bias to arrows a little
* too much. */
GAMESTATE - > m_PlayerOptions [ p ] = PlayerOptions ( ) ;
GAMESTATE - > m_PlayerOptions [ p ] . m_fScrollSpeed = .25f ;
2003-04-01 19:31:27 +00:00
GAMESTATE - > m_PlayerOptions [ p ] . m_fPerspectiveTilt = - 1 ;
2003-02-26 23:26:57 +00:00
GAMESTATE - > m_PlayerOptions [ p ] . m_fEffects [ PlayerOptions : : EFFECT_MINI ] = 1 ;
2003-01-31 21:34:34 +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-31 21:34:34 +00:00
}
2004-05-24 06:10:11 +00:00
FOREACH_PlayerNumber ( p )
2003-01-31 21:34:34 +00:00
{
if ( ! GAMESTATE - > IsPlayerEnabled ( p ) )
continue ;
2003-02-11 02:20:38 +00:00
if ( GAMESTATE - > m_bJukeboxUsesModifiers )
2003-04-21 04:10:52 +00:00
{
GAMESTATE - > m_PlayerOptions [ p ] . Init ( ) ;
GAMESTATE - > m_PlayerOptions [ p ] . FromString ( PREFSMAN - > m_sDefaultModifiers ) ;
2003-02-11 02:20:38 +00:00
GAMESTATE - > m_PlayerOptions [ p ] . ChooseRandomMofifiers ( ) ;
2003-04-21 04:10:52 +00:00
}
2003-01-31 21:34:34 +00:00
}
2003-04-21 04:10:52 +00:00
GAMESTATE - > m_SongOptions . Init ( ) ;
GAMESTATE - > m_SongOptions . FromString ( PREFSMAN - > m_sDefaultModifiers ) ;
2003-01-31 21:34:34 +00:00
2003-02-12 23:11:37 +00:00
GAMESTATE - > m_SongOptions . m_FailType = SongOptions : : FAIL_OFF ;
2003-01-31 21:34:34 +00:00
2003-03-09 00:55:49 +00:00
GAMESTATE - > m_bDemonstrationOrJukebox = true ;
2003-01-31 21:34:34 +00:00
return true ;
}
2004-04-07 23:55:44 +00:00
ScreenJukebox : : ScreenJukebox ( CString sName , bool bDemonstration ) : ScreenGameplay ( " ScreenGameplay " , PrepareForJukebox ( bDemonstration ) ) // this is a hack to get some code to execute before the ScreenGameplay constructor
2003-01-31 21:34:34 +00:00
{
LOG - > Trace ( " ScreenJukebox::ScreenJukebox() " ) ;
if ( GAMESTATE - > m_pCurSong = = NULL ) // we didn't find a song.
{
2003-03-25 21:17:29 +00:00
this - > PostScreenMessage ( SM_GoToNextScreen , 0 ) ; // Abort demonstration.
2003-01-31 21:34:34 +00:00
return ;
}
2003-04-12 17:39:27 +00:00
m_In . Load ( THEME - > GetPathToB ( " ScreenDemonstration in " ) ) ;
2003-03-09 00:55:49 +00:00
this - > AddChild ( & m_In ) ;
m_In . StartTransitioning ( ) ;
2003-04-12 17:39:27 +00:00
m_Out . Load ( THEME - > GetPathToB ( " ScreenDemonstration out " ) ) ;
2003-03-09 00:55:49 +00:00
this - > AddChild ( & m_Out ) ;
2003-01-31 21:34:34 +00:00
ClearMessageQueue ( ) ; // remove all of the messages set in ScreenGameplay that animate "ready", "here we go", etc.
GAMESTATE - > m_bPastHereWeGo = true ;
m_DancingState = STATE_DANCING ;
}
void ScreenJukebox : : Input ( const DeviceInput & DeviceI , const InputEventType type , const GameInput & GameI , const MenuInput & MenuI , const StyleInput & StyleI )
{
//LOG->Trace( "ScreenJukebox::Input()" );
2003-03-17 04:56:47 +00:00
if ( type ! = IET_FIRST_PRESS )
return ; /* ignore */
2003-01-31 21:34:34 +00:00
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_NotesEnded , 0 ) ;
2004-03-23 21:02:58 +00:00
return ;
2003-01-31 21:34:34 +00:00
}
}
2004-03-23 21:02:58 +00:00
ScreenAttract : : AttractInput ( DeviceI , type , GameI , MenuI , StyleI , m_Out . IsTransitioning ( ) ) ;
2003-01-31 21:34:34 +00:00
}
void ScreenJukebox : : HandleScreenMessage ( const ScreenMessage SM )
{
switch ( SM )
{
case SM_NotesEnded :
2003-03-17 04:56:47 +00:00
if ( m_Out . IsTransitioning ( ) | | m_Out . IsFinished ( ) )
return ; // ignore - we're already fading or faded
2003-03-09 00:55:49 +00:00
m_Out . StartTransitioning ( SM_GoToNextScreen ) ;
2003-01-31 21:34:34 +00:00
return ;
case SM_GoToNextScreen :
2004-05-21 00:58:48 +00:00
m_soundMusic . Stop ( ) ;
2003-01-31 21:34:34 +00:00
SCREENMAN - > SetNewScreen ( " ScreenJukebox " ) ;
return ;
}
ScreenGameplay : : HandleScreenMessage ( SM ) ;
2003-02-16 04:56:36 +00:00
}
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.
*/