OptionRow::Reload doesn't take an OptionRowDefinition.
Implement Reload() explicitly, so we can clearly short- circuit for static rows. Fix up ScreenOptionsEditCourseEntry (broken during the course of things).
This commit is contained in:
@@ -877,7 +877,7 @@ void OptionRow::SetExitText( CString sExitText )
|
|||||||
bt->SetText( sExitText );
|
bt->SetText( sExitText );
|
||||||
}
|
}
|
||||||
|
|
||||||
void OptionRow::Reload( const OptionRowDefinition &def )
|
void OptionRow::Reload()
|
||||||
{
|
{
|
||||||
switch( GetRowType() )
|
switch( GetRowType() )
|
||||||
{
|
{
|
||||||
@@ -895,10 +895,8 @@ void OptionRow::Reload( const OptionRowDefinition &def )
|
|||||||
// ExportOptions( vpns, bRowHasFocus );
|
// ExportOptions( vpns, bRowHasFocus );
|
||||||
//}
|
//}
|
||||||
|
|
||||||
if( m_pHand == NULL )
|
if( !m_pHand->Reload() )
|
||||||
m_pHand->m_Def = def;
|
break;
|
||||||
else
|
|
||||||
m_pHand->Reload();
|
|
||||||
m_pHand->m_Def = m_pHand->m_Def;
|
m_pHand->m_Def = m_pHand->m_Def;
|
||||||
ASSERT( !m_pHand->m_Def.m_vsChoices.empty() );
|
ASSERT( !m_pHand->m_Def.m_vsChoices.empty() );
|
||||||
|
|
||||||
@@ -953,7 +951,7 @@ void OptionRow::Reload( const OptionRowDefinition &def )
|
|||||||
|
|
||||||
void OptionRow::HandleMessage( const CString& sMessage )
|
void OptionRow::HandleMessage( const CString& sMessage )
|
||||||
{
|
{
|
||||||
Reload( m_pHand->m_Def );
|
Reload();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -189,7 +189,7 @@ public:
|
|||||||
|
|
||||||
void SetExitText( CString sExitText );
|
void SetExitText( CString sExitText );
|
||||||
|
|
||||||
void Reload( const OptionRowDefinition &def );
|
void Reload();
|
||||||
|
|
||||||
//
|
//
|
||||||
// Messages
|
// Messages
|
||||||
|
|||||||
@@ -32,7 +32,19 @@ public:
|
|||||||
this->LoadInternal( cmds );
|
this->LoadInternal( cmds );
|
||||||
}
|
}
|
||||||
virtual void LoadInternal( const Commands &cmds ) = 0;
|
virtual void LoadInternal( const Commands &cmds ) = 0;
|
||||||
virtual void Reload() { this->Load(m_cmds); }
|
|
||||||
|
/*
|
||||||
|
* We may re-use OptionRowHandlers. This is called before each
|
||||||
|
* use. If the contents of the row are dependent on external
|
||||||
|
* state (for example, the current song), clear the row contents
|
||||||
|
* and reinitialize them. As an optimization, rows which do not
|
||||||
|
* change can be initialized just once and left alone.
|
||||||
|
*
|
||||||
|
* If the row has been reinitialized, return true, and the graphic
|
||||||
|
* elements will also be reinitialized. If the row is static, and
|
||||||
|
* nothing has changed, return false.
|
||||||
|
*/
|
||||||
|
virtual bool Reload() { return false; }
|
||||||
virtual void ImportOption( const OptionRowDefinition &row, const vector<PlayerNumber> &vpns, vector<bool> vbSelectedOut[NUM_PLAYERS] ) const = 0;
|
virtual void ImportOption( const OptionRowDefinition &row, const vector<PlayerNumber> &vpns, vector<bool> vbSelectedOut[NUM_PLAYERS] ) const = 0;
|
||||||
/* Returns an OPT mask. */
|
/* Returns an OPT mask. */
|
||||||
virtual int ExportOption( const OptionRowDefinition &def, const vector<PlayerNumber> &vpns, const vector<bool> vbSelected[NUM_PLAYERS] ) const = 0;
|
virtual int ExportOption( const OptionRowDefinition &def, const vector<PlayerNumber> &vpns, const vector<bool> vbSelected[NUM_PLAYERS] ) const = 0;
|
||||||
|
|||||||
@@ -46,23 +46,61 @@ static void FillSongsAndChoices( const CString &sSongGroup, vector<Song*> &vpSon
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class OptionRowHandlerSongChoices: public OptionRowHandler
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
// corresponds with m_vsChoices:
|
||||||
|
vector<Song*> m_vpDisplayedSongs;
|
||||||
|
CString m_sSongGroup;
|
||||||
|
|
||||||
|
OptionRowHandlerSongChoices() { Init(); }
|
||||||
|
void Init()
|
||||||
|
{
|
||||||
|
OptionRowHandler::Init();
|
||||||
|
m_vpDisplayedSongs.clear();
|
||||||
|
}
|
||||||
|
virtual void LoadInternal( const Commands &cmds )
|
||||||
|
{
|
||||||
|
FillSongsAndChoices( m_sSongGroup, m_vpDisplayedSongs, m_Def.m_vsChoices );
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual bool Reload()
|
||||||
|
{
|
||||||
|
FillSongsAndChoices( m_sSongGroup, m_vpDisplayedSongs, m_Def.m_vsChoices );
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void ImportOption( const OptionRowDefinition &row, const vector<PlayerNumber> &vpns, vector<bool> vbSelectedOut[NUM_PLAYERS] ) const
|
||||||
|
{
|
||||||
|
vector<Song*>::const_iterator iter = find( m_vpDisplayedSongs.begin(), m_vpDisplayedSongs.end(), GAMESTATE->m_pCurSong );
|
||||||
|
int iChoice = 0;
|
||||||
|
if( iter != m_vpDisplayedSongs.end() )
|
||||||
|
iChoice = iter - m_vpDisplayedSongs.begin();
|
||||||
|
FOREACH_PlayerNumber(pn)
|
||||||
|
vbSelectedOut[pn][iChoice] = true;
|
||||||
|
}
|
||||||
|
virtual int ExportOption( const OptionRowDefinition &def, const vector<PlayerNumber> &vpns, const vector<bool> vbSelected[NUM_PLAYERS] ) const
|
||||||
|
{
|
||||||
|
for( size_t iChoice = 0; iChoice < vbSelected[PLAYER_1].size(); ++iChoice )
|
||||||
|
{
|
||||||
|
if( vbSelected[PLAYER_1][iChoice] )
|
||||||
|
{
|
||||||
|
GAMESTATE->m_pCurSong.Set( m_vpDisplayedSongs[iChoice] );
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
REGISTER_SCREEN_CLASS( ScreenOptionsEditCourseEntry );
|
REGISTER_SCREEN_CLASS( ScreenOptionsEditCourseEntry );
|
||||||
|
|
||||||
void ScreenOptionsEditCourseEntry::Init()
|
void ScreenOptionsEditCourseEntry::Init()
|
||||||
{
|
{
|
||||||
ScreenOptions::Init();
|
ScreenOptions::Init();
|
||||||
}
|
|
||||||
|
|
||||||
void ScreenOptionsEditCourseEntry::BeginScreen()
|
|
||||||
{
|
|
||||||
// save a backup that we'll use if we revert.
|
|
||||||
Course *pCourse = GAMESTATE->m_pCurCourse;
|
|
||||||
const CourseEntry &ce = pCourse->m_vEntries[ GAMESTATE->m_iEditCourseEntryIndex ];
|
|
||||||
m_Original = ce;
|
|
||||||
|
|
||||||
|
|
||||||
vector<OptionRowHandler*> vHands;
|
vector<OptionRowHandler*> vHands;
|
||||||
|
|
||||||
OptionRowHandler *pHand = OptionRowHandlerUtil::MakeNull();
|
OptionRowHandler *pHand = OptionRowHandlerUtil::MakeNull();
|
||||||
pHand->m_Def.m_sName = "Song Group";
|
pHand->m_Def.m_sName = "Song Group";
|
||||||
pHand->m_Def.m_layoutType = LAYOUT_SHOW_ONE_IN_ROW;
|
pHand->m_Def.m_layoutType = LAYOUT_SHOW_ONE_IN_ROW;
|
||||||
@@ -75,13 +113,15 @@ void ScreenOptionsEditCourseEntry::BeginScreen()
|
|||||||
pHand->m_Def.m_vsChoices.push_back( *song );
|
pHand->m_Def.m_vsChoices.push_back( *song );
|
||||||
vHands.push_back( pHand );
|
vHands.push_back( pHand );
|
||||||
|
|
||||||
pHand = OptionRowHandlerUtil::MakeNull();
|
{
|
||||||
pHand->m_Def.m_sName = "Song";
|
m_pSongHandler = new OptionRowHandlerSongChoices;
|
||||||
pHand->m_Def.m_layoutType = LAYOUT_SHOW_ONE_IN_ROW;
|
// m_pSongHandler->m_sSongGroup = ce.sSongGroup;
|
||||||
pHand->m_Def.m_bExportOnChange = true;
|
m_pSongHandler->Load( Commands() );
|
||||||
pHand->m_Def.m_vsChoices.clear();
|
m_pSongHandler->m_Def.m_sName = "Song";
|
||||||
FillSongsAndChoices( ce.sSongGroup, m_vpDisplayedSongs, pHand->m_Def.m_vsChoices );
|
m_pSongHandler->m_Def.m_layoutType = LAYOUT_SHOW_ONE_IN_ROW;
|
||||||
vHands.push_back( pHand );
|
m_pSongHandler->m_Def.m_bExportOnChange = true;
|
||||||
|
vHands.push_back( m_pSongHandler );
|
||||||
|
}
|
||||||
|
|
||||||
pHand = OptionRowHandlerUtil::MakeNull();
|
pHand = OptionRowHandlerUtil::MakeNull();
|
||||||
pHand->m_Def.m_sName = "Base Difficulty";
|
pHand->m_Def.m_sName = "Base Difficulty";
|
||||||
@@ -131,16 +171,29 @@ void ScreenOptionsEditCourseEntry::BeginScreen()
|
|||||||
pHand->m_Def.m_vsChoices.push_back( FormatNumberAndSuffix(i+1) );
|
pHand->m_Def.m_vsChoices.push_back( FormatNumberAndSuffix(i+1) );
|
||||||
vHands.push_back( pHand );
|
vHands.push_back( pHand );
|
||||||
|
|
||||||
pHand = OptionRowHandlerUtil::MakeNull();
|
m_pModChangesHandler = OptionRowHandlerUtil::MakeNull();
|
||||||
pHand->m_Def.m_sName = "Set Mods";
|
m_pModChangesHandler->m_Def.m_sName = "Set Mods";
|
||||||
pHand->m_Def.m_layoutType = LAYOUT_SHOW_ONE_IN_ROW;
|
m_pModChangesHandler->m_Def.m_layoutType = LAYOUT_SHOW_ONE_IN_ROW;
|
||||||
pHand->m_Def.m_bExportOnChange = true;
|
m_pModChangesHandler->m_Def.m_bExportOnChange = true;
|
||||||
pHand->m_Def.m_vsChoices.clear();
|
m_pModChangesHandler->m_Def.m_vsChoices.clear();
|
||||||
CString s = ssprintf( "%d mod changes", ce.GetNumModChanges() );
|
m_pModChangesHandler->m_Def.m_vsChoices.push_back( "" );
|
||||||
pHand->m_Def.m_vsChoices.push_back( s );
|
vHands.push_back( m_pModChangesHandler );
|
||||||
vHands.push_back( pHand );
|
|
||||||
|
|
||||||
ScreenOptions::InitMenu( vHands );
|
ScreenOptions::InitMenu( vHands );
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScreenOptionsEditCourseEntry::BeginScreen()
|
||||||
|
{
|
||||||
|
// save a backup that we'll use if we revert.
|
||||||
|
const Course *pCourse = GAMESTATE->m_pCurCourse;
|
||||||
|
const CourseEntry &ce = pCourse->m_vEntries[ GAMESTATE->m_iEditCourseEntryIndex ];
|
||||||
|
m_Original = ce;
|
||||||
|
|
||||||
|
|
||||||
|
m_pSongHandler->m_sSongGroup = ce.sSongGroup;
|
||||||
|
|
||||||
|
CString s = ssprintf( "%d mod changes", ce.GetNumModChanges() );
|
||||||
|
m_pModChangesHandler->m_Def.m_vsChoices[0] = s;
|
||||||
|
|
||||||
ScreenOptions::BeginScreen();
|
ScreenOptions::BeginScreen();
|
||||||
}
|
}
|
||||||
@@ -214,22 +267,12 @@ void ScreenOptionsEditCourseEntry::AfterChangeValueInRow( int iRow, PlayerNumber
|
|||||||
vpns.push_back( PLAYER_1 );
|
vpns.push_back( PLAYER_1 );
|
||||||
ExportOptions( ROW_SONG_GROUP, vpns );
|
ExportOptions( ROW_SONG_GROUP, vpns );
|
||||||
|
|
||||||
|
m_pSongHandler->m_sSongGroup = ce.sSongGroup;
|
||||||
|
|
||||||
OptionRow &row = *m_pRows[ROW_SONG];
|
OptionRow &row = *m_pRows[ROW_SONG];
|
||||||
OptionRowDefinition def = row.GetRowDef();
|
row.Reload();
|
||||||
FillSongsAndChoices( ce.sSongGroup, m_vpDisplayedSongs, def.m_vsChoices );
|
ImportOptions( ROW_SONG, vpns );
|
||||||
|
row.AfterImportOptions();
|
||||||
row.Reload( def );
|
|
||||||
|
|
||||||
vector<Song*>::const_iterator iter = find( m_vpDisplayedSongs.begin(), m_vpDisplayedSongs.end(), ce.pSong );
|
|
||||||
if( iter == m_vpDisplayedSongs.end() )
|
|
||||||
{
|
|
||||||
this->ChangeValueInRowAbsolute( ROW_SONG, PLAYER_1, 0, false );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
int iSongIndex = iter - m_vpDisplayedSongs.begin();
|
|
||||||
this->ChangeValueInRowAbsolute( ROW_SONG, PLAYER_1, iSongIndex, false );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -266,12 +309,13 @@ void ScreenOptionsEditCourseEntry::ImportOptions( int iRow, const vector<PlayerN
|
|||||||
break;
|
break;
|
||||||
case ROW_SONG:
|
case ROW_SONG:
|
||||||
{
|
{
|
||||||
vector<Song*>::const_iterator iter = find( m_vpDisplayedSongs.begin(), m_vpDisplayedSongs.end(), ce.pSong );
|
GAMESTATE->m_pCurSong.Set( ce.pSong );
|
||||||
int iChoice = 0;
|
|
||||||
if( iter != m_vpDisplayedSongs.end() )
|
// XXX: copy and pasted from ScreenOptionsMaster
|
||||||
iChoice = iter - m_vpDisplayedSongs.begin();
|
FOREACH_CONST( PlayerNumber, vpns, pn )
|
||||||
OptionRow &row = *m_pRows[ROW_SONG];
|
ASSERT( GAMESTATE->IsHumanPlayer(*pn) );
|
||||||
row.SetOneSharedSelection( iChoice );
|
OptionRow &row = *m_pRows[iRow];
|
||||||
|
row.ImportOptions( vpns );
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ROW_BASE_DIFFICULTY:
|
case ROW_BASE_DIFFICULTY:
|
||||||
@@ -339,9 +383,18 @@ void ScreenOptionsEditCourseEntry::ExportOptions( int iRow, const vector<PlayerN
|
|||||||
break;
|
break;
|
||||||
case ROW_SONG:
|
case ROW_SONG:
|
||||||
{
|
{
|
||||||
OptionRow &row = *m_pRows[ROW_SONG];
|
// XXX: copy and pasted from ScreenOptionsMaster
|
||||||
int iChoice = row.GetChoiceInRowWithFocus( GAMESTATE->m_MasterPlayerNumber );
|
OptionRow &row = *m_pRows[iRow];
|
||||||
ce.pSong = m_vpDisplayedSongs[iChoice];
|
bool bRowHasFocus[NUM_PLAYERS];
|
||||||
|
ZERO( bRowHasFocus );
|
||||||
|
FOREACH_CONST( PlayerNumber, vpns, p )
|
||||||
|
{
|
||||||
|
int iCurRow = m_iCurrentRow[*p];
|
||||||
|
bRowHasFocus[*p] = iCurRow == iRow;
|
||||||
|
}
|
||||||
|
row.ExportOptions( vpns, bRowHasFocus );
|
||||||
|
|
||||||
|
ce.pSong = GAMESTATE->m_pCurSong;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ROW_BASE_DIFFICULTY:
|
case ROW_BASE_DIFFICULTY:
|
||||||
|
|||||||
@@ -5,6 +5,8 @@
|
|||||||
#include "Course.h"
|
#include "Course.h"
|
||||||
class Song;
|
class Song;
|
||||||
|
|
||||||
|
class OptionRowHandler;
|
||||||
|
class OptionRowHandlerSongChoices;
|
||||||
class ScreenOptionsEditCourseEntry : public ScreenOptionsEditCourseSubMenu
|
class ScreenOptionsEditCourseEntry : public ScreenOptionsEditCourseSubMenu
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -14,6 +16,8 @@ public:
|
|||||||
virtual void HandleScreenMessage( const ScreenMessage SM );
|
virtual void HandleScreenMessage( const ScreenMessage SM );
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
OptionRowHandler *m_pModChangesHandler;
|
||||||
|
OptionRowHandlerSongChoices *m_pSongHandler;
|
||||||
|
|
||||||
virtual void ImportOptions( int iRow, const vector<PlayerNumber> &vpns );
|
virtual void ImportOptions( int iRow, const vector<PlayerNumber> &vpns );
|
||||||
virtual void ExportOptions( int iRow, const vector<PlayerNumber> &vpns );
|
virtual void ExportOptions( int iRow, const vector<PlayerNumber> &vpns );
|
||||||
@@ -21,8 +25,6 @@ protected:
|
|||||||
virtual void AfterChangeValueInRow( int iRow, PlayerNumber pn );
|
virtual void AfterChangeValueInRow( int iRow, PlayerNumber pn );
|
||||||
virtual void ProcessMenuStart( const InputEventPlus &input );
|
virtual void ProcessMenuStart( const InputEventPlus &input );
|
||||||
|
|
||||||
vector<Song*> m_vpDisplayedSongs; // corresponds with the choices in the Song row
|
|
||||||
|
|
||||||
CourseEntry m_Original; // use this to revert when cancelling
|
CourseEntry m_Original; // use this to revert when cancelling
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user