Support eval-style percents
This commit is contained in:
@@ -10,32 +10,58 @@
|
|||||||
#define DANCE_POINT_DIGITS THEME->GetMetricI(m_sName,"DancePointsDigits")
|
#define DANCE_POINT_DIGITS THEME->GetMetricI(m_sName,"DancePointsDigits")
|
||||||
#define PERCENT_DECIMAL_PLACES THEME->GetMetricI(m_sName,"PercentDecimalPlaces")
|
#define PERCENT_DECIMAL_PLACES THEME->GetMetricI(m_sName,"PercentDecimalPlaces")
|
||||||
#define PERCENT_TOTAL_SIZE THEME->GetMetricI(m_sName,"PercentTotalSize")
|
#define PERCENT_TOTAL_SIZE THEME->GetMetricI(m_sName,"PercentTotalSize")
|
||||||
|
#define PERCENT_USE_REMAINDER THEME->GetMetricB(m_sName,"PercentUseRemainder")
|
||||||
|
|
||||||
PercentageDisplay::PercentageDisplay()
|
PercentageDisplay::PercentageDisplay()
|
||||||
{
|
{
|
||||||
this->AddChild( &m_textPercent );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PercentageDisplay::Load( PlayerNumber pn )
|
void PercentageDisplay::Load( PlayerNumber pn )
|
||||||
{
|
{
|
||||||
m_PlayerNumber = pn;
|
m_PlayerNumber = pn;
|
||||||
m_Last = 0;
|
m_Last = -1;
|
||||||
|
|
||||||
m_textPercent.SetName( ssprintf("PercentP%i", pn+1) );
|
|
||||||
m_textPercent.LoadFromNumbers( THEME->GetPathToN(m_sName + " text") );
|
|
||||||
SET_XY_AND_ON_COMMAND( m_textPercent );
|
|
||||||
|
|
||||||
if( PREFSMAN->m_bDancePointsForOni )
|
if( PREFSMAN->m_bDancePointsForOni )
|
||||||
m_textPercent.SetText( " " );
|
m_textPercent.SetName( ssprintf("DancePointsP%i", pn+1) );
|
||||||
else
|
else
|
||||||
m_textPercent.SetText( ssprintf( "%0*.*f%%", PERCENT_TOTAL_SIZE, PERCENT_DECIMAL_PLACES, 0 ) );
|
m_textPercent.SetName( ssprintf("PercentP%i", pn+1) );
|
||||||
|
|
||||||
|
m_textPercent.LoadFromNumbers( THEME->GetPathToN(m_sName + " text") );
|
||||||
|
SET_XY_AND_ON_COMMAND( m_textPercent );
|
||||||
|
this->AddChild( &m_textPercent );
|
||||||
|
|
||||||
|
if( !PREFSMAN->m_bDancePointsForOni && PERCENT_USE_REMAINDER )
|
||||||
|
{
|
||||||
|
m_textPercentRemainder.SetName( ssprintf("PercentRemainderP%d",pn+1) );
|
||||||
|
m_textPercentRemainder.LoadFromNumbers( THEME->GetPathToN(m_sName + " remainder") );
|
||||||
|
SET_XY_AND_ON_COMMAND( m_textPercentRemainder );
|
||||||
|
m_textPercentRemainder.SetText( "456" );
|
||||||
|
this->AddChild( &m_textPercentRemainder );
|
||||||
|
}
|
||||||
|
|
||||||
|
Refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
void PercentageDisplay::TweenOffScreen()
|
||||||
|
{
|
||||||
|
OFF_COMMAND( m_textPercent );
|
||||||
|
if( PREFSMAN->m_bDancePointsForOni && PERCENT_USE_REMAINDER )
|
||||||
|
OFF_COMMAND( m_textPercentRemainder );
|
||||||
}
|
}
|
||||||
|
|
||||||
void PercentageDisplay::Update( float fDeltaTime )
|
void PercentageDisplay::Update( float fDeltaTime )
|
||||||
|
{
|
||||||
|
ActorFrame::Update( fDeltaTime );
|
||||||
|
|
||||||
|
Refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
void PercentageDisplay::Refresh()
|
||||||
{
|
{
|
||||||
const int iActualDancePoints = GAMESTATE->m_CurStageStats.iActualDancePoints[m_PlayerNumber];
|
const int iActualDancePoints = GAMESTATE->m_CurStageStats.iActualDancePoints[m_PlayerNumber];
|
||||||
if( iActualDancePoints == m_Last )
|
if( iActualDancePoints == m_Last )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_Last = iActualDancePoints;
|
m_Last = iActualDancePoints;
|
||||||
|
|
||||||
CString sNumToDisplay;
|
CString sNumToDisplay;
|
||||||
@@ -44,12 +70,21 @@ void PercentageDisplay::Update( float fDeltaTime )
|
|||||||
int iPossibleDancePoints = GAMESTATE->m_CurStageStats.iPossibleDancePoints[m_PlayerNumber];
|
int iPossibleDancePoints = GAMESTATE->m_CurStageStats.iPossibleDancePoints[m_PlayerNumber];
|
||||||
iPossibleDancePoints = max( 1, iPossibleDancePoints );
|
iPossibleDancePoints = max( 1, iPossibleDancePoints );
|
||||||
float fPercentDancePoints = iActualDancePoints / (float)iPossibleDancePoints + 0.00001f; // correct for rounding errors
|
float fPercentDancePoints = iActualDancePoints / (float)iPossibleDancePoints + 0.00001f; // correct for rounding errors
|
||||||
|
fPercentDancePoints = max( fPercentDancePoints, 0 );
|
||||||
|
|
||||||
float fNumToDisplay = max( 0, fPercentDancePoints*100 );
|
if( PERCENT_USE_REMAINDER )
|
||||||
sNumToDisplay = ssprintf( "%0*.*f%%", PERCENT_TOTAL_SIZE, PERCENT_DECIMAL_PLACES, fNumToDisplay );
|
{
|
||||||
|
int iPercentWhole = int(fPercentDancePoints*100);
|
||||||
|
int iPercentRemainder = int( (fPercentDancePoints*100 - int(fPercentDancePoints*100)) * 10 );
|
||||||
|
sNumToDisplay = ssprintf( "%02d", iPercentWhole );
|
||||||
|
m_textPercentRemainder.SetText( ssprintf(".%01d%%", iPercentRemainder) );
|
||||||
|
} else {
|
||||||
|
float fNumToDisplay = max( 0, fPercentDancePoints*100 );
|
||||||
|
sNumToDisplay = ssprintf( "%0*.*f%%", PERCENT_TOTAL_SIZE, PERCENT_DECIMAL_PLACES, fNumToDisplay );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
sNumToDisplay = ssprintf( "%*d", DANCE_POINT_DIGITS, iActualDancePoints );
|
sNumToDisplay = ssprintf( "%*d", DANCE_POINT_DIGITS, max( 0, iActualDancePoints ) );
|
||||||
|
|
||||||
m_textPercent.SetText( sNumToDisplay );
|
m_textPercent.SetText( sNumToDisplay );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,11 +11,14 @@ public:
|
|||||||
PercentageDisplay();
|
PercentageDisplay();
|
||||||
void Load( PlayerNumber pn );
|
void Load( PlayerNumber pn );
|
||||||
void Update( float fDeltaTime );
|
void Update( float fDeltaTime );
|
||||||
|
void TweenOffScreen();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void Refresh();
|
||||||
PlayerNumber m_PlayerNumber;
|
PlayerNumber m_PlayerNumber;
|
||||||
int m_Last;
|
int m_Last;
|
||||||
BitmapText m_textPercent;
|
BitmapText m_textPercent;
|
||||||
|
BitmapText m_textPercentRemainder;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user