Files
itgmania212121/src/ScreenSelect.cpp
T

344 lines
10 KiB
C++
Raw Normal View History

2010-01-26 21:00:30 -06:00
#include "global.h"
#include "ScreenSelect.h"
#include "ScreenManager.h"
#include "GameSoundManager.h"
#include "RageLog.h"
#include "AnnouncerManager.h"
#include "GameState.h"
#include "ThemeManager.h"
#include "GameCommand.h"
#include "InputEventPlus.h"
#define CHOICE_NAMES THEME->GetMetric (m_sName,"ChoiceNames")
#define CHOICE( s ) THEME->GetMetric (m_sName,ssprintf("Choice%s",s.c_str()))
#define IDLE_TIMEOUT_SCREEN THEME->GetMetric (m_sName,"IdleTimeoutScreen")
#define UPDATE_ON_MESSAGE THEME->GetMetric (m_sName,"UpdateOnMessage")
#if defined(SSC_FUTURES)
#define LIST_NAMES THEME->GetMetric (m_sName,"ListNames")
2010-01-26 21:00:30 -06:00
#else
// xxx: USE_TWO_LISTS is just a hack for two players. -aj
2010-01-26 21:00:30 -06:00
#define USE_TWO_LISTS THEME->GetMetricB (m_sName,"UseTwoLists")
#endif
#if defined(SSC_FUTURES)
#define LIST_CONDITION( s ) THEME->GetMetricR (m_sName,"List%sCondition",s.c_str())
#define CHOICE_NAMES_MULTI( s ) THEME->GetMetric (m_sName,ssprintf("List%sChoiceNames",s.c_str()))
#define CHOICEMULTI( s1, s2 ) THEME->GetMetric (m_sName,ssprintf("List%sChoice%s",s1.c_str(),s2.c_str()))
2010-01-26 21:00:30 -06:00
#else
// xxx: these are used by USE_TWO_LISTS. -aj
2010-01-26 21:00:30 -06:00
#define CHOICE_NAMESB THEME->GetMetric (m_sName,"ChoiceNamesB")
#define CHOICEB( s ) THEME->GetMetric (m_sName,ssprintf("ChoiceB%s",s.c_str()))
#endif
void ScreenSelect::Init()
{
IDLE_COMMENT_SECONDS.Load( m_sName, "IdleCommentSeconds" );
IDLE_TIMEOUT_SECONDS.Load( m_sName, "IdleTimeoutSeconds" );
ALLOW_DISABLED_PLAYER_INPUT.Load( m_sName, "AllowDisabledPlayerInput" );
ScreenWithMenuElements::Init();
// Load messages to update on
split( UPDATE_ON_MESSAGE, ",", m_asSubscribedMessages );
for( unsigned i = 0; i < m_asSubscribedMessages.size(); ++i )
MESSAGEMAN->Subscribe( this, m_asSubscribedMessages[i] );
// Subscribe to PlayerJoined, if not already.
if( !MESSAGEMAN->IsSubscribedToMessage(this, Message_PlayerJoined) )
this->SubscribeToMessage( Message_PlayerJoined );
// Load choices
{
// Instead of using NUM_CHOICES, use a comma-separated list of choices.
// Each element in the list is a choice name. This level of indirection
// makes it easier to add or remove items without having to change a
// bunch of indices.
2010-01-26 21:00:30 -06:00
vector<RString> asChoiceNames;
split( CHOICE_NAMES, ",", asChoiceNames, true );
for( unsigned c=0; c<asChoiceNames.size(); c++ )
{
RString sChoiceName = asChoiceNames[c];
GameCommand mc;
mc.ApplyCommitsScreens( false );
mc.m_sName = sChoiceName;
Commands cmd = ParseCommands( CHOICE(sChoiceName) );
mc.Load( c, cmd );
m_aGameCommands.push_back( mc );
}
m_iSelectedList = 0;
if(USE_TWO_LISTS)
{
m_bUsingTwoLists = true;
vector<RString> asChoiceNames2;
split( CHOICE_NAMESB, ",", asChoiceNames2, true );
for( unsigned c=0; c<asChoiceNames2.size(); c++ )
{
RString sChoiceName = asChoiceNames2[c];
GameCommand mc;
mc.ApplyCommitsScreens( false );
mc.m_sName = sChoiceName;
Commands cmd = ParseCommands( CHOICEB(sChoiceName) );
mc.Load( c, cmd );
m_aGameCommandsB.push_back( mc );
}
}
else
{
m_bUsingTwoLists = false;
}
}
if( !m_aGameCommands.size() )
RageException::Throw( "Screen \"%s\" does not set any choices.", m_sName.c_str() );
if(USE_TWO_LISTS)
{
if(!m_aGameCommandsB.size() )
RageException::Throw ("Screen \"%s\" has specified two lists, but does not set any choices for the second list.",m_sName.c_str() );
}
}
void ScreenSelect::BeginScreen()
{
ScreenWithMenuElements::BeginScreen();
if(USE_TWO_LISTS)
{
if( GAMESTATE->GetNumSidesJoined() > 1 )
{
m_iSelectedList = 1;
this->UpdateSelectableChoices();
}
}
m_timerIdleComment.GetDeltaTime();
m_timerIdleTimeout.GetDeltaTime();
}
ScreenSelect::~ScreenSelect()
{
LOG->Trace( "ScreenSelect::~ScreenSelect()" );
for( unsigned i = 0; i < m_asSubscribedMessages.size(); ++i )
MESSAGEMAN->Unsubscribe( this, m_asSubscribedMessages[i] );
}
void ScreenSelect::Update( float fDelta )
{
if( !IsTransitioning() )
{
if( IDLE_COMMENT_SECONDS > 0 && m_timerIdleComment.PeekDeltaTime() >= IDLE_COMMENT_SECONDS )
{
SOUND->PlayOnceFromAnnouncer( m_sName+" IdleComment" );
m_timerIdleComment.GetDeltaTime();
}
if( IDLE_TIMEOUT_SECONDS > 0 && m_timerIdleTimeout.PeekDeltaTime() >= IDLE_TIMEOUT_SECONDS )
{
SCREENMAN->SetNewScreen( IDLE_TIMEOUT_SCREEN );
m_timerIdleTimeout.GetDeltaTime();
return;
}
}
ScreenWithMenuElements::Update( fDelta );
}
void ScreenSelect::Input( const InputEventPlus &input )
{
// LOG->Trace( "ScreenSelect::Input()" );
/* Reset the announcer timers when a key is pressed. */
m_timerIdleComment.GetDeltaTime();
m_timerIdleTimeout.GetDeltaTime();
/* Choices may change when more coins are inserted. */
if( input.MenuI == GAME_BUTTON_COIN && input.type == IET_FIRST_PRESS )
this->UpdateSelectableChoices();
if( input.MenuI == GAME_BUTTON_START && input.type == IET_FIRST_PRESS && GAMESTATE->JoinInput(input.pn) )
{
if( GAMESTATE->GetNumSidesJoined() > 1 )
{
if(USE_TWO_LISTS)
{
m_iSelectedList = 1;
this->UpdateSelectableChoices();
}
// HACK: Only play start sound for the 2nd player who joins. The
2010-01-26 21:00:30 -06:00
// start sound for the 1st player will be played by ScreenTitleMenu
// when the player makes a selection on the screen.
SCREENMAN->PlayStartSound();
}
if( !ALLOW_DISABLED_PLAYER_INPUT )
return; // don't let the screen handle the MENU_START press
}
if( !GAMESTATE->IsPlayerEnabled(input.pn) )
{
// block input of disabled players
if( !ALLOW_DISABLED_PLAYER_INPUT )
return;
/* Never allow a START press by a player that's still not joined, even if
* ALLOW_DISABLED_PLAYER_INPUT would allow other types of input. If we
* let a non-joined player start, we might start the game with no
* players joined (eg. if ScreenTitleJoin is started in pay with no
* credits). */
2010-01-26 21:00:30 -06:00
if( input.MenuI == GAME_BUTTON_START )
return;
}
ScreenWithMenuElements::Input( input ); // default input handler
2010-01-26 21:00:30 -06:00
}
void ScreenSelect::HandleScreenMessage( const ScreenMessage SM )
{
if( SM == SM_BeginFadingOut ) // Screen is starting to tween out.
2010-01-26 21:00:30 -06:00
{
2010-03-01 00:44:39 -06:00
/* Don't call GameCommand::Apply once per player on screens that
* have a shared selection. This can cause change messages to be
* broadcast multiple times. Detect whether all players have the
* same choice, and if so, call ApplyToAll instead.
2010-01-26 21:00:30 -06:00
* TODO: Think of a better way to handle this.
*/
ASSERT( GAMESTATE->m_MasterPlayerNumber != PlayerNumber_Invalid );
int iMastersIndex = this->GetSelectionIndex( GAMESTATE->m_MasterPlayerNumber );
bool bAllPlayersChoseTheSame = true;
FOREACH_HumanPlayer( p )
{
if( this->GetSelectionIndex(p) != iMastersIndex )
{
bAllPlayersChoseTheSame = false;
break;
}
}
if( bAllPlayersChoseTheSame )
{
if(USE_TWO_LISTS) // using two lists
{
if(m_iSelectedList == 0) // first list is selected
{
const GameCommand &gc = m_aGameCommands[iMastersIndex];
m_sNextScreen = gc.m_sScreen;
if( !gc.m_bInvalid )
gc.ApplyToAllPlayers();
}
else // second list is selected
{
const GameCommand &gc = m_aGameCommandsB[iMastersIndex];
m_sNextScreen = gc.m_sScreen;
if( !gc.m_bInvalid )
gc.ApplyToAllPlayers();
}
}
else // not using two lists
{
const GameCommand &gc = m_aGameCommands[iMastersIndex];
m_sNextScreen = gc.m_sScreen;
if( !gc.m_bInvalid )
gc.ApplyToAllPlayers();
}
2010-01-26 21:00:30 -06:00
}
else
{
if(USE_TWO_LISTS) // using two lists
{
if(m_iSelectedList == 0) // first list is selected
{
FOREACH_HumanPlayer( p )
{
int iIndex = this->GetSelectionIndex(p);
const GameCommand &gc = m_aGameCommands[iIndex];
m_sNextScreen = gc.m_sScreen;
if( !gc.m_bInvalid )
gc.Apply( p );
}
}
else
{
FOREACH_HumanPlayer( p )
{
int iIndex = this->GetSelectionIndex(p);
const GameCommand &gc = m_aGameCommandsB[iIndex];
m_sNextScreen = gc.m_sScreen;
if( !gc.m_bInvalid )
gc.Apply( p );
}
}
}
else // only using a single list
{
FOREACH_HumanPlayer( p )
{
int iIndex = this->GetSelectionIndex(p);
const GameCommand &gc = m_aGameCommands[iIndex];
m_sNextScreen = gc.m_sScreen;
if( !gc.m_bInvalid )
gc.Apply( p );
}
}
}
StopTimer();
SCREENMAN->RefreshCreditsMessages();
ASSERT( !IsTransitioning() );
StartTransitioningScreen( SM_GoToNextScreen );
}
ScreenWithMenuElements::HandleScreenMessage( SM );
}
void ScreenSelect::HandleMessage( const Message &msg )
{
if( find(m_asSubscribedMessages.begin(), m_asSubscribedMessages.end(), msg.GetName()) != m_asSubscribedMessages.end() )
this->UpdateSelectableChoices();
ScreenWithMenuElements::HandleMessage( msg );
}
void ScreenSelect::MenuBack( const InputEventPlus &input )
{
Cancel( SM_GoToPrevScreen );
}
/*
* (c) 2001-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.
*/