separate initializing text and setting m_iChoiceInRowWithFocus

This commit is contained in:
Glenn Maynard
2005-07-15 06:54:10 +00:00
parent ff5f5f4035
commit 618f71f3d4
3 changed files with 60 additions and 45 deletions
+58 -45
View File
@@ -230,52 +230,16 @@ CString OptionRow::GetRowTitle() const
return sTitle;
}
void OptionRow::AfterImportOptions()
/* Set up text, underlines and titles for options. This can be called
* as soon as m_RowDef is available. */
void OptionRow::InitText()
{
// Make all selections the same if bOneChoiceForAllPlayers
// Hack: we only import active players, so if only player 2 is imported,
// we need to copy p2 to p1, not p1 to p2.
if( m_RowDef.m_bOneChoiceForAllPlayers )
{
PlayerNumber pnCopyFrom = GAMESTATE->m_MasterPlayerNumber;
if( GAMESTATE->m_MasterPlayerNumber == PLAYER_INVALID )
pnCopyFrom = PLAYER_1;
FOREACH_PlayerNumber( p )
m_vbSelected[p] = m_vbSelected[pnCopyFrom];
}
/* If we have elements already, we're being updated from a new set of options.
* Delete the old ones. */
m_ItemFrame.DeleteAllChildren();
m_textItems.clear();
FOREACH_PlayerNumber( p )
{
switch( m_RowDef.m_selectType )
{
case SELECT_ONE:
{
/* Make sure the row actually has a selection. */
bool bHasASelection = false;
for( unsigned i=0; i<m_vbSelected[p].size(); i++ )
{
if( m_vbSelected[p][i] )
bHasASelection = true;
}
if( !bHasASelection && !m_vbSelected[p].empty() )
m_vbSelected[p][0] = true;
m_iChoiceInRowWithFocus[p] = GetOneSelection(p, true); // focus on the selection we just set
}
break;
case SELECT_MULTIPLE:
case SELECT_NONE:
m_iChoiceInRowWithFocus[p] = 0;
break;
default:
ASSERT(0);
}
}
// init row icons
FOREACH_HumanPlayer( p )
SetOptionIcon( p, "" );
m_Underline[p].clear();
// If the items will go off the edge of the screen, then re-init with the "long row" style.
{
@@ -398,7 +362,56 @@ void OptionRow::AfterImportOptions()
m_textTitle.RunCommands( LABELS_ON_COMMAND );
m_sprBullet.SetX( ARROWS_X );
}
/* After importing options, choose which item is focused. */
void OptionRow::AfterImportOptions()
{
// Make all selections the same if bOneChoiceForAllPlayers
// Hack: we only import active players, so if only player 2 is imported,
// we need to copy p2 to p1, not p1 to p2.
if( m_RowDef.m_bOneChoiceForAllPlayers )
{
PlayerNumber pnCopyFrom = GAMESTATE->m_MasterPlayerNumber;
if( GAMESTATE->m_MasterPlayerNumber == PLAYER_INVALID )
pnCopyFrom = PLAYER_1;
FOREACH_PlayerNumber( p )
m_vbSelected[p] = m_vbSelected[pnCopyFrom];
}
FOREACH_PlayerNumber( p )
{
switch( m_RowDef.m_selectType )
{
case SELECT_ONE:
{
/* Make sure the row actually has a selection. */
bool bHasASelection = false;
for( unsigned i=0; i<m_vbSelected[p].size(); i++ )
{
if( m_vbSelected[p][i] )
bHasASelection = true;
}
if( !bHasASelection && !m_vbSelected[p].empty() )
m_vbSelected[p][0] = true;
m_iChoiceInRowWithFocus[p] = GetOneSelection(p, true); // focus on the selection we just set
}
break;
case SELECT_MULTIPLE:
case SELECT_NONE:
m_iChoiceInRowWithFocus[p] = 0;
break;
default:
ASSERT(0);
}
}
// init row icons
FOREACH_HumanPlayer( p )
SetOptionIcon( p, "" );
//
// HACK: Set focus to one item in the row, which is "go down"
//
+1
View File
@@ -99,6 +99,7 @@ public:
void ImportOptions( const vector<PlayerNumber> &vpns );
int ExportOptions( const vector<PlayerNumber> &vpns, bool bRowHasFocus[NUM_PLAYERS] );
void InitText();
void AfterImportOptions();
void DetachHandler();
+1
View File
@@ -217,6 +217,7 @@ void ScreenOptions::InitMenu( const vector<OptionRowDefinition> &vDefs, const ve
row.LoadMetrics( m_sName );
row.LoadNormal( def, hand, bFirstRowGoesDown );
row.InitText();
vector<PlayerNumber> vpns;
FOREACH_HumanPlayer( p )