diff --git a/stepmania/src/CourseUtil.cpp b/stepmania/src/CourseUtil.cpp index 670094d654..b95b7f0677 100644 --- a/stepmania/src/CourseUtil.cpp +++ b/stepmania/src/CourseUtil.cpp @@ -11,6 +11,7 @@ #include "Foreach.h" #include "GameState.h" #include "LocalizedString.h" +#include "LuaManager.h" // diff --git a/stepmania/src/DifficultyList.cpp b/stepmania/src/DifficultyList.cpp index 0d1d98b594..b9d0263ace 100644 --- a/stepmania/src/DifficultyList.cpp +++ b/stepmania/src/DifficultyList.cpp @@ -247,67 +247,56 @@ void DifficultyList::SetFromGameState() { const Song *pSong = GAMESTATE->m_pCurSong; - const bool bSongChanged = (pSong != m_CurSong); - - /* If the song has changed, update displays: */ - if( bSongChanged ) + for( int m = 0; m < MAX_METERS; ++m ) { - m_CurSong = pSong; + m_Lines[m].m_Meter.Unset(); + } - for( int m = 0; m < MAX_METERS; ++m ) + m_Rows.clear(); + + if( pSong == NULL ) + { + // FIXME: This clamps to between the min and the max difficulty, but + // it really should round to the nearest difficulty that's in + // DIFFICULTIES_TO_SHOW. + unsigned i=0; + FOREACH_CONST( Difficulty, CommonMetrics::DIFFICULTIES_TO_SHOW.GetValue(), d ) { - m_Lines[m].m_Meter.Unset(); + m_Rows.resize( m_Rows.size()+1 ); + + Row &row = m_Rows.back(); + + row.m_dc = *d; + + m_Lines[i].m_Meter.SetFromStepsTypeAndMeterAndDifficulty( StepsType_Invalid, 0, *d ); + + i++; } + } + else + { + vector vpSteps; + SongUtil::GetPlayableSteps( pSong, vpSteps ); + /* Should match the sort in ScreenSelectMusic::AfterMusicChange. */ - m_Rows.clear(); - - if( pSong == NULL ) + m_Rows.resize( vpSteps.size() ); + for( unsigned i = 0; i < vpSteps.size(); ++i ) { - // FIXME: This clamps to between the min and the max difficulty, but - // it really should round to the nearest difficulty that's in - // DIFFICULTIES_TO_SHOW. - unsigned i=0; - FOREACH_CONST( Difficulty, CommonMetrics::DIFFICULTIES_TO_SHOW.GetValue(), d ) - { - m_Rows.resize( m_Rows.size()+1 ); + Row &row = m_Rows[i]; - Row &row = m_Rows.back(); + row.m_Steps = vpSteps[i]; - row.m_dc = *d; + m_Lines[i].m_Meter.SetFromSteps( m_Rows[i].m_Steps ); - m_Lines[i].m_Meter.SetFromStepsTypeAndMeterAndDifficulty( StepsType_Invalid, 0, *d ); - - i++; - } - } - else - { - vector vpSteps; - SongUtil::GetPossibleSteps( pSong, vpSteps ); - /* Should match the sort in ScreenSelectMusic::AfterMusicChange. */ - - m_Rows.resize( vpSteps.size() ); - for( unsigned i = 0; i < vpSteps.size(); ++i ) - { - Row &row = m_Rows[i]; - - row.m_Steps = vpSteps[i]; - - m_Lines[i].m_Meter.SetFromSteps( m_Rows[i].m_Steps ); - - row.m_dc = row.m_Steps->GetDifficulty(); - } + row.m_dc = row.m_Steps->GetDifficulty(); } } UpdatePositions(); PositionItems(); - if( bSongChanged ) - { - for( int m = 0; m < MAX_METERS; ++m ) - m_Lines[m].m_Meter.FinishTweening(); - } + for( int m = 0; m < MAX_METERS; ++m ) + m_Lines[m].m_Meter.FinishTweening(); } void DifficultyList::HideRows() diff --git a/stepmania/src/GameManager.cpp b/stepmania/src/GameManager.cpp index 66a4d6bd36..baea4bbf9f 100644 --- a/stepmania/src/GameManager.cpp +++ b/stepmania/src/GameManager.cpp @@ -2340,21 +2340,23 @@ void GameManager::GetCompatibleStyles( const Game *pGame, int iNumPlayers, vecto { FOREACH_ENUM( StyleType, styleType ) { + int iNumPlayersRequired; switch( styleType ) { DEFAULT_FAIL( styleType ); case StyleType_OnePlayerOneSide: case StyleType_OnePlayerTwoSides: - if( iNumPlayers != 1 ) - continue; + iNumPlayersRequired = 1; break; case StyleType_TwoPlayersTwoSides: case StyleType_TwoPlayersSharedSides: - if( iNumPlayers != 2 ) - continue; + iNumPlayersRequired = 2; break; } + if( iNumPlayers != iNumPlayersRequired ) + continue; + for( unsigned s=0; sm_pCurSteps[p] != NULL ) { vector vpPossibleSteps; - SongUtil::GetPossibleSteps( GAMESTATE->m_pCurSong, vpPossibleSteps ); + SongUtil::GetPlayableSteps( GAMESTATE->m_pCurSong, vpPossibleSteps ); bool bStepsIsPossible = find( vpPossibleSteps.begin(), vpPossibleSteps.end(), GAMESTATE->m_pCurSteps[p] ) == vpPossibleSteps.end(); if( !bStepsIsPossible ) GAMESTATE->m_pCurSteps[p].Set( NULL ); diff --git a/stepmania/src/ScreenSelectMusic.cpp b/stepmania/src/ScreenSelectMusic.cpp index 707b715796..3239e64491 100644 --- a/stepmania/src/ScreenSelectMusic.cpp +++ b/stepmania/src/ScreenSelectMusic.cpp @@ -298,6 +298,9 @@ void ScreenSelectMusic::Input( const InputEventPlus &input ) // Handle late joining if( input.MenuI == MENU_BUTTON_START && input.type == IET_FIRST_PRESS && GAMESTATE->JoinInput(input.pn) ) { + // refresh the steps list so that 2-side StepsTypes will be removed since they're no longer playable + AfterMusicChange(); + int iSel = 0; PlayerNumber pn = input.pn; m_iSelection[pn] = iSel; @@ -311,6 +314,7 @@ void ScreenSelectMusic::Input( const InputEventPlus &input ) Steps* pSteps = m_vpSteps.empty()? NULL: m_vpSteps[m_iSelection[pn]]; GAMESTATE->m_pCurSteps[pn].Set( pSteps ); } + return; // don't handle this press again below } @@ -1058,7 +1062,7 @@ void ScreenSelectMusic::AfterMusicChange() m_fSampleStartSeconds = pSong->m_fMusicSampleStartSeconds; m_fSampleLengthSeconds = pSong->m_fMusicSampleLengthSeconds; - SongUtil::GetPossibleSteps( pSong, m_vpSteps ); + SongUtil::GetPlayableSteps( pSong, m_vpSteps ); if ( PREFSMAN->m_bShowBanners ) g_sBannerPath = pSong->GetBannerPath(); diff --git a/stepmania/src/SongUtil.cpp b/stepmania/src/SongUtil.cpp index ee5b886a66..ef5b50094c 100644 --- a/stepmania/src/SongUtil.cpp +++ b/stepmania/src/SongUtil.cpp @@ -16,6 +16,8 @@ #include "RageLog.h" #include "GameManager.h" #include "CommonMetrics.h" +#include "LuaBinding.h" +#include "EnumHelper.h" bool SongCriteria::Matches( const Song *pSong ) const { @@ -810,30 +812,35 @@ void SongUtil::FilterSongs( const SongCriteria &sc, const vector &in, vec } } -void SongUtil::GetPossibleSteps( const Song *pSong, vector &vOut ) +static void GetPlayableStepsTypes( set &vOut ) { vector vpPossibleStyles; if( CommonMetrics::ALL_STEPS_TYPES_IN_ONE_LIST ) GAMEMAN->GetCompatibleStyles( GAMESTATE->m_pCurGame, GAMESTATE->GetNumPlayersEnabled(), vpPossibleStyles ); else vpPossibleStyles.push_back( GAMESTATE->m_pCurStyle ); - set vStepsType; FOREACH( const Style*, vpPossibleStyles, s ) - vStepsType.insert( (*s)->m_StepsType ); + vOut.insert( (*s)->m_StepsType ); // filter out hidden StepsTypes const vector &vstToShow = CommonMetrics::STEPS_TYPES_TO_SHOW.GetValue(); - FOREACHS( StepsType, vStepsType, st ) + FOREACHS( StepsType, vOut, st ) { bool bShowThis = find( vstToShow.begin(), vstToShow.end(), *st ) != vstToShow.end(); if( !bShowThis ) { set::iterator to_erase = st; ++st; - vStepsType.erase( to_erase ); + vOut.erase( to_erase ); --st; } } +} + +void SongUtil::GetPlayableSteps( const Song *pSong, vector &vOut ) +{ + set vStepsType; + GetPlayableStepsTypes( vStepsType ); FOREACHS( StepsType, vStepsType, st ) SongUtil::GetSteps( pSong, vOut, *st ); @@ -853,6 +860,13 @@ void SongUtil::GetPossibleSteps( const Song *pSong, vector &vOut ) } } +bool SongUtil::IsStepsTypePlayable( StepsType st ) +{ + set vStepsType; + GetPlayableStepsTypes( vStepsType ); + return vStepsType.find( st ) != vStepsType.end(); +} + ////////////////////////////////// // SongID ////////////////////////////////// @@ -906,6 +920,29 @@ bool SongID::IsValid() const return !sDir.empty(); } +// lua start +#include "LuaBinding.h" + +namespace +{ + int IsStepsTypePlayable( lua_State *L ) + { + StepsType st = Enum::Check(L, 1); + bool b = SongUtil::IsStepsTypePlayable( st ); + LuaHelpers::Push( L, b ); + return 1; + } + + const luaL_Reg SongUtilTable[] = + { + LIST_METHOD( IsStepsTypePlayable ), + { NULL, NULL } + }; +} + +LUA_REGISTER_NAMESPACE( SongUtil ) + + /* * (c) 2001-2004 Chris Danford, Glenn Maynard * All rights reserved. diff --git a/stepmania/src/SongUtil.h b/stepmania/src/SongUtil.h index 1216f568cd..2a2f1e6178 100644 --- a/stepmania/src/SongUtil.h +++ b/stepmania/src/SongUtil.h @@ -110,7 +110,8 @@ namespace SongUtil void GetAllSongGenres( vector &vsOut ); void FilterSongs( const SongCriteria &sc, const vector &in, vector &out ); - void GetPossibleSteps( const Song *pSong, vector &vOut ); + void GetPlayableSteps( const Song *pSong, vector &vOut ); + bool IsStepsTypePlayable( StepsType st ); } class SongID