From cf80f30e3b20143b9ee5f4b851963a8692610751 Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Sun, 4 Mar 2007 08:52:06 +0000 Subject: [PATCH] beginnings of late join --- stepmania/Themes/default/metrics.ini | 1 + stepmania/src/GameState.cpp | 26 ++++++++++++++++++++++---- stepmania/src/Screen.h | 1 + stepmania/src/ScreenSelect.cpp | 2 +- stepmania/src/ScreenSelectMaster.h | 1 + stepmania/src/ScreenSelectMusic.cpp | 20 ++++++++++++++++---- stepmania/src/ScreenSelectMusic.h | 1 + 7 files changed, 43 insertions(+), 9 deletions(-) diff --git a/stepmania/Themes/default/metrics.ini b/stepmania/Themes/default/metrics.ini index 7c3abb135b..c678767269 100644 --- a/stepmania/Themes/default/metrics.ini +++ b/stepmania/Themes/default/metrics.ini @@ -3909,6 +3909,7 @@ AreStagePlayerModsForced=AreStagePlayerModsForced AreStageSongModsForced=AreStageSongModsForced GradeTierForExtra1="Grade_Tier03" GradeTierForExtra2="Grade_Tier03" +AllowLateJoin=false [ScreenMiniMenuContext] Fallback="ScreenMiniMenu" diff --git a/stepmania/src/GameState.cpp b/stepmania/src/GameState.cpp index 28467dfb31..a5c76cf8c9 100644 --- a/stepmania/src/GameState.cpp +++ b/stepmania/src/GameState.cpp @@ -35,6 +35,8 @@ #include "Style.h" #include "ThemeManager.h" #include "UnlockManager.h" +#include "ScreenManager.h" +#include "Screen.h" #include #include @@ -76,6 +78,7 @@ struct GameStateImpl }; static GameStateImpl *g_pImpl = NULL; +ThemeMetric ALLOW_LATE_JOIN("GameState","AllowLateJoin"); ThemeMetric USE_NAME_BLACKLIST("GameState","UseNameBlacklist"); ThemeMetric DEFAULT_SORT ("GameState","DefaultSort"); @@ -317,9 +320,6 @@ void GameState::Reset() void GameState::JoinPlayer( PlayerNumber pn ) { m_bSideIsJoined[pn] = true; - Message msg( MessageIDToString(Message_PlayerJoined) ); - msg.SetParam( "Player", pn ); - MESSAGEMAN->Broadcast( msg ); if( m_MasterPlayerNumber == PLAYER_INVALID ) m_MasterPlayerNumber = pn; @@ -327,6 +327,17 @@ void GameState::JoinPlayer( PlayerNumber pn ) // if first player to join, set start time if( GetNumSidesJoined() == 1 ) BeginGame(); + + // Set the current style to something appropriate for the new number of joined players. + if( ALLOW_LATE_JOIN && GAMESTATE->m_pCurStyle != NULL ) + { + const Style *pStyle = GAMEMAN->GetFirstCompatibleStyle( m_pCurGame, GetNumSidesJoined(), m_pCurStyle->m_StepsType ); + GAMESTATE->m_pCurStyle.Set( pStyle ); + } + + Message msg( MessageIDToString(Message_PlayerJoined) ); + msg.SetParam( "Player", pn ); + MESSAGEMAN->Broadcast( msg ); } /* Handle an input that can join a player. Return true if the player joined. */ @@ -906,7 +917,14 @@ RString GameState::GetPlayerDisplayName( PlayerNumber pn ) const bool GameState::PlayersCanJoin() const { - return GetNumSidesJoined() == 0 || GetCurrentStyle() == NULL; // selecting a style finalizes the players + bool b = GetNumSidesJoined() == 0 || GetCurrentStyle() == NULL; // selecting a style finalizes the players + if( ALLOW_LATE_JOIN.IsLoaded() && ALLOW_LATE_JOIN ) + { + Screen *pScreen = SCREENMAN->GetTopScreen(); + if( pScreen ) + b |= pScreen->AllowLateJoin(); + } + return b; } int GameState::GetNumSidesJoined() const diff --git a/stepmania/src/Screen.h b/stepmania/src/Screen.h index 00583c1aa2..3a98386e3b 100644 --- a/stepmania/src/Screen.h +++ b/stepmania/src/Screen.h @@ -55,6 +55,7 @@ public: virtual ScreenType GetScreenType() const { return ALLOW_OPERATOR_MENU_BUTTON ? game_menu : system_menu; } bool AllowOperatorMenuButton() const { return ALLOW_OPERATOR_MENU_BUTTON; } + virtual bool AllowLateJoin() const { return false; } // // Lua diff --git a/stepmania/src/ScreenSelect.cpp b/stepmania/src/ScreenSelect.cpp index 4521b249a6..93535f45dc 100644 --- a/stepmania/src/ScreenSelect.cpp +++ b/stepmania/src/ScreenSelect.cpp @@ -134,7 +134,7 @@ void ScreenSelect::Input( const InputEventPlus &input ) { // LOG->Trace( "ScreenSelect::Input()" ); - /* Reset the demonstration timer when a key is pressed. */ + /* Reset the announcer timers when a key is pressed. */ m_timerIdleComment.GetDeltaTime(); m_timerIdleTimeout.GetDeltaTime(); diff --git a/stepmania/src/ScreenSelectMaster.h b/stepmania/src/ScreenSelectMaster.h index 7b6b3d07c2..b2379c9293 100644 --- a/stepmania/src/ScreenSelectMaster.h +++ b/stepmania/src/ScreenSelectMaster.h @@ -38,6 +38,7 @@ public: virtual void TweenOffScreen(); virtual void HandleScreenMessage( const ScreenMessage SM ); + virtual bool AllowLateJoin() const { return true; } protected: enum Page { PAGE_1, PAGE_2, NUM_PAGES }; // on PAGE_2, cursors are locked together diff --git a/stepmania/src/ScreenSelectMusic.cpp b/stepmania/src/ScreenSelectMusic.cpp index 79a373c86e..7c1c4def3f 100644 --- a/stepmania/src/ScreenSelectMusic.cpp +++ b/stepmania/src/ScreenSelectMusic.cpp @@ -147,7 +147,7 @@ void ScreenSelectMusic::Init() COMMAND( m_sprCDTitleBack, "Back" ); this->AddChild( &m_sprCDTitleBack ); - FOREACH_HumanPlayer( p ) + FOREACH_ENUM( PlayerNumber, p ) { m_sprHighScoreFrame[p].SetName( ssprintf("ScoreFrameP%d",p+1) ); m_sprHighScoreFrame[p].Load( THEME->GetPathG(m_sName,ssprintf("score frame p%d",p+1)) ); @@ -287,6 +287,18 @@ void ScreenSelectMusic::Input( const InputEventPlus &input ) { // LOG->Trace( "ScreenSelectMusic::Input()" ); + + if( input.MenuI == MENU_BUTTON_START && input.type == IET_FIRST_PRESS && GAMESTATE->JoinInput(input.pn) ) + { + + int iSel = 0; + m_iSelection[input.pn] = iSel; + SwitchToPreferredDifficulty(); + return; // don't handle this press again below + } + + + // temp Chris debug if( input.DeviceI.device == DEVICE_KEYBOARD && input.DeviceI.button == KEY_F8 ) { @@ -432,7 +444,7 @@ void ScreenSelectMusic::Input( const InputEventPlus &input ) bool bLeftIsDown = false; bool bRightIsDown = false; - FOREACH_EnabledPlayer( p ) + FOREACH_HumanPlayer( p ) { bLeftIsDown |= INPUTMAPPER->IsBeingPressed( m_GameButtonPreviousSong, p ); bRightIsDown |= INPUTMAPPER->IsBeingPressed( m_GameButtonNextSong, p ); @@ -540,7 +552,7 @@ bool ScreenSelectMusic::DetectCodes( const InputEventPlus &input ) void ScreenSelectMusic::UpdateSelectButton() { bool bSelectIsDown = false; - FOREACH_EnabledPlayer( pn ) + FOREACH_HumanPlayer( pn ) bSelectIsDown |= INPUTMAPPER->IsBeingPressed( MENU_BUTTON_SELECT, pn ); if( !SELECT_MENU_AVAILABLE ) bSelectIsDown = false; @@ -590,7 +602,7 @@ void ScreenSelectMusic::ChangeDifficulty( PlayerNumber pn, int dir ) } vector vpns; - FOREACH_HumanPlayer( p ) + FOREACH_ENUM( PlayerNumber, p ) { if( pn == p || GAMESTATE->DifficultiesLocked() ) { diff --git a/stepmania/src/ScreenSelectMusic.h b/stepmania/src/ScreenSelectMusic.h index 90a5836d78..0d90c40ec3 100644 --- a/stepmania/src/ScreenSelectMusic.h +++ b/stepmania/src/ScreenSelectMusic.h @@ -27,6 +27,7 @@ public: virtual void Update( float fDeltaTime ); virtual void Input( const InputEventPlus &input ); virtual void HandleScreenMessage( const ScreenMessage SM ); + virtual bool AllowLateJoin() const { return true; } virtual void MenuStart( const InputEventPlus &input ); virtual void MenuBack( const InputEventPlus &input );