New options / metrics for StreamDisplay to help make three-part lifebars easier to implement.

This commit is contained in:
Andrew Livy
2009-05-18 17:43:08 +00:00
parent 2b88264093
commit 89e81956d0
3 changed files with 49 additions and 12 deletions
+2
View File
@@ -4388,6 +4388,8 @@ end
TextureCoordScaleX=10 TextureCoordScaleX=10
NumPills=20 NumPills=20
UseThreePartMethod=false UseThreePartMethod=false
ThreePartWidth=128
AlwaysBounceNormalBar=false
[StreamDisplayExtra] [StreamDisplayExtra]
Fallback="StreamDisplay" Fallback="StreamDisplay"
+44 -12
View File
@@ -20,6 +20,8 @@ StreamDisplay::StreamDisplay()
m_fVelocity = 0; m_fVelocity = 0;
m_fPassingAlpha = 0; m_fPassingAlpha = 0;
m_fHotAlpha = 0; m_fHotAlpha = 0;
m_fThreePartWidth = 0;
m_bAlwaysBounce = false;
} }
void StreamDisplay::Load( const RString &_sMetricsGroup ) void StreamDisplay::Load( const RString &_sMetricsGroup )
@@ -32,6 +34,11 @@ void StreamDisplay::Load( const RString &_sMetricsGroup )
float fTextureCoordScaleX = THEME->GetMetricF(sMetricsGroup,"TextureCoordScaleX"); float fTextureCoordScaleX = THEME->GetMetricF(sMetricsGroup,"TextureCoordScaleX");
int iNumPills = THEME->GetMetricF(sMetricsGroup,"NumPills"); int iNumPills = THEME->GetMetricF(sMetricsGroup,"NumPills");
m_bUsingThreePart = THEME->GetMetricB(sMetricsGroup,"UseThreePartMethod"); m_bUsingThreePart = THEME->GetMetricB(sMetricsGroup,"UseThreePartMethod");
m_bAlwaysBounce = THEME->GetMetricB(sMetricsGroup,"AlwaysBounceNormalBar");
// three part method only uses 3 pills
if(iNumPills != 3)
m_bUsingThreePart = false;
FOREACH_ENUM( StreamType, st ) FOREACH_ENUM( StreamType, st )
{ {
@@ -40,16 +47,30 @@ void StreamDisplay::Load( const RString &_sMetricsGroup )
for( int i=0; i<iNumPills; i++ ) for( int i=0; i<iNumPills; i++ )
{ {
Sprite *pSpr = new Sprite; Sprite *pSpr = new Sprite;
pSpr->Load( THEME->GetPathG(sMetricsGroup,StreamTypeToString(st)) );
if(m_bUsingThreePart)
pSpr->Load( THEME->GetPathG(sMetricsGroup,ssprintf("%s part%d",StreamTypeToString(st).c_str(),i) ) );
else
pSpr->Load( THEME->GetPathG(sMetricsGroup,StreamTypeToString(st)) );
m_vpSprPill[st].push_back( pSpr ); m_vpSprPill[st].push_back( pSpr );
m_transformPill.TransformItemDirect( *pSpr, -1, i, iNumPills ); if(!m_bUsingThreePart)
{
float f = 1 / fTextureCoordScaleX; m_transformPill.TransformItemDirect( *pSpr, -1, i, iNumPills );
pSpr->SetCustomTextureRect( RectF(f*i,0,f*(i+1),1) ); float f = 1 / fTextureCoordScaleX;
pSpr->SetCustomTextureRect( RectF(f*i,0,f*(i+1),1) );
}
this->AddChild( pSpr ); this->AddChild( pSpr );
} }
if(m_bUsingThreePart)
{
m_fThreePartWidth = THEME->GetMetricF(sMetricsGroup,"ThreePartWidth");
float fCroppedWidthRight = (1-m_vpSprPill[st][0]->GetCropRight())*m_vpSprPill[st][0]->GetZoomedWidth();
// first element positioned depending on metric width specified
m_vpSprPill[st][0]->AddX(-(m_fThreePartWidth/2 + m_vpSprPill[st][0]->GetZoomedWidth()/2) + fCroppedWidthRight);
}
} }
} }
@@ -57,6 +78,8 @@ void StreamDisplay::Update( float fDeltaSecs )
{ {
ActorFrame::Update( fDeltaSecs ); ActorFrame::Update( fDeltaSecs );
// HACK: Tweaking these values is very difficulty. Update the // HACK: Tweaking these values is very difficulty. Update the
// "physics" many times so that the spring motion appears faster // "physics" many times so that the spring motion appears faster
for( int i=0; i<10; i++ ) for( int i=0; i<10; i++ )
@@ -78,6 +101,7 @@ void StreamDisplay::Update( float fDeltaSecs )
m_fVelocity += fSpringForce * fDeltaSecs; m_fVelocity += fSpringForce * fDeltaSecs;
const float fViscousForce = -m_fVelocity * 0.2f; const float fViscousForce = -m_fVelocity * 0.2f;
if(!m_bAlwaysBounce)
m_fVelocity += fViscousForce * fDeltaSecs; m_fVelocity += fViscousForce * fDeltaSecs;
} }
@@ -100,22 +124,30 @@ void StreamDisplay::Update( float fDeltaSecs )
Sprite *pSpr = m_vpSprPill[st][i]; Sprite *pSpr = m_vpSprPill[st][i];
float fPercentFilledThisPill = SCALE( m_fTrailingPercent, fPillWidthPercent*i, fPillWidthPercent*(i+1), 0.0f, 1.0f ); float fPercentFilledThisPill = SCALE( m_fTrailingPercent, fPillWidthPercent*i, fPillWidthPercent*(i+1), 0.0f, 1.0f );
CLAMP( fPercentFilledThisPill, 0.0f, 1.0f ); CLAMP( fPercentFilledThisPill, 0.0f, 1.0f );
pSpr->SetCropRight( 1.0f - fPercentFilledThisPill );
// XXX scale by current song speed // XXX scale by current song speed
if(!m_bUsingThreePart) // usual lifebar if(!m_bUsingThreePart) // usual lifebar
{ {
pSpr->SetCropRight( 1.0f - fPercentFilledThisPill );
pSpr->SetTexCoordVelocity(-1,0); pSpr->SetTexCoordVelocity(-1,0);
} }
else // using the three-part method else // using the three-part method
{ {
if(i==0) if(i==1) // middle pill
pSpr->SetCustomTextureRect( RectF(0,0,0.33f,1) ); {
else if(fPercentFilledThisPill >= 100) float fMiddleWidth = m_fThreePartWidth * m_fTrailingPercent;
pSpr->SetCustomTextureRect( RectF(0.33f,0,0.66f,1) ); pSpr->ZoomToWidth(fMiddleWidth);
else
pSpr->SetCustomTextureRect( RectF(0.66f,0,1,1) ); float fMiddleX = m_vpSprPill[st][0]->GetX() + (fMiddleWidth/2) + (m_vpSprPill[st][0]->GetZoomedWidth()/2);
pSpr->SetX(fMiddleX);
}
else if(i!=0) // last pill
{
float fEndX = m_vpSprPill[st][1]->GetX() + (m_vpSprPill[st][1]->GetZoomedWidth()/2) + (pSpr->GetZoomedWidth()/2);
pSpr->SetX(fEndX);
}
} }
// Optimization: Don't draw pills that are covered up // Optimization: Don't draw pills that are covered up
switch( st ) switch( st )
+3
View File
@@ -43,6 +43,9 @@ private:
float m_fHotAlpha; float m_fHotAlpha;
bool m_bUsingThreePart; bool m_bUsingThreePart;
float m_fThreePartWidth;
bool m_bAlwaysBounce;
}; };
#endif #endif