format the percentDP score in PaneDisplay using the same code in PercentageDisplay

This commit is contained in:
Chris Danford
2005-04-05 09:29:05 +00:00
parent 9643e9986a
commit 62a2834202
3 changed files with 20 additions and 12 deletions
+2 -1
View File
@@ -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:
+16 -11
View File
@@ -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.
+2
View File
@@ -19,6 +19,8 @@ public:
void Update( float fDeltaTime );
void TweenOffScreen();
static CString FormatPercentScore( float fPercentDancePoints, int iTotalSize, int iDecimalPlaces );
private:
ThemeMetric<int> DANCE_POINT_DIGITS;
ThemeMetric<int> PERCENT_DECIMAL_PLACES;