Files
itgmania212121/stepmania/src/Screen.cpp
T

412 lines
13 KiB
C++
Raw Normal View History

2003-02-16 04:01:45 +00:00
#include "global.h"
2002-05-20 08:59:37 +00:00
#include "Screen.h"
2002-06-14 22:25:22 +00:00
#include "GameManager.h"
2002-07-23 01:41:40 +00:00
#include "GameState.h"
2002-12-17 21:08:38 +00:00
#include "PrefsManager.h"
2003-01-19 04:44:22 +00:00
#include "RageSound.h"
#include "ThemeManager.h"
#include "ScreenManager.h"
2004-07-08 00:10:34 +00:00
#include "GameSoundManager.h"
2004-01-03 03:42:40 +00:00
#include "ProfileManager.h"
2002-05-20 08:59:37 +00:00
#define NEXT_SCREEN THEME->GetMetric (m_sName,"NextScreen")
#define PREV_SCREEN THEME->GetMetric (m_sName,"PrevScreen")
2003-04-12 06:16:12 +00:00
Screen::Screen( CString sName )
2002-05-20 08:59:37 +00:00
{
2003-04-12 06:16:12 +00:00
SetName( sName );
m_bIsTransparent = false;
2002-05-20 08:59:37 +00:00
}
Screen::~Screen()
{
}
bool Screen::SortMessagesByDelayRemaining(const Screen::QueuedScreenMessage &m1,
const Screen::QueuedScreenMessage &m2)
{
return m1.fDelayRemaining < m2.fDelayRemaining;
}
2002-05-20 08:59:37 +00:00
void Screen::Update( float fDeltaTime )
{
ActorFrame::Update( fDeltaTime );
/* We need to ensure two things:
* 1. Messages must be sent in the order of delay. If two messages are sent
* simultaneously, one with a .001 delay and another with a .002 delay, the
* .001 delay message must be sent first.
* 2. Messages to be delivered simultaneously must be sent in the order queued.
*
* Stable sort by time to ensure #2. */
stable_sort(m_QueuedMessages.begin(), m_QueuedMessages.end(), SortMessagesByDelayRemaining);
2002-05-20 08:59:37 +00:00
// update the times of queued ScreenMessages and send if timer has expired
// The order you remove messages in must be very careful! Sending a message can
// potentially clear all m_QueuedMessages, and set a new state!
/* Also, it might call ClearMessageQueue() to clear a single message type.
* This might clear previous messages on the queue. So, first apply time to
* everything. */
2004-09-21 07:53:39 +00:00
for( unsigned i=0; i<m_QueuedMessages.size(); i++ )
{
/* Hack:
*
* If we simply subtract time and then send messages, we have a problem.
* Messages are queued to arrive at specific times, and those times line
* up with things like tweens finishing. If we send the message at the
* exact time given, then it'll be on the same cycle that would be rendering
* the last frame of a tween (such as an object going off the screen). However,
* when we send the message, we're likely to set up a new screen, which
* causes everything to stop in place; this results in actors occasionally
* not quite finishing their tweens.
*
* Let's delay all messages that have a non-zero time an extra frame.
*/
if(m_QueuedMessages[i].fDelayRemaining > 0.0001f)
{
m_QueuedMessages[i].fDelayRemaining -= fDeltaTime;
m_QueuedMessages[i].fDelayRemaining = max(m_QueuedMessages[i].fDelayRemaining, 0.0001f);
} else {
m_QueuedMessages[i].fDelayRemaining -= fDeltaTime;
}
}
/* Now dispatch messages. If the number of messages on the queue changes
* within HandleScreenMessage, someone cleared messages on the queue. This
* means we have no idea where 'i' is, so start over. Since we applied time
* already, this won't cause messages to be mistimed. */
2004-09-21 07:53:39 +00:00
for( unsigned i=0; i<m_QueuedMessages.size(); i++ )
2002-05-20 08:59:37 +00:00
{
if( m_QueuedMessages[i].fDelayRemaining > 0.0f )
continue; /* not yet */
/* Remove the message from the list. */
const ScreenMessage SM = m_QueuedMessages[i].SM;
m_QueuedMessages.erase(m_QueuedMessages.begin()+i);
i--;
unsigned size = m_QueuedMessages.size();
// send this sucker!
2004-03-24 03:08:24 +00:00
CHECKPOINT_M( ssprintf("ScreenMessage(%i)", SM) );
this->HandleScreenMessage( SM );
/* If the size changed, start over. */
if(size != m_QueuedMessages.size())
i = 0;
2002-05-20 08:59:37 +00:00
}
}
void Screen::MenuBack( PlayerNumber pn, const InputEventType type )
2002-08-22 03:35:33 +00:00
{
if(!PREFSMAN->m_bDelayedEscape || type==IET_SLOW_REPEAT || type==IET_FAST_REPEAT)
MenuBack(pn);
2002-08-22 03:35:33 +00:00
}
2002-05-20 08:59:37 +00:00
void Screen::Input( const DeviceInput& DeviceI, const InputEventType type, const GameInput &GameI, const MenuInput &MenuI, const StyleInput &StyleI )
{
/* Don't send release messages with the default handler. */
2004-09-09 22:21:50 +00:00
switch( type )
{
case IET_FIRST_PRESS:
case IET_SLOW_REPEAT:
case IET_FAST_REPEAT:
break; /* OK */
default:
return; // don't care
}
2003-10-17 08:03:46 +00:00
/* Don't make the user hold the back button if they're pressing escape and escape is the back button. */
2004-09-09 17:48:25 +00:00
if( MenuI.button == MENU_BUTTON_BACK && DeviceI.device == DEVICE_KEYBOARD && DeviceI.button == KEY_ESC )
{
this->MenuBack( MenuI.player );
return;
}
2002-05-20 08:59:37 +00:00
// default input handler used by most menus
if( !MenuI.IsValid() )
return;
if( !GAMESTATE->IsHumanPlayer(MenuI.player) )
2002-06-14 22:25:22 +00:00
return;
2002-05-20 08:59:37 +00:00
switch( MenuI.button )
{
2002-05-27 18:36:01 +00:00
case MENU_BUTTON_UP: this->MenuUp( MenuI.player, type ); return;
case MENU_BUTTON_DOWN: this->MenuDown( MenuI.player, type ); return;
case MENU_BUTTON_LEFT: this->MenuLeft( MenuI.player, type ); return;
case MENU_BUTTON_RIGHT: this->MenuRight( MenuI.player, type ); return;
case MENU_BUTTON_BACK: this->MenuBack( MenuI.player, type ); return;
case MENU_BUTTON_START: this->MenuStart( MenuI.player, type ); return;
2003-01-19 04:44:22 +00:00
case MENU_BUTTON_COIN: this->MenuCoin( MenuI.player, type ); return;
2002-05-20 08:59:37 +00:00
}
}
void Screen::HandleScreenMessage( const ScreenMessage SM )
{
switch( SM )
{
case SM_MenuTimer:
FOREACH_HumanPlayer(p)
MenuStart( p );
break;
case SM_GoToNextScreen:
SCREENMAN->SetNewScreen( NEXT_SCREEN );
break;
case SM_GoToPrevScreen:
SCREENMAN->SetNewScreen( PREV_SCREEN );
break;
}
}
2003-03-09 03:28:34 +00:00
bool Screen::ChangeCoinModeInput( const DeviceInput& DeviceI, const InputEventType type, const GameInput &GameI, const MenuInput &MenuI, const StyleInput &StyleI )
{
if( type != IET_FIRST_PRESS )
return false;
2004-09-09 17:48:25 +00:00
if( DeviceI.device == DEVICE_KEYBOARD && DeviceI.button == KEY_F3 )
2003-03-09 03:28:34 +00:00
{
PREFSMAN->m_iCoinMode++;
wrap( PREFSMAN->m_iCoinMode, NUM_COIN_MODES );
2003-03-09 03:28:34 +00:00
/* Show the real coin mode, not GetCoinMode(), or F3 will go "home, free, free"
* in event mode. XXX: move GetCoinMode to GameState to keep PrefsManager dumb? */
CString sMessage = CoinModeToString( (CoinMode)PREFSMAN->m_iCoinMode );
sMessage.MakeUpper();
sMessage = "Coin Mode: " + sMessage;
2003-03-09 03:28:34 +00:00
SCREENMAN->RefreshCreditsMessages();
SCREENMAN->SystemMessage( sMessage );
return true;
}
return false;
}
bool Screen::JoinInput( const DeviceInput& DeviceI, const InputEventType type, const GameInput &GameI, const MenuInput &MenuI, const StyleInput &StyleI )
{
if( !GAMESTATE->PlayersCanJoin() )
2003-03-09 03:28:34 +00:00
return false;
if( MenuI.IsValid() && MenuI.button==MENU_BUTTON_START )
{
/* If this side is already in, don't re-join (and re-pay!). */
if(GAMESTATE->m_bSideIsJoined[MenuI.player])
return false;
/* subtract coins */
2003-03-09 10:21:08 +00:00
int iCoinsToCharge = 0;
if( PREFSMAN->GetCoinMode() == COIN_PAY )
2003-03-09 10:21:08 +00:00
iCoinsToCharge = PREFSMAN->m_iCoinsPerCredit;
2003-11-09 01:09:35 +00:00
// If joint premium don't take away a credit for the 2nd join.
if( PREFSMAN->GetPremium() == PrefsManager::JOINT_PREMIUM &&
2003-11-09 01:09:35 +00:00
GAMESTATE->GetNumSidesJoined() == 1 )
iCoinsToCharge = 0;
2003-03-09 10:21:08 +00:00
if( GAMESTATE->m_iCoins < iCoinsToCharge )
return false; // not enough coins
else
GAMESTATE->m_iCoins -= iCoinsToCharge;
2003-03-09 03:28:34 +00:00
SCREENMAN->PlayStartSound();
2004-04-30 07:48:02 +00:00
GAMESTATE->JoinPlayer( MenuI.player );
2004-08-09 05:01:24 +00:00
// don't load memory card profiles here. It's slow and can cause a big skip.
PROFILEMAN->LoadLocalProfileFromMachine( MenuI.player );
SCREENMAN->RefreshCreditsMessages();
2003-03-09 03:28:34 +00:00
return true;
}
return false;
}
2003-01-19 04:44:22 +00:00
void Screen::MenuCoin( PlayerNumber pn )
{
// This is now handled globally by Stepmania.cpp -- Miryokuteki
2003-01-19 04:44:22 +00:00
}
2002-05-20 08:59:37 +00:00
2003-03-25 21:17:29 +00:00
void Screen::PostScreenMessage( const ScreenMessage SM, float fDelay )
2002-05-20 08:59:37 +00:00
{
ASSERT( fDelay >= 0.0 );
2002-05-20 08:59:37 +00:00
QueuedScreenMessage QSM;
QSM.SM = SM;
QSM.fDelayRemaining = fDelay;
2002-10-31 04:23:39 +00:00
m_QueuedMessages.push_back( QSM );
2002-09-04 00:17:51 +00:00
}
2003-01-26 20:49:05 +00:00
void Screen::ClearMessageQueue()
{
m_QueuedMessages.clear();
}
void Screen::ClearMessageQueue( const ScreenMessage SM )
{
for( int i=m_QueuedMessages.size()-1; i>=0; i-- )
2003-07-17 23:36:29 +00:00
if( m_QueuedMessages[i].SM == SM )
m_QueuedMessages.erase( m_QueuedMessages.begin()+i );
2003-01-26 20:49:05 +00:00
}
2003-03-03 10:03:02 +00:00
// Screen classes
#include "ScreenCaution.h"
#include "ScreenEdit.h"
#include "ScreenEditMenu.h"
#include "ScreenEvaluation.h"
#include "ScreenEz2SelectPlayer.h"
#include "ScreenGameOver.h"
#include "ScreenGameplay.h"
#include "ScreenHowToPlay.h"
#include "ScreenMapControllers.h"
#include "ScreenMusicScroll.h"
#include "ScreenPlayerOptions.h"
2003-03-30 20:17:59 +00:00
#include "ScreenSandbox.h"
2003-03-09 00:55:49 +00:00
#include "ScreenSelectDifficulty.h"
2003-03-03 10:03:02 +00:00
#include "ScreenSelectGroup.h"
#include "ScreenSelectMusic.h"
2003-03-09 00:55:49 +00:00
#include "ScreenSelectStyle.h"
2003-03-03 10:03:02 +00:00
#include "ScreenSongOptions.h"
#include "ScreenStage.h"
#include "ScreenTest.h"
#include "ScreenTestFonts.h"
#include "ScreenTestSound.h"
#include "ScreenTitleMenu.h"
2004-08-26 08:06:22 +00:00
#include "ScreenNetSelectMusic.h"
#include "ScreenNetEvaluation.h"
2003-03-03 10:03:02 +00:00
#include "ScreenEz2SelectMusic.h"
#include "ScreenRanking.h"
#include "ScreenLogo.h"
#include "ScreenUnlock.h"
#include "ScreenDemonstration.h"
#include "ScreenInstructions.h"
#include "ScreenNameEntry.h"
2003-10-14 09:54:48 +00:00
#include "ScreenNameEntryTraditional.h"
2003-03-03 10:03:02 +00:00
#include "ScreenJukebox.h"
#include "ScreenJukeboxMenu.h"
#include "ScreenStyleSplash.h"
2003-04-03 22:10:40 +00:00
#include "ScreenCredits.h"
#include "ScreenSelectCharacter.h"
#include "ScreenSelectMode.h"
#include "ScreenSelectMaster.h"
2003-08-10 23:48:10 +00:00
#include "ScreenEditCoursesMenu.h"
2004-06-02 22:45:19 +00:00
#include "ScreenNetworkOptions.h"
#include "ScreenProfileOptions.h"
2003-09-27 00:14:38 +00:00
#include "ScreenExit.h"
2003-09-27 22:41:05 +00:00
#include "ScreenAttract.h"
2003-09-28 02:57:09 +00:00
#include "ScreenReloadSongs.h"
#include "ScreenOptionsMaster.h"
#include "ScreenCenterImage.h"
2003-10-11 07:47:34 +00:00
#include "ScreenTestInput.h"
2003-10-13 08:33:39 +00:00
#include "ScreenBookkeeping.h"
#include "ScreenBranch.h"
2004-01-07 02:56:47 +00:00
#include "ScreenEnding.h"
2004-03-14 02:45:49 +00:00
#include "ScreenDownloadMachineStats.h"
2004-03-14 06:39:39 +00:00
#include "ScreenSetTime.h"
2004-03-23 06:33:01 +00:00
#include "ScreenTestLights.h"
2004-05-16 20:04:30 +00:00
#include "ScreenClearMachineStats.h"
#include "ScreenResetToDefaults.h"
#include "ScreenClearBookkeepingData.h"
2004-06-13 05:05:42 +00:00
#include "ScreenInsertCredit.h"
2003-03-03 10:03:02 +00:00
Screen* Screen::Create( CString sClassName )
{
2003-09-27 22:30:51 +00:00
CString sName = sClassName;
2004-02-01 03:14:37 +00:00
// Look up the class in the metrics group sName
if( THEME->HasMetric(sClassName,"Class") )
sClassName = THEME->GetMetric(sClassName,"Class");
2003-09-27 22:30:51 +00:00
#define IF_RETURN(X) if(sClassName.CompareNoCase(#X)==0) return new X(sName);
2003-09-27 22:41:05 +00:00
IF_RETURN( ScreenAttract );
IF_RETURN( ScreenCaution );
IF_RETURN( ScreenEdit );
IF_RETURN( ScreenEditMenu );
2003-09-27 23:31:42 +00:00
IF_RETURN( ScreenEvaluation );
IF_RETURN( ScreenEz2SelectPlayer );
IF_RETURN( ScreenGameOver );
IF_RETURN( ScreenGameplay );
IF_RETURN( ScreenHowToPlay );
IF_RETURN( ScreenMapControllers );
IF_RETURN( ScreenMusicScroll );
IF_RETURN( ScreenPlayerOptions );
IF_RETURN( ScreenSandbox );
IF_RETURN( ScreenSelectDifficulty );
IF_RETURN( ScreenSelectGroup );
IF_RETURN( ScreenSelectMusic );
IF_RETURN( ScreenSelectStyle5th );
IF_RETURN( ScreenSelectStyle );
IF_RETURN( ScreenSelectMode );
IF_RETURN( ScreenSongOptions );
IF_RETURN( ScreenStage );
IF_RETURN( ScreenTest );
IF_RETURN( ScreenTestFonts );
IF_RETURN( ScreenTestSound );
IF_RETURN( ScreenTitleMenu );
IF_RETURN( ScreenEz2SelectMusic );
IF_RETURN( ScreenRanking );
IF_RETURN( ScreenLogo );
IF_RETURN( ScreenUnlock );
IF_RETURN( ScreenDemonstration );
IF_RETURN( ScreenInstructions );
IF_RETURN( ScreenNameEntry );
2003-10-14 09:54:48 +00:00
IF_RETURN( ScreenNameEntryTraditional );
IF_RETURN( ScreenJukebox );
IF_RETURN( ScreenJukeboxMenu );
IF_RETURN( ScreenStyleSplash );
IF_RETURN( ScreenCredits );
IF_RETURN( ScreenSelectCharacter );
IF_RETURN( ScreenSelectMaster );
2003-08-10 23:48:10 +00:00
IF_RETURN( ScreenEditCoursesMenu );
IF_RETURN( ScreenProfileOptions );
2003-09-27 00:14:38 +00:00
IF_RETURN( ScreenExit );
2003-09-28 02:57:09 +00:00
IF_RETURN( ScreenReloadSongs );
IF_RETURN( ScreenOptionsMaster );
IF_RETURN( ScreenCenterImage );
2003-10-11 07:47:34 +00:00
IF_RETURN( ScreenTestInput );
2003-10-13 08:33:39 +00:00
IF_RETURN( ScreenBookkeeping );
IF_RETURN( ScreenBranch );
2004-01-07 02:56:47 +00:00
IF_RETURN( ScreenEnding );
2004-03-14 02:45:49 +00:00
IF_RETURN( ScreenDownloadMachineStats );
2004-03-14 06:39:39 +00:00
IF_RETURN( ScreenSetTime );
2004-03-23 06:33:01 +00:00
IF_RETURN( ScreenTestLights );
2004-05-16 20:04:30 +00:00
IF_RETURN( ScreenClearMachineStats );
IF_RETURN( ScreenResetToDefaults );
IF_RETURN( ScreenClearBookkeepingData );
2004-06-13 05:05:42 +00:00
IF_RETURN( ScreenInsertCredit );
2004-09-10 23:21:56 +00:00
#if !defined(WITHOUT_NETWORKING)
IF_RETURN( ScreenNetworkOptions );
IF_RETURN( ScreenNetSelectMusic );
IF_RETURN( ScreenNetEvaluation );
#endif
2003-04-25 00:27:30 +00:00
RageException::Throw( "Invalid Screen class name '%s'", sClassName.c_str() );
2003-04-25 05:39:53 +00:00
}
2004-06-08 05:22:33 +00:00
/*
* (c) 2001-2004 Chris Danford, Glenn Maynard
* 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.
*/