diff --git a/stepmania/src/PaneDisplay.cpp b/stepmania/src/PaneDisplay.cpp index 16fe51c90e..afd8fc25c7 100644 --- a/stepmania/src/PaneDisplay.cpp +++ b/stepmania/src/PaneDisplay.cpp @@ -12,6 +12,7 @@ #include "Command.h" #include "ActorUtil.h" #include "Foreach.h" +#include "PercentageDisplay.h" #define SHIFT_X(p) THEME->GetMetricF(m_sName, ssprintf("ShiftP%iX", p+1)) #define SHIFT_Y(p) THEME->GetMetricF(m_sName, ssprintf("ShiftP%iY", p+1)) @@ -300,7 +301,7 @@ void PaneDisplay::SetContent( PaneContents c ) case COURSE_MACHINE_HIGH_SCORE: case SONG_PROFILE_HIGH_SCORE: case COURSE_PROFILE_HIGH_SCORE: - str = ssprintf( "%.2f%%", val ); + str = PercentageDisplay::FormatPercentScore( val, 5, 2 ); break; case SONG_NUM_STEPS: case SONG_JUMPS: diff --git a/stepmania/src/PercentageDisplay.cpp b/stepmania/src/PercentageDisplay.cpp index 9f47170167..1e77e90652 100644 --- a/stepmania/src/PercentageDisplay.cpp +++ b/stepmania/src/PercentageDisplay.cpp @@ -121,17 +121,7 @@ void PercentageDisplay::Refresh() } else { - // TRICKY: printf will round, but we want to truncate. Otherwise, we may display a percent - // score that's too high and doesn't match up with the calculated grade. - float fTruncInterval = powf(0.1f, (float) PERCENT_TOTAL_SIZE-1); - - // TRICKY: ftruncf is rounding 1.0000000 to 0.99990004. Give a little boost to - // fPercentDancePoints to correct for this. - fPercentDancePoints += 0.000001f; - - fPercentDancePoints = ftruncf( fPercentDancePoints, fTruncInterval ); - - sNumToDisplay = ssprintf( "%*.*f%%", (int) PERCENT_TOTAL_SIZE, (int) PERCENT_DECIMAL_PLACES, fPercentDancePoints*100 ); + sNumToDisplay = FormatPercentScore( fPercentDancePoints, PERCENT_TOTAL_SIZE, PERCENT_DECIMAL_PLACES ); // HACK: Use the last frame in the numbers texture as '-' sNumToDisplay.Replace('-','x'); @@ -141,6 +131,21 @@ void PercentageDisplay::Refresh() m_textPercent.SetText( sNumToDisplay ); } +CString PercentageDisplay::FormatPercentScore( float fPercentDancePoints, int iTotalSize, int iDecimalPlaces ) +{ + // TRICKY: printf will round, but we want to truncate. Otherwise, we may display a percent + // score that's too high and doesn't match up with the calculated grade. + float fTruncInterval = powf( 0.1f, (float)iTotalSize-1 ); + + // TRICKY: ftruncf is rounding 1.0000000 to 0.99990004. Give a little boost to + // fPercentDancePoints to correct for this. + fPercentDancePoints += 0.000001f; + + fPercentDancePoints = ftruncf( fPercentDancePoints, fTruncInterval ); + + return ssprintf( "%*.*f%%", iTotalSize, iDecimalPlaces, fPercentDancePoints*100 ); +} + /* * (c) 2001-2003 Chris Danford * All rights reserved. diff --git a/stepmania/src/PercentageDisplay.h b/stepmania/src/PercentageDisplay.h index 5ba262e62d..58f5af78f4 100644 --- a/stepmania/src/PercentageDisplay.h +++ b/stepmania/src/PercentageDisplay.h @@ -19,6 +19,8 @@ public: void Update( float fDeltaTime ); void TweenOffScreen(); + static CString FormatPercentScore( float fPercentDancePoints, int iTotalSize, int iDecimalPlaces ); + private: ThemeMetric DANCE_POINT_DIGITS; ThemeMetric PERCENT_DECIMAL_PLACES;