Files
itgmania212121/stepmania/src/MenuElements.cpp
T

335 lines
9.3 KiB
C++
Raw Normal View History

#include "stdafx.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 "RageTextureManager.h"
#include "RageUtil.h"
2003-01-02 07:54:28 +00:00
#include "RageSoundManager.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 "RageLog.h"
#include "GameManager.h"
2002-07-23 01:41:40 +00:00
#include "GameState.h"
#include "ThemeManager.h"
2002-08-27 16:53:25 +00:00
#define TOP_EDGE_X THEME->GetMetricF("MenuElements","TopEdgeX")
#define TOP_EDGE_Y THEME->GetMetricF("MenuElements","TopEdgeY")
#define BOTTOM_EDGE_X THEME->GetMetricF("MenuElements","BottomEdgeX")
#define BOTTOM_EDGE_Y THEME->GetMetricF("MenuElements","BottomEdgeY")
#define STYLE_ICON_X THEME->GetMetricF("MenuElements","StyleIconX")
#define STYLE_ICON_Y THEME->GetMetricF("MenuElements","StyleIconY")
#define TIMER_X THEME->GetMetricF("MenuElements","TimerX")
#define TIMER_Y THEME->GetMetricF("MenuElements","TimerY")
#define HELP_X THEME->GetMetricF("MenuElements","HelpX")
#define HELP_Y THEME->GetMetricF("MenuElements","HelpY")
2002-05-27 18:36:01 +00:00
MenuElements::MenuElements()
{
this->AddChild( &m_sprTopEdge );
this->AddChild( &m_sprStyleIcon );
this->AddChild( &m_MenuTimer );
this->AddChild( &m_sprBottomEdge );
this->AddChild( &m_Background );
this->AddChild( &m_quadBrightness );
this->AddChild( &m_textHelp );
2002-05-28 20:01:22 +00:00
m_KeepAlive.SetOpened();
this->AddChild( &m_KeepAlive );
2002-05-28 20:01:22 +00:00
m_Wipe.SetOpened();
this->AddChild( &m_Wipe );
2002-06-27 17:49:10 +00:00
this->AddChild( &m_Invisible );
}
void MenuElements::StealthTimer( int iActive )
{
m_MenuTimer.StealthTimer( iActive ); // go a bit deeper... get rid of the sound...
if (iActive == 0) // if we wanna hide the timer...
{
m_MenuTimer.SetXY( TIMER_X, TIMER_Y ); // set it off-screen
}
else if (iActive == 1) // we wanna hide the timer
{
m_MenuTimer.SetXY( 999.0f, 999.0f ); // otherwise position it off-screen
}
// else... take no action :)
}
void MenuElements::Load( CString sBackgroundPath, CString sTopEdgePath, CString sHelpText, bool bShowStyleIcon, bool bTimerEnabled, int iTimerSeconds )
{
LOG->Trace( "MenuElements::MenuElements()" );
m_Background.LoadFromAniDir( sBackgroundPath );
m_quadBrightness.SetDiffuse( RageColor(0,0,0,0) );
2002-10-31 05:52:12 +00:00
m_quadBrightness.StretchTo( RectI(SCREEN_LEFT, SCREEN_TOP, SCREEN_RIGHT, SCREEN_BOTTOM) );
m_sprTopEdge.Load( sTopEdgePath );
2002-08-27 16:53:25 +00:00
m_sprTopEdge.SetXY( TOP_EDGE_X, TOP_EDGE_Y );
2002-05-27 18:36:01 +00:00
m_sprStyleIcon.Load( THEME->GetPathTo("Graphics",ssprintf("menu style icons %s",GAMESTATE->GetCurrentGameDef()->m_szName)) );
2002-05-27 18:36:01 +00:00
m_sprStyleIcon.StopAnimating();
2002-08-27 16:53:25 +00:00
m_sprStyleIcon.SetXY( STYLE_ICON_X, STYLE_ICON_Y );
2003-01-30 07:18:33 +00:00
if( GAMESTATE->m_CurStyle == STYLE_INVALID || !bShowStyleIcon )
m_sprStyleIcon.SetDiffuse( RageColor(1,1,1,0) );
2002-05-28 20:01:22 +00:00
else
{
int iRowNum = GetStyleIndexRelativeToGame( GAMESTATE->m_CurGame, GAMESTATE->m_CurStyle );
m_sprStyleIcon.SetState( iRowNum*2+GAMESTATE->m_MasterPlayerNumber );
}
2002-05-27 08:23:27 +00:00
2002-08-27 16:53:25 +00:00
m_MenuTimer.SetXY( TIMER_X, TIMER_Y );
2002-07-11 19:02:26 +00:00
if( !bTimerEnabled || !PREFSMAN->m_bMenuTimer )
{
m_MenuTimer.SetTimer( 99 );
2002-07-27 19:29:51 +00:00
m_MenuTimer.Update( 0 );
2002-07-11 19:02:26 +00:00
m_MenuTimer.StopTimer();
}
else
m_MenuTimer.SetTimer( iTimerSeconds );
2002-05-27 08:23:27 +00:00
m_sprBottomEdge.Load( THEME->GetPathTo("Graphics","menu bottom edge") );
2002-08-27 16:53:25 +00:00
m_sprBottomEdge.SetXY( BOTTOM_EDGE_X, BOTTOM_EDGE_Y );
m_textHelp.SetXY( HELP_X, HELP_Y );
2002-07-23 01:41:40 +00:00
CStringArray asHelpTips;
split( sHelpText, "\n", asHelpTips );
2002-07-23 01:41:40 +00:00
m_textHelp.SetTips( asHelpTips );
m_textHelp.SetZoom( 0.5f );
m_soundSwoosh.Load( THEME->GetPathTo("Sounds","menu swoosh") );
m_soundBack.Load( THEME->GetPathTo("Sounds","menu back") );
2002-05-28 20:01:22 +00:00
}
void MenuElements::TweenTopLayerOnScreen(float tm)
2002-05-28 20:01:22 +00:00
{
if(tm == -1)
tm = MENU_ELEMENTS_TWEEN_TIME;
2003-01-03 05:56:28 +00:00
vector<Actor*> apActorsInTopFrame;
2002-10-31 04:23:39 +00:00
apActorsInTopFrame.push_back( &m_sprTopEdge );
apActorsInTopFrame.push_back( &m_sprStyleIcon );
apActorsInTopFrame.push_back( &m_MenuTimer );
for( unsigned i=0; i<apActorsInTopFrame.size(); i++ )
2002-08-27 16:53:25 +00:00
{
float fOriginalX = apActorsInTopFrame[i]->GetX();
apActorsInTopFrame[i]->SetX( fOriginalX+SCREEN_WIDTH );
apActorsInTopFrame[i]->BeginTweening( tm, TWEEN_SPRING );
2002-08-27 16:53:25 +00:00
apActorsInTopFrame[i]->SetTweenX( fOriginalX );
}
2002-05-28 20:01:22 +00:00
float fOriginalZoom = m_textHelp.GetZoomY();
m_textHelp.SetZoomY( 0 );
m_textHelp.BeginTweening( tm/2 );
2002-05-28 20:01:22 +00:00
m_textHelp.SetTweenZoomY( fOriginalZoom );
}
void MenuElements::TweenOnScreenFromMenu( ScreenMessage smSendWhenDone, bool bLeaveKeepAliveOn )
2002-05-28 20:01:22 +00:00
{
TweenTopLayerOnScreen();
if( !bLeaveKeepAliveOn )
m_KeepAlive.OpenWipingRight( smSendWhenDone );
else
m_KeepAlive.SetClosed();
2002-05-19 01:59:48 +00:00
m_soundSwoosh.Play();
}
2002-12-19 22:09:44 +00:00
void MenuElements::TweenTopLayerOffScreen(float tm)
{
/*
This trick is neat, but there's a problem: fOriginalX may not be the settled
position--we might still be tweening, and if it's a bounce tween, it might be
left of center, which means fOriginalX+SCREEN_WIDTH won't actually take it
completely off-screen. fOriginalX+SCREEN_WIDTH*2 would, but that'd make the
bounce faster. SCREEN_WIDTH+SCREEN_WIDTH/2 would, but ignoring fOriginalX
will make each component tween off at a different rate ...
-glenn
2003-01-03 05:56:28 +00:00
vector<Actor*> apActorsInTopFrame;
2002-10-31 04:23:39 +00:00
apActorsInTopFrame.push_back( &m_sprTopEdge );
apActorsInTopFrame.push_back( &m_sprStyleIcon );
apActorsInTopFrame.push_back( &m_MenuTimer );
for( unsigned i=0; i<apActorsInTopFrame.size(); i++ )
2002-08-27 16:53:25 +00:00
{
float fOriginalX = apActorsInTopFrame[i]->GetX();
apActorsInTopFrame[i]->BeginTweening( MENU_ELEMENTS_TWEEN_TIME, TWEEN_BOUNCE_BEGIN );
apActorsInTopFrame[i]->SetTweenX( fOriginalX+SCREEN_WIDTH );
}
*/
2002-12-19 22:09:44 +00:00
if(tm == -1)
tm = MENU_ELEMENTS_TWEEN_TIME;
m_sprTopEdge.StopTweening();
2002-12-19 22:09:44 +00:00
m_sprTopEdge.BeginTweening( tm, TWEEN_BOUNCE_BEGIN );
m_sprTopEdge.SetTweenX( TOP_EDGE_X+SCREEN_WIDTH );
m_sprStyleIcon.StopTweening();
2002-12-19 22:09:44 +00:00
m_sprStyleIcon.BeginTweening( tm, TWEEN_BOUNCE_BEGIN );
m_sprStyleIcon.SetTweenX( STYLE_ICON_X+SCREEN_WIDTH );
m_MenuTimer.StopTweening();
2002-12-19 22:09:44 +00:00
m_MenuTimer.BeginTweening( tm, TWEEN_BOUNCE_BEGIN );
m_MenuTimer.SetTweenX( TIMER_X+SCREEN_WIDTH );
2002-04-16 17:31:00 +00:00
m_textHelp.StopTweening();
2002-12-19 22:09:44 +00:00
m_textHelp.BeginTweening( tm/2 );
m_textHelp.SetTweenZoomY( 0 );
2002-05-28 20:01:22 +00:00
}
2002-05-28 20:01:22 +00:00
void MenuElements::TweenOffScreenToMenu( ScreenMessage smSendWhenDone )
{
2002-08-29 20:18:41 +00:00
m_MenuTimer.StopTimer();
2002-05-28 20:01:22 +00:00
TweenTopLayerOffScreen();
if( !m_KeepAlive.IsClosed() )
m_KeepAlive.CloseWipingRight( smSendWhenDone );
else
SCREENMAN->SendMessageToTopScreen( smSendWhenDone, m_KeepAlive.GetTransitionTime() );
2002-05-19 01:59:48 +00:00
m_soundSwoosh.Play();
}
void MenuElements::ImmedOnScreenFromMenu( bool bLeaveKeepAliveOn )
{
TweenTopLayerOnScreen(0);
Update(0);
if( !bLeaveKeepAliveOn )
m_KeepAlive.SetOpened();
else
m_KeepAlive.SetClosed();
}
2002-09-04 22:56:19 +00:00
void MenuElements::ImmedOffScreenToMenu()
{
m_MenuTimer.StopTimer();
m_KeepAlive.SetClosed();
2002-12-19 22:09:44 +00:00
/* Remove the top layer immediately. */
TweenTopLayerOffScreen(0);
2002-09-04 22:56:19 +00:00
2002-12-19 22:09:44 +00:00
/* We need to do a null update after doing null tweens (tweens with zero time),
* or they'll show up in their default positions for a frame (since screens
* draw once before they're updated for the first time). */
Update(0);
2002-09-04 22:56:19 +00:00
}
2002-05-28 20:01:22 +00:00
void MenuElements::TweenBottomLayerOnScreen()
{
2002-08-27 16:53:25 +00:00
float fOriginalY = m_sprBottomEdge.GetY();
m_sprBottomEdge.SetY( fOriginalY + 100 );
m_sprBottomEdge.BeginTweening( MENU_ELEMENTS_TWEEN_TIME/2 );
m_sprBottomEdge.SetTweenY( fOriginalY );
m_quadBrightness.SetDiffuse( RageColor(0,0,0,1) );
m_quadBrightness.BeginTweening( MENU_ELEMENTS_TWEEN_TIME/2 );
m_quadBrightness.SetTweenDiffuse( RageColor(0,0,0,0) );
}
2002-05-28 20:01:22 +00:00
void MenuElements::TweenBottomLayerOffScreen()
{
2002-08-27 16:53:25 +00:00
float fOriginalY = m_sprBottomEdge.GetY();
m_sprBottomEdge.StopTweening();
2002-08-27 16:53:25 +00:00
m_sprBottomEdge.BeginTweening( MENU_ELEMENTS_TWEEN_TIME/2 );
m_sprBottomEdge.SetTweenY( fOriginalY + 100 );
m_quadBrightness.SetDiffuse( RageColor(0,0,0,0) );
m_quadBrightness.StopTweening();
m_quadBrightness.BeginTweening( MENU_ELEMENTS_TWEEN_TIME*3/2.0f ); // sleep
m_quadBrightness.BeginTweening( MENU_ELEMENTS_TWEEN_TIME/2 ); // fade
m_quadBrightness.SetTweenDiffuse( RageColor(0,0,0,1) );
}
2002-05-28 20:01:22 +00:00
void MenuElements::TweenOnScreenFromBlack( ScreenMessage smSendWhenDone )
{
2002-05-28 20:01:22 +00:00
TweenTopLayerOnScreen();
TweenBottomLayerOnScreen();
2002-05-29 09:47:24 +00:00
//m_Wipe.OpenWipingRight( smSendWhenDone );
2002-05-28 20:01:22 +00:00
m_soundSwoosh.Play();
}
2002-05-28 20:01:22 +00:00
void MenuElements::TweenOffScreenToBlack( ScreenMessage smSendWhenDone, bool bPlayBackSound )
{
2002-08-29 20:18:41 +00:00
m_MenuTimer.StopTimer();
2002-05-28 20:01:22 +00:00
if( !bPlayBackSound )
{
TweenTopLayerOffScreen();
TweenBottomLayerOffScreen();
2002-07-28 20:28:37 +00:00
m_Invisible.SetTransitionTime( MENU_ELEMENTS_TWEEN_TIME*2 );
2002-06-27 17:49:10 +00:00
m_Invisible.CloseWipingRight( smSendWhenDone );
2002-05-28 20:01:22 +00:00
}
2002-05-29 09:47:24 +00:00
else
{
2002-05-28 20:01:22 +00:00
m_soundBack.Play();
2002-05-29 09:47:24 +00:00
m_Wipe.CloseWipingLeft( smSendWhenDone );
}
}
2002-05-19 01:59:48 +00:00
void MenuElements::DrawPrimitives()
{
// do nothing. Call DrawBottomLayer() and DrawTopLayer() instead.
}
void MenuElements::DrawTopLayer()
{
2002-08-19 20:02:30 +00:00
BeginDraw();
2002-08-27 16:53:25 +00:00
m_sprTopEdge.Draw();
m_sprStyleIcon.Draw();
m_MenuTimer.Draw();
m_sprBottomEdge.Draw();
m_textHelp.Draw();
2002-05-28 20:01:22 +00:00
m_KeepAlive.Draw();
m_Wipe.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();
m_quadBrightness.Draw();
2002-08-27 16:53:25 +00:00
2002-08-19 20:02:30 +00:00
EndDraw();
}
void MenuElements::SetTimer( int iTimerSeconds )
2002-07-11 19:02:26 +00:00
{
m_MenuTimer.SetTimer( iTimerSeconds );
2002-07-11 19:02:26 +00:00
}
void MenuElements::StartTimer()
2002-08-20 21:00:56 +00:00
{
m_MenuTimer.StartTimer();
}
void MenuElements::StopTimer()
{
m_MenuTimer.StopTimer();
2002-08-20 21:00:56 +00:00
}
void MenuElements::StallTimer()
{
m_MenuTimer.StallTimer();
}