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"
2003-07-08 19:56:56 +00:00
#include "RageDisplay.h"
2003-07-11 03:15:28 +00:00
#include "arch/ArchHooks/ArchHooks.h"
2003-03-03 10:03:02 +00:00
2003-04-12 06:16:12 +00:00
#define CHOICES THEME->GetMetric (m_sName,"Choices")
#define HELP_TEXT THEME->GetMetric (m_sName,"HelpText")
#define TIMER_SECONDS THEME->GetMetricI(m_sName,"TimerSeconds")
#define NEXT_SCREEN( choice ) THEME->GetMetric (m_sName,ssprintf("NextScreen%d",choice+1))
2003-03-03 10:03:02 +00:00
2003-07-10 03:36:41 +00:00
// Temporary hack: specify announcer in selection
#define SPECIFY_ANNOUNCER THEME->HasMetric(m_sName,"Announcer1")
#define ANNOUNCER( choice ) THEME->GetMetric (m_sName,ssprintf("Announcer%d",choice+1))
2003-03-03 10:03:02 +00:00
2003-04-12 06:16:12 +00:00
ScreenSelect :: ScreenSelect ( CString sClassName ) : Screen ( sClassName )
2003-03-03 10:03:02 +00:00
{
LOG -> Trace ( "ScreenSelect::ScreenSelect()" );
2003-04-12 06:16:12 +00:00
m_sName = sClassName ;
2003-03-03 10:03:02 +00:00
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 ++ )
2003-03-03 10:03:02 +00:00
{
2003-03-09 00:55:49 +00:00
CString sChoice = asChoices [ c ];
2003-07-10 03:36:41 +00:00
ModeChoice mc ;
mc . game = GAME_INVALID ;
mc . style = STYLE_INVALID ;
mc . pm = PLAY_MODE_INVALID ;
mc . dc = DIFFICULTY_INVALID ;
mc . sAnnouncer = "" ;
strcpy ( mc . name , "" );
mc . numSidesJoinedToPlay = 1 ;
2003-03-09 00:55:49 +00:00
strncpy ( mc . name , sChoice , sizeof ( mc . name ) );
bool bChoiceIsInvalid = false ;
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 ;
}
PlayMode pm = StringToPlayMode ( sBit );
if ( pm != PLAY_MODE_INVALID )
{
mc . pm = pm ;
continue ;
}
Difficulty dc = StringToDifficulty ( sBit );
if ( dc != DIFFICULTY_INVALID )
{
mc . dc = dc ;
continue ;
}
2003-07-08 19:56:56 +00:00
CString sError = ssprintf ( "The choice token '%s' is not recognized as a Game, Style, PlayMode, or Difficulty. The choice containing this token will be ignored." , sBit . c_str () );
LOG -> Warn ( sError );
if ( DISPLAY -> IsWindowed () )
HOOKS -> MessageBoxOK ( sError );
2003-03-09 00:55:49 +00:00
bChoiceIsInvalid |= true ;
}
2003-07-10 03:36:41 +00:00
if ( SPECIFY_ANNOUNCER )
mc . sAnnouncer = ANNOUNCER ( c );
2003-03-09 00:55:49 +00:00
if ( mc . style != STYLE_INVALID )
{
const StyleDef * pStyleDef = GAMEMAN -> GetStyleDefForStyle ( mc . style );
switch ( pStyleDef -> m_StyleType )
{
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 );
2003-03-03 10:03:02 +00:00
2003-03-09 00:55:49 +00:00
2003-04-25 00:27:30 +00:00
CString sBGAnimationDir = THEME -> GetPathTo ( BGAnimations , ssprintf ( "%s %s" , m_sName . c_str (), mc . name ), true ); // true="optional"
2003-03-03 10:03:02 +00:00
if ( sBGAnimationDir == "" )
2003-04-12 17:39:27 +00:00
sBGAnimationDir = THEME -> GetPathToB ( m_sName + " 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 );
}
ScreenSelect ::~ ScreenSelect ()
{
LOG -> Trace ( "ScreenSelect::~ScreenSelect()" );
}
void ScreenSelect :: Update ( float fDelta )
{
2003-05-17 20:45:45 +00:00
if ( m_bFirstUpdate )
{
/* Don't play sounds during the ctor, since derived classes havn't loaded yet. */
SOUNDMAN -> PlayOnceFromDir ( ANNOUNCER -> GetPathTo ( m_sName + " intro" ) );
SOUNDMAN -> PlayMusic ( THEME -> GetPathToS ( m_sName + " music" ) );
}
2003-03-03 10:03:02 +00:00
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 )
{
2003-04-11 01:49:57 +00:00
// LOG->Trace( "ScreenSelect::Input()" );
2003-03-03 10:03:02 +00:00
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
2003-05-01 23:40:12 +00:00
* credit. -Chris
*/
/* Indeed, I can see three different premium settings here:
AnyPlayersTwoCoins (2 coins for doubles and 2 coins for versus)
OnePlayerOneCoin (1 coin for doubles, but 2 coins for versus (like pump and ez2))
TwoPlayerOneCoin (1 coin for doubles / versus play)
perhaps we should change the joint premium system to work this way?
That way we can support all gametypes.
*/
2003-03-09 00:55:49 +00:00
2003-04-13 04:50:08 +00:00
if ( PREFSMAN -> m_iCoinMode == COIN_PAY )
2003-03-03 10:03:02 +00:00
{
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-04-12 17:39:27 +00:00
SOUNDMAN -> PlayOnce ( THEME -> GetPathToS ( "Common start" ) );
2003-03-03 10:03:02 +00:00
GAMESTATE -> m_bSideIsJoined [ pn ] = true ;
SCREENMAN -> RefreshCreditsMessages ();
this -> UpdateSelectableChoices ();
return ;
}
}
}
2003-05-20 14:48:38 +00:00
// For some reason the menu likes to take 10 seconds to transition O_o
// quite noticeable pause... and in the meantime the player is sitting there
// wondering why their keys aren't working... even ESC... @_@
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
}