2003-03-03 10:03:02 +00:00
# include "global.h"
/*
-----------------------------------------------------------------------------
Class: ScreenSelect
Desc: See Header.
Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved.
Chris Danford
-----------------------------------------------------------------------------
*/
# include "ScreenSelect.h"
# include "ScreenManager.h"
# include "PrefsManager.h"
# include "RageSoundManager.h"
# include "GameConstantsAndTypes.h"
# include "PrefsManager.h"
# include "GameManager.h"
# include "RageLog.h"
# include "AnnouncerManager.h"
# include "GameState.h"
# include "GameConstantsAndTypes.h"
# include "ThemeManager.h"
# include "ModeChoice.h"
# define CHOICES THEME->GetMetric (m_sClassName,"Choices")
# define HELP_TEXT THEME->GetMetric (m_sClassName,"HelpText")
# define TIMER_SECONDS THEME->GetMetricI(m_sClassName,"TimerSeconds")
2003-03-09 00:55:49 +00:00
# define NEXT_SCREEN( choice ) THEME->GetMetric (m_sClassName,ssprintf("NextScreen%d",choice+1))
2003-03-03 10:03:02 +00:00
ScreenSelect : : ScreenSelect ( CString sClassName )
{
LOG - > Trace ( " ScreenSelect::ScreenSelect() " ) ;
m_sClassName = sClassName ;
2003-03-09 00:55:49 +00:00
GAMESTATE - > m_bPlayersCanJoin = false ;
// Set this true later if we discover a choice that chooses the Style
2003-03-03 10:03:02 +00:00
2003-03-09 00:55:49 +00:00
CStringArray asChoices ;
split ( CHOICES , " , " , asChoices ) ;
2003-03-03 10:03:02 +00:00
2003-03-09 00:55:49 +00:00
for ( unsigned c = 0 ; c < asChoices . size ( ) ; c + + )
{
CString sChoice = asChoices [ c ] ;
2003-03-03 10:03:02 +00:00
2003-03-09 00:55:49 +00:00
ModeChoice mc = { // fill this in below
GAME_INVALID ,
STYLE_INVALID ,
PLAY_MODE_INVALID ,
DIFFICULTY_INVALID ,
" " ,
1 } ;
2003-03-03 10:03:02 +00:00
2003-03-09 00:55:49 +00:00
strncpy ( mc . name , sChoice , sizeof ( mc . name ) ) ;
2003-03-03 10:03:02 +00:00
2003-03-09 00:55:49 +00:00
bool bChoiceIsInvalid = false ;
2003-03-03 10:03:02 +00:00
2003-03-09 00:55:49 +00:00
CStringArray asBits ;
split ( sChoice , " - " , asBits ) ;
for ( unsigned b = 0 ; b < asBits . size ( ) ; b + + )
2003-03-03 10:03:02 +00:00
{
2003-03-09 00:55:49 +00:00
CString sBit = asBits [ b ] ;
2003-03-03 10:03:02 +00:00
2003-03-09 00:55:49 +00:00
Game game = GAMEMAN - > StringToGameType ( sBit ) ;
if ( game ! = GAME_INVALID )
2003-03-03 10:03:02 +00:00
{
2003-03-09 00:55:49 +00:00
mc . game = game ;
continue ;
}
2003-03-03 10:03:02 +00:00
2003-03-09 00:55:49 +00:00
Style style = GAMEMAN - > GameAndStringToStyle ( GAMESTATE - > m_CurGame , sBit ) ;
if ( style ! = STYLE_INVALID )
{
mc . style = style ;
// There is a choices that allows players to choose a style. Allow joining.
GAMESTATE - > m_bPlayersCanJoin = true ;
continue ;
}
2003-03-03 10:03:02 +00:00
2003-03-09 00:55:49 +00:00
PlayMode pm = StringToPlayMode ( sBit ) ;
if ( pm ! = PLAY_MODE_INVALID )
{
mc . pm = pm ;
continue ;
2003-03-03 10:03:02 +00:00
}
2003-03-09 00:55:49 +00:00
Difficulty dc = StringToDifficulty ( sBit ) ;
if ( dc ! = DIFFICULTY_INVALID )
{
mc . dc = dc ;
continue ;
}
2003-03-03 10:03:02 +00:00
2003-03-09 00:55:49 +00:00
LOG - > Warn ( " The choice token '%s' is not recognized as a Game, Style, PlayMode, or Difficulty. The choice containing this token will be ignored. " , sBit . GetString ( ) ) ;
bChoiceIsInvalid | = true ;
}
2003-03-03 10:03:02 +00:00
2003-03-09 00:55:49 +00:00
if ( mc . style ! = STYLE_INVALID )
{
const StyleDef * pStyleDef = GAMEMAN - > GetStyleDefForStyle ( mc . style ) ;
switch ( pStyleDef - > m_StyleType )
2003-03-03 10:03:02 +00:00
{
2003-03-09 00:55:49 +00:00
case StyleDef : : ONE_PLAYER_ONE_CREDIT :
mc . numSidesJoinedToPlay = 1 ;
break ;
case StyleDef : : TWO_PLAYERS_TWO_CREDITS :
case StyleDef : : ONE_PLAYER_TWO_CREDITS :
mc . numSidesJoinedToPlay = 2 ;
break ;
default :
ASSERT ( 0 ) ;
2003-03-03 10:03:02 +00:00
}
}
2003-03-09 00:55:49 +00:00
if ( ! bChoiceIsInvalid )
m_aModeChoices . push_back ( mc ) ;
CString sBGAnimationDir = THEME - > GetPathToOptional ( " BGAnimations " , ssprintf ( " %s %s " , m_sClassName . GetString ( ) , mc . name ) ) ;
2003-03-03 10:03:02 +00:00
if ( sBGAnimationDir = = " " )
2003-03-09 00:55:49 +00:00
sBGAnimationDir = THEME - > GetPathTo ( " BGAnimations " , m_sClassName + " background " ) ;
2003-03-03 10:03:02 +00:00
m_BGAnimations [ c ] . LoadFromAniDir ( sBGAnimationDir ) ;
}
2003-03-30 21:02:15 +00:00
m_Menu . Load ( sClassName ) ;
2003-03-03 10:03:02 +00:00
this - > AddChild ( & m_Menu ) ;
SOUNDMAN - > PlayOnceFromDir ( ANNOUNCER - > GetPathTo ( m_sClassName + " intro " ) ) ;
SOUNDMAN - > PlayMusic ( THEME - > GetPathTo ( " Sounds " , m_sClassName + " music " ) ) ;
}
ScreenSelect : : ~ ScreenSelect ( )
{
LOG - > Trace ( " ScreenSelect::~ScreenSelect() " ) ;
}
void ScreenSelect : : Update ( float fDelta )
{
Screen : : Update ( fDelta ) ;
m_BGAnimations [ this - > GetSelectionIndex ( GAMESTATE - > m_MasterPlayerNumber ) ] . Update ( fDelta ) ;
}
void ScreenSelect : : DrawPrimitives ( )
{
m_BGAnimations [ this - > GetSelectionIndex ( GAMESTATE - > m_MasterPlayerNumber ) ] . Draw ( ) ;
m_Menu . DrawBottomLayer ( ) ;
Screen : : DrawPrimitives ( ) ;
m_Menu . DrawTopLayer ( ) ;
}
void ScreenSelect : : Input ( const DeviceInput & DeviceI , const InputEventType type , const GameInput & GameI , const MenuInput & MenuI , const StyleInput & StyleI )
{
LOG - > Trace ( " ScreenSelect::Input() " ) ;
if ( MenuI . IsValid ( ) & & MenuI . button = = MENU_BUTTON_START )
{
PlayerNumber pn = MenuI . player ;
2003-03-09 00:55:49 +00:00
if ( GAMESTATE - > m_bPlayersCanJoin )
2003-03-03 10:03:02 +00:00
{
if ( pn ! = PLAYER_INVALID & & ! GAMESTATE - > m_bSideIsJoined [ pn ] )
{
/* I think JP should allow playing two-pad singleplayer modes (doubles),
* but not two-pad two-player modes (battle). (Battle mode isn't "joint".)
* That means we should leave player-entry logic alone and simply enable
* couples mode if JP is on and only one person has clicked in. (However,
* that means we'll display couples even if we don't really know if we have
* a second pad, which is a little annoying.)
*
* Also, credit deduction should be handled in StepMania.cpp (along with
* the coin logic) using GAMESTATE->m_bPlayersCanJoin, since there
* are other screens you can join (eg ScreenCaution). -glenn */
2003-03-09 00:55:49 +00:00
/* Joint premium on a DDR machine does allow two player modes with a single
* credit. -Chris */
2003-03-03 10:03:02 +00:00
if ( PREFSMAN - > m_CoinMode = = PrefsManager : : COIN_PAY )
{
if ( ! PREFSMAN - > m_bJointPremium )
{
if ( GAMESTATE - > m_iCoins < PREFSMAN - > m_iCoinsPerCredit )
{
/* Joint Premium is NOT enabled, and we do not have enough credits */
return ;
}
/* Joint Premium is NOT enabled, but we have enough credits. Pay up! */
GAMESTATE - > m_iCoins - = PREFSMAN - > m_iCoinsPerCredit ;
}
}
/* If credits had to be used, it's already taken care of.. add the player */
2003-03-09 00:55:49 +00:00
SOUNDMAN - > PlayOnce ( THEME - > GetPathTo ( " Sounds " , " Common start " ) ) ;
2003-03-03 10:03:02 +00:00
GAMESTATE - > m_bSideIsJoined [ pn ] = true ;
SCREENMAN - > RefreshCreditsMessages ( ) ;
this - > UpdateSelectableChoices ( ) ;
return ;
}
}
}
2003-03-09 00:55:49 +00:00
if ( m_Menu . IsTransitioning ( ) )
2003-03-03 10:03:02 +00:00
return ;
Screen : : Input ( DeviceI , type , GameI , MenuI , StyleI ) ; // default input handler
}
void ScreenSelect : : HandleScreenMessage ( const ScreenMessage SM )
{
switch ( SM )
{
case SM_AllDoneChoosing :
{
for ( int p = 0 ; p < NUM_PLAYERS ; p + + )
2003-04-07 03:25:44 +00:00
if ( GAMESTATE - > IsHumanPlayer ( p ) )
2003-03-03 10:03:02 +00:00
GAMESTATE - > ApplyModeChoice ( m_aModeChoices [ this - > GetSelectionIndex ( ( PlayerNumber ) p ) ] , ( PlayerNumber ) p ) ;
GAMESTATE - > m_bPlayersCanJoin = false ;
SCREENMAN - > RefreshCreditsMessages ( ) ;
2003-03-09 00:55:49 +00:00
if ( ! m_Menu . IsTransitioning ( ) )
m_Menu . StartTransitioning ( SM_GoToNextScreen ) ;
2003-03-03 10:03:02 +00:00
}
break ;
case SM_MenuTimer :
{
for ( int p = 0 ; p < NUM_PLAYERS ; p + + )
2003-04-10 05:46:31 +00:00
if ( GAMESTATE - > IsHumanPlayer ( p ) )
2003-03-03 10:03:02 +00:00
MenuStart ( ( PlayerNumber ) p ) ;
}
break ;
case SM_GoToPrevScreen :
SOUNDMAN - > StopMusic ( ) ;
SCREENMAN - > SetNewScreen ( " ScreenTitleMenu " ) ;
break ;
case SM_GoToNextScreen :
{
2003-03-09 00:55:49 +00:00
int iSelectionIndex = GetSelectionIndex ( GAMESTATE - > m_MasterPlayerNumber ) ;
SCREENMAN - > SetNewScreen ( NEXT_SCREEN ( iSelectionIndex ) ) ;
2003-03-03 10:03:02 +00:00
}
break ;
}
}
void ScreenSelect : : MenuBack ( PlayerNumber pn )
{
SOUNDMAN - > StopMusic ( ) ;
2003-03-09 00:55:49 +00:00
m_Menu . Back ( SM_GoToPrevScreen ) ;
2003-03-03 10:03:02 +00:00
}