Lots of PlayerNumber style loops.
This commit is contained in:
+61
-61
@@ -88,21 +88,21 @@ void ScreenSelectMaster::Init()
|
|||||||
// init cursor
|
// init cursor
|
||||||
if( SHOW_CURSOR )
|
if( SHOW_CURSOR )
|
||||||
{
|
{
|
||||||
FOREACH( PlayerNumber, vpns, p )
|
for (PlayerNumber const &p : vpns)
|
||||||
{
|
{
|
||||||
RString sElement = "Cursor" + PLAYER_APPEND_NO_SPACE(*p);
|
RString sElement = "Cursor" + PLAYER_APPEND_NO_SPACE(p);
|
||||||
m_sprCursor[*p].Load( THEME->GetPathG(m_sName,sElement) );
|
m_sprCursor[p].Load( THEME->GetPathG(m_sName,sElement) );
|
||||||
sElement.Replace( " ", "" );
|
sElement.Replace( " ", "" );
|
||||||
m_sprCursor[*p]->SetName( sElement );
|
m_sprCursor[p]->SetName( sElement );
|
||||||
this->AddChild( m_sprCursor[*p] );
|
this->AddChild( m_sprCursor[p] );
|
||||||
LOAD_ALL_COMMANDS( m_sprCursor[*p] );
|
LOAD_ALL_COMMANDS( m_sprCursor[p] );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Resize vectors depending on how many choices there are
|
// Resize vectors depending on how many choices there are
|
||||||
m_vsprIcon.resize( m_aGameCommands.size() );
|
m_vsprIcon.resize( m_aGameCommands.size() );
|
||||||
FOREACH( PlayerNumber, vpns, p )
|
for (PlayerNumber const &p : vpns)
|
||||||
m_vsprScroll[*p].resize( m_aGameCommands.size() );
|
m_vsprScroll[p].resize( m_aGameCommands.size() );
|
||||||
|
|
||||||
for( unsigned c=0; c<m_aGameCommands.size(); c++ )
|
for( unsigned c=0; c<m_aGameCommands.size(); c++ )
|
||||||
{
|
{
|
||||||
@@ -129,21 +129,21 @@ void ScreenSelectMaster::Init()
|
|||||||
// init scroll
|
// init scroll
|
||||||
if( SHOW_SCROLLER )
|
if( SHOW_SCROLLER )
|
||||||
{
|
{
|
||||||
FOREACH( PlayerNumber, vpns, p )
|
for (PlayerNumber const &p : vpns)
|
||||||
{
|
{
|
||||||
vector<RString> vs;
|
vector<RString> vs;
|
||||||
vs.push_back( "Scroll" );
|
vs.push_back( "Scroll" );
|
||||||
if( PER_CHOICE_SCROLL_ELEMENT )
|
if( PER_CHOICE_SCROLL_ELEMENT )
|
||||||
vs.push_back( "Choice" + mc.m_sName );
|
vs.push_back( "Choice" + mc.m_sName );
|
||||||
if( !SHARED_SELECTION )
|
if( !SHARED_SELECTION )
|
||||||
vs.push_back( PLAYER_APPEND_NO_SPACE(*p) );
|
vs.push_back( PLAYER_APPEND_NO_SPACE(p) );
|
||||||
RString sElement = join( " ", vs );
|
RString sElement = join( " ", vs );
|
||||||
m_vsprScroll[*p][c].Load( THEME->GetPathG(m_sName,sElement) );
|
m_vsprScroll[p][c].Load( THEME->GetPathG(m_sName,sElement) );
|
||||||
RString sName = "Scroll" "Choice" + mc.m_sName;
|
RString sName = "Scroll" "Choice" + mc.m_sName;
|
||||||
if( !SHARED_SELECTION )
|
if( !SHARED_SELECTION )
|
||||||
sName += PLAYER_APPEND_NO_SPACE(*p);
|
sName += PLAYER_APPEND_NO_SPACE(p);
|
||||||
m_vsprScroll[*p][c]->SetName( sName );
|
m_vsprScroll[p][c]->SetName( sName );
|
||||||
m_Scroller[*p].AddChild( m_vsprScroll[*p][c] );
|
m_Scroller[p].AddChild( m_vsprScroll[p][c] );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -152,17 +152,17 @@ void ScreenSelectMaster::Init()
|
|||||||
// init scroll
|
// init scroll
|
||||||
if( SHOW_SCROLLER )
|
if( SHOW_SCROLLER )
|
||||||
{
|
{
|
||||||
FOREACH( PlayerNumber, vpns, p )
|
for (PlayerNumber const &p : vpns)
|
||||||
{
|
{
|
||||||
m_Scroller[*p].SetLoop( LOOP_SCROLLER );
|
m_Scroller[p].SetLoop( LOOP_SCROLLER );
|
||||||
m_Scroller[*p].SetNumItemsToDraw( SCROLLER_NUM_ITEMS_TO_DRAW );
|
m_Scroller[p].SetNumItemsToDraw( SCROLLER_NUM_ITEMS_TO_DRAW );
|
||||||
m_Scroller[*p].Load2();
|
m_Scroller[p].Load2();
|
||||||
m_Scroller[*p].SetTransformFromReference( SCROLLER_TRANSFORM );
|
m_Scroller[p].SetTransformFromReference( SCROLLER_TRANSFORM );
|
||||||
m_Scroller[*p].SetSecondsPerItem( SCROLLER_SECONDS_PER_ITEM );
|
m_Scroller[p].SetSecondsPerItem( SCROLLER_SECONDS_PER_ITEM );
|
||||||
m_Scroller[*p].SetNumSubdivisions( SCROLLER_SUBDIVISIONS );
|
m_Scroller[p].SetNumSubdivisions( SCROLLER_SUBDIVISIONS );
|
||||||
m_Scroller[*p].SetName( "Scroller"+PLAYER_APPEND_NO_SPACE(*p) );
|
m_Scroller[p].SetName( "Scroller"+PLAYER_APPEND_NO_SPACE(p) );
|
||||||
LOAD_ALL_COMMANDS_AND_SET_XY( m_Scroller[*p] );
|
LOAD_ALL_COMMANDS_AND_SET_XY( m_Scroller[p] );
|
||||||
this->AddChild( &m_Scroller[*p] );
|
this->AddChild( &m_Scroller[p] );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -302,16 +302,16 @@ void ScreenSelectMaster::HandleScreenMessage( const ScreenMessage SM )
|
|||||||
|
|
||||||
if( SHOW_CURSOR )
|
if( SHOW_CURSOR )
|
||||||
{
|
{
|
||||||
FOREACH( PlayerNumber, vpns, p )
|
for (PlayerNumber const &p : vpns)
|
||||||
m_sprCursor[*p]->HandleMessage( msg );
|
m_sprCursor[p]->HandleMessage( msg );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( SHOW_SCROLLER )
|
if( SHOW_SCROLLER )
|
||||||
{
|
{
|
||||||
FOREACH( PlayerNumber, vpns, p )
|
for (PlayerNumber const &p : vpns)
|
||||||
{
|
{
|
||||||
int iChoice = m_iChoice[*p];
|
int iChoice = m_iChoice[p];
|
||||||
m_vsprScroll[*p][iChoice]->HandleMessage( msg );
|
m_vsprScroll[p][iChoice]->HandleMessage( msg );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
MESSAGEMAN->Broadcast(msg);
|
MESSAGEMAN->Broadcast(msg);
|
||||||
@@ -359,9 +359,12 @@ void ScreenSelectMaster::UpdateSelectableChoices()
|
|||||||
if( SHOW_ICON )
|
if( SHOW_ICON )
|
||||||
m_vsprIcon[c]->PlayCommand( m_aGameCommands[c].IsPlayable()? "Enabled":"Disabled" );
|
m_vsprIcon[c]->PlayCommand( m_aGameCommands[c].IsPlayable()? "Enabled":"Disabled" );
|
||||||
|
|
||||||
FOREACH( PlayerNumber, vpns, p )
|
for (PlayerNumber const &p : vpns)
|
||||||
if( m_vsprScroll[*p][c].IsLoaded() )
|
{
|
||||||
m_vsprScroll[*p][c]->PlayCommand( m_aGameCommands[c].IsPlayable()? "Enabled":"Disabled" );
|
auto & actor = m_vsprScroll[p][c];
|
||||||
|
if( actor.IsLoaded() )
|
||||||
|
actor->PlayCommand( m_aGameCommands[c].IsPlayable()? "Enabled":"Disabled" );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If no options are playable at all, just wait. Some external
|
/* If no options are playable at all, just wait. Some external
|
||||||
@@ -566,18 +569,18 @@ bool ScreenSelectMaster::ChangePage( int iNewChoice )
|
|||||||
msg.SetParam( "NewPageIndex", (int)newPage );
|
msg.SetParam( "NewPageIndex", (int)newPage );
|
||||||
MESSAGEMAN->Broadcast( msg );
|
MESSAGEMAN->Broadcast( msg );
|
||||||
|
|
||||||
FOREACH( PlayerNumber, vpns, p )
|
for (PlayerNumber const &p : vpns)
|
||||||
{
|
{
|
||||||
if( GAMESTATE->IsHumanPlayer(*p) )
|
if( GAMESTATE->IsHumanPlayer(p) )
|
||||||
{
|
{
|
||||||
if( SHOW_CURSOR )
|
if( SHOW_CURSOR )
|
||||||
{
|
{
|
||||||
m_sprCursor[*p]->HandleMessage( msg );
|
m_sprCursor[p]->HandleMessage( msg );
|
||||||
m_sprCursor[*p]->SetXY( GetCursorX(*p), GetCursorY(*p) );
|
m_sprCursor[p]->SetXY( GetCursorX(p), GetCursorY(p) );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( SHOW_SCROLLER )
|
if( SHOW_SCROLLER )
|
||||||
m_vsprScroll[*p][m_iChoice[*p]]->HandleMessage( msg );
|
m_vsprScroll[p][m_iChoice[p]]->HandleMessage( msg );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -620,10 +623,10 @@ bool ScreenSelectMaster::ChangeSelection( PlayerNumber pn, MenuDir dir, int iNew
|
|||||||
vpns.push_back( pn );
|
vpns.push_back( pn );
|
||||||
}
|
}
|
||||||
|
|
||||||
FOREACH( PlayerNumber, vpns, p )
|
for (PlayerNumber const &p : vpns)
|
||||||
{
|
{
|
||||||
const int iOldChoice = m_iChoice[*p];
|
const int iOldChoice = m_iChoice[p];
|
||||||
m_iChoice[*p] = iNewChoice;
|
m_iChoice[p] = iNewChoice;
|
||||||
|
|
||||||
if( SHOW_ICON )
|
if( SHOW_ICON )
|
||||||
{
|
{
|
||||||
@@ -634,7 +637,7 @@ bool ScreenSelectMaster::ChangeSelection( PlayerNumber pn, MenuDir dir, int iNew
|
|||||||
bool bNewAlreadyHadFocus = false;
|
bool bNewAlreadyHadFocus = false;
|
||||||
FOREACH_HumanPlayer( p2 )
|
FOREACH_HumanPlayer( p2 )
|
||||||
{
|
{
|
||||||
if( p2 == *p )
|
if( p2 == p )
|
||||||
continue;
|
continue;
|
||||||
bOldStillHasFocus |= m_iChoice[p2] == iOldChoice;
|
bOldStillHasFocus |= m_iChoice[p2] == iOldChoice;
|
||||||
bNewAlreadyHadFocus |= m_iChoice[p2] == iNewChoice;
|
bNewAlreadyHadFocus |= m_iChoice[p2] == iNewChoice;
|
||||||
@@ -669,17 +672,17 @@ bool ScreenSelectMaster::ChangeSelection( PlayerNumber pn, MenuDir dir, int iNew
|
|||||||
|
|
||||||
if( SHOW_CURSOR )
|
if( SHOW_CURSOR )
|
||||||
{
|
{
|
||||||
if( GAMESTATE->IsHumanPlayer(*p) )
|
if( GAMESTATE->IsHumanPlayer(p) )
|
||||||
{
|
{
|
||||||
m_sprCursor[*p]->PlayCommand( "Change" );
|
m_sprCursor[p]->PlayCommand( "Change" );
|
||||||
m_sprCursor[*p]->SetXY( GetCursorX(*p), GetCursorY(*p) );
|
m_sprCursor[p]->SetXY( GetCursorX(p), GetCursorY(p) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( SHOW_SCROLLER )
|
if( SHOW_SCROLLER )
|
||||||
{
|
{
|
||||||
ActorScroller &scroller = (SHARED_SELECTION || page != PAGE_1 ? m_Scroller[0] : m_Scroller[*p]);
|
ActorScroller &scroller = (SHARED_SELECTION || page != PAGE_1 ? m_Scroller[0] : m_Scroller[p]);
|
||||||
vector<AutoActor> &vScroll = (SHARED_SELECTION || page != PAGE_1 ? m_vsprScroll[0] : m_vsprScroll[*p]);
|
vector<AutoActor> &vScroll = (SHARED_SELECTION || page != PAGE_1 ? m_vsprScroll[0] : m_vsprScroll[p]);
|
||||||
|
|
||||||
if( WRAP_SCROLLER )
|
if( WRAP_SCROLLER )
|
||||||
{
|
{
|
||||||
@@ -898,27 +901,27 @@ void ScreenSelectMaster::TweenOnScreen()
|
|||||||
|
|
||||||
if( SHOW_SCROLLER )
|
if( SHOW_SCROLLER )
|
||||||
{
|
{
|
||||||
FOREACH( PlayerNumber, vpns, p )
|
for (PlayerNumber const &p : vpns)
|
||||||
{
|
{
|
||||||
// Play Gain/LoseFocus before playing the on command.
|
// Play Gain/LoseFocus before playing the on command.
|
||||||
// Gain/Lose will often stop tweening, which ruins the OnCommand.
|
// Gain/Lose will often stop tweening, which ruins the OnCommand.
|
||||||
for( unsigned c=0; c<m_aGameCommands.size(); c++ )
|
for( unsigned c=0; c<m_aGameCommands.size(); c++ )
|
||||||
{
|
{
|
||||||
m_vsprScroll[*p][c]->PlayCommand( int(c) == m_iChoice[*p]? "GainFocus":"LoseFocus" );
|
m_vsprScroll[p][c]->PlayCommand( int(c) == m_iChoice[p]? "GainFocus":"LoseFocus" );
|
||||||
m_vsprScroll[*p][c]->FinishTweening();
|
m_vsprScroll[p][c]->FinishTweening();
|
||||||
}
|
}
|
||||||
|
|
||||||
m_Scroller[*p].SetCurrentAndDestinationItem( (float)m_iChoice[*p] );
|
m_Scroller[p].SetCurrentAndDestinationItem( (float)m_iChoice[p] );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Need to SetXY of Cursor after Icons since it depends on the Icons' positions.
|
// Need to SetXY of Cursor after Icons since it depends on the Icons' positions.
|
||||||
if( SHOW_CURSOR )
|
if( SHOW_CURSOR )
|
||||||
{
|
{
|
||||||
FOREACH( PlayerNumber, vpns, p )
|
for (PlayerNumber const &p : vpns)
|
||||||
{
|
{
|
||||||
if( GAMESTATE->IsHumanPlayer(*p) )
|
if( GAMESTATE->IsHumanPlayer(p) )
|
||||||
m_sprCursor[*p]->SetXY( GetCursorX(*p), GetCursorY(*p) );
|
m_sprCursor[p]->SetXY( GetCursorX(p), GetCursorY(p) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -937,20 +940,17 @@ void ScreenSelectMaster::TweenOffScreen()
|
|||||||
if( GetPage(c) != GetCurrentPage() )
|
if( GetPage(c) != GetCurrentPage() )
|
||||||
continue; // skip
|
continue; // skip
|
||||||
|
|
||||||
bool bSelectedByEitherPlayer = false;
|
bool bSelectedByEitherPlayer = std::any_of(vpns.begin(), vpns.end(), [&](PlayerNumber const &p) {
|
||||||
FOREACH( PlayerNumber, vpns, p )
|
return m_iChoice[p] == static_cast<int>(c);
|
||||||
{
|
});
|
||||||
if( m_iChoice[*p] == (int)c )
|
|
||||||
bSelectedByEitherPlayer = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if( SHOW_ICON )
|
if( SHOW_ICON )
|
||||||
m_vsprIcon[c]->PlayCommand( bSelectedByEitherPlayer? "OffFocused":"OffUnfocused" );
|
m_vsprIcon[c]->PlayCommand( bSelectedByEitherPlayer? "OffFocused":"OffUnfocused" );
|
||||||
|
|
||||||
if( SHOW_SCROLLER )
|
if( SHOW_SCROLLER )
|
||||||
{
|
{
|
||||||
FOREACH( PlayerNumber, vpns, p )
|
for (PlayerNumber const &p : vpns)
|
||||||
m_vsprScroll[*p][c]->PlayCommand( bSelectedByEitherPlayer? "OffFocused":"OffUnfocused" );
|
m_vsprScroll[p][c]->PlayCommand( bSelectedByEitherPlayer? "OffFocused":"OffUnfocused" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user