Modularize coin logic
This commit is contained in:
@@ -261,9 +261,12 @@ bool GameState::IsPlayable( const ModeChoice& mc )
|
|||||||
|
|
||||||
bool GameState::IsPlayerEnabled( PlayerNumber pn )
|
bool GameState::IsPlayerEnabled( PlayerNumber pn )
|
||||||
{
|
{
|
||||||
if( m_CurStyle == STYLE_INVALID ) // if no style set (we're in TitleMenu, ConfigInstruments or something)
|
if( GAMESTATE->m_bIsOnSystemMenu ) // if no style set (we're in TitleMenu, ConfigInstruments or something)
|
||||||
return true; // allow input from both sides
|
return true; // allow input from both sides
|
||||||
|
|
||||||
|
if( m_CurStyle == STYLE_INVALID )
|
||||||
|
return m_bSideIsJoined[pn];
|
||||||
|
|
||||||
switch( GetCurrentStyleDef()->m_StyleType )
|
switch( GetCurrentStyleDef()->m_StyleType )
|
||||||
{
|
{
|
||||||
case StyleDef::TWO_PLAYERS_TWO_CREDITS:
|
case StyleDef::TWO_PLAYERS_TWO_CREDITS:
|
||||||
|
|||||||
@@ -100,6 +100,64 @@ void Screen::Input( const DeviceInput& DeviceI, const InputEventType type, const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Screen::ChangeCoinModeInput( const DeviceInput& DeviceI, const InputEventType type, const GameInput &GameI, const MenuInput &MenuI, const StyleInput &StyleI )
|
||||||
|
{
|
||||||
|
if( type != IET_FIRST_PRESS )
|
||||||
|
return false;
|
||||||
|
if( DeviceI.device == DEVICE_KEYBOARD && DeviceI.button == SDLK_F3 )
|
||||||
|
{
|
||||||
|
(int&)PREFSMAN->m_CoinMode = (PREFSMAN->m_CoinMode+1) % PrefsManager::NUM_COIN_MODES;
|
||||||
|
/* ResetGame();
|
||||||
|
This causes problems on ScreenIntroMovie, which results in the
|
||||||
|
movie being restarted and/or becoming out-of-synch -- Miryokuteki */
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
SCREENMAN->RefreshCreditsMessages();
|
||||||
|
SCREENMAN->SystemMessage( sMessage );
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Screen::JoinInput( const DeviceInput& DeviceI, const InputEventType type, const GameInput &GameI, const MenuInput &MenuI, const StyleInput &StyleI )
|
||||||
|
{
|
||||||
|
if( !GAMESTATE->m_bPlayersCanJoin )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if( MenuI.IsValid() && MenuI.button==MENU_BUTTON_START )
|
||||||
|
{
|
||||||
|
/* If this side is already in, don't re-join (and re-pay!). */
|
||||||
|
if(GAMESTATE->m_bSideIsJoined[MenuI.player])
|
||||||
|
return false;
|
||||||
|
|
||||||
|
/* subtract coins */
|
||||||
|
if( PREFSMAN->m_CoinMode == PrefsManager::COIN_PAY )
|
||||||
|
if( GAMESTATE->m_iCoins < PREFSMAN->m_iCoinsPerCredit )
|
||||||
|
return false; // not enough coins
|
||||||
|
else
|
||||||
|
GAMESTATE->m_iCoins -= PREFSMAN->m_iCoinsPerCredit;
|
||||||
|
|
||||||
|
GAMESTATE->m_bSideIsJoined[MenuI.player] = true;
|
||||||
|
if( GAMESTATE->m_MasterPlayerNumber == PLAYER_INVALID )
|
||||||
|
GAMESTATE->m_MasterPlayerNumber = MenuI.player;
|
||||||
|
|
||||||
|
SCREENMAN->RefreshCreditsMessages();
|
||||||
|
|
||||||
|
SOUNDMAN->PlayOnce( THEME->GetPathTo("Sounds","Common start") );
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void Screen::MenuCoin( PlayerNumber pn )
|
void Screen::MenuCoin( PlayerNumber pn )
|
||||||
{
|
{
|
||||||
// This is now handled globally by Stepmania.cpp -- Miryokuteki
|
// This is now handled globally by Stepmania.cpp -- Miryokuteki
|
||||||
|
|||||||
@@ -33,6 +33,8 @@ public:
|
|||||||
|
|
||||||
virtual void Update( float fDeltaTime );
|
virtual void Update( float fDeltaTime );
|
||||||
virtual void Input( const DeviceInput& DeviceI, const InputEventType type, const GameInput &GameI, const MenuInput &MenuI, const StyleInput &StyleI );
|
virtual void Input( const DeviceInput& DeviceI, const InputEventType type, const GameInput &GameI, const MenuInput &MenuI, const StyleInput &StyleI );
|
||||||
|
static bool ChangeCoinModeInput( const DeviceInput& DeviceI, const InputEventType type, const GameInput &GameI, const MenuInput &MenuI, const StyleInput &StyleI ); // return true if CoinMode changed
|
||||||
|
static bool JoinInput( const DeviceInput& DeviceI, const InputEventType type, const GameInput &GameI, const MenuInput &MenuI, const StyleInput &StyleI ); // return true if a player joined
|
||||||
virtual void HandleScreenMessage( const ScreenMessage SM ) {};
|
virtual void HandleScreenMessage( const ScreenMessage SM ) {};
|
||||||
|
|
||||||
void SendScreenMessage( const ScreenMessage SM, const float fDelay );
|
void SendScreenMessage( const ScreenMessage SM, const float fDelay );
|
||||||
|
|||||||
@@ -76,31 +76,6 @@ void ScreenAttract::Input( const DeviceInput& DeviceI, const InputEventType type
|
|||||||
AttractInput( DeviceI, type, GameI, MenuI, StyleI, m_In.IsTransitioning() || m_Out.IsTransitioning() );
|
AttractInput( DeviceI, type, GameI, MenuI, StyleI, m_In.IsTransitioning() || m_Out.IsTransitioning() );
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ScreenAttract::ChangeCoinModeInput( const DeviceInput& DeviceI, const InputEventType type, const GameInput &GameI, const MenuInput &MenuI, const StyleInput &StyleI )
|
|
||||||
{
|
|
||||||
if( type != IET_FIRST_PRESS )
|
|
||||||
return false;
|
|
||||||
if( DeviceI.device == DEVICE_KEYBOARD && DeviceI.button == SDLK_F3 )
|
|
||||||
{
|
|
||||||
(int&)PREFSMAN->m_CoinMode = (PREFSMAN->m_CoinMode+1) % PrefsManager::NUM_COIN_MODES;
|
|
||||||
/* ResetGame();
|
|
||||||
This causes problems on ScreenIntroMovie, which results in the
|
|
||||||
movie being restarted and/or becoming out-of-synch -- Miryokuteki */
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
SCREENMAN->RefreshCreditsMessages();
|
|
||||||
SCREENMAN->SystemMessage( sMessage );
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ScreenAttract::AttractInput( const DeviceInput& DeviceI, const InputEventType type, const GameInput &GameI, const MenuInput &MenuI, const StyleInput &StyleI, bool bTransitioning )
|
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)
|
if(type != IET_FIRST_PRESS)
|
||||||
@@ -124,6 +99,8 @@ void ScreenAttract::AttractInput( const DeviceInput& DeviceI, const InputEventTy
|
|||||||
case PrefsManager::COIN_FREE:
|
case PrefsManager::COIN_FREE:
|
||||||
case PrefsManager::COIN_HOME:
|
case PrefsManager::COIN_HOME:
|
||||||
SOUNDMAN->StopMusic();
|
SOUNDMAN->StopMusic();
|
||||||
|
/* We already played the it was a coin was inserted. Don't play it again. */
|
||||||
|
if( MenuI.button != MENU_BUTTON_COIN )
|
||||||
SOUNDMAN->PlayOnce( THEME->GetPathTo("Sounds","Common coin") );
|
SOUNDMAN->PlayOnce( THEME->GetPathTo("Sounds","Common coin") );
|
||||||
SDL_Delay( 800 ); // do a little pause, like the arcade does
|
SDL_Delay( 800 ); // do a little pause, like the arcade does
|
||||||
SCREENMAN->SetNewScreen( "ScreenTitleMenu" );
|
SCREENMAN->SetNewScreen( "ScreenTitleMenu" );
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ public:
|
|||||||
virtual ~ScreenAttract();
|
virtual ~ScreenAttract();
|
||||||
|
|
||||||
virtual void Input( const DeviceInput& DeviceI, const InputEventType type, const GameInput &GameI, const MenuInput &MenuI, const StyleInput &StyleI );
|
virtual void Input( const DeviceInput& DeviceI, const InputEventType type, const GameInput &GameI, const MenuInput &MenuI, const StyleInput &StyleI );
|
||||||
static bool ChangeCoinModeInput( const DeviceInput& DeviceI, const InputEventType type, const GameInput &GameI, const MenuInput &MenuI, const StyleInput &StyleI ); /* return true if CoinMode changed */
|
|
||||||
static void AttractInput( const DeviceInput& DeviceI, const InputEventType type, const GameInput &GameI, const MenuInput &MenuI, const StyleInput &StyleI, bool bTransitioning );
|
static void AttractInput( const DeviceInput& DeviceI, const InputEventType type, const GameInput &GameI, const MenuInput &MenuI, const StyleInput &StyleI, bool bTransitioning );
|
||||||
virtual void Update( float fDelta );
|
virtual void Update( float fDelta );
|
||||||
virtual void HandleScreenMessage( const ScreenMessage SM );
|
virtual void HandleScreenMessage( const ScreenMessage SM );
|
||||||
|
|||||||
@@ -57,17 +57,8 @@ ScreenCaution::ScreenCaution()
|
|||||||
|
|
||||||
void ScreenCaution::Input( const DeviceInput& DeviceI, const InputEventType type, const GameInput &GameI, const MenuInput &MenuI, const StyleInput &StyleI )
|
void ScreenCaution::Input( const DeviceInput& DeviceI, const InputEventType type, const GameInput &GameI, const MenuInput &MenuI, const StyleInput &StyleI )
|
||||||
{
|
{
|
||||||
PlayerNumber pn = MenuI.player;
|
if( Screen::JoinInput( DeviceI, type, GameI, MenuI, StyleI ) )
|
||||||
if( MenuI.IsValid() && pn!=PLAYER_INVALID && !GAMESTATE->m_bSideIsJoined[pn] )
|
return; // handled
|
||||||
{
|
|
||||||
GAMESTATE->m_bSideIsJoined[pn] = true;
|
|
||||||
SOUNDMAN->PlayOnce( THEME->GetPathTo("Sounds","Common start") );
|
|
||||||
SCREENMAN->RefreshCreditsMessages();
|
|
||||||
return; // don't fall though
|
|
||||||
}
|
|
||||||
|
|
||||||
if( m_In.IsTransitioning() || m_Out.IsTransitioning() || m_Back.IsTransitioning() )
|
|
||||||
return;
|
|
||||||
|
|
||||||
Screen::Input( DeviceI, type, GameI, MenuI, StyleI );
|
Screen::Input( DeviceI, type, GameI, MenuI, StyleI );
|
||||||
}
|
}
|
||||||
@@ -95,6 +86,7 @@ void ScreenCaution::HandleScreenMessage( const ScreenMessage SM )
|
|||||||
|
|
||||||
void ScreenCaution::MenuStart( PlayerNumber pn )
|
void ScreenCaution::MenuStart( PlayerNumber pn )
|
||||||
{
|
{
|
||||||
|
if( !m_Out.IsTransitioning() )
|
||||||
m_Out.StartTransitioning( SM_GoToNextScreen );
|
m_Out.StartTransitioning( SM_GoToNextScreen );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -86,33 +86,19 @@ void ScreenDemonstration::Input( const DeviceInput& DeviceI, const InputEventTyp
|
|||||||
//LOG->Trace( "ScreenDemonstration::Input()" );
|
//LOG->Trace( "ScreenDemonstration::Input()" );
|
||||||
|
|
||||||
|
|
||||||
// Stop music on Start or Coin
|
|
||||||
// TODO: Change ScreenGameplay to play sound through the global sound object
|
|
||||||
// so that this don't need to be special cased.
|
|
||||||
if( MenuI.IsValid() )
|
if( MenuI.IsValid() )
|
||||||
{
|
{
|
||||||
switch( MenuI.button )
|
switch( MenuI.button )
|
||||||
{
|
{
|
||||||
case MENU_BUTTON_COIN:
|
case MENU_BUTTON_COIN:
|
||||||
m_soundMusic.Stop();
|
|
||||||
break;
|
|
||||||
case MENU_BUTTON_START:
|
case MENU_BUTTON_START:
|
||||||
case MENU_BUTTON_BACK:
|
case MENU_BUTTON_BACK:
|
||||||
|
|
||||||
switch( PREFSMAN->m_CoinMode )
|
if( PREFSMAN->m_CoinMode == PrefsManager::COIN_PAY )
|
||||||
{
|
|
||||||
case PrefsManager::COIN_PAY:
|
|
||||||
if( GAMESTATE->m_iCoins < PREFSMAN->m_iCoinsPerCredit )
|
if( GAMESTATE->m_iCoins < PREFSMAN->m_iCoinsPerCredit )
|
||||||
break; // don't fall through
|
break; // don't fall through
|
||||||
// fall through
|
|
||||||
case PrefsManager::COIN_FREE:
|
|
||||||
case PrefsManager::COIN_HOME:
|
|
||||||
m_soundMusic.Stop();
|
m_soundMusic.Stop();
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
ASSERT(0);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -51,6 +51,8 @@ ScreenTitleMenu::ScreenTitleMenu()
|
|||||||
{
|
{
|
||||||
LOG->Trace( "ScreenTitleMenu::ScreenTitleMenu()" );
|
LOG->Trace( "ScreenTitleMenu::ScreenTitleMenu()" );
|
||||||
|
|
||||||
|
GAMESTATE->m_bPlayersCanJoin = true;
|
||||||
|
|
||||||
if( PREFSMAN->m_CoinMode!=PrefsManager::COIN_HOME && PREFSMAN->m_bJointPremium )
|
if( PREFSMAN->m_CoinMode!=PrefsManager::COIN_HOME && PREFSMAN->m_bJointPremium )
|
||||||
{
|
{
|
||||||
m_JointPremium.LoadFromAniDir( THEME->GetPathTo("BGAnimations","ScreenTitleMenu joint premium") );
|
m_JointPremium.LoadFromAniDir( THEME->GetPathTo("BGAnimations","ScreenTitleMenu joint premium") );
|
||||||
@@ -159,12 +161,13 @@ void ScreenTitleMenu::Input( const DeviceInput& DeviceI, const InputEventType ty
|
|||||||
if( !MenuI.IsValid() )
|
if( !MenuI.IsValid() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
switch( PREFSMAN->m_CoinMode )
|
|
||||||
{
|
|
||||||
case PrefsManager::COIN_HOME:
|
|
||||||
switch( MenuI.button )
|
switch( MenuI.button )
|
||||||
{
|
{
|
||||||
case MENU_BUTTON_UP:
|
case MENU_BUTTON_UP:
|
||||||
|
if( PREFSMAN->m_CoinMode != PrefsManager::COIN_HOME )
|
||||||
|
break;
|
||||||
if( m_In.IsTransitioning() || m_Out.IsTransitioning() )
|
if( m_In.IsTransitioning() || m_Out.IsTransitioning() )
|
||||||
break;
|
break;
|
||||||
TimeToDemonstration.GetDeltaTime(); /* Reset the demonstration timer when a key is pressed. */
|
TimeToDemonstration.GetDeltaTime(); /* Reset the demonstration timer when a key is pressed. */
|
||||||
@@ -176,6 +179,8 @@ void ScreenTitleMenu::Input( const DeviceInput& DeviceI, const InputEventType ty
|
|||||||
GainFocus( m_Choice );
|
GainFocus( m_Choice );
|
||||||
break;
|
break;
|
||||||
case MENU_BUTTON_DOWN:
|
case MENU_BUTTON_DOWN:
|
||||||
|
if( PREFSMAN->m_CoinMode != PrefsManager::COIN_HOME )
|
||||||
|
break;
|
||||||
if( m_In.IsTransitioning() || m_Out.IsTransitioning() )
|
if( m_In.IsTransitioning() || m_Out.IsTransitioning() )
|
||||||
break;
|
break;
|
||||||
TimeToDemonstration.GetDeltaTime(); /* Reset the demonstration timer when a key is pressed. */
|
TimeToDemonstration.GetDeltaTime(); /* Reset the demonstration timer when a key is pressed. */
|
||||||
@@ -220,58 +225,10 @@ void ScreenTitleMenu::Input( const DeviceInput& DeviceI, const InputEventType ty
|
|||||||
ASSERT(0);
|
ASSERT(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If this side is already in, don't re-join (and re-pay!). */
|
if( Screen::JoinInput( DeviceI, type, GameI, MenuI, StyleI ) )
|
||||||
if(GAMESTATE->m_bSideIsJoined[MenuI.player])
|
if( !m_Out.IsTransitioning() )
|
||||||
break;
|
|
||||||
|
|
||||||
GAMESTATE->m_bSideIsJoined[MenuI.player] = true;
|
|
||||||
if( GAMESTATE->m_MasterPlayerNumber == PLAYER_INVALID )
|
|
||||||
GAMESTATE->m_MasterPlayerNumber = MenuI.player;
|
|
||||||
|
|
||||||
SCREENMAN->RefreshCreditsMessages();
|
|
||||||
|
|
||||||
m_soundSelect.Play();
|
|
||||||
|
|
||||||
if( m_In.IsTransitioning() || m_Out.IsTransitioning() )
|
|
||||||
break;
|
|
||||||
m_Out.StartTransitioning( SM_GoToNextScreen );
|
m_Out.StartTransitioning( SM_GoToNextScreen );
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
case PrefsManager::COIN_PAY:
|
|
||||||
case PrefsManager::COIN_FREE:
|
|
||||||
switch( MenuI.button )
|
|
||||||
{
|
|
||||||
case MENU_BUTTON_BACK:
|
|
||||||
m_Out.StartTransitioning( SM_GoToAttractLoop );
|
|
||||||
break;
|
|
||||||
case MENU_BUTTON_START:
|
|
||||||
/* If this side is already in, don't re-join (and re-pay!). */
|
|
||||||
if(GAMESTATE->m_bSideIsJoined[MenuI.player])
|
|
||||||
break;
|
|
||||||
|
|
||||||
/* subtract coins */
|
|
||||||
if( PREFSMAN->m_CoinMode == PrefsManager::COIN_PAY )
|
|
||||||
if( GAMESTATE->m_iCoins < PREFSMAN->m_iCoinsPerCredit )
|
|
||||||
break; // not enough coins
|
|
||||||
else
|
|
||||||
GAMESTATE->m_iCoins -= PREFSMAN->m_iCoinsPerCredit;
|
|
||||||
|
|
||||||
GAMESTATE->m_bSideIsJoined[MenuI.player] = true;
|
|
||||||
if( GAMESTATE->m_MasterPlayerNumber == PLAYER_INVALID )
|
|
||||||
GAMESTATE->m_MasterPlayerNumber = MenuI.player;
|
|
||||||
|
|
||||||
SCREENMAN->RefreshCreditsMessages();
|
|
||||||
|
|
||||||
m_soundSelect.Play();
|
|
||||||
|
|
||||||
if( m_In.IsTransitioning() || m_Out.IsTransitioning() )
|
|
||||||
break;
|
|
||||||
m_Out.StartTransitioning( SM_GoToNextScreen );
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Screen::Input( DeviceI, type, GameI, MenuI, StyleI );
|
// Screen::Input( DeviceI, type, GameI, MenuI, StyleI );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -386,7 +386,7 @@ int main(int argc, char* argv[])
|
|||||||
bool HandleGlobalInputs( DeviceInput DeviceI, InputEventType type, GameInput GameI, MenuInput MenuI, StyleInput StyleI )
|
bool HandleGlobalInputs( DeviceInput DeviceI, InputEventType type, GameInput GameI, MenuInput MenuI, StyleInput StyleI )
|
||||||
{
|
{
|
||||||
/* None of the globals keys act on types other than FIRST_PRESS */
|
/* None of the globals keys act on types other than FIRST_PRESS */
|
||||||
if( type == IET_FIRST_PRESS )
|
if( type != IET_FIRST_PRESS )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
switch( MenuI.button )
|
switch( MenuI.button )
|
||||||
|
|||||||
Reference in New Issue
Block a user