Files
itgmania212121/stepmania/src/ScreenSelectMaster.cpp
T

824 lines
23 KiB
C++
Raw Normal View History

2003-06-20 23:07:45 +00:00
#include "global.h"
#include "ScreenSelectMaster.h"
#include "ScreenManager.h"
#include "PrefsManager.h"
#include "GameManager.h"
#include "ThemeManager.h"
2004-07-08 00:10:34 +00:00
#include "GameSoundManager.h"
2003-06-20 23:07:45 +00:00
#include "GameState.h"
#include "AnnouncerManager.h"
2004-12-02 06:29:20 +00:00
#include "GameCommand.h"
2003-06-20 23:07:45 +00:00
#include "ActorUtil.h"
#include "RageLog.h"
2004-04-13 23:11:32 +00:00
#include <set>
#include "Foreach.h"
2003-06-20 23:07:45 +00:00
2003-11-04 20:57:19 +00:00
#define NUM_ICON_PARTS THEME->GetMetricI(m_sName,"NumIconParts")
#define NUM_PREVIEW_PARTS THEME->GetMetricI(m_sName,"NumPreviewParts")
#define NUM_CURSOR_PARTS THEME->GetMetricI(m_sName,"NumCursorParts")
#define SHARED_PREVIEW_AND_CURSOR THEME->GetMetricB(m_sName,"SharedPreviewAndCursor")
#define NUM_CHOICES_ON_PAGE_1 THEME->GetMetricI(m_sName,"NumChoicesOnPage1")
#define CURSOR_OFFSET_X_FROM_ICON( p, part ) THEME->GetMetricF(m_sName,ssprintf("CursorPart%dP%dOffsetXFromIcon",part+1,p+1))
#define CURSOR_OFFSET_Y_FROM_ICON( p, part ) THEME->GetMetricF(m_sName,ssprintf("CursorPart%dP%dOffsetYFromIcon",part+1,p+1))
#define PRE_SWITCH_PAGE_SECONDS THEME->GetMetricF(m_sName,"PreSwitchPageSeconds")
#define POST_SWITCH_PAGE_SECONDS THEME->GetMetricF(m_sName,"PostSwitchPageSeconds")
#define EXTRA_SLEEP_AFTER_TWEEN_OFF_SECONDS THEME->GetMetricF(m_sName,"ExtraSleepAfterTweenOffSeconds")
2003-11-12 02:53:28 +00:00
#define OPTION_ORDER( dir ) THEME->GetMetric (m_sName,"OptionOrder"+CString(dir))
2004-01-17 23:14:56 +00:00
#define SHOW_SCROLLER THEME->GetMetricB(m_sName,"ShowScroller")
#define SCROLLER_SECONDS_PER_ITEM THEME->GetMetricF(m_sName,"ScrollerSecondsPerItem")
2005-01-06 21:24:32 +00:00
#define SCROLLER_NUM_ITEMS_TO_DRAW THEME->GetMetricF(m_sName,"ScrollerNumItemsToDraw")
2004-01-17 23:14:56 +00:00
#define SCROLLER_SPACING_X THEME->GetMetricF(m_sName,"ScrollerSpacingX")
#define SCROLLER_SPACING_Y THEME->GetMetricF(m_sName,"ScrollerSpacingY")
#define DEFAULT_CHOICE THEME->GetMetric (m_sName,"DefaultChoice")
2003-11-12 02:53:28 +00:00
/* OptionOrderLeft=0:1,1:2,2:3,3:4 */
const char *ScreenSelectMaster::dirs[NUM_DIRS] =
{
"Up", "Down", "Left", "Right", "Auto"
};
2003-06-20 23:07:45 +00:00
const ScreenMessage SM_PlayPostSwitchPage = (ScreenMessage)(SM_User+1);
2004-11-26 17:28:47 +00:00
REGISTER_SCREEN_CLASS( ScreenSelectMaster );
2003-09-27 22:30:51 +00:00
ScreenSelectMaster::ScreenSelectMaster( CString sClassName ) : ScreenSelect( sClassName )
2003-06-20 23:07:45 +00:00
{
2005-01-04 10:47:28 +00:00
// TODO: Move default choice to ScreenSelect
int iDefaultChoice = -1;
2004-12-02 06:29:20 +00:00
for( unsigned c=0; c<m_aGameCommands.size(); c++ )
{
2004-12-02 06:29:20 +00:00
const GameCommand& mc = m_aGameCommands[c];
if( mc.m_sName == DEFAULT_CHOICE )
{
iDefaultChoice = c;
break;
}
}
FOREACH_PlayerNumber( p )
2003-06-20 23:07:45 +00:00
{
m_iChoice[p] = (iDefaultChoice!=-1) ? iDefaultChoice : 0;
2003-06-20 23:07:45 +00:00
m_bChosen[p] = false;
}
2004-01-17 23:14:56 +00:00
// init cursor
2003-06-20 23:07:45 +00:00
if( SHARED_PREVIEW_AND_CURSOR )
{
for( int i=0; i<NUM_CURSOR_PARTS; i++ )
2003-06-20 23:07:45 +00:00
{
CString sFName = ssprintf("%s Cursor Part%d", m_sName.c_str(),i+1);
m_sprCursor[i][0].Load( THEME->GetPathToG(sFName) );
2005-01-04 10:47:28 +00:00
m_sprCursor[i][0]->SetName( ssprintf("CursorPart%d",i+1) );
this->AddChild( m_sprCursor[i][0] );
2003-06-20 23:07:45 +00:00
}
}
else
{
for( int i=0; i<NUM_CURSOR_PARTS; i++ )
2003-06-20 23:07:45 +00:00
{
FOREACH_HumanPlayer( p )
2003-06-20 23:07:45 +00:00
{
CString sFName = ssprintf("%s Cursor Part%d P%d", m_sName.c_str(),i+1,p+1);
m_sprCursor[i][p].Load( THEME->GetPathToG(sFName) );
2005-01-04 10:47:28 +00:00
m_sprCursor[i][p]->SetName( ssprintf("CursorPart%dP%d",i+1,p+1) );
this->AddChild( m_sprCursor[i][p] );
2003-06-20 23:07:45 +00:00
}
}
}
2004-01-17 23:14:56 +00:00
// init scroll
if( SHOW_SCROLLER )
{
if( SHARED_PREVIEW_AND_CURSOR )
{
2004-02-01 03:14:37 +00:00
m_Scroller[0].Load(
SCROLLER_SECONDS_PER_ITEM,
2005-01-06 01:59:44 +00:00
SCROLLER_NUM_ITEMS_TO_DRAW,
2004-02-01 03:14:37 +00:00
RageVector3( 0, 0, 0 ),
RageVector3( 0, 0, 0 ),
RageVector3( SCROLLER_SPACING_X, SCROLLER_SPACING_Y, 0 ),
RageVector3( 0, 0, 0 ) );
2004-01-17 23:14:56 +00:00
m_Scroller[0].SetName( "Scroller" );
this->AddChild( &m_Scroller[0] );
2004-12-02 06:29:20 +00:00
for( unsigned c=0; c<m_aGameCommands.size(); c++ )
2004-01-17 23:14:56 +00:00
{
2004-12-02 06:29:20 +00:00
const GameCommand& mc = m_aGameCommands[c];
2004-01-17 23:14:56 +00:00
CString sFName = ssprintf("%s Scroll Choice%s", m_sName.c_str(),mc.m_sName.c_str());
2004-01-17 23:14:56 +00:00
m_sprScroll[c][0].Load( THEME->GetPathToG(sFName) );
m_sprScroll[c][0]->SetName( ssprintf("Scroll") );
2005-01-06 21:24:32 +00:00
m_sprScroll[c][0]->PlayCommand( "Init" );
2004-01-17 23:14:56 +00:00
m_Scroller[0].AddChild( m_sprScroll[c][0] );
}
}
else
{
FOREACH_HumanPlayer( p )
2004-01-17 23:14:56 +00:00
{
2004-02-01 03:14:37 +00:00
m_Scroller[p].Load(
SCROLLER_SECONDS_PER_ITEM,
2005-01-06 01:59:44 +00:00
SCROLLER_NUM_ITEMS_TO_DRAW,
2004-02-01 03:14:37 +00:00
RageVector3( 0, 0, 0 ),
RageVector3( 0, 0, 0 ),
RageVector3( SCROLLER_SPACING_X, SCROLLER_SPACING_Y, 0 ),
RageVector3( 0, 0, 0 ) );
2004-01-17 23:14:56 +00:00
m_Scroller[p].SetName( ssprintf("ScrollerP%d",p+1) );
this->AddChild( &m_Scroller[p] );
2004-12-02 06:29:20 +00:00
for( unsigned c=0; c<m_aGameCommands.size(); c++ )
2004-01-17 23:14:56 +00:00
{
2004-12-02 06:29:20 +00:00
const GameCommand& mc = m_aGameCommands[c];
2004-01-17 23:14:56 +00:00
2004-02-13 09:32:32 +00:00
CString sFName = ssprintf("%s Scroll Choice%s P%d", m_sName.c_str(),mc.m_sName.c_str(),p+1);
2004-01-17 23:14:56 +00:00
m_sprScroll[c][p].Load( THEME->GetPathToG(sFName) );
m_sprScroll[c][p]->SetName( ssprintf("ScrollP%d",p+1) );
2005-01-06 21:24:32 +00:00
m_sprScroll[c][p]->PlayCommand( "Init" );
2004-01-17 23:14:56 +00:00
m_Scroller[p].AddChild( m_sprScroll[c][p] );
}
}
}
}
2004-12-02 06:29:20 +00:00
for( unsigned c=0; c<m_aGameCommands.size(); c++ )
2003-06-20 23:07:45 +00:00
{
2004-12-02 06:29:20 +00:00
const GameCommand& mc = m_aGameCommands[c];
2003-06-20 23:07:45 +00:00
2004-01-17 23:14:56 +00:00
// init icon
for( int i=0; i<NUM_ICON_PARTS; i++ )
2003-06-20 23:07:45 +00:00
{
CString sFName = ssprintf("%s Icon Part%d Choice%s", m_sName.c_str(),i+1,mc.m_sName.c_str());
2003-06-20 23:07:45 +00:00
m_sprIcon[i][c].Load( THEME->GetPathToG(sFName) );
m_sprIcon[i][c]->SetName( ssprintf("IconPart%dChoice%s",i+1,mc.m_sName.c_str()) );
2003-11-05 04:09:10 +00:00
this->AddChild( m_sprIcon[i][c] );
2003-06-20 23:07:45 +00:00
}
2004-01-17 23:14:56 +00:00
// init preview
2003-06-20 23:07:45 +00:00
if( SHARED_PREVIEW_AND_CURSOR )
{
2004-05-24 08:17:19 +00:00
for( int i=0; i<NUM_PREVIEW_PARTS; i++ )
2003-06-20 23:07:45 +00:00
{
CString sFName = ssprintf("%s Preview Part%d Choice%s", m_sName.c_str(),i+1,mc.m_sName.c_str());
2003-06-20 23:07:45 +00:00
m_sprPreview[i][c][0].Load( THEME->GetPathToG(sFName) );
2003-11-05 04:09:10 +00:00
m_sprPreview[i][c][0]->SetName( ssprintf("PreviewPart%d",i+1) );
this->AddChild( m_sprPreview[i][c][0] );
2003-06-20 23:07:45 +00:00
}
}
else
{
FOREACH_HumanPlayer( p )
2003-06-20 23:07:45 +00:00
{
2004-05-24 08:17:19 +00:00
for( int i=0; i<NUM_PREVIEW_PARTS; i++ )
2003-06-20 23:07:45 +00:00
{
CString sFName = ssprintf("%s Preview Part%d Choice%s P%d", m_sName.c_str(),i+1,mc.m_sName.c_str(),p+1);
2003-06-20 23:07:45 +00:00
m_sprPreview[i][c][p].Load( THEME->GetPathToG(sFName) );
2003-11-05 04:09:10 +00:00
m_sprPreview[i][c][p]->SetName( ssprintf("PreviewPart%dP%d",i+1,p+1) );
this->AddChild( m_sprPreview[i][c][p] );
2003-06-20 23:07:45 +00:00
}
}
}
}
2004-01-17 23:14:56 +00:00
2003-06-20 23:07:45 +00:00
for( int page=0; page<NUM_PAGES; page++ )
{
2003-11-04 21:07:36 +00:00
m_sprMore[page].Load( THEME->GetPathToG( ssprintf("%s more page%d",m_sName.c_str(), page+1) ) );
2005-01-04 10:47:28 +00:00
m_sprMore[page]->SetName( ssprintf("MorePage%d",page+1) );
this->AddChild( m_sprMore[page] );
2003-06-20 23:07:45 +00:00
2003-11-04 21:07:36 +00:00
m_sprExplanation[page].Load( THEME->GetPathToG( ssprintf("%s explanation page%d",m_sName.c_str(), page+1) ) );
2003-11-05 19:35:57 +00:00
m_sprExplanation[page]->SetName( ssprintf("ExplanationPage%d",page+1) );
this->AddChild( m_sprExplanation[page] );
2003-06-20 23:07:45 +00:00
}
FOREACH_PlayerNumber( p )
2003-06-20 23:07:45 +00:00
{
2004-12-02 06:29:20 +00:00
CLAMP( m_iChoice[p], 0, (int)m_aGameCommands.size()-1 );
2003-06-20 23:07:45 +00:00
m_bChosen[p] = false;
}
2004-12-04 21:23:37 +00:00
m_soundChange.Load( THEME->GetPathToS( ssprintf("%s change", m_sName.c_str())), true );
2003-06-20 23:07:45 +00:00
m_soundDifficult.Load( ANNOUNCER->GetPathTo("select difficulty challenge") );
2004-12-04 21:16:00 +00:00
m_soundStart.Load( THEME->GetPathToS( ssprintf("%s start", m_sName.c_str())) );
2003-06-20 23:07:45 +00:00
2004-01-17 23:14:56 +00:00
// init m_Next order info
2003-11-12 02:53:28 +00:00
for( int dir = 0; dir < NUM_DIRS; ++dir )
{
2004-04-13 22:23:37 +00:00
/* Reasonable defaults: */
2004-12-02 06:29:20 +00:00
for( unsigned c = 0; c < m_aGameCommands.size(); ++c )
2004-04-13 22:23:37 +00:00
{
int add;
switch( dir )
{
case DIR_UP:
case DIR_LEFT: add = -1; break;
default: add = +1; break;
}
m_Next[dir][c] = c + add;
2004-04-13 23:11:32 +00:00
/* By default, only wrap around for DIR_AUTO. */
if( dir == DIR_AUTO )
2004-12-02 06:29:20 +00:00
wrap( m_Next[dir][c], m_aGameCommands.size() );
2004-04-13 23:11:32 +00:00
else
2004-12-02 06:29:20 +00:00
m_Next[dir][c] = clamp( m_Next[dir][c], 0, (int)m_aGameCommands.size()-1 );
2004-04-13 22:23:37 +00:00
}
2003-11-12 02:53:28 +00:00
const CString dirname = dirs[dir];
const CString order = OPTION_ORDER( dirname );
vector<CString> parts;
split( order, ",", parts, true );
if( parts.size() == 0 )
continue;
for( unsigned part = 0; part < parts.size(); ++part )
{
unsigned from, to;
if( sscanf( parts[part], "%u:%u", &from, &to ) != 2 )
{
LOG->Warn( "%s::OptionOrder%s parse error", m_sName.c_str(), dirname.c_str() );
continue;
}
--from;
--to;
2004-12-02 06:29:20 +00:00
if( from >= m_aGameCommands.size() ||
to >= m_aGameCommands.size() )
2003-11-12 02:53:28 +00:00
{
LOG->Warn( "%s::OptionOrder%s out of range", m_sName.c_str(), dirname.c_str() );
continue;
}
m_Next[dir][from] = to;
}
}
this->UpdateSelectableChoices();
2004-02-01 05:03:45 +00:00
TweenOnScreen();
2004-05-15 23:11:20 +00:00
m_fLockInputSecs =
THEME->HasMetric(m_sName,"LockInputSeconds") ?
THEME->GetMetricF(m_sName,"LockInputSeconds") :
this->GetTweenTimeLeft();
2003-06-20 23:07:45 +00:00
}
void ScreenSelectMaster::Update( float fDelta )
{
ScreenSelect::Update( fDelta );
m_fLockInputSecs = max( 0, m_fLockInputSecs-fDelta );
}
void ScreenSelectMaster::HandleScreenMessage( const ScreenMessage SM )
{
ScreenSelect::HandleScreenMessage( SM );
switch( SM )
{
case SM_PlayPostSwitchPage:
{
if( SHARED_PREVIEW_AND_CURSOR )
{
for( int i=0; i<NUM_CURSOR_PARTS; i++ )
{
2005-01-04 10:47:28 +00:00
m_sprCursor[i][0]->SetXY( GetCursorX((PlayerNumber)0,i), GetCursorY((PlayerNumber)0,i) );
2004-02-01 03:14:37 +00:00
COMMAND( m_sprCursor[i][0], "PostSwitchPage" );
2003-06-20 23:07:45 +00:00
}
}
else
{
for( int i=0; i<NUM_CURSOR_PARTS; i++ )
FOREACH_HumanPlayer( p )
{
2005-01-04 10:47:28 +00:00
m_sprCursor[i][p]->SetXY( GetCursorX(p,i), GetCursorY(p,i) );
COMMAND( m_sprCursor[i][p], "PostSwitchPage" );
}
2003-06-20 23:07:45 +00:00
}
if( SHARED_PREVIEW_AND_CURSOR )
{
for( int i=0; i<NUM_PREVIEW_PARTS; i++ )
2004-02-01 03:14:37 +00:00
COMMAND( m_sprPreview[i][m_iChoice[0]][0], "PostSwitchPage" );
2003-06-20 23:07:45 +00:00
}
else
{
for( int i=0; i<NUM_PREVIEW_PARTS; i++ )
FOREACH_HumanPlayer( p )
COMMAND( m_sprPreview[i][m_iChoice[p]][p], "PostSwitchPage" );
2003-06-20 23:07:45 +00:00
}
m_fLockInputSecs = POST_SWITCH_PAGE_SECONDS;
}
break;
case SM_BeginFadingOut:
2004-02-01 03:14:37 +00:00
{
TweenOffScreen();
float fSecs = GetTweenTimeLeft();
/* This can be used to allow overlap between the main tween-off and the MenuElements
* tweenoff. */
fSecs += EXTRA_SLEEP_AFTER_TWEEN_OFF_SECONDS;
fSecs = max( fSecs, 0 );
SCREENMAN->PostMessageToTopScreen( SM_AllDoneChoosing, fSecs ); // nofify parent that we're finished
StopTimer();
2004-02-01 03:14:37 +00:00
}
2003-06-20 23:07:45 +00:00
break;
}
}
int ScreenSelectMaster::GetSelectionIndex( PlayerNumber pn )
{
return m_iChoice[pn];
}
void ScreenSelectMaster::UpdateSelectableChoices()
{
2004-12-02 06:29:20 +00:00
for( unsigned c=0; c<m_aGameCommands.size(); c++ )
for( int i=0; i<NUM_ICON_PARTS; i++ )
2004-12-02 06:29:20 +00:00
COMMAND( m_sprIcon[i][c], m_aGameCommands[c].IsPlayable()? "Enabled":"Disabled" );
2003-06-20 23:07:45 +00:00
2005-01-04 10:47:28 +00:00
FOREACH_HumanPlayer( p )
2003-06-20 23:07:45 +00:00
{
2004-12-02 06:29:20 +00:00
if( !m_aGameCommands[m_iChoice[p]].IsPlayable() )
2005-01-04 10:47:28 +00:00
Move( p, DIR_AUTO );
2004-12-02 06:29:20 +00:00
ASSERT( m_aGameCommands[m_iChoice[p]].IsPlayable() );
}
}
2003-11-12 02:53:28 +00:00
bool ScreenSelectMaster::Move( PlayerNumber pn, Dirs dir )
{
int iSwitchToIndex = m_iChoice[pn];
2004-04-13 23:11:32 +00:00
set<int> seen;
2003-11-10 19:05:04 +00:00
do
{
2003-11-12 02:53:28 +00:00
iSwitchToIndex = m_Next[dir][iSwitchToIndex];
if( iSwitchToIndex == -1 )
return false; // can't go that way
2004-04-13 23:11:32 +00:00
if( seen.find(iSwitchToIndex) != seen.end() )
2003-11-12 02:53:28 +00:00
return false; // went full circle and none found
2004-04-13 23:11:32 +00:00
seen.insert( iSwitchToIndex );
2003-06-20 23:07:45 +00:00
}
2004-12-02 06:29:20 +00:00
while( !m_aGameCommands[iSwitchToIndex].IsPlayable() );
return ChangeSelection( pn, iSwitchToIndex );
2003-06-20 23:07:45 +00:00
}
void ScreenSelectMaster::MenuLeft( PlayerNumber pn )
{
2003-11-12 02:53:28 +00:00
if( m_fLockInputSecs > 0 || m_bChosen[pn] )
2003-06-20 23:07:45 +00:00
return;
2003-11-12 02:53:28 +00:00
if( Move(pn, DIR_LEFT) )
m_soundChange.Play();
2003-06-20 23:07:45 +00:00
}
void ScreenSelectMaster::MenuRight( PlayerNumber pn )
{
2003-11-12 02:53:28 +00:00
if( m_fLockInputSecs > 0 || m_bChosen[pn] )
return;
if( Move(pn, DIR_RIGHT) )
m_soundChange.Play();
}
void ScreenSelectMaster::MenuUp( PlayerNumber pn )
{
if( m_fLockInputSecs > 0 || m_bChosen[pn] )
2003-06-20 23:07:45 +00:00
return;
2003-11-12 02:53:28 +00:00
if( Move(pn, DIR_UP) )
m_soundChange.Play();
}
void ScreenSelectMaster::MenuDown( PlayerNumber pn )
{
if( m_fLockInputSecs > 0 || m_bChosen[pn] )
2003-06-20 23:07:45 +00:00
return;
2003-11-12 02:53:28 +00:00
if( Move(pn, DIR_DOWN) )
m_soundChange.Play();
2003-06-20 23:07:45 +00:00
}
bool ScreenSelectMaster::ChangePage( int iNewChoice )
2003-06-20 23:07:45 +00:00
{
Page newPage = GetPage(iNewChoice);
2003-06-20 23:07:45 +00:00
// If anyone has already chosen, don't allow changing of pages
FOREACH_PlayerNumber( p )
2003-06-20 23:07:45 +00:00
if( GAMESTATE->IsHumanPlayer(p) && m_bChosen[p] )
return false;
2003-06-20 23:07:45 +00:00
if( SHARED_PREVIEW_AND_CURSOR )
{
for( int i=0; i<NUM_CURSOR_PARTS; i++ )
2004-02-01 03:14:37 +00:00
COMMAND( m_sprCursor[i][0], "PreSwitchPage" );
2003-06-20 23:07:45 +00:00
}
else
{
for( int i=0; i<NUM_CURSOR_PARTS; i++ )
FOREACH_PlayerNumber( p )
2003-06-20 23:07:45 +00:00
if( GAMESTATE->IsHumanPlayer(p) )
2004-02-01 03:14:37 +00:00
COMMAND( m_sprCursor[i][p], "PreSwitchPage" );
2003-06-20 23:07:45 +00:00
}
const CString sIconAndExplanationCommand = ssprintf( "SwitchToPage%d", newPage+1 );
2004-12-02 06:29:20 +00:00
for( unsigned c=0; c<m_aGameCommands.size(); c++ )
2003-06-20 23:07:45 +00:00
for( int i=0; i<NUM_ICON_PARTS; i++ )
2004-02-01 03:14:37 +00:00
COMMAND( m_sprIcon[i][c], sIconAndExplanationCommand );
2003-06-20 23:07:45 +00:00
if( SHARED_PREVIEW_AND_CURSOR )
{
int iChoice = m_iChoice[GAMESTATE->m_MasterPlayerNumber];
2003-06-20 23:07:45 +00:00
for( int i=0; i<NUM_PREVIEW_PARTS; i++ )
COMMAND( m_sprPreview[i][iChoice][0], "PreSwitchPage" );
2003-06-20 23:07:45 +00:00
}
else
{
for( int i=0; i<NUM_PREVIEW_PARTS; i++ )
FOREACH_HumanPlayer( p )
{
int iChoice = m_iChoice[p];
COMMAND( m_sprPreview[i][iChoice][p], "PreSwitchPage" );
}
2003-06-20 23:07:45 +00:00
}
for( int page=0; page<NUM_PAGES; page++ )
{
2004-02-01 03:14:37 +00:00
COMMAND( m_sprExplanation[page], sIconAndExplanationCommand );
COMMAND( m_sprMore[page], sIconAndExplanationCommand );
2003-06-20 23:07:45 +00:00
}
if( newPage == PAGE_2 )
{
// XXX: only play this once (I thought we already did that?)
// DDR plays it on every change to page 2. -Chris
2003-11-04 20:57:19 +00:00
/* That sounds ugly if you go back and forth quickly. -g */
2004-01-17 23:14:56 +00:00
// DDR locks input while it's scrolling. Should we do the same? -Chris
2003-06-20 23:07:45 +00:00
m_soundDifficult.Stop();
m_soundDifficult.PlayRandom();
}
// change both players
FOREACH_PlayerNumber( p )
2003-06-20 23:07:45 +00:00
m_iChoice[p] = iNewChoice;
m_fLockInputSecs = PRE_SWITCH_PAGE_SECONDS;
this->PostScreenMessage( SM_PlayPostSwitchPage, PRE_SWITCH_PAGE_SECONDS );
return true;
2003-06-20 23:07:45 +00:00
}
bool ScreenSelectMaster::ChangeSelection( PlayerNumber pn, int iNewChoice )
2003-06-20 23:07:45 +00:00
{
2004-04-13 23:11:32 +00:00
if( iNewChoice == m_iChoice[pn] )
return false; // already there
if( GetPage(m_iChoice[pn]) != GetPage(iNewChoice) )
return ChangePage( iNewChoice );
FOREACH_PlayerNumber( p )
2003-06-20 23:07:45 +00:00
{
const int iOldChoice = m_iChoice[p];
2004-01-21 02:11:23 +00:00
/* Set the new m_iChoice even for disabled players, since a player might
* join on a SHARED_PREVIEW_AND_CURSOR after the cursor has been moved. */
m_iChoice[p] = iNewChoice;
if( p!=pn )
2003-06-20 23:07:45 +00:00
continue; // skip
if( SHARED_PREVIEW_AND_CURSOR )
{
for( int i=0; i<NUM_PREVIEW_PARTS; i++ )
{
COMMAND( m_sprPreview[i][iOldChoice][0], "LoseFocus" );
COMMAND( m_sprPreview[i][iNewChoice][0], "GainFocus" );
}
}
else
{
for( int i=0; i<NUM_PREVIEW_PARTS; i++ )
{
COMMAND( m_sprPreview[i][iOldChoice][p], "LoseFocus" );
COMMAND( m_sprPreview[i][iNewChoice][p], "GainFocus" );
}
}
2003-11-05 04:09:10 +00:00
{
/* XXX: If !SharedPreviewAndCursor, this is incorrect. (Nothing uses
* both icon focus and !SharedPreviewAndCursor right now.) */
for( int i=0; i<NUM_ICON_PARTS; i++ )
2003-11-05 04:09:10 +00:00
{
COMMAND( m_sprIcon[i][iOldChoice], "LoseFocus" );
COMMAND( m_sprIcon[i][iNewChoice], "GainFocus" );
}
}
2003-06-20 23:07:45 +00:00
if( SHARED_PREVIEW_AND_CURSOR )
{
for( int i=0; i<NUM_CURSOR_PARTS; i++ )
{
COMMAND( m_sprCursor[i][0], "Change" );
2005-01-04 10:47:28 +00:00
m_sprCursor[i][0]->SetXY( GetCursorX((PlayerNumber)0,i), GetCursorY((PlayerNumber)0,i) );
2003-06-20 23:07:45 +00:00
}
}
else
{
for( int i=0; i<NUM_CURSOR_PARTS; i++ )
{
COMMAND( m_sprCursor[i][p], "Change" );
2005-01-04 10:47:28 +00:00
m_sprCursor[i][p]->SetXY( GetCursorX(p,i), GetCursorY(p,i) );
2003-06-20 23:07:45 +00:00
}
}
2004-01-17 23:14:56 +00:00
if( SHOW_SCROLLER )
{
if( SHARED_PREVIEW_AND_CURSOR )
m_Scroller[0].SetDestinationItem( iNewChoice );
else
m_Scroller[p].SetDestinationItem( iNewChoice );
if( SHARED_PREVIEW_AND_CURSOR )
2004-12-02 06:29:20 +00:00
for( unsigned c=0; c<m_aGameCommands.size(); c++ )
2004-01-17 23:14:56 +00:00
COMMAND( *m_sprScroll[c][0], int(c) == m_iChoice[0]? "GainFocus":"LoseFocus" );
else
2004-12-02 06:29:20 +00:00
for( unsigned c=0; c<m_aGameCommands.size(); c++ )
2004-01-17 23:14:56 +00:00
COMMAND( *m_sprScroll[c][p], int(c) == m_iChoice[p]? "GainFocus":"LoseFocus" );
}
2003-06-20 23:07:45 +00:00
}
2004-01-17 23:14:56 +00:00
return true;
2003-06-20 23:07:45 +00:00
}
ScreenSelectMaster::Page ScreenSelectMaster::GetPage( int iChoiceIndex ) const
2003-06-20 23:07:45 +00:00
{
return iChoiceIndex < NUM_CHOICES_ON_PAGE_1? PAGE_1:PAGE_2;
2003-06-20 23:07:45 +00:00
}
ScreenSelectMaster::Page ScreenSelectMaster::GetCurrentPage() const
2003-06-20 23:07:45 +00:00
{
// Both players are guaranteed to be on the same page.
return GetPage( m_iChoice[GAMESTATE->m_MasterPlayerNumber] );
}
2004-02-01 05:03:45 +00:00
float ScreenSelectMaster::DoMenuStart( PlayerNumber pn )
2003-06-20 23:07:45 +00:00
{
2004-09-06 21:28:56 +00:00
if( m_bChosen[pn] )
2004-02-01 05:03:45 +00:00
return 0;
2003-06-20 23:07:45 +00:00
m_bChosen[pn] = true;
2004-02-01 05:03:45 +00:00
float fSecs = 0;
for( int page=0; page<NUM_PAGES; page++ )
2004-02-01 05:03:45 +00:00
{
2004-02-01 03:14:37 +00:00
OFF_COMMAND( m_sprMore[page] );
2005-01-04 10:47:28 +00:00
fSecs = max( fSecs, m_sprMore[page]->GetTweenTimeLeft() );
2004-02-01 05:03:45 +00:00
}
2003-06-20 23:07:45 +00:00
for( int i=0; i<NUM_CURSOR_PARTS; i++ )
2004-02-01 05:03:45 +00:00
{
2004-02-01 03:14:37 +00:00
COMMAND( m_sprCursor[i][pn], "Choose");
2005-01-04 10:47:28 +00:00
fSecs = max( fSecs, m_sprCursor[i][pn]->GetTweenTimeLeft() );
2004-02-01 05:03:45 +00:00
}
return fSecs;
}
2003-06-20 23:07:45 +00:00
void ScreenSelectMaster::MenuStart( PlayerNumber pn )
{
if( m_fLockInputSecs > 0 )
return;
2004-09-06 21:28:56 +00:00
if( m_bChosen[pn] )
return;
2004-12-02 06:29:20 +00:00
GameCommand &mc = m_aGameCommands[m_iChoice[pn]];
SOUND->PlayOnceFromDir( ANNOUNCER->GetPathTo(ssprintf("%s comment %s",m_sName.c_str(), mc.m_sName.c_str())) );
2004-12-04 21:16:00 +00:00
m_soundStart.Play();
2004-02-01 05:03:45 +00:00
float fSecs = 0;
bool bAllDone = true;
if( SHARED_PREVIEW_AND_CURSOR || GetCurrentPage() == PAGE_2 )
{
/* Only one player has to pick. Choose this for all the other players, too. */
2004-07-28 16:05:39 +00:00
FOREACH_HumanPlayer( p )
{
ASSERT( !m_bChosen[p] );
fSecs = max( fSecs, DoMenuStart(p) );
}
2004-02-01 03:14:37 +00:00
}
else
{
2004-02-01 05:03:45 +00:00
fSecs = max( fSecs, DoMenuStart(pn) );
// check to see if everyone has chosen
2004-07-28 16:05:39 +00:00
FOREACH_HumanPlayer( p )
bAllDone &= m_bChosen[p];
}
2003-06-20 23:07:45 +00:00
if( bAllDone )
2004-02-01 05:03:45 +00:00
this->PostScreenMessage( SM_BeginFadingOut, fSecs );// tell our owner it's time to move on
2003-06-20 23:07:45 +00:00
}
/*
* We want all items to always run OnCommand and either GainFocus or LoseFocus on
* tween-in. If we only run OnCommand, then it has to contain a copy of either
* GainFocus or LoseFocus, which implies that the default setting is hard-coded in
* the theme. Always run both.
*
* However, the actual tween-in is OnCommand; we don't always want to actually run
* through the Gain/LoseFocus tweens during initial tween-in. So, we run the focus
* command first, do a FinishTweening to pop it in place, and then run OnCommand.
* This means that the focus command should be position neutral; eg. only use "addx",
* not "x".
*/
2004-02-01 03:14:37 +00:00
void ScreenSelectMaster::TweenOnScreen()
2003-06-20 23:07:45 +00:00
{
2004-12-02 06:29:20 +00:00
for( unsigned c=0; c<m_aGameCommands.size(); c++ )
2003-06-20 23:07:45 +00:00
{
for( int i=0; i<NUM_ICON_PARTS; i++ )
2003-11-05 04:09:10 +00:00
{
COMMAND( m_sprIcon[i][c], (int(c) == m_iChoice[0])? "GainFocus":"LoseFocus" );
m_sprIcon[i][c]->FinishTweening();
2004-02-01 03:14:37 +00:00
SET_XY_AND_ON_COMMAND( m_sprIcon[i][c] );
2003-11-05 04:09:10 +00:00
}
2003-06-20 23:07:45 +00:00
if( SHARED_PREVIEW_AND_CURSOR )
{
int p=0;
for( int i=0; i<NUM_PREVIEW_PARTS; i++ )
{
COMMAND( m_sprPreview[i][c][p], (int(c) == m_iChoice[p])? "GainFocus":"LoseFocus" );
m_sprPreview[i][c][p]->FinishTweening();
2004-02-01 03:14:37 +00:00
SET_XY_AND_ON_COMMAND( m_sprPreview[i][c][p] );
2003-06-20 23:07:45 +00:00
}
}
else
{
FOREACH_HumanPlayer( p )
for( int i=0; i<NUM_PREVIEW_PARTS; i++ )
{
COMMAND( m_sprPreview[i][c][p], int(c) == m_iChoice[p]? "GainFocus":"LoseFocus" );
m_sprPreview[i][c][p]->FinishTweening();
SET_XY_AND_ON_COMMAND( m_sprPreview[i][c][p] );
}
2003-06-20 23:07:45 +00:00
}
}
// Need to SetXY of Cursor after Icons since it depends on the Icons' positions.
if( SHARED_PREVIEW_AND_CURSOR )
{
for( int i=0; i<NUM_CURSOR_PARTS; i++ )
{
2005-01-04 10:47:28 +00:00
m_sprCursor[i][0]->SetXY( GetCursorX((PlayerNumber)0,i), GetCursorY((PlayerNumber)0,i) );
2004-02-01 03:14:37 +00:00
ON_COMMAND( m_sprCursor[i][0] );
2003-06-20 23:07:45 +00:00
}
}
else
{
for( int i=0; i<NUM_CURSOR_PARTS; i++ )
FOREACH_HumanPlayer( p )
{
2005-01-04 10:47:28 +00:00
m_sprCursor[i][p]->SetXY( GetCursorX(p,i), GetCursorY(p,i) );
ON_COMMAND( m_sprCursor[i][p] );
}
2003-06-20 23:07:45 +00:00
}
2004-01-17 23:14:56 +00:00
if( SHOW_SCROLLER )
{
if( SHARED_PREVIEW_AND_CURSOR )
{
m_Scroller[0].SetCurrentAndDestinationItem( m_iChoice[0] );
2004-02-01 03:14:37 +00:00
SET_XY_AND_ON_COMMAND( m_Scroller[0] );
2004-12-02 06:29:20 +00:00
for( unsigned c=0; c<m_aGameCommands.size(); c++ )
2004-02-01 03:14:37 +00:00
COMMAND( *m_sprScroll[c][0], int(c) == m_iChoice[0]? "GainFocus":"LoseFocus" );
2004-01-17 23:14:56 +00:00
}
else
FOREACH_HumanPlayer( p )
{
m_Scroller[p].SetCurrentAndDestinationItem( m_iChoice[p] );
SET_XY_AND_ON_COMMAND( m_Scroller[p] );
2004-12-02 06:29:20 +00:00
for( unsigned c=0; c<m_aGameCommands.size(); c++ )
COMMAND( *m_sprScroll[c][p], int(c) == m_iChoice[p]? "GainFocus":"LoseFocus" );
}
2004-01-17 23:14:56 +00:00
}
2003-06-20 23:07:45 +00:00
//We have to move page two's explanation and more off the screen
//so it doesn't just sit there on page one. (Thanks Zhek)
for (int page=0;page<NUM_PAGES;page++)
{
2005-01-04 10:47:28 +00:00
m_sprMore[page]->SetXY(999,999);
m_sprExplanation[page]->SetXY(999,999);
}
2004-02-01 03:14:37 +00:00
SET_XY_AND_ON_COMMAND( m_sprExplanation[GetCurrentPage()] );
SET_XY_AND_ON_COMMAND( m_sprMore[GetCurrentPage()] );
2003-06-20 23:07:45 +00:00
2004-05-02 03:01:27 +00:00
this->SortByDrawOrder();
2003-06-20 23:07:45 +00:00
}
2004-02-01 03:14:37 +00:00
void ScreenSelectMaster::TweenOffScreen()
2003-06-20 23:07:45 +00:00
{
if( SHARED_PREVIEW_AND_CURSOR )
{
for( int i=0; i<NUM_CURSOR_PARTS; i++ )
2004-02-01 03:14:37 +00:00
OFF_COMMAND( m_sprCursor[i][0] );
2003-06-20 23:07:45 +00:00
}
else
{
for( int i=0; i<NUM_CURSOR_PARTS; i++ )
FOREACH_HumanPlayer( p )
OFF_COMMAND( m_sprCursor[i][p] );
2003-06-20 23:07:45 +00:00
}
2004-12-02 06:29:20 +00:00
for( unsigned c=0; c<m_aGameCommands.size(); c++ )
2003-06-20 23:07:45 +00:00
{
if( GetPage(c) != GetCurrentPage() )
continue; // skip
2003-11-05 21:34:14 +00:00
bool SelectedByEitherPlayer = false;
2003-11-24 03:59:09 +00:00
if( SHARED_PREVIEW_AND_CURSOR )
{
if( m_iChoice[0] == (int)c )
2003-11-05 21:34:14 +00:00
SelectedByEitherPlayer = true;
2003-11-24 03:59:09 +00:00
}
else
FOREACH_HumanPlayer( p )
if( m_iChoice[p] == (int)c )
2003-11-24 03:59:09 +00:00
SelectedByEitherPlayer = true;
2003-11-05 21:34:14 +00:00
2003-06-20 23:07:45 +00:00
for( int i=0; i<NUM_ICON_PARTS; i++ )
{
2004-02-01 03:14:37 +00:00
OFF_COMMAND( m_sprIcon[i][c] );
COMMAND( m_sprIcon[i][c], SelectedByEitherPlayer? "OffFocused":"OffUnfocused" );
}
2003-06-20 23:07:45 +00:00
if( SHARED_PREVIEW_AND_CURSOR )
{
for( int i=0; i<NUM_PREVIEW_PARTS; i++ )
2003-11-05 21:34:14 +00:00
{
2004-02-01 03:14:37 +00:00
OFF_COMMAND( m_sprPreview[i][c][0] );
COMMAND( m_sprPreview[i][c][0], SelectedByEitherPlayer? "OffFocused":"OffUnfocused" );
2003-11-05 21:34:14 +00:00
}
2003-06-20 23:07:45 +00:00
}
else
{
for( int i=0; i<NUM_PREVIEW_PARTS; i++ )
FOREACH_HumanPlayer( p )
{
OFF_COMMAND( m_sprPreview[i][c][p] );
COMMAND( m_sprPreview[i][c][0], SelectedByEitherPlayer? "OffFocused":"OffUnfocused" );
}
2003-06-20 23:07:45 +00:00
}
}
2004-01-17 23:14:56 +00:00
if( SHOW_SCROLLER )
{
if( SHARED_PREVIEW_AND_CURSOR )
2004-02-01 03:14:37 +00:00
OFF_COMMAND( m_Scroller[0] );
2004-01-17 23:14:56 +00:00
else
FOREACH_PlayerNumber( p )
2004-02-01 03:14:37 +00:00
OFF_COMMAND( m_Scroller[p] );
2004-01-17 23:14:56 +00:00
}
2004-02-01 03:14:37 +00:00
OFF_COMMAND( m_sprExplanation[GetCurrentPage()] );
OFF_COMMAND( m_sprMore[GetCurrentPage()] );
2003-06-20 23:07:45 +00:00
}
float ScreenSelectMaster::GetCursorX( PlayerNumber pn, int iPartIndex )
{
2003-11-05 04:09:10 +00:00
return m_sprIcon[0][m_iChoice[pn]]->GetX() + CURSOR_OFFSET_X_FROM_ICON(pn, iPartIndex);
2003-06-20 23:07:45 +00:00
}
float ScreenSelectMaster::GetCursorY( PlayerNumber pn, int iPartIndex )
{
2003-11-05 04:09:10 +00:00
return m_sprIcon[0][m_iChoice[pn]]->GetY() + CURSOR_OFFSET_Y_FROM_ICON(pn, iPartIndex);
2003-06-20 23:07:45 +00:00
}
2004-06-08 05:22:33 +00:00
/*
* (c) 2003-2004 Chris Danford
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, and/or sell copies of the Software, and to permit persons to
* whom the Software is furnished to do so, provided that the above
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/