Files
itgmania212121/stepmania/src/BPMDisplay.cpp
T

226 lines
4.7 KiB
C++
Raw Normal View History

2003-02-16 04:01:45 +00:00
#include "global.h"
2001-12-28 10:15:59 +00:00
/*
-----------------------------------------------------------------------------
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"
2003-07-20 04:22:25 +00:00
#include "Course.h"
#include "StyleDef.h"
2001-12-28 10:15:59 +00:00
#define NORMAL_COLOR THEME->GetMetricC("BPMDisplay","NormalColor")
#define CHANGE_COLOR THEME->GetMetricC("BPMDisplay","ChangeColor")
#define EXTRA_COLOR THEME->GetMetricC("BPMDisplay","ExtraColor")
2002-08-28 22:42:40 +00:00
2001-12-28 10:15:59 +00:00
BPMDisplay::BPMDisplay()
{
2003-07-20 04:22:25 +00:00
m_fBPMFrom = m_fBPMTo = 0;
m_iCurrentBPM = 0;
m_BPMS.push_back(0);
m_fPercentInState = 0;
m_fCycleTime = 1.0f;
2001-12-28 10:15:59 +00:00
m_textBPM.LoadFromNumbers( THEME->GetPathToN("BPMDisplay") );
2003-03-02 01:43:33 +00:00
m_textBPM.EnableShadow( false );
m_textBPM.SetHorizAlign( Actor::align_right );
m_textBPM.SetDiffuse( NORMAL_COLOR );
m_textBPM.SetXY( 0, 0 );
m_sprLabel.Load( THEME->GetPathToG("BPMDisplay label") );
2003-03-02 01:43:33 +00:00
m_sprLabel.EnableShadow( false );
m_sprLabel.SetDiffuse( NORMAL_COLOR );
m_sprLabel.SetHorizAlign( Actor::align_left );
m_sprLabel.SetXY( 0, 0 );
this->AddChild( &m_textBPM );
this->AddChild( &m_sprLabel );
2001-12-28 10:15:59 +00:00
}
2003-07-20 04:22:25 +00:00
float BPMDisplay::GetActiveBPM() const
{
return m_fBPMTo + (m_fBPMFrom-m_fBPMTo)*m_fPercentInState;
}
2001-12-28 10:15:59 +00:00
void BPMDisplay::Update( float fDeltaTime )
{
ActorFrame::Update( fDeltaTime );
2003-07-20 04:22:25 +00:00
if( m_BPMS.size() == 0 )
return; /* no bpm */
m_fPercentInState -= fDeltaTime / m_fCycleTime;
if( m_fPercentInState < 0 )
2001-12-28 10:15:59 +00:00
{
2003-03-30 19:30:54 +00:00
// go to next state
2003-07-20 04:22:25 +00:00
m_fPercentInState = 1; // reset timer
m_iCurrentBPM = (m_iCurrentBPM + 1) % m_BPMS.size();
m_fBPMFrom = m_fBPMTo;
m_fBPMTo = m_BPMS[m_iCurrentBPM];
if(m_fBPMTo == -1)
2001-12-28 10:15:59 +00:00
{
2003-07-20 04:22:25 +00:00
m_fBPMFrom = -1;
2003-03-30 18:12:57 +00:00
m_textBPM.SetText( (RandomFloat(0,1)>0.90) ? "xxx" : ssprintf("%03.0f",RandomFloat(0,600)) );
2003-07-20 04:22:25 +00:00
} else if(m_fBPMFrom == -1)
m_fBPMFrom = m_fBPMTo;
2001-12-28 10:15:59 +00:00
}
2003-03-30 19:30:54 +00:00
2003-07-20 04:22:25 +00:00
// update m_textBPM
if( m_fBPMTo != -1)
2001-12-28 10:15:59 +00:00
{
2003-07-20 04:22:25 +00:00
const float fActualBPM = GetActiveBPM();
m_textBPM.SetText( ssprintf("%03.0f", fActualBPM) );
2001-12-28 10:15:59 +00:00
}
}
2003-07-20 04:22:25 +00:00
void BPMDisplay::SetBPMRange( const vector<float> &BPMS )
2001-12-28 10:15:59 +00:00
{
2003-07-20 05:08:32 +00:00
ASSERT( BPMS.size() );
2003-07-20 04:22:25 +00:00
m_BPMS.clear();
unsigned i;
bool AllIdentical = true;
for( i = 0; i < BPMS.size(); ++i )
{
2003-07-21 20:11:13 +00:00
if( i > 0 && BPMS[i] != BPMS[i-1] )
2003-07-20 04:22:25 +00:00
AllIdentical = false;
m_BPMS.push_back(BPMS[i]);
if( BPMS[i] != -1 )
m_BPMS.push_back(BPMS[i]); /* hold */
}
2003-07-21 20:11:13 +00:00
m_iCurrentBPM = min(1u, m_BPMS.size()); /* start on the first hold */
2003-07-20 04:22:25 +00:00
m_fBPMFrom = BPMS[0];
m_fBPMTo = BPMS[0];
m_fPercentInState = 1;
2001-12-28 10:15:59 +00:00
m_textBPM.StopTweening();
m_sprLabel.StopTweening();
2002-08-28 22:42:40 +00:00
m_textBPM.BeginTweening(0.5f);
m_sprLabel.BeginTweening(0.5f);
2002-08-28 22:42:40 +00:00
if( GAMESTATE->IsExtraStage() || GAMESTATE->IsExtraStage2() )
{
2003-04-12 06:16:12 +00:00
m_textBPM.SetDiffuse( EXTRA_COLOR );
m_sprLabel.SetDiffuse( EXTRA_COLOR );
2002-08-28 22:42:40 +00:00
}
2003-07-20 04:22:25 +00:00
else if( !AllIdentical )
2001-12-28 10:15:59 +00:00
{
2003-04-12 06:16:12 +00:00
m_textBPM.SetDiffuse( CHANGE_COLOR );
m_sprLabel.SetDiffuse( CHANGE_COLOR );
2001-12-28 10:15:59 +00:00
}
else
{
2003-04-12 06:16:12 +00:00
m_textBPM.SetDiffuse( NORMAL_COLOR );
m_sprLabel.SetDiffuse( NORMAL_COLOR );
2001-12-28 10:15:59 +00:00
}
2003-02-16 04:56:36 +00:00
}
2003-03-30 19:30:54 +00:00
void BPMDisplay::CycleRandomly()
{
2003-07-20 04:22:25 +00:00
vector<float> BPMS;
BPMS.push_back(-1);
SetBPMRange( BPMS );
2003-03-30 21:02:15 +00:00
2003-07-20 04:22:25 +00:00
m_fCycleTime = 0.2f;
2003-03-30 19:30:54 +00:00
}
void BPMDisplay::NoBPM()
{
2003-07-20 04:22:25 +00:00
m_BPMS.clear();
2003-03-30 19:30:54 +00:00
m_textBPM.SetText( "..." );
2003-03-30 21:02:15 +00:00
2003-04-12 06:16:12 +00:00
m_textBPM.SetDiffuse( NORMAL_COLOR );
m_sprLabel.SetDiffuse( NORMAL_COLOR );
2003-03-30 19:30:54 +00:00
}
void BPMDisplay::SetBPM( const Song* pSong )
{
ASSERT( pSong );
switch( pSong->m_DisplayBPMType )
{
case Song::DISPLAY_ACTUAL:
2003-07-20 04:22:25 +00:00
case Song::DISPLAY_SPECIFIED:
{
float fMinBPM, fMaxBPM;
2003-07-20 04:22:25 +00:00
pSong->GetDisplayBPM( fMinBPM, fMaxBPM );
vector<float> BPMS;
BPMS.push_back(fMinBPM);
BPMS.push_back(fMaxBPM);
SetBPMRange( BPMS );
2003-07-20 05:08:32 +00:00
m_fCycleTime = 1.0f;
}
break;
case Song::DISPLAY_RANDOM:
2003-06-12 20:10:08 +00:00
CycleRandomly();
break;
default:
ASSERT(0);
}
2003-07-20 04:22:25 +00:00
}
void BPMDisplay::SetBPM( const Course* pCourse )
{
2003-07-21 20:11:13 +00:00
ASSERT( pCourse );
2003-07-20 04:22:25 +00:00
2003-07-21 21:54:07 +00:00
vector<Course::Info> ci;
2003-08-07 06:36:34 +00:00
pCourse->GetCourseInfo( GAMESTATE->GetCurrentStyleDef()->m_StepsType, ci );
2003-07-21 21:54:07 +00:00
ASSERT( ci.size() );
2003-07-20 04:22:25 +00:00
vector<float> BPMS;
2003-07-21 21:54:07 +00:00
for( unsigned i = 0; i < ci.size(); ++i )
2003-07-20 04:22:25 +00:00
{
if( ci[i].Mystery )
2003-07-20 04:22:25 +00:00
{
BPMS.push_back( -1 );
continue;
}
2003-07-21 23:16:06 +00:00
Song *pSong = ci[i].pSong;
2003-07-20 04:22:25 +00:00
ASSERT( pSong );
switch( pSong->m_DisplayBPMType )
{
case Song::DISPLAY_ACTUAL:
case Song::DISPLAY_SPECIFIED:
{
float fMinBPM, fMaxBPM;
pSong->GetDisplayBPM( fMinBPM, fMaxBPM );
BPMS.push_back( fMinBPM );
if( fMinBPM != fMaxBPM )
BPMS.push_back( fMaxBPM );
}
break;
case Song::DISPLAY_RANDOM:
BPMS.push_back( -1 );
break;
default:
ASSERT(0);
}
}
SetBPMRange( BPMS );
m_fCycleTime = 0.2f;
}
void BPMDisplay::DrawPrimitives()
{
ActorFrame::DrawPrimitives();
}