Dynamic m_textItems. This solves potential problems with

MAX_VISIBLE_VALUES_PER_LINE overflows.
This commit is contained in:
Glenn Maynard
2003-09-04 19:53:07 +00:00
parent 95e3575094
commit 413593f1e4
2 changed files with 69 additions and 36 deletions
+68 -35
View File
@@ -129,15 +129,21 @@ void ScreenOptions::Init( InputMode im, OptionRow OptionRow[], int iNumOptionLin
m_framePage.AddChild( &m_textTitles[r] ); m_framePage.AddChild( &m_textTitles[r] );
int iNumChoices = min( m_OptionRow[r].choices.size(), MAX_VISIBLE_VALUES_PER_LINE ); for( unsigned c=0; c<m_OptionRow[r].choices.size(); c++ )
for( int c=0; c<iNumChoices; c++ )
{ {
m_framePage.AddChild( &m_textItems[r][c] ); BitmapText *bt = new BitmapText;
m_textItems[r].push_back( bt );
m_framePage.AddChild( bt );
} }
} }
// TRICKY: Add one more item. This will be "EXIT" // TRICKY: Add one more item. This will be "EXIT"
m_framePage.AddChild( &m_textItems[r][0] ); {
BitmapText *bt = new BitmapText;
m_textItems[r].push_back( bt );
m_framePage.AddChild( bt );
}
// add explanation here so it appears on top // add explanation here so it appears on top
m_textExplanation.LoadFromFont( THEME->GetPathToF("ScreenOptions explanation") ); m_textExplanation.LoadFromFont( THEME->GetPathToF("ScreenOptions explanation") );
@@ -151,10 +157,15 @@ void ScreenOptions::Init( InputMode im, OptionRow OptionRow[], int iNumOptionLin
PositionItems(); PositionItems();
PositionUnderlines(); PositionUnderlines();
PositionIcons(); PositionIcons();
CHECKPOINT;
RefreshIcons(); RefreshIcons();
CHECKPOINT;
PositionCursors(); PositionCursors();
CHECKPOINT;
UpdateEnabledDisabled(); UpdateEnabledDisabled();
CHECKPOINT;
OnChange(); OnChange();
CHECKPOINT;
/* It's tweening into position, but on the initial tween-in we only want to /* It's tweening into position, but on the initial tween-in we only want to
* tween in the whole page at once. Since the tweens are nontrivial, it's * tween in the whole page at once. Since the tweens are nontrivial, it's
@@ -163,8 +174,10 @@ void ScreenOptions::Init( InputMode im, OptionRow OptionRow[], int iNumOptionLin
{ {
m_textTitles[r].FinishTweening(); m_textTitles[r].FinishTweening();
m_sprBullets[r].FinishTweening(); m_sprBullets[r].FinishTweening();
for( unsigned c=0; c<m_OptionRow[r].choices.size(); c++ ) for( unsigned c=0; c<m_textItems[r].size(); c++ )
m_textItems[r][c].FinishTweening(); {
m_textItems[r][c]->FinishTweening();
}
for( int p=0; p<NUM_PLAYERS; p++ ) // foreach player for( int p=0; p<NUM_PLAYERS; p++ ) // foreach player
{ {
@@ -177,6 +190,9 @@ void ScreenOptions::Init( InputMode im, OptionRow OptionRow[], int iNumOptionLin
ScreenOptions::~ScreenOptions() ScreenOptions::~ScreenOptions()
{ {
LOG->Trace( "ScreenOptions::~ScreenOptions()" ); LOG->Trace( "ScreenOptions::~ScreenOptions()" );
for( int i=0; i<m_iNumOptionRows; i++ )
for( unsigned j = 0; j < m_textItems[i].size(); ++j)
delete m_textItems[i][j];
} }
@@ -184,9 +200,10 @@ void ScreenOptions::GetWidthXY( PlayerNumber pn, int iRow, int &iWidthOut, int &
{ {
bool bExitRow = iRow == m_iNumOptionRows; bool bExitRow = iRow == m_iNumOptionRows;
bool bLotsOfOptions = m_bRowIsLong[iRow]; bool bLotsOfOptions = m_bRowIsLong[iRow];
int iOptionInRow = bExitRow ? 0 : bLotsOfOptions ? pn : m_iSelectedOption[pn][iRow]; unsigned iOptionInRow = bExitRow ? 0 : bLotsOfOptions ? pn : m_iSelectedOption[pn][iRow];
BitmapText &text = m_textItems[iRow][iOptionInRow]; ASSERT( iOptionInRow < m_textItems[iRow].size() );
BitmapText &text = *m_textItems[iRow][iOptionInRow];
iWidthOut = int(roundf( text.GetWidestLineWidthInSourcePixels() * text.GetZoomX() )); iWidthOut = int(roundf( text.GetWidestLineWidthInSourcePixels() * text.GetZoomX() ));
iXOut = int(roundf( text.GetDestX() )); iXOut = int(roundf( text.GetDestX() ));
@@ -229,7 +246,8 @@ void ScreenOptions::InitOptionsText()
float fX = ITEMS_START_X; // indent 70 pixels float fX = ITEMS_START_X; // indent 70 pixels
for( unsigned j=0; j<optline.choices.size(); j++ ) // for each option on this line for( unsigned j=0; j<optline.choices.size(); j++ ) // for each option on this line
{ {
BitmapText &option = m_textItems[i][j]; ASSERT( j < m_textItems[i].size() );
BitmapText &option = *m_textItems[i][j];
option.LoadFromFont( THEME->GetPathToF("ScreenOptions item") ); option.LoadFromFont( THEME->GetPathToF("ScreenOptions item") );
option.SetText( optline.choices[j] ); option.SetText( optline.choices[j] );
@@ -248,16 +266,24 @@ void ScreenOptions::InitOptionsText()
if( m_bRowIsLong[i] ) if( m_bRowIsLong[i] )
{ {
// re-init with "long row" style // re-init with "long row" style
unsigned j; unsigned j;
for( j=0; j<optline.choices.size(); j++ ) // for each option on this line for( j=0; j<optline.choices.size(); j++ ) // for each option on this line
m_textItems[i][j].SetText( "" ); m_textItems[i][j]->SetText( "" );
for( int p=0; p<NUM_PLAYERS; p++ ) for( unsigned p=0; p<NUM_PLAYERS; p++ )
{ {
if( !GAMESTATE->IsHumanPlayer(p) ) if( !GAMESTATE->IsHumanPlayer(p) )
continue; continue;
BitmapText &option = m_textItems[i][p]; if( p >= m_textItems[i].size() )
{
BitmapText *bt = new BitmapText;
m_textItems[i].push_back( bt );
m_framePage.AddChild( bt );
}
BitmapText &option = *m_textItems[i][p];
const int iChoiceInRow = m_iSelectedOption[p][i]; const int iChoiceInRow = m_iSelectedOption[p][i];
@@ -279,7 +305,7 @@ void ScreenOptions::InitOptionsText()
} }
} }
BitmapText &option = m_textItems[i][0]; BitmapText &option = *m_textItems[i][0];
option.LoadFromFont( THEME->GetPathToF("ScreenOptions item") ); option.LoadFromFont( THEME->GetPathToF("ScreenOptions item") );
option.SetText( "EXIT" ); option.SetText( "EXIT" );
option.SetZoom( ITEMS_ZOOM ); option.SetZoom( ITEMS_ZOOM );
@@ -349,6 +375,8 @@ void ScreenOptions::PositionIcons()
void ScreenOptions::RefreshIcons() void ScreenOptions::RefreshIcons()
{ {
ASSERT( m_iNumOptionRows < MAX_OPTION_LINES );
for( int p=0; p<NUM_PLAYERS; p++ ) // foreach player for( int p=0; p<NUM_PLAYERS; p++ ) // foreach player
{ {
if( !GAMESTATE->IsHumanPlayer(p) ) if( !GAMESTATE->IsHumanPlayer(p) )
@@ -427,7 +455,10 @@ void ScreenOptions::UpdateText( PlayerNumber player_no, int iRow )
OptionRow &row = m_OptionRow[iRow]; OptionRow &row = m_OptionRow[iRow];
if( bLotsOfOptions ) if( bLotsOfOptions )
m_textItems[iRow][row.bOneChoiceForAllPlayers?0:player_no].SetText( m_OptionRow[iRow].choices[iChoiceInRow] ); {
unsigned item_no = row.bOneChoiceForAllPlayers?0:player_no;
m_textItems[iRow][item_no]->SetText( m_OptionRow[iRow].choices[iChoiceInRow] );
}
} }
void ScreenOptions::UpdateEnabledDisabled() void ScreenOptions::UpdateEnabledDisabled()
@@ -450,10 +481,10 @@ void ScreenOptions::UpdateEnabledDisabled()
if( m_bRowIsLong[i] ) if( m_bRowIsLong[i] )
for( unsigned j=0; j<NUM_PLAYERS; j++ ) for( unsigned j=0; j<NUM_PLAYERS; j++ )
m_textItems[i][j].SetGlobalDiffuseColor( color ); m_textItems[i][j]->SetGlobalDiffuseColor( color );
else else
for( unsigned j=0; j<m_OptionRow[i].choices.size(); j++ ) for( unsigned j=0; j<m_OptionRow[i].choices.size(); j++ )
m_textItems[i][j].SetGlobalDiffuseColor( color ); m_textItems[i][j]->SetGlobalDiffuseColor( color );
if( m_sprBullets[i].GetDestY() != m_fRowY[i] ) if( m_sprBullets[i].GetDestY() != m_fRowY[i] )
{ {
@@ -468,21 +499,23 @@ void ScreenOptions::UpdateEnabledDisabled()
m_sprBullets[i].SetY( m_fRowY[i] ); m_sprBullets[i].SetY( m_fRowY[i] );
m_textTitles[i].SetY( m_fRowY[i] ); m_textTitles[i].SetY( m_fRowY[i] );
/* XXX: If we're long, then remove the old choices when we switch to long so we don't
* need a special case here. */
if( m_bRowIsLong[i] ) if( m_bRowIsLong[i] )
for( unsigned j=0; j<NUM_PLAYERS; j++ ) for( unsigned j=0; j<NUM_PLAYERS; j++ )
{ {
m_textItems[i][j].StopTweening(); m_textItems[i][j]->StopTweening();
m_textItems[i][j].BeginTweening( 0.3f ); m_textItems[i][j]->BeginTweening( 0.3f );
m_textItems[i][j].SetDiffuseAlpha( m_bRowIsHidden[i]? 0.0f:1.0f ); m_textItems[i][j]->SetDiffuseAlpha( m_bRowIsHidden[i]? 0.0f:1.0f );
m_textItems[i][j].SetY( m_fRowY[i] ); m_textItems[i][j]->SetY( m_fRowY[i] );
} }
else else
for( unsigned j=0; j<m_OptionRow[i].choices.size(); j++ ) for( unsigned j=0; j<m_OptionRow[i].choices.size(); j++ )
{ {
m_textItems[i][j].StopTweening(); m_textItems[i][j]->StopTweening();
m_textItems[i][j].BeginTweening( 0.3f ); m_textItems[i][j]->BeginTweening( 0.3f );
m_textItems[i][j].SetDiffuseAlpha( m_bRowIsHidden[i]? 0.0f:1.0f ); m_textItems[i][j]->SetDiffuseAlpha( m_bRowIsHidden[i]? 0.0f:1.0f );
m_textItems[i][j].SetY( m_fRowY[i] ); m_textItems[i][j]->SetY( m_fRowY[i] );
} }
} }
@@ -500,8 +533,8 @@ void ScreenOptions::UpdateEnabledDisabled()
continue; continue;
} }
} }
m_textItems[i][j].StopTweening(); m_textItems[i][j]->StopTweening();
m_textItems[i][j].SetDiffuse( RageColor(1,1,1,0) ); m_textItems[i][j]->SetDiffuse( RageColor(1,1,1,0) );
} }
} }
} }
@@ -512,20 +545,20 @@ void ScreenOptions::UpdateEnabledDisabled()
bExitRowIsSelectedByBoth = false; bExitRowIsSelectedByBoth = false;
RageColor color = bExitRowIsSelectedByBoth ? colorSelected : colorNotSelected; RageColor color = bExitRowIsSelectedByBoth ? colorSelected : colorNotSelected;
m_textItems[m_iNumOptionRows][0].SetGlobalDiffuseColor( color ); m_textItems[m_iNumOptionRows][0]->SetGlobalDiffuseColor( color );
if( m_textItems[m_iNumOptionRows][0].GetDestY() != m_fRowY[m_iNumOptionRows] ) if( m_textItems[m_iNumOptionRows][0]->GetDestY() != m_fRowY[m_iNumOptionRows] )
{ {
m_textItems[m_iNumOptionRows][0].StopTweening(); m_textItems[m_iNumOptionRows][0]->StopTweening();
m_textItems[m_iNumOptionRows][0].BeginTweening( 0.3f ); m_textItems[m_iNumOptionRows][0]->BeginTweening( 0.3f );
m_textItems[m_iNumOptionRows][0].SetDiffuseAlpha( m_bRowIsHidden[m_iNumOptionRows]? 0.0f:1.0f ); m_textItems[m_iNumOptionRows][0]->SetDiffuseAlpha( m_bRowIsHidden[m_iNumOptionRows]? 0.0f:1.0f );
m_textItems[m_iNumOptionRows][0].SetY( m_fRowY[m_iNumOptionRows] ); m_textItems[m_iNumOptionRows][0]->SetY( m_fRowY[m_iNumOptionRows] );
} }
if( bExitRowIsSelectedByBoth ) if( bExitRowIsSelectedByBoth )
m_textItems[m_iNumOptionRows][0].SetEffectDiffuseShift( 1.0f, colorSelected, colorNotSelected ); m_textItems[m_iNumOptionRows][0]->SetEffectDiffuseShift( 1.0f, colorSelected, colorNotSelected );
else else
m_textItems[m_iNumOptionRows][0].SetEffectNone(); m_textItems[m_iNumOptionRows][0]->SetEffectNone();
} }
void ScreenOptions::Update( float fDeltaTime ) void ScreenOptions::Update( float fDeltaTime )
+1 -1
View File
@@ -106,7 +106,7 @@ private:
Sprite m_sprPage; Sprite m_sprPage;
Sprite m_sprBullets[MAX_OPTION_LINES]; Sprite m_sprBullets[MAX_OPTION_LINES];
BitmapText m_textTitles[MAX_OPTION_LINES]; BitmapText m_textTitles[MAX_OPTION_LINES];
BitmapText m_textItems[MAX_OPTION_LINES][MAX_VISIBLE_VALUES_PER_LINE]; // this array has to be big enough to hold all of the options vector<BitmapText *> m_textItems[MAX_OPTION_LINES];
bool m_bRowIsLong[MAX_OPTION_LINES]; // goes off edge of screen bool m_bRowIsLong[MAX_OPTION_LINES]; // goes off edge of screen