move constants to metrics
This commit is contained in:
@@ -9,25 +9,15 @@ REGISTER_ACTOR_CLASS( RollingNumbers )
|
||||
|
||||
RollingNumbers::RollingNumbers()
|
||||
{
|
||||
m_sFormat = "%9.0f";
|
||||
m_fApproachSeconds = 0.2f;
|
||||
|
||||
m_fCurrentNumber = 0;
|
||||
m_fTargetNumber = 0;
|
||||
m_fScoreVelocity = 0;
|
||||
}
|
||||
|
||||
void RollingNumbers::LoadFromNode( const XNode* pNode )
|
||||
void RollingNumbers::Load( const RString &sMetricsGroup )
|
||||
{
|
||||
BitmapText::LoadFromNode( pNode );
|
||||
|
||||
pNode->GetAttrValue( "Format", m_sFormat );
|
||||
ThemeManager::EvaluateString( m_sFormat );
|
||||
pNode->GetAttrValue( "ApproachSeconds", m_fApproachSeconds );
|
||||
|
||||
float fTargetNumber;
|
||||
if( pNode->GetAttrValue( "TargetNumber", fTargetNumber ) )
|
||||
SetTargetNumber( fTargetNumber );
|
||||
TEXT_FORMAT.Load(sMetricsGroup, "TextFormat");
|
||||
APPROACH_SECONDS.Load(sMetricsGroup, "ApproachSeconds");
|
||||
|
||||
UpdateText();
|
||||
}
|
||||
@@ -48,12 +38,13 @@ void RollingNumbers::SetTargetNumber( float fTargetNumber )
|
||||
if( fTargetNumber == m_fTargetNumber ) // no change
|
||||
return;
|
||||
m_fTargetNumber = fTargetNumber;
|
||||
m_fScoreVelocity = (m_fTargetNumber-m_fCurrentNumber) / m_fApproachSeconds;
|
||||
m_fScoreVelocity = (m_fTargetNumber-m_fCurrentNumber) / APPROACH_SECONDS.GetValue();
|
||||
}
|
||||
|
||||
void RollingNumbers::UpdateText()
|
||||
{
|
||||
SetText( ssprintf(m_sFormat, m_fCurrentNumber) );
|
||||
RString s = ssprintf( TEXT_FORMAT.GetValue(), m_fCurrentNumber );
|
||||
SetText( s );
|
||||
}
|
||||
|
||||
// lua start
|
||||
|
||||
@@ -4,13 +4,14 @@
|
||||
#define RollingNumbers_H
|
||||
|
||||
#include "BitmapText.h"
|
||||
#include "ThemeMetric.h"
|
||||
|
||||
class RollingNumbers : public BitmapText
|
||||
{
|
||||
public:
|
||||
RollingNumbers();
|
||||
|
||||
void LoadFromNode( const XNode* pNode );
|
||||
void Load( const RString &sMetricsGroup );
|
||||
virtual RollingNumbers *Copy() const;
|
||||
|
||||
virtual void Update( float fDeltaTime );
|
||||
@@ -25,16 +26,9 @@ public:
|
||||
virtual void PushSelf( lua_State *L );
|
||||
|
||||
private:
|
||||
// Loaded attributes
|
||||
//
|
||||
// Time between the call to SetTargetNumber and m_fCurrentNumber ==
|
||||
// m_fTargetNumber. Used to calculate m_fScoreVelocity.
|
||||
float m_fApproachSeconds;
|
||||
RString m_sFormat;
|
||||
ThemeMetric<RString> TEXT_FORMAT;
|
||||
ThemeMetric<float> APPROACH_SECONDS;
|
||||
|
||||
//
|
||||
// Calculated
|
||||
//
|
||||
float m_fCurrentNumber; // currently showing this
|
||||
float m_fTargetNumber; // approach this
|
||||
float m_fScoreVelocity; // approach target at this speed
|
||||
|
||||
Reference in New Issue
Block a user