2002-05-20 08:59:37 +00:00
|
|
|
#include "stdafx.h"
|
|
|
|
|
/*
|
|
|
|
|
-----------------------------------------------------------------------------
|
2002-08-13 23:26:46 +00:00
|
|
|
Class: ScreenManager
|
2002-05-20 08:59:37 +00:00
|
|
|
|
2002-08-13 23:26:46 +00:00
|
|
|
Desc: See header.
|
2002-05-20 08:59:37 +00:00
|
|
|
|
|
|
|
|
Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved.
|
2002-08-13 23:26:46 +00:00
|
|
|
Chris Danford
|
2002-05-20 08:59:37 +00:00
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "ScreenManager.h"
|
|
|
|
|
#include "IniFile.h"
|
|
|
|
|
#include "GameConstantsAndTypes.h"
|
2002-07-23 01:41:40 +00:00
|
|
|
#include "PrefsManager.h"
|
2002-05-20 08:59:37 +00:00
|
|
|
#include "RageLog.h"
|
2002-08-13 23:26:46 +00:00
|
|
|
#include "GameState.h"
|
2002-05-20 08:59:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
ScreenManager* SCREENMAN = NULL; // global and accessable from anywhere in our program
|
|
|
|
|
|
|
|
|
|
|
2002-08-18 17:48:50 +00:00
|
|
|
#define STATS_X THEME->GetMetricF("Other","StatsX")
|
|
|
|
|
#define STATS_Y THEME->GetMetricF("Other","StatsY")
|
2002-08-13 23:26:46 +00:00
|
|
|
#define CREDITS_P1_X THEME->GetMetricF("Other","CreditsP1X")
|
|
|
|
|
#define CREDITS_P1_Y THEME->GetMetricF("Other","CreditsP1Y")
|
|
|
|
|
#define CREDITS_P2_X THEME->GetMetricF("Other","CreditsP2X")
|
|
|
|
|
#define CREDITS_P2_Y THEME->GetMetricF("Other","CreditsP2Y")
|
|
|
|
|
|
|
|
|
|
float CREDITS_X( int p ) {
|
|
|
|
|
switch( p ) {
|
|
|
|
|
case PLAYER_1: return CREDITS_P1_X;
|
|
|
|
|
case PLAYER_2: return CREDITS_P2_X;
|
|
|
|
|
default: ASSERT(0); return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
float CREDITS_Y( int p ) {
|
|
|
|
|
switch( p ) {
|
|
|
|
|
case PLAYER_1: return CREDITS_P1_Y;
|
|
|
|
|
case PLAYER_2: return CREDITS_P2_Y;
|
|
|
|
|
default: ASSERT(0); return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-05-20 08:59:37 +00:00
|
|
|
|
|
|
|
|
ScreenManager::ScreenManager()
|
|
|
|
|
{
|
2002-08-18 17:48:50 +00:00
|
|
|
m_textStats.LoadFromFont( THEME->GetPathTo("Fonts","normal") );
|
|
|
|
|
m_textStats.SetXY( STATS_X, STATS_Y );
|
|
|
|
|
m_textStats.SetHorizAlign( Actor::align_right );
|
|
|
|
|
m_textStats.SetVertAlign( Actor::align_top );
|
|
|
|
|
m_textStats.SetZoom( 0.5f );
|
|
|
|
|
m_textStats.SetShadowLength( 2 );
|
2002-05-20 08:59:37 +00:00
|
|
|
|
2002-08-13 23:26:46 +00:00
|
|
|
for( int p=0; p<NUM_PLAYERS; p++ )
|
|
|
|
|
{
|
|
|
|
|
m_textCreditInfo[p].LoadFromFont( THEME->GetPathTo("Fonts","normal") );
|
|
|
|
|
m_textCreditInfo[p].SetXY( CREDITS_X(p), CREDITS_Y(p) );
|
|
|
|
|
m_textCreditInfo[p].SetZoom( 0.5f );
|
|
|
|
|
m_textCreditInfo[p].SetDiffuseColor( D3DXCOLOR(1,1,1,1) );
|
|
|
|
|
m_textCreditInfo[p].SetShadowLength( 2 );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_textSystemMessage.LoadFromFont( THEME->GetPathTo("Fonts","normal") );
|
2002-05-20 08:59:37 +00:00
|
|
|
m_textSystemMessage.SetHorizAlign( Actor::align_left );
|
|
|
|
|
m_textSystemMessage.SetVertAlign( Actor::align_bottom );
|
|
|
|
|
m_textSystemMessage.SetXY( 5.0f, 10.0f );
|
|
|
|
|
m_textSystemMessage.SetZoom( 0.5f );
|
|
|
|
|
m_textSystemMessage.SetShadowLength( 2 );
|
|
|
|
|
m_textSystemMessage.SetDiffuseColor( D3DXCOLOR(1,1,1,0) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ScreenManager::~ScreenManager()
|
|
|
|
|
{
|
2002-07-31 19:40:40 +00:00
|
|
|
LOG->Trace( "ScreenManager::~ScreenManager()" );
|
2002-05-20 08:59:37 +00:00
|
|
|
|
|
|
|
|
// delete current states
|
|
|
|
|
for( int i=0; i<m_ScreenStack.GetSize(); i++ )
|
|
|
|
|
SAFE_DELETE( m_ScreenStack[i] );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ScreenManager::Update( float fDeltaTime )
|
|
|
|
|
{
|
|
|
|
|
m_textSystemMessage.Update( fDeltaTime );
|
2002-08-18 17:48:50 +00:00
|
|
|
m_textStats.Update( fDeltaTime );
|
2002-08-13 23:26:46 +00:00
|
|
|
for( int p=0; p<NUM_PLAYERS; p++ )
|
|
|
|
|
m_textCreditInfo[p].Update( fDeltaTime );
|
2002-05-20 08:59:37 +00:00
|
|
|
|
|
|
|
|
// delete all ScreensToDelete
|
|
|
|
|
for( int i=0; i<m_ScreensToDelete.GetSize(); i++ ) {
|
|
|
|
|
SAFE_DELETE( m_ScreensToDelete[i] );
|
|
|
|
|
m_ScreensToDelete.RemoveAt(i);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// HACK! If we deleted at least one state, then skip this update!
|
|
|
|
|
if( i>0 ) return;
|
|
|
|
|
|
|
|
|
|
// Update all windows in the stack
|
|
|
|
|
for( i=0; i<m_ScreenStack.GetSize(); i++ )
|
|
|
|
|
m_ScreenStack[i]->Update( fDeltaTime );
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ScreenManager::Restore()
|
|
|
|
|
{
|
|
|
|
|
// Draw all CurrentScreens (back to front)
|
|
|
|
|
for( int i=0; i<m_ScreenStack.GetSize(); i++ )
|
|
|
|
|
m_ScreenStack[i]->Restore();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScreenManager::Invalidate()
|
|
|
|
|
{
|
|
|
|
|
for( int i=0; i<m_ScreenStack.GetSize(); i++ )
|
|
|
|
|
m_ScreenStack[i]->Invalidate();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScreenManager::Draw()
|
|
|
|
|
{
|
|
|
|
|
// Draw all CurrentScreens (back to front)
|
|
|
|
|
for( int i=0; i<m_ScreenStack.GetSize(); i++ )
|
|
|
|
|
m_ScreenStack[i]->Draw();
|
|
|
|
|
|
|
|
|
|
if( m_textSystemMessage.GetDiffuseColor().a != 0 )
|
|
|
|
|
m_textSystemMessage.Draw();
|
|
|
|
|
|
2002-08-18 17:48:50 +00:00
|
|
|
if( PREFSMAN && PREFSMAN->m_bShowStats )
|
2002-05-20 08:59:37 +00:00
|
|
|
{
|
2002-08-18 17:48:50 +00:00
|
|
|
m_textStats.SetText( ssprintf("%d FPS\n%d TPF\n%d DPF", DISPLAY->GetFPS(),DISPLAY->GetTPF(),DISPLAY->GetDPF()) );
|
|
|
|
|
m_textStats.Draw();
|
2002-05-20 08:59:37 +00:00
|
|
|
}
|
2002-08-13 23:26:46 +00:00
|
|
|
for( int p=0; p<NUM_PLAYERS; p++ )
|
|
|
|
|
m_textCreditInfo[p].Draw();
|
|
|
|
|
|
2002-05-20 08:59:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ScreenManager::Input( const DeviceInput& DeviceI, const InputEventType type, const GameInput &GameI, const MenuInput &MenuI, const StyleInput &StyleI )
|
|
|
|
|
{
|
2002-07-31 19:40:40 +00:00
|
|
|
LOG->Trace( "ScreenManager::Input( %d-%d, %d-%d, %d-%d, %d-%d )",
|
2002-07-27 19:29:51 +00:00
|
|
|
DeviceI.device, DeviceI.button, GameI.controller, GameI.button, MenuI.player, MenuI.button, StyleI.player, StyleI.col );
|
2002-05-20 08:59:37 +00:00
|
|
|
|
|
|
|
|
// pass input only to topmost state
|
|
|
|
|
if( m_ScreenStack.GetSize() > 0 )
|
|
|
|
|
m_ScreenStack[m_ScreenStack.GetSize()-1]->Input( DeviceI, type, GameI, MenuI, StyleI );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScreenManager::SetNewScreen( Screen *pNewScreen )
|
|
|
|
|
{
|
|
|
|
|
// move CurrentScreen to ScreenToDelete
|
2002-08-13 23:26:46 +00:00
|
|
|
RefreshCreditsMessages();
|
2002-05-20 08:59:37 +00:00
|
|
|
m_ScreensToDelete.Copy( m_ScreenStack );
|
|
|
|
|
|
|
|
|
|
m_ScreenStack.RemoveAll();
|
|
|
|
|
m_ScreenStack.Add( pNewScreen );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScreenManager::AddScreenToTop( Screen *pNewScreen )
|
|
|
|
|
{
|
|
|
|
|
// our responsibility to tell the old state that it's losing focus
|
2002-07-27 19:29:51 +00:00
|
|
|
// m_ScreenStack[m_ScreenStack.GetSize()-1]->HandleScreenMessage( SM_LosingInputFocus );
|
2002-05-20 08:59:37 +00:00
|
|
|
|
|
|
|
|
// add the new state onto the back of the array
|
|
|
|
|
m_ScreenStack.Add( pNewScreen );
|
|
|
|
|
}
|
|
|
|
|
|
2002-07-27 19:29:51 +00:00
|
|
|
void ScreenManager::PopTopScreen( ScreenMessage SM )
|
2002-05-20 08:59:37 +00:00
|
|
|
{
|
|
|
|
|
Screen* pScreenToPop = m_ScreenStack[m_ScreenStack.GetSize()-1]; // top menu
|
|
|
|
|
//pScreenToPop->HandleScreenMessage( SM_LosingInputFocus );
|
|
|
|
|
m_ScreenStack.RemoveAt(m_ScreenStack.GetSize()-1);
|
|
|
|
|
m_ScreensToDelete.Add( pScreenToPop );
|
|
|
|
|
|
|
|
|
|
Screen* pNewTopScreen = m_ScreenStack[m_ScreenStack.GetSize()-1];
|
2002-07-27 19:29:51 +00:00
|
|
|
pNewTopScreen->HandleScreenMessage( SM );
|
2002-05-20 08:59:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScreenManager::SendMessageToTopScreen( ScreenMessage SM, float fDelay )
|
|
|
|
|
{
|
|
|
|
|
Screen* pTopScreen = m_ScreenStack[m_ScreenStack.GetSize()-1];
|
|
|
|
|
pTopScreen->SendScreenMessage( SM, fDelay );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ScreenManager::SystemMessage( CString sMessage )
|
|
|
|
|
{
|
|
|
|
|
// Look for an open spot
|
|
|
|
|
m_textSystemMessage.StopTweening();
|
|
|
|
|
m_textSystemMessage.SetText( sMessage );
|
|
|
|
|
m_textSystemMessage.SetDiffuseColor( D3DXCOLOR(1,1,1,1) );
|
|
|
|
|
m_textSystemMessage.BeginTweeningQueued( 5 );
|
|
|
|
|
m_textSystemMessage.BeginTweeningQueued( 1 );
|
|
|
|
|
m_textSystemMessage.SetTweenDiffuseColor( D3DXCOLOR(1,1,1,0) );
|
|
|
|
|
|
2002-07-31 19:40:40 +00:00
|
|
|
LOG->Trace( "WARNING: Didn't find an empty system messages slot." );
|
2002-05-20 08:59:37 +00:00
|
|
|
}
|
|
|
|
|
|
2002-08-13 23:26:46 +00:00
|
|
|
/*
|
|
|
|
|
void ScreenManager::OverrideCreditsMessage( PlayerNumber p, CString sNewString )
|
|
|
|
|
{
|
|
|
|
|
m_textCreditInfo[p].SetText( sNewString );
|
|
|
|
|
}
|
|
|
|
|
*/
|
2002-05-20 08:59:37 +00:00
|
|
|
|
2002-08-13 23:26:46 +00:00
|
|
|
void ScreenManager::RefreshCreditsMessages()
|
|
|
|
|
{
|
|
|
|
|
// update joined
|
|
|
|
|
for( int p=0; p<NUM_PLAYERS; p++ )
|
|
|
|
|
{
|
|
|
|
|
if( GAMESTATE->m_bIsJoined[p] ) m_textCreditInfo[p].SetText( "" );
|
|
|
|
|
else if( GAMESTATE->m_bPlayersCanJoin ) m_textCreditInfo[p].SetText( "PRESS START" );
|
|
|
|
|
else m_textCreditInfo[p].SetText( "CREDIT(s) 0 / 0" );
|
|
|
|
|
}
|
|
|
|
|
}
|