Modularize coin logic

This commit is contained in:
Chris Danford
2003-03-09 03:28:34 +00:00
parent 769dac616f
commit 51ca82a8e6
9 changed files with 136 additions and 162 deletions
+4 -1
View File
@@ -261,9 +261,12 @@ bool GameState::IsPlayable( const ModeChoice& mc )
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
if( m_CurStyle == STYLE_INVALID )
return m_bSideIsJoined[pn];
switch( GetCurrentStyleDef()->m_StyleType )
{
case StyleDef::TWO_PLAYERS_TWO_CREDITS:
+58
View File
@@ -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 )
{
// This is now handled globally by Stepmania.cpp -- Miryokuteki
+2
View File
@@ -33,6 +33,8 @@ public:
virtual void Update( float fDeltaTime );
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 ) {};
void SendScreenMessage( const ScreenMessage SM, const float fDelay );
+3 -26
View File
@@ -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() );
}
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 )
{
if(type != IET_FIRST_PRESS)
@@ -124,7 +99,9 @@ void ScreenAttract::AttractInput( const DeviceInput& DeviceI, const InputEventTy
case PrefsManager::COIN_FREE:
case PrefsManager::COIN_HOME:
SOUNDMAN->StopMusic();
SOUNDMAN->PlayOnce( THEME->GetPathTo("Sounds","Common coin") );
/* 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") );
SDL_Delay( 800 ); // do a little pause, like the arcade does
SCREENMAN->SetNewScreen( "ScreenTitleMenu" );
break;
-1
View File
@@ -29,7 +29,6 @@ public:
virtual ~ScreenAttract();
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 );
virtual void Update( float fDelta );
virtual void HandleScreenMessage( const ScreenMessage SM );
+4 -12
View File
@@ -57,17 +57,8 @@ ScreenCaution::ScreenCaution()
void ScreenCaution::Input( const DeviceInput& DeviceI, const InputEventType type, const GameInput &GameI, const MenuInput &MenuI, const StyleInput &StyleI )
{
PlayerNumber pn = MenuI.player;
if( MenuI.IsValid() && pn!=PLAYER_INVALID && !GAMESTATE->m_bSideIsJoined[pn] )
{
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;
if( Screen::JoinInput( DeviceI, type, GameI, MenuI, StyleI ) )
return; // handled
Screen::Input( DeviceI, type, GameI, MenuI, StyleI );
}
@@ -95,7 +86,8 @@ void ScreenCaution::HandleScreenMessage( const ScreenMessage SM )
void ScreenCaution::MenuStart( PlayerNumber pn )
{
m_Out.StartTransitioning( SM_GoToNextScreen );
if( !m_Out.IsTransitioning() )
m_Out.StartTransitioning( SM_GoToNextScreen );
}
void ScreenCaution::MenuBack( PlayerNumber pn )
+2 -16
View File
@@ -86,32 +86,18 @@ void ScreenDemonstration::Input( const DeviceInput& DeviceI, const InputEventTyp
//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() )
{
switch( MenuI.button )
{
case MENU_BUTTON_COIN:
m_soundMusic.Stop();
break;
case MENU_BUTTON_START:
case MENU_BUTTON_BACK:
switch( PREFSMAN->m_CoinMode )
{
case PrefsManager::COIN_PAY:
if( PREFSMAN->m_CoinMode == 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();
break;
default:
ASSERT(0);
}
m_soundMusic.Stop();
break;
}
}
+62 -105
View File
@@ -51,6 +51,8 @@ ScreenTitleMenu::ScreenTitleMenu()
{
LOG->Trace( "ScreenTitleMenu::ScreenTitleMenu()" );
GAMESTATE->m_bPlayersCanJoin = true;
if( PREFSMAN->m_CoinMode!=PrefsManager::COIN_HOME && PREFSMAN->m_bJointPremium )
{
m_JointPremium.LoadFromAniDir( THEME->GetPathTo("BGAnimations","ScreenTitleMenu joint premium") );
@@ -159,119 +161,74 @@ void ScreenTitleMenu::Input( const DeviceInput& DeviceI, const InputEventType ty
if( !MenuI.IsValid() )
return;
switch( PREFSMAN->m_CoinMode )
switch( MenuI.button )
{
case PrefsManager::COIN_HOME:
switch( MenuI.button )
case MENU_BUTTON_UP:
if( PREFSMAN->m_CoinMode != PrefsManager::COIN_HOME )
break;
if( m_In.IsTransitioning() || m_Out.IsTransitioning() )
break;
TimeToDemonstration.GetDeltaTime(); /* Reset the demonstration timer when a key is pressed. */
LoseFocus( m_Choice );
if( m_Choice == 0 ) // wrap around
m_Choice = (Choice)((int)NUM_CHOICES);
m_Choice = Choice( m_Choice-1 );
m_soundChange.Play();
GainFocus( m_Choice );
break;
case MENU_BUTTON_DOWN:
if( PREFSMAN->m_CoinMode != PrefsManager::COIN_HOME )
break;
if( m_In.IsTransitioning() || m_Out.IsTransitioning() )
break;
TimeToDemonstration.GetDeltaTime(); /* Reset the demonstration timer when a key is pressed. */
LoseFocus( m_Choice );
if( m_Choice == (int)ScreenTitleMenu::NUM_CHOICES-1 )
m_Choice = (Choice)-1; // wrap around
m_Choice = Choice( m_Choice+1 );
m_soundChange.Play();
GainFocus( m_Choice );
break;
case MENU_BUTTON_BACK:
if( m_In.IsTransitioning() || m_Out.IsTransitioning() )
break;
m_Out.StartTransitioning( SM_GoToAttractLoop );
break;
case MENU_BUTTON_START:
if( m_In.IsTransitioning() )
break;
/* break if the choice is invalid */
switch( m_Choice )
{
case MENU_BUTTON_UP:
if( m_In.IsTransitioning() || m_Out.IsTransitioning() )
break;
TimeToDemonstration.GetDeltaTime(); /* Reset the demonstration timer when a key is pressed. */
LoseFocus( m_Choice );
if( m_Choice == 0 ) // wrap around
m_Choice = (Choice)((int)NUM_CHOICES);
m_Choice = Choice( m_Choice-1 );
m_soundChange.Play();
GainFocus( m_Choice );
break;
case MENU_BUTTON_DOWN:
if( m_In.IsTransitioning() || m_Out.IsTransitioning() )
break;
TimeToDemonstration.GetDeltaTime(); /* Reset the demonstration timer when a key is pressed. */
LoseFocus( m_Choice );
if( m_Choice == (int)ScreenTitleMenu::NUM_CHOICES-1 )
m_Choice = (Choice)-1; // wrap around
m_Choice = Choice( m_Choice+1 );
m_soundChange.Play();
GainFocus( m_Choice );
break;
case MENU_BUTTON_BACK:
if( m_In.IsTransitioning() || m_Out.IsTransitioning() )
break;
m_Out.StartTransitioning( SM_GoToAttractLoop );
break;
case MENU_BUTTON_START:
if( m_In.IsTransitioning() )
break;
/* break if the choice is invalid */
switch( m_Choice )
case CHOICE_GAME_START:
case CHOICE_SELECT_GAME:
case CHOICE_OPTIONS:
#ifdef DEBUG
case CHOICE_SANDBOX:
#endif
case CHOICE_JUKEBOX:
case CHOICE_EDIT:
if( SONGMAN->GetNumSongs() == 0 )
{
case CHOICE_GAME_START:
case CHOICE_SELECT_GAME:
case CHOICE_OPTIONS:
#ifdef DEBUG
case CHOICE_SANDBOX:
#endif
case CHOICE_JUKEBOX:
case CHOICE_EDIT:
if( SONGMAN->GetNumSongs() == 0 )
{
m_soundInvalid.Play();
SCREENMAN->SystemMessage( "No songs are installed" );
break;
}
m_soundInvalid.Play();
SCREENMAN->SystemMessage( "No songs are installed" );
break;
case CHOICE_EXIT:
ExitGame();
LOG->Trace("CHOICE_EXIT: shutting down");
return;
default:
ASSERT(0);
}
/* If this side is already in, don't re-join (and re-pay!). */
if(GAMESTATE->m_bSideIsJoined[MenuI.player])
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 );
}
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;
case CHOICE_EXIT:
ExitGame();
LOG->Trace("CHOICE_EXIT: shutting down");
return;
default:
ASSERT(0);
}
break;
if( Screen::JoinInput( DeviceI, type, GameI, MenuI, StyleI ) )
if( !m_Out.IsTransitioning() )
m_Out.StartTransitioning( SM_GoToNextScreen );
}
// Screen::Input( DeviceI, type, GameI, MenuI, StyleI );
}
+1 -1
View File
@@ -386,7 +386,7 @@ int main(int argc, char* argv[])
bool HandleGlobalInputs( DeviceInput DeviceI, InputEventType type, GameInput GameI, MenuInput MenuI, StyleInput StyleI )
{
/* None of the globals keys act on types other than FIRST_PRESS */
if( type == IET_FIRST_PRESS )
if( type != IET_FIRST_PRESS )
return false;
switch( MenuI.button )