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