Make a OptionRow own its own definition
This commit is contained in:
@@ -123,15 +123,19 @@ void ScreenOptions::Init( InputMode im, OptionRow OptionRows[], int iNumOptionLi
|
||||
LOG->Trace( "ScreenOptions::Set()" );
|
||||
|
||||
m_InputMode = im;
|
||||
m_OptionRow = OptionRows;
|
||||
m_iNumOptionRows = iNumOptionLines;
|
||||
|
||||
this->ImportOptions();
|
||||
|
||||
for( int l=0; l<m_iNumOptionRows; l++ )
|
||||
if( m_OptionRow[l].bOneChoiceForAllPlayers )
|
||||
m_iSelectedOption[PLAYER_2][l] = m_iSelectedOption[PLAYER_1][l];
|
||||
int r;
|
||||
for( r=0; r<iNumOptionLines; r++ ) // foreach row
|
||||
{
|
||||
m_Rows.push_back( new Row() );
|
||||
m_Rows[r]->m_RowDef = OptionRows[r];
|
||||
|
||||
if( m_Rows[r]->m_RowDef.bOneChoiceForAllPlayers )
|
||||
for( int p=1; p<NUM_PLAYERS; p++ )
|
||||
m_iSelectedOption[0][r] = m_iSelectedOption[p][r];
|
||||
}
|
||||
|
||||
|
||||
int p;
|
||||
@@ -157,11 +161,6 @@ void ScreenOptions::Init( InputMode im, OptionRow OptionRows[], int iNumOptionLi
|
||||
m_framePage.AddChild( &m_Highlight[p] );
|
||||
}
|
||||
|
||||
int r;
|
||||
for( r=0; r<m_iNumOptionRows; r++ ) // foreach row
|
||||
{
|
||||
m_Rows.push_back( new Row() );
|
||||
}
|
||||
|
||||
// init underlines
|
||||
for( p=0; p<NUM_PLAYERS; p++ )
|
||||
@@ -169,7 +168,7 @@ void ScreenOptions::Init( InputMode im, OptionRow OptionRows[], int iNumOptionLi
|
||||
if( !GAMESTATE->IsHumanPlayer(p) )
|
||||
continue; // skip
|
||||
|
||||
for( int l=0; l<m_iNumOptionRows; l++ )
|
||||
for( unsigned l=0; l<m_Rows.size(); l++ )
|
||||
{
|
||||
Row &row = *m_Rows[l];
|
||||
|
||||
@@ -182,13 +181,13 @@ void ScreenOptions::Init( InputMode im, OptionRow OptionRows[], int iNumOptionLi
|
||||
}
|
||||
|
||||
// init m_textItems from optionLines
|
||||
for( r=0; r<m_iNumOptionRows; r++ ) // foreach row
|
||||
for( r=0; r<m_Rows.size(); r++ ) // foreach row
|
||||
{
|
||||
Row &row = *m_Rows[r];
|
||||
row.Type = Row::ROW_NORMAL;
|
||||
|
||||
vector<BitmapText *> & textItems = row.m_textItems;
|
||||
const OptionRow &optline = m_OptionRow[r];
|
||||
const OptionRow &optline = m_Rows[r]->m_RowDef;
|
||||
|
||||
unsigned c;
|
||||
|
||||
@@ -382,7 +381,7 @@ CString ScreenOptions::GetExplanationText( int iRow ) const
|
||||
if( m_Rows[iRow]->Type == Row::ROW_EXIT )
|
||||
return "";
|
||||
|
||||
CString sLineName = m_OptionRow[iRow].name;
|
||||
CString sLineName = m_Rows[iRow]->m_RowDef.name;
|
||||
sLineName.Replace("\n-","");
|
||||
sLineName.Replace("\n","");
|
||||
sLineName.Replace(" ","");
|
||||
@@ -394,7 +393,7 @@ CString ScreenOptions::GetExplanationTitle( int iRow ) const
|
||||
if( m_Rows[iRow]->Type == Row::ROW_EXIT )
|
||||
return "";
|
||||
|
||||
CString sLineName = m_OptionRow[iRow].name;
|
||||
CString sLineName = m_Rows[iRow]->m_RowDef.name;
|
||||
sLineName.Replace("\n-","");
|
||||
sLineName.Replace("\n","");
|
||||
sLineName.Replace(" ","");
|
||||
@@ -429,7 +428,7 @@ BitmapText &ScreenOptions::GetTextItemForRow( PlayerNumber pn, int iRow )
|
||||
return *row.m_textItems[iOptionInRow];
|
||||
}
|
||||
|
||||
const bool bOneChoice = m_OptionRow[iRow].bOneChoiceForAllPlayers;
|
||||
const bool bOneChoice = m_Rows[iRow]->m_RowDef.bOneChoiceForAllPlayers;
|
||||
|
||||
if( bOneChoice )
|
||||
return *row.m_textItems[0];
|
||||
@@ -510,7 +509,7 @@ void ScreenOptions::PositionUnderlines()
|
||||
|
||||
// If there's only one choice (ScreenOptionsMenu), don't show underlines.
|
||||
// It looks silly.
|
||||
bool bOnlyOneChoice = m_OptionRow[i].choices.size() == 1;
|
||||
bool bOnlyOneChoice = m_Rows[i]->m_RowDef.choices.size() == 1;
|
||||
bool hidden = bOnlyOneChoice || row.m_bHidden;
|
||||
|
||||
if( underline.GetDestY() != row.m_fY )
|
||||
@@ -618,14 +617,14 @@ void ScreenOptions::UpdateText( PlayerNumber player_no, int iRow )
|
||||
|
||||
int iChoiceInRow = m_iSelectedOption[player_no][iRow];
|
||||
|
||||
const OptionRow &optrow = m_OptionRow[iRow];
|
||||
const OptionRow &optrow = m_Rows[iRow]->m_RowDef;
|
||||
|
||||
unsigned item_no = optrow.bOneChoiceForAllPlayers?0:player_no;
|
||||
|
||||
/* If player_no is 2 and there is no player 1: */
|
||||
item_no = min( item_no, m_Rows[iRow]->m_textItems.size()-1 );
|
||||
|
||||
m_Rows[iRow]->m_textItems[item_no]->SetText( m_OptionRow[iRow].choices[iChoiceInRow] );
|
||||
m_Rows[iRow]->m_textItems[item_no]->SetText( m_Rows[iRow]->m_RowDef.choices[iChoiceInRow] );
|
||||
}
|
||||
|
||||
void ScreenOptions::UpdateEnabledDisabled()
|
||||
@@ -1014,7 +1013,7 @@ void ScreenOptions::ChangeValue( PlayerNumber pn, int iDelta, bool Repeat )
|
||||
{
|
||||
const int iCurRow = m_iCurrentRow[pn];
|
||||
Row &row = *m_Rows[iCurRow];
|
||||
OptionRow &optrow = m_OptionRow[iCurRow];
|
||||
OptionRow &optrow = m_Rows[iCurRow]->m_RowDef;
|
||||
|
||||
/* If START is being pressed, and in NAV_THREE_KEY, then we're holding left/right
|
||||
* and start to move backwards. Don't move left and right, too. */
|
||||
|
||||
@@ -30,8 +30,9 @@ struct OptionRow
|
||||
CString name;
|
||||
bool bOneChoiceForAllPlayers;
|
||||
vector<CString> choices;
|
||||
bool bMultiSelect;
|
||||
|
||||
OptionRow(): name(""), bOneChoiceForAllPlayers(false) { }
|
||||
OptionRow(): name(""), bOneChoiceForAllPlayers(false), bMultiSelect(false) { }
|
||||
|
||||
OptionRow( const char *n, int b, const char *c0=NULL, const char *c1=NULL, const char *c2=NULL, const char *c3=NULL, const char *c4=NULL, const char *c5=NULL, const char *c6=NULL, const char *c7=NULL, const char *c8=NULL, const char *c9=NULL, const char *c10=NULL, const char *c11=NULL, const char *c12=NULL, const char *c13=NULL, const char *c14=NULL, const char *c15=NULL, const char *c16=NULL, const char *c17=NULL, const char *c18=NULL, const char *c19=NULL )
|
||||
{
|
||||
@@ -40,6 +41,7 @@ struct OptionRow
|
||||
#define PUSH( c ) if(c) choices.push_back(c);
|
||||
PUSH(c0);PUSH(c1);PUSH(c2);PUSH(c3);PUSH(c4);PUSH(c5);PUSH(c6);PUSH(c7);PUSH(c8);PUSH(c9);PUSH(c10);PUSH(c11);PUSH(c12);PUSH(c13);PUSH(c14);PUSH(c15);PUSH(c16);PUSH(c17);PUSH(c18);PUSH(c19);
|
||||
#undef PUSH
|
||||
bMultiSelect = false;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -98,22 +100,21 @@ protected:
|
||||
int GetCurrentRow(PlayerNumber pn = PLAYER_1) const;
|
||||
|
||||
MenuElements m_Menu;
|
||||
OptionRow* m_OptionRow;
|
||||
|
||||
protected: // derived classes need access to these
|
||||
int m_iSelectedOption[NUM_PLAYERS][MAX_OPTION_LINES];
|
||||
int m_iNumOptionRows;
|
||||
|
||||
void LoadOptionIcon( PlayerNumber pn, int iRow, CString sText );
|
||||
enum Navigation { NAV_THREE_KEY, NAV_THREE_KEY_MENU, NAV_FIVE_KEY };
|
||||
void SetNavigation( Navigation nav ) { m_OptionsNavigation = nav; }
|
||||
|
||||
private:
|
||||
protected:
|
||||
/* Map menu lines to m_OptionRow entries. */
|
||||
struct Row
|
||||
{
|
||||
Row();
|
||||
~Row();
|
||||
OptionRow m_RowDef;
|
||||
enum { ROW_NORMAL, ROW_EXIT } Type;
|
||||
vector<BitmapText *> m_textItems;
|
||||
Sprite m_sprBullet;
|
||||
|
||||
@@ -571,27 +571,30 @@ void ScreenOptionsMaster::GoToPrevState()
|
||||
|
||||
void ScreenOptionsMaster::RefreshIcons()
|
||||
{
|
||||
ASSERT( m_iNumOptionRows < (int) MAX_OPTION_LINES );
|
||||
ASSERT( m_Rows.size() < MAX_OPTION_LINES );
|
||||
|
||||
for( int p=0; p<NUM_PLAYERS; p++ ) // foreach player
|
||||
{
|
||||
if( !GAMESTATE->IsHumanPlayer(p) )
|
||||
continue;
|
||||
|
||||
for( int i=0; i<m_iNumOptionRows; i++ ) // foreach options line
|
||||
for( int i=0; i<m_Rows.size(); i++ ) // foreach options line
|
||||
{
|
||||
const OptionRow &row = m_OptionRow[i];
|
||||
if( m_Rows[i]->Type == Row::ROW_EXIT )
|
||||
continue; // skip
|
||||
|
||||
const OptionRow &row = m_Rows[i]->m_RowDef;
|
||||
|
||||
int iSelection = m_iSelectedOption[p][i];
|
||||
if( iSelection >= (int)m_OptionRow[i].choices.size() )
|
||||
if( iSelection >= (int)row.choices.size() )
|
||||
{
|
||||
/* Invalid selection. Send debug output, to aid debugging. */
|
||||
CString error = ssprintf("Option row with name '%s' selects item %i, but there are only %i items:\n",
|
||||
m_OptionRow[i].name.c_str(),
|
||||
iSelection, (int) m_OptionRow[i].choices.size() );
|
||||
row.name.c_str(),
|
||||
iSelection, (int) row.choices.size() );
|
||||
|
||||
for( unsigned j = 0; j < m_OptionRow[i].choices.size(); ++j )
|
||||
error += ssprintf(" %s\n", m_OptionRow[i].choices[j].c_str());
|
||||
for( unsigned j = 0; j < row.choices.size(); ++j )
|
||||
error += ssprintf(" %s\n", row.choices[j].c_str());
|
||||
|
||||
RageException::Throw( "%s", error.c_str() );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user