New options / metrics for StreamDisplay to help make three-part lifebars easier to implement.
This commit is contained in:
@@ -4388,6 +4388,8 @@ end
|
||||
TextureCoordScaleX=10
|
||||
NumPills=20
|
||||
UseThreePartMethod=false
|
||||
ThreePartWidth=128
|
||||
AlwaysBounceNormalBar=false
|
||||
|
||||
[StreamDisplayExtra]
|
||||
Fallback="StreamDisplay"
|
||||
|
||||
@@ -20,6 +20,8 @@ StreamDisplay::StreamDisplay()
|
||||
m_fVelocity = 0;
|
||||
m_fPassingAlpha = 0;
|
||||
m_fHotAlpha = 0;
|
||||
m_fThreePartWidth = 0;
|
||||
m_bAlwaysBounce = false;
|
||||
}
|
||||
|
||||
void StreamDisplay::Load( const RString &_sMetricsGroup )
|
||||
@@ -32,6 +34,11 @@ void StreamDisplay::Load( const RString &_sMetricsGroup )
|
||||
float fTextureCoordScaleX = THEME->GetMetricF(sMetricsGroup,"TextureCoordScaleX");
|
||||
int iNumPills = THEME->GetMetricF(sMetricsGroup,"NumPills");
|
||||
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 )
|
||||
{
|
||||
@@ -40,16 +47,30 @@ void StreamDisplay::Load( const RString &_sMetricsGroup )
|
||||
for( int i=0; i<iNumPills; i++ )
|
||||
{
|
||||
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_transformPill.TransformItemDirect( *pSpr, -1, i, iNumPills );
|
||||
|
||||
float f = 1 / fTextureCoordScaleX;
|
||||
pSpr->SetCustomTextureRect( RectF(f*i,0,f*(i+1),1) );
|
||||
if(!m_bUsingThreePart)
|
||||
{
|
||||
m_transformPill.TransformItemDirect( *pSpr, -1, i, iNumPills );
|
||||
float f = 1 / fTextureCoordScaleX;
|
||||
pSpr->SetCustomTextureRect( RectF(f*i,0,f*(i+1),1) );
|
||||
}
|
||||
|
||||
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 );
|
||||
|
||||
|
||||
|
||||
// HACK: Tweaking these values is very difficulty. Update the
|
||||
// "physics" many times so that the spring motion appears faster
|
||||
for( int i=0; i<10; i++ )
|
||||
@@ -78,6 +101,7 @@ void StreamDisplay::Update( float fDeltaSecs )
|
||||
m_fVelocity += fSpringForce * fDeltaSecs;
|
||||
|
||||
const float fViscousForce = -m_fVelocity * 0.2f;
|
||||
if(!m_bAlwaysBounce)
|
||||
m_fVelocity += fViscousForce * fDeltaSecs;
|
||||
}
|
||||
|
||||
@@ -100,22 +124,30 @@ void StreamDisplay::Update( float fDeltaSecs )
|
||||
Sprite *pSpr = m_vpSprPill[st][i];
|
||||
float fPercentFilledThisPill = SCALE( m_fTrailingPercent, fPillWidthPercent*i, fPillWidthPercent*(i+1), 0.0f, 1.0f );
|
||||
CLAMP( fPercentFilledThisPill, 0.0f, 1.0f );
|
||||
pSpr->SetCropRight( 1.0f - fPercentFilledThisPill );
|
||||
|
||||
// XXX scale by current song speed
|
||||
|
||||
if(!m_bUsingThreePart) // usual lifebar
|
||||
{
|
||||
pSpr->SetCropRight( 1.0f - fPercentFilledThisPill );
|
||||
pSpr->SetTexCoordVelocity(-1,0);
|
||||
}
|
||||
else // using the three-part method
|
||||
{
|
||||
|
||||
if(i==1) // middle pill
|
||||
{
|
||||
float fMiddleWidth = m_fThreePartWidth * m_fTrailingPercent;
|
||||
pSpr->ZoomToWidth(fMiddleWidth);
|
||||
|
||||
if(i==0)
|
||||
pSpr->SetCustomTextureRect( RectF(0,0,0.33f,1) );
|
||||
else if(fPercentFilledThisPill >= 100)
|
||||
pSpr->SetCustomTextureRect( RectF(0.33f,0,0.66f,1) );
|
||||
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
|
||||
switch( st )
|
||||
|
||||
@@ -43,6 +43,9 @@ private:
|
||||
float m_fHotAlpha;
|
||||
|
||||
bool m_bUsingThreePart;
|
||||
|
||||
float m_fThreePartWidth;
|
||||
bool m_bAlwaysBounce;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user