Files
itgmania212121/stepmania/src/Screen.cpp
T

315 lines
9.5 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-12-17 21:08:38 +00:00
#include "PrefsManager.h"
2003-01-19 04:44:22 +00:00
#include "RageSound.h"
#include "RageLog.h"
2003-01-19 04:44:22 +00:00
#include "ThemeManager.h"
#include "ScreenManager.h"
2005-05-03 09:13:43 +00:00
#include "ActorUtil.h"
#include "InputEventPlus.h"
2002-05-20 08:59:37 +00:00
2006-02-03 19:24:14 +00:00
#define NEXT_SCREEN THEME->GetMetric (m_sName,"NextScreen")
#define PREV_SCREEN THEME->GetMetric (m_sName,"PrevScreen")
#define PREPARE_SCREENS THEME->GetMetric (m_sName,"PrepareScreens")
#define PERSIST_SCREENS THEME->GetMetric (m_sName,"PersistScreens")
#define GROUPED_SCREENS THEME->GetMetric (m_sName,"GroupedScreens")
void Screen::InitScreen( Screen *pScreen )
{
pScreen->Init();
}
2002-05-20 08:59:37 +00:00
Screen::~Screen()
{
}
2006-03-14 02:23:45 +00:00
bool Screen::SortMessagesByDelayRemaining( const Screen::QueuedScreenMessage &m1,
const Screen::QueuedScreenMessage &m2 )
{
return m1.fDelayRemaining < m2.fDelayRemaining;
}
2005-05-03 09:13:43 +00:00
void Screen::Init()
{
ALLOW_OPERATOR_MENU_BUTTON.Load( m_sName, "AllowOperatorMenuButton" );
2007-03-16 06:00:06 +00:00
REPEAT_RATE.Load( m_sName, "RepeatRate" );
REPEAT_DELAY.Load( m_sName, "RepeatDelay" );
2007-06-11 19:00:47 +00:00
LIGHTS_MODE.Load( m_sName, "LightsMode" );
2007-03-16 23:56:10 +00:00
m_Codes.Load( m_sName );
2007-03-16 23:33:41 +00:00
SetFOV( 0 );
m_smSendOnPop = SM_None;
2005-09-07 20:44:43 +00:00
ActorUtil::LoadAllCommandsFromName( *this, m_sName, "Screen" );
PlayCommandNoRecurse( Message("Init") );
2006-01-22 01:00:06 +00:00
vector<RString> asList;
2005-07-23 01:18:48 +00:00
split( PREPARE_SCREENS, ",", asList );
for( unsigned i = 0; i < asList.size(); ++i )
{
2005-07-29 03:22:48 +00:00
LOG->Trace( "Screen \"%s\" preparing \"%s\"", m_sName.c_str(), asList[i].c_str() );
SCREENMAN->PrepareScreen( asList[i] );
}
asList.clear();
2005-07-23 01:18:48 +00:00
split( GROUPED_SCREENS, ",", asList );
for( unsigned i = 0; i < asList.size(); ++i )
SCREENMAN->GroupScreen( asList[i] );
2005-07-23 01:18:48 +00:00
asList.clear();
split( PERSIST_SCREENS, ",", asList );
for( unsigned i = 0; i < asList.size(); ++i )
SCREENMAN->PersistantScreen( asList[i] );
2005-05-03 09:13:43 +00:00
}
2005-08-03 00:39:21 +00:00
void Screen::BeginScreen()
{
2007-03-26 22:52:54 +00:00
m_bFirstUpdate = true;
/* Screens set these when they determine their next screen dynamically. Reset them
* here, so a reused screen doesn't inherit these from the last time it was used. */
m_sNextScreen = RString();
2006-06-27 23:07:11 +00:00
m_fLockInputSecs = 0;
2005-08-03 00:39:21 +00:00
this->RunCommands( THEME->GetMetricA(m_sName, "ScreenOnCommand") );
if( m_fLockInputSecs == 0 )
m_fLockInputSecs = 0.0001f; // always lock for a tiny amount of time so that we throw away any queued inputs during the load.
2006-07-01 05:33:49 +00:00
this->PlayCommand( "Begin" );
2005-08-03 00:39:21 +00:00
}
2007-04-17 17:53:36 +00:00
void Screen::EndScreen()
{
this->PlayCommand( "End" );
}
2002-05-20 08:59:37 +00:00
void Screen::Update( float fDeltaTime )
{
ActorFrame::Update( fDeltaTime );
2006-06-27 22:51:43 +00:00
m_fLockInputSecs = max( 0, m_fLockInputSecs-fDeltaTime );
2002-05-20 08:59:37 +00:00
2005-07-11 23:42:45 +00:00
/*
* 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.
*
2005-07-11 23:42:45 +00:00
* Sort by time to ensure #1; use a stable sort to ensure #2.
*/
stable_sort(m_QueuedMessages.begin(), m_QueuedMessages.end(), SortMessagesByDelayRemaining);
2002-05-20 08:59:37 +00:00
2005-07-11 23:42:45 +00:00
/* Update the times of queued ScreenMessages. */
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.
*/
2005-07-11 23:42:45 +00:00
if( m_QueuedMessages[i].fDelayRemaining > 0.0001f )
{
m_QueuedMessages[i].fDelayRemaining -= fDeltaTime;
2005-07-11 23:42:45 +00:00
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;
2005-07-11 23:42:45 +00:00
m_QueuedMessages.erase( m_QueuedMessages.begin()+i );
i--;
2005-07-11 23:42:45 +00:00
unsigned iSize = 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. */
2005-07-11 23:42:45 +00:00
if( iSize != m_QueuedMessages.size() )
i = 0;
2002-05-20 08:59:37 +00:00
}
}
/* ScreenManager sends input here first. Overlay screens can use it to get a first
* pass at input. Return true if the input was handled and should not be passed
* to lower screens, or false if not handled. If true is returned, Input() will
* not be called, either. Normal screens should not overload this function. */
bool Screen::OverlayInput( const InputEventPlus &input )
{
return false;
}
void Screen::Input( const InputEventPlus &input )
2002-05-20 08:59:37 +00:00
{
2007-03-16 23:56:10 +00:00
Message msg("");
if( m_Codes.InputMessage(input, msg) )
2007-03-16 23:33:41 +00:00
this->HandleMessage( msg );
/* Don't send release messages with the default handler. */
switch( input.type )
2004-09-09 22:21:50 +00:00
{
case IET_FIRST_PRESS:
2006-09-13 02:59:05 +00:00
case IET_REPEAT:
2004-09-09 22:21:50 +00:00
break; /* OK */
default:
return; // don't care
}
2002-05-20 08:59:37 +00:00
// default input handler used by most menus
2006-09-14 20:52:34 +00:00
switch( input.MenuI )
2002-05-20 08:59:37 +00:00
{
2007-05-10 17:59:13 +00:00
case GAME_BUTTON_MENUUP: this->MenuUp ( input ); return;
case GAME_BUTTON_MENUDOWN: this->MenuDown ( input ); return;
case GAME_BUTTON_MENULEFT: this->MenuLeft ( input ); return;
case GAME_BUTTON_MENURIGHT: this->MenuRight ( input ); return;
case GAME_BUTTON_BACK:
2006-09-14 21:28:29 +00:00
/* Don't make the user hold the back button if they're pressing escape and escape is the back button. */
if( !PREFSMAN->m_bDelayedBack || input.type==IET_REPEAT || (input.DeviceI.device == DEVICE_KEYBOARD && input.DeviceI.button == KEY_ESC) )
this->MenuBack( input );
return;
2007-05-10 17:59:13 +00:00
case GAME_BUTTON_START: this->MenuStart ( input ); return;
case GAME_BUTTON_SELECT:this->MenuSelect( input ); return;
case GAME_BUTTON_COIN: this->MenuCoin ( input ); return;
2002-05-20 08:59:37 +00:00
}
}
void Screen::HandleScreenMessage( const ScreenMessage SM )
{
if( SM == SM_GoToNextScreen || SM == SM_GoToPrevScreen )
2006-02-24 00:20:41 +00:00
{
if( SCREENMAN->IsStackedScreen(this) )
SCREENMAN->PopTopScreen( m_smSendOnPop );
else
SCREENMAN->SetNewScreen( SM == SM_GoToNextScreen? GetNextScreenName():GetPrevScreen() );
2006-02-24 00:20:41 +00:00
}
2007-03-16 06:00:06 +00:00
else if( SM == SM_GainFocus )
{
if( REPEAT_RATE != -1.0f )
INPUTFILTER->SetRepeatRate( REPEAT_RATE );
if( REPEAT_DELAY != -1.0f )
INPUTFILTER->SetRepeatDelay( REPEAT_DELAY );
2007-06-11 19:00:47 +00:00
LIGHTSMAN->SetLightsMode( LIGHTS_MODE );
2007-03-16 06:00:06 +00:00
}
else if( SM == SM_LoseFocus )
{
INPUTFILTER->ResetRepeatRate();
}
}
RString Screen::GetNextScreenName() const
{
if( !m_sNextScreen.empty() )
return m_sNextScreen;
return NEXT_SCREEN;
}
2006-01-22 01:00:06 +00:00
RString Screen::GetPrevScreen() const
{
return PREV_SCREEN;
}
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
2005-07-12 05:44:54 +00:00
// lua start
#include "LuaBinding.h"
class LunaScreen: public Luna<Screen>
{
public:
static int GetNextScreenName( T* p, lua_State *L ) { lua_pushstring(L, p->GetNextScreenName() ); return 1; }
2006-06-27 23:07:11 +00:00
static int lockinput( T* p, lua_State *L ) { p->SetLockInputSecs(FArg(1)); return 0; }
2006-06-25 20:06:06 +00:00
2006-02-24 01:09:42 +00:00
static int PostScreenMessage( T* p, lua_State *L )
{
RString sMessage = SArg(1);
ScreenMessage SM = ScreenMessageHelpers::ToMessageNumber( sMessage );
p->PostScreenMessage( SM, 0 );
return 0;
}
2005-07-12 05:44:54 +00:00
2006-09-27 19:47:52 +00:00
LunaScreen()
2005-07-12 05:44:54 +00:00
{
ADD_METHOD( GetNextScreenName );
2006-02-24 01:09:42 +00:00
ADD_METHOD( PostScreenMessage );
2006-06-27 23:07:11 +00:00
ADD_METHOD( lockinput );
2005-07-12 05:44:54 +00:00
}
};
LUA_REGISTER_DERIVED_CLASS( Screen, ActorFrame )
// lua end
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.
*/