From 7ef60095679acd6726d941ffd0b9e926e02805ab Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Tue, 21 Nov 2006 19:57:58 +0000 Subject: [PATCH] Screen::JoinInput -> GameState::JoinInput --- stepmania/src/GameState.cpp | 23 +++++++++++++++++++++++ stepmania/src/GameState.h | 1 + stepmania/src/Screen.cpp | 23 ----------------------- stepmania/src/Screen.h | 2 -- stepmania/src/ScreenSelect.cpp | 2 +- 5 files changed, 25 insertions(+), 26 deletions(-) diff --git a/stepmania/src/GameState.cpp b/stepmania/src/GameState.cpp index d472ac5f7a..dd0f8261c5 100644 --- a/stepmania/src/GameState.cpp +++ b/stepmania/src/GameState.cpp @@ -344,6 +344,29 @@ void GameState::JoinPlayer( PlayerNumber pn ) BeginGame(); } +/* Handle an input that can join a player. Return true if the player joined. */ +bool GameState::JoinInput( PlayerNumber pn ) +{ + if( !PlayersCanJoin() ) + return false; + + /* If this side is already in, don't re-join. */ + if( m_bSideIsJoined[pn] ) + return false; + + /* subtract coins */ + int iCoinsNeededToJoin = GetCoinsNeededToJoin(); + + if( m_iCoins < iCoinsNeededToJoin ) + return false; // not enough coins + + m_iCoins -= iCoinsNeededToJoin; + + JoinPlayer( pn ); + + return true; +} + int GameState::GetCoinsNeededToJoin() const { int iCoinsToCharge = 0; diff --git a/stepmania/src/GameState.h b/stepmania/src/GameState.h index 076de29a2d..ba024ee77b 100644 --- a/stepmania/src/GameState.h +++ b/stepmania/src/GameState.h @@ -42,6 +42,7 @@ public: void ApplyGameCommand( const RString &sCommand, PlayerNumber pn=PLAYER_INVALID ); void BeginGame(); // called when first player joins void JoinPlayer( PlayerNumber pn ); + bool JoinInput( PlayerNumber pn ); void PlayersFinalized(); // called after a style is chosen, which means the number of players is finalized void EndGame(); // called on ScreenGameOver, ScreenMusicScroll, ScreenCredits void SaveCurrentSettingsToProfile( PlayerNumber pn ); // called at the beginning of each stage diff --git a/stepmania/src/Screen.cpp b/stepmania/src/Screen.cpp index ccaa5508a2..791f88cac3 100644 --- a/stepmania/src/Screen.cpp +++ b/stepmania/src/Screen.cpp @@ -219,29 +219,6 @@ RString Screen::GetPrevScreen() const return PREV_SCREEN; } - -bool Screen::JoinInput( PlayerNumber pn ) -{ - if( !GAMESTATE->PlayersCanJoin() ) - return false; - - /* If this side is already in, don't re-join (and re-pay!). */ - if(GAMESTATE->m_bSideIsJoined[pn]) - return false; - - /* subtract coins */ - int iCoinsNeededToJoin = GAMESTATE->GetCoinsNeededToJoin(); - - if( GAMESTATE->m_iCoins < iCoinsNeededToJoin ) - return false; // not enough coins - - GAMESTATE->m_iCoins -= iCoinsNeededToJoin; - - GAMESTATE->JoinPlayer( pn ); - - return true; -} - void Screen::PostScreenMessage( const ScreenMessage SM, float fDelay ) { ASSERT( fDelay >= 0.0 ); diff --git a/stepmania/src/Screen.h b/stepmania/src/Screen.h index 6c11f5486d..00583c1aa2 100644 --- a/stepmania/src/Screen.h +++ b/stepmania/src/Screen.h @@ -56,8 +56,6 @@ public: virtual ScreenType GetScreenType() const { return ALLOW_OPERATOR_MENU_BUTTON ? game_menu : system_menu; } bool AllowOperatorMenuButton() const { return ALLOW_OPERATOR_MENU_BUTTON; } - static bool JoinInput( PlayerNumber pn ); // return true if player joined - // // Lua // diff --git a/stepmania/src/ScreenSelect.cpp b/stepmania/src/ScreenSelect.cpp index f03aeca5ba..05af20afdc 100644 --- a/stepmania/src/ScreenSelect.cpp +++ b/stepmania/src/ScreenSelect.cpp @@ -142,7 +142,7 @@ void ScreenSelect::Input( const InputEventPlus &input ) if( input.MenuI == MENU_BUTTON_COIN && input.type == IET_FIRST_PRESS ) this->UpdateSelectableChoices(); - if( input.MenuI == MENU_BUTTON_START && input.type == IET_FIRST_PRESS && JoinInput(input.pn) ) + if( input.MenuI == MENU_BUTTON_START && input.type == IET_FIRST_PRESS && GAMESTATE->JoinInput(input.pn) ) { // HACK: Only play start sound for the 2nd player who joins. The // start sound for the 1st player will be played by ScreenTitleMenu