Files
itgmania212121/stepmania/src/BPMDisplay.cpp
T

142 lines
4.4 KiB
C++
Raw Normal View History

2001-12-28 10:15:59 +00:00
#include "stdafx.h"
/*
-----------------------------------------------------------------------------
File: BPMDisplay.h
Desc: A graphic displayed in the BPMDisplay during Dancing.
2002-05-19 01:59:48 +00:00
Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved.
2001-12-28 10:15:59 +00:00
-----------------------------------------------------------------------------
*/
#include "BPMDisplay.h"
#include "RageUtil.h"
2002-05-01 19:14:55 +00:00
#include "GameConstantsAndTypes.h"
2002-07-23 01:41:40 +00:00
#include "PrefsManager.h"
2002-08-28 22:42:40 +00:00
#include "GameState.h"
#include "ThemeManager.h"
2001-12-28 10:15:59 +00:00
2002-08-28 22:42:40 +00:00
#define NORMAL_COLOR_TOP THEME->GetMetricC("BPMDisplay","NormalColorTop")
#define NORMAL_COLOR_BOTTOM THEME->GetMetricC("BPMDisplay","NormalColorBottom")
#define CHANGE_COLOR_TOP THEME->GetMetricC("BPMDisplay","ChangeColorTop")
#define CHANGE_COLOR_BOTTOM THEME->GetMetricC("BPMDisplay","ChangeColorBottom")
#define EXTRA_COLOR_TOP THEME->GetMetricC("BPMDisplay","ExtraColorTop")
#define EXTRA_COLOR_BOTTOM THEME->GetMetricC("BPMDisplay","ExtraColorBottom")
2001-12-28 10:15:59 +00:00
BPMDisplay::BPMDisplay()
{
m_fCurrentBPM = m_fLowBPM = m_fHighBPM = 0;
m_CountingState = holding_down;
m_fTimeLeftInState = 0;
2002-08-28 22:42:40 +00:00
m_bExtraStage = GAMESTATE->IsExtraStage() || GAMESTATE->IsExtraStage2();
2001-12-28 10:15:59 +00:00
m_rectFrame.SetDiffuse( RageColor(0,0,0,0.3f) );
2001-12-28 10:15:59 +00:00
m_rectFrame.SetZoomX( 120 );
m_rectFrame.SetZoomY( 40 );
m_textBPM.LoadFromFont( THEME->GetPathTo("Fonts","bpmdisplay") );
2002-03-31 07:55:25 +00:00
m_textBPM.TurnShadowOff();
2002-01-16 10:01:32 +00:00
m_textBPM.SetXY( CENTER_X, SCREEN_HEIGHT - 50 );
//m_textBPM.SetSequence( ssprintf("999") );
2002-03-31 07:55:25 +00:00
m_textBPM.SetXY( -23, 0 );
m_textBPM.SetZoom( 1.0f );
m_textBPM.SetDiffuseTopEdge( NORMAL_COLOR_TOP ); // yellow
m_textBPM.SetDiffuseBottomEdge( NORMAL_COLOR_BOTTOM ); // orange
2001-12-28 10:15:59 +00:00
m_textLabel.LoadFromFont( THEME->GetPathTo("Fonts","bpmdisplay") );
2002-03-31 07:55:25 +00:00
m_textLabel.TurnShadowOff();
m_textLabel.SetXY( 34, 2 );
2001-12-28 10:15:59 +00:00
m_textLabel.SetText( "BPM" );
2002-03-31 07:55:25 +00:00
m_textLabel.SetZoom( 0.7f );
m_textLabel.SetZoomX( 0.5f );
m_textLabel.SetDiffuseTopEdge( NORMAL_COLOR_TOP ); // yellow
m_textLabel.SetDiffuseBottomEdge( NORMAL_COLOR_BOTTOM ); // orange
2001-12-28 10:15:59 +00:00
//this->AddChild( &m_rectFrame );
this->AddChild( &m_textBPM );
this->AddChild( &m_textLabel );
2001-12-28 10:15:59 +00:00
}
void BPMDisplay::Update( float fDeltaTime )
{
ActorFrame::Update( fDeltaTime );
2002-08-28 22:42:40 +00:00
if( m_bExtraStage )
2001-12-28 10:15:59 +00:00
{
2002-08-28 22:42:40 +00:00
m_fTimeLeftInState -= fDeltaTime;
if( m_fTimeLeftInState < 0 )
2001-12-28 10:15:59 +00:00
{
2002-08-28 22:42:40 +00:00
m_textBPM.SetText( (RandomFloat(0,1)>0.90) ? "???" : ssprintf("%03.0f",RandomFloat(0,600)) );
m_fTimeLeftInState = 0.2f; // reset timer
2001-12-28 10:15:59 +00:00
}
}
2002-08-28 22:42:40 +00:00
else // !m_bExtraStage
2001-12-28 10:15:59 +00:00
{
2002-08-28 22:42:40 +00:00
m_fTimeLeftInState -= fDeltaTime;
if( m_fTimeLeftInState < 0 )
{
// go to next state
switch( m_CountingState )
{
case counting_up: m_CountingState = holding_up; break;
case holding_up: m_CountingState = counting_down; break;
case counting_down: m_CountingState = holding_down; break;
case holding_down: m_CountingState = counting_up; break;
}
m_fTimeLeftInState = 1; // reset timer
}
switch( m_CountingState )
{
case counting_down: m_fCurrentBPM = m_fLowBPM + (m_fHighBPM-m_fLowBPM)*m_fTimeLeftInState; break;
case counting_up: m_fCurrentBPM = m_fHighBPM + (m_fLowBPM-m_fHighBPM)*m_fTimeLeftInState; break;
case holding_up: m_fCurrentBPM = m_fHighBPM; break;
case holding_down: m_fCurrentBPM = m_fLowBPM; break;
}
m_textBPM.SetText( ssprintf("%03.0f", m_fCurrentBPM) );
2001-12-28 10:15:59 +00:00
}
}
void BPMDisplay::SetBPMRange( float fLowBPM, float fHighBPM )
{
m_fLowBPM = fLowBPM;
m_fHighBPM = fHighBPM;
if( m_fCurrentBPM > m_fHighBPM )
m_CountingState = counting_down;
else
m_CountingState = counting_up;
m_fTimeLeftInState = 1;
m_textBPM.StopTweening();
m_textLabel.StopTweening();
2002-08-28 22:42:40 +00:00
m_textBPM.BeginTweening(0.5f);
m_textLabel.BeginTweening(0.5f);
if( GAMESTATE->IsExtraStage() || GAMESTATE->IsExtraStage2() )
{
m_textBPM.SetTweenDiffuseTopEdge( EXTRA_COLOR_TOP );
m_textBPM.SetTweenDiffuseBottomEdge( EXTRA_COLOR_BOTTOM );
m_textLabel.SetTweenDiffuseTopEdge( EXTRA_COLOR_TOP );
m_textLabel.SetTweenDiffuseBottomEdge( EXTRA_COLOR_BOTTOM );
2002-08-28 22:42:40 +00:00
}
else if( m_fLowBPM != m_fHighBPM )
2001-12-28 10:15:59 +00:00
{
m_textBPM.SetTweenDiffuseTopEdge( CHANGE_COLOR_TOP );
m_textBPM.SetTweenDiffuseBottomEdge( CHANGE_COLOR_BOTTOM );
m_textLabel.SetTweenDiffuseTopEdge( CHANGE_COLOR_TOP );
m_textLabel.SetTweenDiffuseBottomEdge( CHANGE_COLOR_BOTTOM );
2001-12-28 10:15:59 +00:00
}
else
{
m_textBPM.SetTweenDiffuseTopEdge( NORMAL_COLOR_TOP );
m_textBPM.SetTweenDiffuseBottomEdge( NORMAL_COLOR_BOTTOM );
m_textLabel.SetTweenDiffuseTopEdge( NORMAL_COLOR_TOP );
m_textLabel.SetTweenDiffuseBottomEdge( NORMAL_COLOR_BOTTOM );
2001-12-28 10:15:59 +00:00
}
}