Files
itgmania212121/src/ScreenSelect.cpp
T

335 lines
9.5 KiB
C++
Raw Normal View History

2003-03-03 10:03:02 +00:00
#include "global.h"
#include "ScreenSelect.h"
#include "ScreenManager.h"
2004-07-08 00:10:34 +00:00
#include "GameSoundManager.h"
2003-03-03 10:03:02 +00:00
#include "RageLog.h"
#include "AnnouncerManager.h"
#include "GameState.h"
#include "ThemeManager.h"
2004-12-02 06:29:20 +00:00
#include "GameCommand.h"
#include "InputEventPlus.h"
2003-03-03 10:03:02 +00:00
2006-01-29 00:25:33 +00:00
#define CHOICE_NAMES THEME->GetMetric (m_sName,"ChoiceNames")
#define CHOICE( s ) THEME->GetMetric (m_sName,ssprintf("Choice%s",s.c_str()))
2006-01-29 00:25:33 +00:00
#define IDLE_TIMEOUT_SCREEN THEME->GetMetric (m_sName,"IdleTimeoutScreen")
#define UPDATE_ON_MESSAGE THEME->GetMetric (m_sName,"UpdateOnMessage")
#define USE_TWO_LISTS THEME->GetMetricB (m_sName,"UseTwoLists")
#define CHOICE_NAMESB THEME->GetMetric (m_sName,"ChoiceNamesB")
#define CHOICEB( s ) THEME->GetMetric (m_sName,ssprintf("ChoiceB%s",s.c_str()))
2003-03-03 10:03:02 +00:00
void ScreenSelect::Init()
{
2006-01-15 19:22:17 +00:00
IDLE_COMMENT_SECONDS.Load( m_sName, "IdleCommentSeconds" );
IDLE_TIMEOUT_SECONDS.Load( m_sName, "IdleTimeoutSeconds" );
ALLOW_DISABLED_PLAYER_INPUT.Load( m_sName, "AllowDisabledPlayerInput" );
ScreenWithMenuElements::Init();
2003-03-03 10:03:02 +00:00
2005-03-10 19:41:37 +00:00
//
// 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 );
2005-03-10 19:41:37 +00:00
2004-02-13 08:15:05 +00:00
//
// Load choices
//
2003-03-09 00:55:49 +00:00
{
2004-02-13 08:15:05 +00:00
// 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.
2006-01-22 01:00:06 +00:00
vector<RString> asChoiceNames;
2004-02-13 08:15:05 +00:00
split( CHOICE_NAMES, ",", asChoiceNames, true );
for( unsigned c=0; c<asChoiceNames.size(); c++ )
{
2006-01-22 01:00:06 +00:00
RString sChoiceName = asChoiceNames[c];
2004-02-13 08:15:05 +00:00
2004-12-02 06:29:20 +00:00
GameCommand mc;
2006-01-15 08:09:03 +00:00
mc.ApplyCommitsScreens( false );
2004-02-13 08:15:05 +00:00
mc.m_sName = sChoiceName;
Commands cmd = ParseCommands( CHOICE(sChoiceName) );
mc.Load( c, cmd );
2004-12-02 06:29:20 +00:00
m_aGameCommands.push_back( mc );
2004-02-13 08:15:05 +00:00
}
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;
}
2003-03-03 10:03:02 +00:00
}
2004-12-02 06:29:20 +00:00
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() );
}
2005-09-21 17:23:11 +00:00
}
void ScreenSelect::BeginScreen()
{
ScreenWithMenuElements::BeginScreen();
if(USE_TWO_LISTS)
{
if( GAMESTATE->GetNumSidesJoined() > 1 )
{
m_iSelectedList = 1;
this->UpdateSelectableChoices();
}
}
2006-01-10 00:14:35 +00:00
m_timerIdleComment.GetDeltaTime();
m_timerIdleTimeout.GetDeltaTime();
2003-03-03 10:03:02 +00:00
}
ScreenSelect::~ScreenSelect()
{
LOG->Trace( "ScreenSelect::~ScreenSelect()" );
2005-03-10 19:41:37 +00:00
for( unsigned i = 0; i < m_asSubscribedMessages.size(); ++i )
MESSAGEMAN->Unsubscribe( this, m_asSubscribedMessages[i] );
2003-03-03 10:03:02 +00:00
}
void ScreenSelect::Update( float fDelta )
{
if( !IsTransitioning() )
{
2008-06-23 10:57:14 +00:00
if( IDLE_COMMENT_SECONDS > 0 && m_timerIdleComment.PeekDeltaTime() >= IDLE_COMMENT_SECONDS )
{
SOUND->PlayOnceFromAnnouncer( m_sName+" IdleComment" );
m_timerIdleComment.GetDeltaTime();
}
2008-06-23 10:57:14 +00:00
if( IDLE_TIMEOUT_SECONDS > 0 && m_timerIdleTimeout.PeekDeltaTime() >= IDLE_TIMEOUT_SECONDS )
{
SCREENMAN->SetNewScreen( IDLE_TIMEOUT_SCREEN );
m_timerIdleTimeout.GetDeltaTime();
return;
}
}
ScreenWithMenuElements::Update( fDelta );
2003-03-03 10:03:02 +00:00
}
void ScreenSelect::Input( const InputEventPlus &input )
2003-03-03 10:03:02 +00:00
{
// LOG->Trace( "ScreenSelect::Input()" );
2003-03-03 10:03:02 +00:00
2007-03-04 08:52:06 +00:00
/* Reset the announcer timers when a key is pressed. */
m_timerIdleComment.GetDeltaTime();
m_timerIdleTimeout.GetDeltaTime();
/* Choices may change when more coins are inserted. */
2007-05-10 17:59:13 +00:00
if( input.MenuI == GAME_BUTTON_COIN && input.type == IET_FIRST_PRESS )
this->UpdateSelectableChoices();
2005-01-08 09:50:59 +00:00
2008-05-21 05:36:09 +00:00
if( input.MenuI == GAME_BUTTON_START && input.type == IET_FIRST_PRESS && GAMESTATE->JoinInput(input.pn) )
2003-03-03 10:03:02 +00:00
{
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
// start sound for the 1st player will be played by ScreenTitleMenu
// when the player makes a selection on the screen.
SCREENMAN->PlayStartSound();
}
2005-01-08 09:50:59 +00:00
if( !ALLOW_DISABLED_PLAYER_INPUT )
return; // don't let the screen handle the MENU_START press
2003-03-03 10:03:02 +00:00
}
if( !GAMESTATE->IsPlayerEnabled(input.pn) )
{
// block input of disabled players
if( !ALLOW_DISABLED_PLAYER_INPUT )
return;
2005-01-04 11:51:53 +00:00
/* 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). */
if( input.MenuI == GAME_BUTTON_START )
return;
}
2003-03-03 10:03:02 +00:00
2006-11-21 19:33:24 +00:00
ScreenWithMenuElements::Input( input ); // default input handler
2003-03-03 10:03:02 +00:00
}
void ScreenSelect::HandleScreenMessage( const ScreenMessage SM )
{
if( SM == SM_BeginFadingOut ) /* Screen is starting to tween out. */
2003-03-03 10:03:02 +00: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.
* 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 )
2003-03-03 10:03:02 +00:00
{
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();
}
}
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 );
}
}
}
2005-10-13 22:59:53 +00:00
StopTimer();
SCREENMAN->RefreshCreditsMessages();
ASSERT( !IsTransitioning() );
StartTransitioningScreen( SM_GoToNextScreen );
}
2004-05-08 06:26:24 +00:00
2006-11-21 19:33:24 +00:00
ScreenWithMenuElements::HandleScreenMessage( SM );
2003-03-03 10:03:02 +00:00
}
2006-11-13 23:11:25 +00:00
void ScreenSelect::HandleMessage( const Message &msg )
2005-03-10 19:41:37 +00:00
{
2007-02-03 06:02:46 +00:00
if( find(m_asSubscribedMessages.begin(), m_asSubscribedMessages.end(), msg.GetName()) != m_asSubscribedMessages.end() )
this->UpdateSelectableChoices();
2005-03-10 19:41:37 +00:00
2006-11-21 19:33:24 +00:00
ScreenWithMenuElements::HandleMessage( msg );
2005-03-10 19:41:37 +00:00
}
2006-09-15 01:47:24 +00:00
void ScreenSelect::MenuBack( const InputEventPlus &input )
2003-03-03 10:03:02 +00:00
{
Cancel( SM_GoToPrevScreen );
2003-03-03 10:03:02 +00:00
}
2004-06-08 05:22:33 +00:00
/*
* (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.
*/