Files
itgmania212121/stepmania/src/MenuElements.cpp
T

219 lines
5.7 KiB
C++
Raw Normal View History

2003-02-16 04:01:45 +00:00
#include "global.h"
/*
-----------------------------------------------------------------------------
File: MenuElements.h
2002-05-19 01:59:48 +00:00
Desc: Base class for menu Screens.
2002-05-19 01:59:48 +00:00
Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved.
Chris Danford
-----------------------------------------------------------------------------
*/
#include "MenuElements.h"
#include "RageUtil.h"
2002-05-19 01:59:48 +00:00
#include "ScreenManager.h"
2002-05-01 19:14:55 +00:00
#include "GameConstantsAndTypes.h"
2002-07-23 01:41:40 +00:00
#include "PrefsManager.h"
2002-05-01 19:14:55 +00:00
#include "RageLog.h"
2002-05-28 20:01:22 +00:00
#include "GameManager.h"
2002-07-23 01:41:40 +00:00
#include "GameState.h"
#include "ThemeManager.h"
2003-11-07 20:10:38 +00:00
#include "MenuTimer.h"
2003-11-17 01:01:44 +00:00
#include "HelpDisplay.h"
#define TIMER_SECONDS THEME->GetMetricI(m_sName,"TimerSeconds")
#define STYLE_ICON THEME->GetMetricB(m_sName,"StyleIcon")
#define MEMORY_CARD_ICONS THEME->GetMetricB(m_sName,"MemoryCardIcons")
2002-05-27 18:36:01 +00:00
MenuElements::MenuElements()
{
2003-11-07 20:10:38 +00:00
m_MenuTimer = new MenuTimer;
2003-11-17 01:01:44 +00:00
m_textHelp = new HelpDisplay;
2003-11-07 20:10:38 +00:00
}
MenuElements::~MenuElements()
{
delete m_MenuTimer;
2003-11-17 01:01:44 +00:00
delete m_textHelp;
}
void MenuElements::Load( CString sClassName )
{
LOG->Trace( "MenuElements::MenuElements()" );
2003-03-09 00:55:49 +00:00
ASSERT( this->m_SubActors.empty() ); // don't call Load twice!
2003-11-07 20:57:22 +00:00
this->SetName( sClassName );
2003-03-09 00:55:49 +00:00
m_Background.LoadFromAniDir( THEME->GetPathToB(m_sName+" background") );
2003-03-09 00:55:49 +00:00
this->AddChild( &m_Background );
2003-11-04 21:49:38 +00:00
m_autoHeader.Load( THEME->GetPathToG(m_sName+" header") );
m_autoHeader->SetName("Header");
UtilSetXY( m_autoHeader, "MenuElements" );
2003-11-04 21:49:38 +00:00
UtilOnCommand( m_autoHeader, "MenuElements" );
this->AddChild( m_autoHeader );
if( STYLE_ICON && GAMESTATE->m_CurStyle != STYLE_INVALID )
2003-03-09 00:55:49 +00:00
{
CString sIconFileName = ssprintf("MenuElements icon %s", GAMESTATE->GetCurrentStyleDef()->m_szName );
2003-11-04 21:49:38 +00:00
m_sprStyleIcon.SetName( "StyleIcon" );
m_sprStyleIcon.Load( THEME->GetPathToG(sIconFileName) );
2003-03-09 00:55:49 +00:00
m_sprStyleIcon.StopAnimating();
UtilSetXY( m_sprStyleIcon, "MenuElements" );
2003-11-04 21:49:38 +00:00
UtilOnCommand( m_sprStyleIcon, "MenuElements" );
2003-03-09 00:55:49 +00:00
this->AddChild( &m_sprStyleIcon );
}
2002-05-27 18:36:01 +00:00
if( MEMORY_CARD_ICONS )
{
for( int p=0; p<NUM_PLAYERS; p++ )
{
m_MemoryCardDisplay[p].Load( (PlayerNumber)p );
m_MemoryCardDisplay[p].SetName( ssprintf("MemoryCardDisplayP%d",p+1) );
UtilSetXY( m_MemoryCardDisplay[p], "MenuElements" );
UtilOnCommand( m_MemoryCardDisplay[p], "MenuElements" );
this->AddChild( &m_MemoryCardDisplay[p] );
}
}
m_bTimerEnabled = (TIMER_SECONDS != -1);
if( m_bTimerEnabled )
{
2003-11-07 20:10:38 +00:00
m_MenuTimer->SetName( "Timer" );
UtilSetXY( m_MenuTimer, "MenuElements" );
2003-11-04 21:49:38 +00:00
UtilOnCommand( m_MenuTimer, "MenuElements" );
if( TIMER_SECONDS > 0 && PREFSMAN->m_bMenuTimer && !GAMESTATE->m_bEditing )
2003-11-07 20:10:38 +00:00
m_MenuTimer->SetSeconds( TIMER_SECONDS );
else
2003-11-07 20:10:38 +00:00
m_MenuTimer->Disable();
this->AddChild( m_MenuTimer );
}
2002-05-27 08:23:27 +00:00
2003-11-04 21:49:38 +00:00
m_autoFooter.Load( THEME->GetPathToG(m_sName+" footer") );
m_autoFooter->SetName("Footer");
UtilSetXY( m_autoFooter, "MenuElements" );
2003-11-04 21:49:38 +00:00
UtilOnCommand( m_autoFooter, "MenuElements" );
this->AddChild( m_autoFooter );
2003-11-17 01:39:34 +00:00
m_textHelp->SetName( "HelpDisplay", "Help" );
m_textHelp->Load();
UtilSetXY( m_textHelp, "MenuElements" );
2003-11-04 21:49:38 +00:00
UtilOnCommand( m_textHelp, "MenuElements" );
2002-07-23 01:41:40 +00:00
CStringArray asHelpTips;
2003-04-12 06:16:12 +00:00
split( THEME->GetMetric(m_sName,"HelpText"), "\n", asHelpTips );
2003-11-17 01:01:44 +00:00
m_textHelp->SetTips( asHelpTips );
this->AddChild( m_textHelp );
m_In.Load( THEME->GetPathToB(m_sName+" in") );
2003-03-09 00:55:49 +00:00
this->AddChild( &m_In );
m_Out.Load( THEME->GetPathToB(m_sName+" out") );
2003-03-09 00:55:49 +00:00
this->AddChild( &m_Out );
m_Back.Load( THEME->GetPathToB("Common back") );
2003-03-09 00:55:49 +00:00
this->AddChild( &m_Back );
2002-12-19 22:09:44 +00:00
m_soundBack.Load( THEME->GetPathToS("Common back") );
m_In.StartTransitioning();
}
void MenuElements::Update( float fDeltaTime )
{
ActorFrame::Update(fDeltaTime);
2002-05-28 20:01:22 +00:00
}
2003-03-09 00:55:49 +00:00
void MenuElements::StartTransitioning( ScreenMessage smSendWhenDone )
2002-05-28 20:01:22 +00:00
{
if( m_bTimerEnabled )
{
2003-11-07 20:10:38 +00:00
m_MenuTimer->SetSeconds( 0 );
m_MenuTimer->Stop();
2003-11-04 21:49:38 +00:00
UtilOffCommand( m_MenuTimer, "MenuElements" );
}
2003-11-04 21:49:38 +00:00
UtilOffCommand( m_autoHeader, "MenuElements" );
UtilOffCommand( m_sprStyleIcon, "MenuElements" );
for( int p=0; p<NUM_PLAYERS; p++ )
UtilOffCommand( m_MemoryCardDisplay[p], "MenuElements" );
2003-11-04 21:49:38 +00:00
UtilOffCommand( m_autoFooter, "MenuElements" );
UtilOffCommand( m_textHelp, "MenuElements" );
m_Background.PlayCommand("Off");
2003-07-10 03:37:13 +00:00
m_Out.StartTransitioning(smSendWhenDone);
/* Ack. If the transition finishes transparent (eg. _options to options),
* then we don't want to send the message until all of the *actors* are
* done tweening. However, if it finishes with something onscreen (most
* of the rest), we have to send the message immediately after it finishes,
* or we'll draw a frame without the transition.
*
* For now, I'll make the SMMAX2 option tweening faster. */
/* This includes all of the actors: */
// float TimeUntilFinished = GetTweenTimeLeft();
// TimeUntilFinished = max(TimeUntilFinished, m_Out.GetLengthSeconds());
// SCREENMAN->PostMessageToTopScreen( smSendWhenDone, TimeUntilFinished );
}
2003-03-09 00:55:49 +00:00
void MenuElements::Back( ScreenMessage smSendWhenDone )
2002-09-04 22:56:19 +00:00
{
2003-03-11 08:52:45 +00:00
if( m_Back.IsTransitioning() )
return; // ignore
2003-11-07 20:10:38 +00:00
m_MenuTimer->Stop();
2003-03-09 00:55:49 +00:00
m_Back.StartTransitioning( smSendWhenDone );
m_soundBack.Play();
}
2002-05-19 01:59:48 +00:00
void MenuElements::DrawPrimitives()
{
// do nothing. Call DrawBottomLayer() and DrawTopLayer() instead.
}
void MenuElements::DrawTopLayer()
{
2003-11-07 20:57:22 +00:00
ASSERT( !this->m_SubActors.empty() ); // Load first
2002-08-19 20:02:30 +00:00
BeginDraw();
2002-08-27 16:53:25 +00:00
2003-11-04 21:49:38 +00:00
m_autoHeader->Draw();
2002-08-27 16:53:25 +00:00
m_sprStyleIcon.Draw();
2004-03-17 06:01:17 +00:00
m_autoFooter->Draw();
for( int p=0; p<NUM_PLAYERS; p++ )
m_MemoryCardDisplay[p].Draw();
if( m_bTimerEnabled )
2003-11-07 20:10:38 +00:00
m_MenuTimer->Draw();
2003-11-17 01:01:44 +00:00
m_textHelp->Draw();
2003-03-09 00:55:49 +00:00
m_In.Draw();
m_Out.Draw();
m_Back.Draw();
2002-08-27 16:53:25 +00:00
2002-08-19 20:02:30 +00:00
EndDraw();
}
void MenuElements::DrawBottomLayer()
{
2002-08-19 20:02:30 +00:00
BeginDraw();
2002-08-27 16:53:25 +00:00
m_Background.Draw();
2002-08-27 16:53:25 +00:00
2002-08-19 20:02:30 +00:00
EndDraw();
}
2003-03-09 00:55:49 +00:00
bool MenuElements::IsTransitioning()
2002-08-20 21:00:56 +00:00
{
2003-03-09 00:55:49 +00:00
return m_In.IsTransitioning() || m_Out.IsTransitioning() || m_Back.IsTransitioning();
}
2003-11-07 20:10:38 +00:00
void MenuElements::StopTimer()
{
m_MenuTimer->Stop();
}