add Backing element, load using ThemeManager for easier discoverability and overriding, add texture coords to body
This commit is contained in:
@@ -113,20 +113,28 @@ REGISTER_ACTOR_CLASS( GraphLine )
|
|||||||
class GraphBody: public Actor
|
class GraphBody: public Actor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
GraphBody()
|
GraphBody( RString sFile )
|
||||||
{
|
{
|
||||||
|
m_pTexture = TEXTUREMAN->LoadTexture( sFile );
|
||||||
|
|
||||||
for( int i = 0; i < 2*VALUE_RESOLUTION; ++i )
|
for( int i = 0; i < 2*VALUE_RESOLUTION; ++i )
|
||||||
{
|
{
|
||||||
m_Slices[i].c = RageColor(1,1,1,1);
|
m_Slices[i].c = RageColor(1,1,1,1);
|
||||||
m_Slices[i].t = RageVector2( 0,0 );
|
m_Slices[i].t = RageVector2( 0,0 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
~GraphBody()
|
||||||
|
{
|
||||||
|
TEXTUREMAN->UnloadTexture( m_pTexture );
|
||||||
|
m_pTexture = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
void DrawPrimitives()
|
void DrawPrimitives()
|
||||||
{
|
{
|
||||||
Actor::SetGlobalRenderStates(); // set Actor-specified render states
|
Actor::SetGlobalRenderStates(); // set Actor-specified render states
|
||||||
|
|
||||||
DISPLAY->ClearAllTextures();
|
DISPLAY->ClearAllTextures();
|
||||||
|
DISPLAY->SetTexture( TextureUnit_1, m_pTexture->GetTexHandle() );
|
||||||
|
|
||||||
// Must call this after setting the texture or else texture
|
// Must call this after setting the texture or else texture
|
||||||
// parameters have no effect.
|
// parameters have no effect.
|
||||||
@@ -136,11 +144,10 @@ public:
|
|||||||
DISPLAY->DrawQuadStrip( m_Slices, ARRAYLEN(m_Slices) );
|
DISPLAY->DrawQuadStrip( m_Slices, ARRAYLEN(m_Slices) );
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual GraphBody *Copy() const;
|
|
||||||
|
|
||||||
|
RageTexture* m_pTexture;
|
||||||
RageSpriteVertex m_Slices[2*VALUE_RESOLUTION];
|
RageSpriteVertex m_Slices[2*VALUE_RESOLUTION];
|
||||||
};
|
};
|
||||||
REGISTER_ACTOR_CLASS( GraphBody )
|
|
||||||
|
|
||||||
GraphDisplay::GraphDisplay()
|
GraphDisplay::GraphDisplay()
|
||||||
{
|
{
|
||||||
@@ -157,48 +164,7 @@ GraphDisplay::~GraphDisplay()
|
|||||||
SAFE_DELETE( m_pGraphBody );
|
SAFE_DELETE( m_pGraphBody );
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraphDisplay::LoadFromNode( const XNode* pNode )
|
void GraphDisplay::Set( const StageStats &ss, const PlayerStageStats &pss )
|
||||||
{
|
|
||||||
ActorFrame::LoadFromNode( pNode );
|
|
||||||
|
|
||||||
const XNode *pChild = pNode->GetChild( "Body" );
|
|
||||||
if( pChild == NULL )
|
|
||||||
RageException::Throw( "%s: GraphDisplay: missing the node \"Body\"", ActorUtil::GetWhere(pNode).c_str() );
|
|
||||||
Actor *p = ActorUtil::LoadFromNode( pChild, this );
|
|
||||||
m_pGraphBody = dynamic_cast<GraphBody *>(p);
|
|
||||||
if( m_pGraphBody == NULL )
|
|
||||||
RageException::Throw( "%s: GraphDisplay: \"Body\" child is not a GraphBody", ActorUtil::GetWhere(pNode).c_str() );
|
|
||||||
this->AddChild( m_pGraphBody );
|
|
||||||
|
|
||||||
pChild = pNode->GetChild( "Texture" );
|
|
||||||
if( pChild == NULL )
|
|
||||||
RageException::Throw( "%s: GraphDisplay: missing the node \"Texture\"", ActorUtil::GetWhere(pNode).c_str() );
|
|
||||||
m_sprTexture.LoadActorFromNode( pChild, this );
|
|
||||||
m_size.x = m_sprTexture->GetUnzoomedWidth();
|
|
||||||
m_size.y = m_sprTexture->GetUnzoomedHeight();
|
|
||||||
this->AddChild( m_sprTexture );
|
|
||||||
|
|
||||||
pChild = pNode->GetChild( "Line" );
|
|
||||||
if( pChild == NULL )
|
|
||||||
RageException::Throw( "%s: GraphDisplay: missing the node \"Line\"", ActorUtil::GetWhere(pNode).c_str() );
|
|
||||||
p = ActorUtil::LoadFromNode( pChild, this );
|
|
||||||
m_pGraphLine = dynamic_cast<GraphLine *>(p);
|
|
||||||
if( m_pGraphLine == NULL )
|
|
||||||
RageException::Throw( "%s: GraphDisplay: \"Body\" child is not a GraphLine", ActorUtil::GetWhere(pNode).c_str() );
|
|
||||||
this->AddChild( m_pGraphLine );
|
|
||||||
|
|
||||||
pChild = pNode->GetChild( "SongBoundary" );
|
|
||||||
if( pChild == NULL )
|
|
||||||
RageException::Throw( "%s: GraphDisplay: missing the node \"SongBoundary\"", ActorUtil::GetWhere(pNode).c_str() );
|
|
||||||
m_sprSongBoundary.LoadActorFromNode( pChild, this );
|
|
||||||
|
|
||||||
pChild = pNode->GetChild( "Barely" );
|
|
||||||
if( pChild == NULL )
|
|
||||||
RageException::Throw( "%s: GraphDisplay: missing the node \"Barely\"", ActorUtil::GetWhere(pNode).c_str() );
|
|
||||||
m_sprJustBarely.LoadActorFromNode( pChild, this );
|
|
||||||
}
|
|
||||||
|
|
||||||
void GraphDisplay::LoadFromStageStats( const StageStats &ss, const PlayerStageStats &pss )
|
|
||||||
{
|
{
|
||||||
float fTotalStepSeconds = ss.GetTotalPossibleStepsSeconds();
|
float fTotalStepSeconds = ss.GetTotalPossibleStepsSeconds();
|
||||||
|
|
||||||
@@ -207,6 +173,8 @@ void GraphDisplay::LoadFromStageStats( const StageStats &ss, const PlayerStageSt
|
|||||||
for( unsigned i=0; i<ARRAYLEN(m_Values); i++ )
|
for( unsigned i=0; i<ARRAYLEN(m_Values); i++ )
|
||||||
CLAMP( m_Values[i], 0.f, 1.f );
|
CLAMP( m_Values[i], 0.f, 1.f );
|
||||||
|
|
||||||
|
UpdateVerts();
|
||||||
|
|
||||||
//
|
//
|
||||||
// Show song boundaries
|
// Show song boundaries
|
||||||
//
|
//
|
||||||
@@ -224,8 +192,6 @@ void GraphDisplay::LoadFromStageStats( const StageStats &ss, const PlayerStageSt
|
|||||||
this->AddChild( p );
|
this->AddChild( p );
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateVerts();
|
|
||||||
|
|
||||||
if( !pss.m_bFailed )
|
if( !pss.m_bFailed )
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
@@ -247,16 +213,37 @@ void GraphDisplay::LoadFromStageStats( const StageStats &ss, const PlayerStageSt
|
|||||||
if( fMinLifeSoFar > 0.0f && fMinLifeSoFar < 0.1f )
|
if( fMinLifeSoFar > 0.0f && fMinLifeSoFar < 0.1f )
|
||||||
{
|
{
|
||||||
float fX = SCALE( float(iMinLifeSoFarAt), 0.0f, float(VALUE_RESOLUTION-1), m_quadVertices.left, m_quadVertices.right );
|
float fX = SCALE( float(iMinLifeSoFarAt), 0.0f, float(VALUE_RESOLUTION-1), m_quadVertices.left, m_quadVertices.right );
|
||||||
m_sprJustBarely->SetX( fX );
|
m_sprBarely->SetX( fX );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_sprJustBarely->SetVisible( false );
|
m_sprBarely->SetVisible( false );
|
||||||
}
|
}
|
||||||
this->AddChild( m_sprJustBarely );
|
this->AddChild( m_sprBarely );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GraphDisplay::Load( RString sMetricsGroup )
|
||||||
|
{
|
||||||
|
m_size.x = THEME->GetMetricI( sMetricsGroup, "BodyWidth" );
|
||||||
|
m_size.y = THEME->GetMetricI( sMetricsGroup, "BodyHeight" );
|
||||||
|
|
||||||
|
m_sprBacking.Load( THEME->GetPathG(sMetricsGroup,"Backing") );
|
||||||
|
m_sprBacking->ZoomToWidth( m_size.x );
|
||||||
|
m_sprBacking->ZoomToHeight( m_size.y );
|
||||||
|
this->AddChild( m_sprBacking );
|
||||||
|
|
||||||
|
m_pGraphBody = new GraphBody( THEME->GetPathG(sMetricsGroup,"Body") );
|
||||||
|
this->AddChild( m_pGraphBody );
|
||||||
|
|
||||||
|
m_pGraphLine = new GraphLine;
|
||||||
|
this->AddChild( m_pGraphLine );
|
||||||
|
|
||||||
|
m_sprSongBoundary.Load( THEME->GetPathG(sMetricsGroup,"SongBoundary") );
|
||||||
|
|
||||||
|
m_sprBarely.Load( THEME->GetPathG(sMetricsGroup,"Barely") );
|
||||||
|
}
|
||||||
|
|
||||||
void GraphDisplay::UpdateVerts()
|
void GraphDisplay::UpdateVerts()
|
||||||
{
|
{
|
||||||
m_quadVertices.left = -m_size.x/2;
|
m_quadVertices.left = -m_size.x/2;
|
||||||
@@ -270,8 +257,15 @@ void GraphDisplay::UpdateVerts()
|
|||||||
const float fX = SCALE( float(i), 0.0f, float(VALUE_RESOLUTION-1), m_quadVertices.left, m_quadVertices.right );
|
const float fX = SCALE( float(i), 0.0f, float(VALUE_RESOLUTION-1), m_quadVertices.left, m_quadVertices.right );
|
||||||
const float fY = SCALE( m_Values[i], 0.0f, 1.0f, m_quadVertices.bottom, m_quadVertices.top );
|
const float fY = SCALE( m_Values[i], 0.0f, 1.0f, m_quadVertices.bottom, m_quadVertices.top );
|
||||||
|
|
||||||
m_pGraphBody->m_Slices[i*2+0].p = RageVector3( fX, m_quadVertices.top, 0 );
|
m_pGraphBody->m_Slices[i*2+0].p = RageVector3( fX, fY, 0 );
|
||||||
m_pGraphBody->m_Slices[i*2+1].p = RageVector3( fX, fY, 0 );
|
m_pGraphBody->m_Slices[i*2+1].p = RageVector3( fX, m_quadVertices.bottom, 0 );
|
||||||
|
|
||||||
|
const RectF *pRect = m_pGraphBody->m_pTexture->GetTextureCoordRect( 0 );
|
||||||
|
|
||||||
|
const float fU = SCALE( fX, m_quadVertices.left, m_quadVertices.right, pRect->left, pRect->right );
|
||||||
|
const float fV = SCALE( fY, m_quadVertices.top, m_quadVertices.bottom, pRect->top, pRect->bottom );
|
||||||
|
m_pGraphBody->m_Slices[i*2+0].t = RageVector2( fU, fV );
|
||||||
|
m_pGraphBody->m_Slices[i*2+1].t = RageVector2( fU, pRect->bottom );
|
||||||
|
|
||||||
LineStrip[i].p = RageVector3( fX, fY, 0 );
|
LineStrip[i].p = RageVector3( fX, fY, 0 );
|
||||||
LineStrip[i].c = RageColor( 1,1,1,1 );
|
LineStrip[i].c = RageColor( 1,1,1,1 );
|
||||||
@@ -287,17 +281,23 @@ void GraphDisplay::UpdateVerts()
|
|||||||
class LunaGraphDisplay: public Luna<GraphDisplay>
|
class LunaGraphDisplay: public Luna<GraphDisplay>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static int LoadFromStats( T* p, lua_State *L )
|
static int Load( T* p, lua_State *L )
|
||||||
|
{
|
||||||
|
p->Load( SArg(1) );
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
static int Set( T* p, lua_State *L )
|
||||||
{
|
{
|
||||||
StageStats *pStageStats = Luna<StageStats>::check( L, 1 );
|
StageStats *pStageStats = Luna<StageStats>::check( L, 1 );
|
||||||
PlayerStageStats *pPlayerStageStats = Luna<PlayerStageStats>::check( L, 2 );
|
PlayerStageStats *pPlayerStageStats = Luna<PlayerStageStats>::check( L, 2 );
|
||||||
p->LoadFromStageStats( *pStageStats, *pPlayerStageStats );
|
p->Set( *pStageStats, *pPlayerStageStats );
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
LunaGraphDisplay()
|
LunaGraphDisplay()
|
||||||
{
|
{
|
||||||
ADD_METHOD( LoadFromStats );
|
ADD_METHOD( Load );
|
||||||
|
ADD_METHOD( Set );
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -14,9 +14,9 @@ public:
|
|||||||
GraphDisplay();
|
GraphDisplay();
|
||||||
~GraphDisplay();
|
~GraphDisplay();
|
||||||
virtual GraphDisplay *Copy() const;
|
virtual GraphDisplay *Copy() const;
|
||||||
virtual void LoadFromNode( const XNode* pNode );
|
|
||||||
|
|
||||||
void LoadFromStageStats( const StageStats &ss, const PlayerStageStats &s );
|
void Load( RString sMetricsGroup );
|
||||||
|
void Set( const StageStats &ss, const PlayerStageStats &s );
|
||||||
|
|
||||||
//
|
//
|
||||||
// Lua
|
// Lua
|
||||||
@@ -31,8 +31,8 @@ private:
|
|||||||
RectF m_quadVertices;
|
RectF m_quadVertices;
|
||||||
|
|
||||||
vector<Actor*> m_vpSongBoundaries;
|
vector<Actor*> m_vpSongBoundaries;
|
||||||
AutoActor m_sprJustBarely;
|
AutoActor m_sprBarely;
|
||||||
AutoActor m_sprTexture;
|
AutoActor m_sprBacking;
|
||||||
AutoActor m_sprSongBoundary;
|
AutoActor m_sprSongBoundary;
|
||||||
|
|
||||||
GraphLine *m_pGraphLine;
|
GraphLine *m_pGraphLine;
|
||||||
|
|||||||
Reference in New Issue
Block a user