From 7d0c89661271803eb1f1b67bc8d3f21eea3cb3da Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Sun, 17 Aug 2008 14:34:53 +0000 Subject: [PATCH] to score leading character coloring in code. Font hacks are messy because there would need to be leading versions of both '0' and ',' --- stepmania/src/BitmapText.h | 1 + stepmania/src/RollingNumbers.cpp | 41 ++++++++++++++++++++++++++++++ stepmania/src/RollingNumbers.h | 3 +++ stepmania/src/ScreenEvaluation.cpp | 5 ++-- stepmania/src/ScreenEvaluation.h | 5 ++-- 5 files changed, 50 insertions(+), 5 deletions(-) diff --git a/stepmania/src/BitmapText.h b/stepmania/src/BitmapText.h index ee5721f55e..61bc9aef01 100644 --- a/stepmania/src/BitmapText.h +++ b/stepmania/src/BitmapText.h @@ -40,6 +40,7 @@ public: void SetHorizAlign( float f ); void SetStrokeColor( RageColor c ) { m_StrokeColor = c; } + RageColor GetStrokeColor() { return m_StrokeColor; } void GetLines( vector &wTextLines ) const { wTextLines = m_wTextLines; } const vector &GetLines() const { return m_wTextLines; } diff --git a/stepmania/src/RollingNumbers.cpp b/stepmania/src/RollingNumbers.cpp index 06a83cca6c..95439780c0 100644 --- a/stepmania/src/RollingNumbers.cpp +++ b/stepmania/src/RollingNumbers.cpp @@ -18,10 +18,49 @@ void RollingNumbers::Load( const RString &sMetricsGroup ) { TEXT_FORMAT.Load(sMetricsGroup, "TextFormat"); APPROACH_SECONDS.Load(sMetricsGroup, "ApproachSeconds"); + COMMIFY.Load(sMetricsGroup, "Commify"); + LEADING_ZERO_MULTIPLY_COLOR.Load(sMetricsGroup, "LeadingZeroMultiplyColor"); UpdateText(); } +void RollingNumbers::DrawPrimitives() +{ + RageColor c_orig = this->GetDiffuse(); + RageColor c2_orig = this->GetStrokeColor(); + + RageColor c = this->GetDiffuse(); + c *= LEADING_ZERO_MULTIPLY_COLOR; + RageColor c2 = this->GetStrokeColor(); + c2 *= LEADING_ZERO_MULTIPLY_COLOR; + + RString s = this->GetText(); + int i; + for( i=0; i<(int)s.length(); i++ ) + { + if( s[i] != '0' && s[i] != ',' ) + break; + } + float f = i / (float)s.length(); + + // draw leading part + SetDiffuse( c ); + SetStrokeColor( c2 ); + SetCropLeft( 0 ); + SetCropRight( 1-f ); + BitmapText::DrawPrimitives(); + + // draw regular color part + SetDiffuse( c_orig ); + SetStrokeColor( c2_orig ); + SetCropLeft( f ); + SetCropRight( 0 ); + BitmapText::DrawPrimitives(); + + SetCropLeft( 0 ); + SetCropRight( 0 ); +} + void RollingNumbers::Update( float fDeltaTime ) { if( m_fCurrentNumber != m_fTargetNumber ) @@ -44,6 +83,8 @@ void RollingNumbers::SetTargetNumber( float fTargetNumber ) void RollingNumbers::UpdateText() { RString s = ssprintf( TEXT_FORMAT.GetValue(), m_fCurrentNumber ); + if( COMMIFY ) + s = Commify( s ); SetText( s ); } diff --git a/stepmania/src/RollingNumbers.h b/stepmania/src/RollingNumbers.h index 58c2d66838..80cdcddc45 100644 --- a/stepmania/src/RollingNumbers.h +++ b/stepmania/src/RollingNumbers.h @@ -14,6 +14,7 @@ public: void Load( const RString &sMetricsGroup ); virtual RollingNumbers *Copy() const; + virtual void DrawPrimitives(); virtual void Update( float fDeltaTime ); void SetTargetNumber( float fTargetNumber ); @@ -28,6 +29,8 @@ public: private: ThemeMetric TEXT_FORMAT; ThemeMetric APPROACH_SECONDS; + ThemeMetric COMMIFY; + ThemeMetric LEADING_ZERO_MULTIPLY_COLOR; float m_fCurrentNumber; // currently showing this float m_fTargetNumber; // approach this diff --git a/stepmania/src/ScreenEvaluation.cpp b/stepmania/src/ScreenEvaluation.cpp index bb8ab60b2b..951226e6d3 100644 --- a/stepmania/src/ScreenEvaluation.cpp +++ b/stepmania/src/ScreenEvaluation.cpp @@ -30,8 +30,6 @@ #include "ScoreKeeperNormal.h" #include "InputEventPlus.h" -const int NUM_SCORE_DIGITS = 9; - // metrics that are common to all ScreenEvaluation classes #define BANNER_WIDTH THEME->GetMetricF(m_sName,"BannerWidth") @@ -581,9 +579,10 @@ void ScreenEvaluation::Init() { m_textScore[p].LoadFromFont( THEME->GetPathF(m_sName, "ScoreNumber") ); m_textScore[p].SetName( ssprintf("ScoreNumberP%d",p+1) ); + m_textScore[p].Load( "RollingNumbersEvaluation" ); ActorUtil::LoadAllCommands( m_textScore[p], m_sName ); SET_XY( m_textScore[p] ); - m_textScore[p].SetText( ssprintf("%*.0i", NUM_SCORE_DIGITS, m_pStageStats->m_player[p].m_iScore) ); + m_textScore[p].SetTargetNumber( m_pStageStats->m_player[p].m_iScore ); this->AddChild( &m_textScore[p] ); } } diff --git a/stepmania/src/ScreenEvaluation.h b/stepmania/src/ScreenEvaluation.h index 4d5538e64d..4d61157657 100644 --- a/stepmania/src/ScreenEvaluation.h +++ b/stepmania/src/ScreenEvaluation.h @@ -12,6 +12,7 @@ #include "ActorUtil.h" #include "RageSound.h" #include "ThemeMetric.h" +#include "RollingNumbers.h" const int MAX_SONGS_TO_SHOW = 5; // In summary, we show last 3 stages, plus extra stages if passed enum JudgmentLine @@ -100,7 +101,7 @@ protected: // score area AutoActor m_sprScoreLabel; - BitmapText m_textScore[NUM_PLAYERS]; + RollingNumbers m_textScore[NUM_PLAYERS]; // time area AutoActor m_sprTimeLabel; @@ -110,7 +111,7 @@ protected: AutoActor m_sprMachineRecord[NUM_PLAYERS]; AutoActor m_sprProfileRecord[NUM_PLAYERS]; AutoActor m_sprTryExtraStage; - bool m_bFailed; + bool m_bFailed; RageSound m_soundStart; // sound played if the player passes or fails