2003-05-13 13:35:32 +00:00
|
|
|
#include "global.h"
|
|
|
|
|
#include "MeterDisplay.h"
|
2004-06-08 00:47:53 +00:00
|
|
|
#include "RageUtil.h"
|
2005-02-26 08:46:52 +00:00
|
|
|
#include "GameState.h"
|
|
|
|
|
#include "song.h"
|
2005-02-26 10:08:12 +00:00
|
|
|
#include "ActorUtil.h"
|
|
|
|
|
#include "XmlFile.h"
|
|
|
|
|
#include "RageLog.h"
|
2005-11-29 05:56:20 +00:00
|
|
|
#include "LuaManager.h"
|
2003-05-13 13:35:32 +00:00
|
|
|
|
2005-02-26 10:08:12 +00:00
|
|
|
REGISTER_ACTOR_CLASS(MeterDisplay)
|
|
|
|
|
REGISTER_ACTOR_CLASS(SongMeterDisplay)
|
2003-05-13 13:35:32 +00:00
|
|
|
|
2003-06-30 18:08:27 +00:00
|
|
|
MeterDisplay::MeterDisplay()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2006-01-22 01:00:06 +00:00
|
|
|
void MeterDisplay::Load( RString sStreamPath, float fStreamWidth, RString sTipPath )
|
2003-05-13 13:35:32 +00:00
|
|
|
{
|
|
|
|
|
m_fStreamWidth = fStreamWidth;
|
|
|
|
|
|
2004-01-12 01:43:38 +00:00
|
|
|
m_sprStream.Load( sStreamPath );
|
2005-03-27 07:04:04 +00:00
|
|
|
m_sprStream->SetZoomX( fStreamWidth / m_sprStream->GetUnzoomedWidth() );
|
|
|
|
|
this->AddChild( m_sprStream );
|
2004-01-20 03:32:48 +00:00
|
|
|
|
2005-02-26 10:08:12 +00:00
|
|
|
m_sprTip.Load( sTipPath );
|
2005-02-26 12:54:35 +00:00
|
|
|
this->AddChild( m_sprTip );
|
2005-02-26 10:08:12 +00:00
|
|
|
|
2003-05-13 13:35:32 +00:00
|
|
|
SetPercent( 0.5f );
|
|
|
|
|
}
|
|
|
|
|
|
2006-01-22 01:00:06 +00:00
|
|
|
void MeterDisplay::LoadFromNode( const RString& sDir, const XNode* pNode )
|
2005-02-26 10:08:12 +00:00
|
|
|
{
|
|
|
|
|
LOG->Trace( "MeterDisplay::LoadFromNode(%s,node)", sDir.c_str() );
|
|
|
|
|
|
2006-01-22 01:00:06 +00:00
|
|
|
RString sExpr;
|
2005-11-29 05:56:20 +00:00
|
|
|
if( !pNode->GetAttrValue( "StreamWidth", sExpr ) )
|
2006-09-17 01:19:19 +00:00
|
|
|
RageException::Throw( "MeterDisplay in \"%s\" is missing the \"StreamWidth\" attribute.", sDir.c_str() );
|
2005-11-29 05:56:20 +00:00
|
|
|
m_fStreamWidth = LuaHelpers::RunExpressionF( sExpr );
|
2005-02-26 10:08:12 +00:00
|
|
|
|
|
|
|
|
{
|
2006-01-22 01:00:06 +00:00
|
|
|
RString sStreamPath;
|
2005-02-26 10:08:12 +00:00
|
|
|
if( !pNode->GetAttrValue( "StreamPath", sStreamPath ) )
|
2006-09-17 01:19:19 +00:00
|
|
|
RageException::Throw( "MeterDisplay in \"%s\" is missing the \"StreamPath\" attribute.", sDir.c_str() );
|
2005-02-26 10:08:12 +00:00
|
|
|
|
2006-06-14 02:44:02 +00:00
|
|
|
LuaHelpers::RunAtExpressionS( sStreamPath );
|
|
|
|
|
if( !sStreamPath.empty() && sStreamPath[0] != '/' )
|
|
|
|
|
{
|
|
|
|
|
sStreamPath = sDir + sStreamPath;
|
|
|
|
|
ActorUtil::ResolvePath( sStreamPath, sDir );
|
|
|
|
|
}
|
2005-02-26 10:08:12 +00:00
|
|
|
|
|
|
|
|
m_sprStream.Load( sStreamPath );
|
2005-03-27 07:04:04 +00:00
|
|
|
m_sprStream->SetZoomX( m_fStreamWidth / m_sprStream->GetUnzoomedWidth() );
|
|
|
|
|
this->AddChild( m_sprStream );
|
2005-02-26 10:08:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const XNode* pChild = pNode->GetChild( "Tip" );
|
|
|
|
|
if( pChild != NULL )
|
|
|
|
|
{
|
|
|
|
|
m_sprTip.LoadFromNode( sDir, pChild );
|
|
|
|
|
this->AddChild( m_sprTip );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SetPercent( 0.5f );
|
|
|
|
|
|
|
|
|
|
ActorFrame::LoadFromNode( sDir, pNode );
|
|
|
|
|
}
|
|
|
|
|
|
2003-05-13 13:35:32 +00:00
|
|
|
void MeterDisplay::SetPercent( float fPercent )
|
|
|
|
|
{
|
|
|
|
|
ASSERT( fPercent >= 0 && fPercent <= 1 );
|
|
|
|
|
|
2005-03-27 07:04:04 +00:00
|
|
|
m_sprStream->SetCropRight( 1-fPercent );
|
2004-01-18 20:43:36 +00:00
|
|
|
|
2004-01-20 03:32:48 +00:00
|
|
|
m_sprTip->SetX( SCALE(fPercent, 0.f, 1.f, -m_fStreamWidth/2, m_fStreamWidth/2) );
|
2003-05-13 13:35:32 +00:00
|
|
|
}
|
2004-06-01 00:53:06 +00:00
|
|
|
|
2005-02-26 08:46:52 +00:00
|
|
|
void SongMeterDisplay::Update( float fDeltaTime )
|
|
|
|
|
{
|
2006-03-09 06:39:24 +00:00
|
|
|
if( GAMESTATE->m_pCurSong )
|
|
|
|
|
{
|
|
|
|
|
float fSongStartSeconds = GAMESTATE->m_pCurSong->m_Timing.GetElapsedTimeFromBeat( GAMESTATE->m_pCurSong->m_fFirstBeat );
|
|
|
|
|
float fSongEndSeconds = GAMESTATE->m_pCurSong->m_Timing.GetElapsedTimeFromBeat( GAMESTATE->m_pCurSong->m_fLastBeat );
|
|
|
|
|
float fPercentPositionSong = SCALE( GAMESTATE->m_fMusicSeconds, fSongStartSeconds, fSongEndSeconds, 0.0f, 1.0f );
|
|
|
|
|
CLAMP( fPercentPositionSong, 0, 1 );
|
|
|
|
|
|
|
|
|
|
SetPercent( fPercentPositionSong );
|
|
|
|
|
}
|
2005-02-26 08:46:52 +00:00
|
|
|
|
|
|
|
|
MeterDisplay::Update( fDeltaTime );
|
|
|
|
|
}
|
|
|
|
|
|
2004-06-01 00:53:06 +00:00
|
|
|
/*
|
|
|
|
|
* (c) 2003-2004 Chris Danford
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
|
* copy of this software and associated documentation files (the
|
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
|
* distribute, and/or sell copies of the Software, and to permit persons to
|
|
|
|
|
* whom the Software is furnished to do so, provided that the above
|
|
|
|
|
* copyright notice(s) and this permission notice appear in all copies of
|
|
|
|
|
* the Software and that both the above copyright notice(s) and this
|
|
|
|
|
* permission notice appear in supporting documentation.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
|
|
|
|
|
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
|
|
|
|
|
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
|
|
|
|
|
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
|
|
|
|
|
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
|
|
|
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
|
|
|
* PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
|
*/
|