2003-10-23 06:15:10 +00:00
|
|
|
#include "global.h"
|
|
|
|
|
#include "ComboGraph.h"
|
|
|
|
|
#include "RageLog.h"
|
2003-12-22 23:27:54 +00:00
|
|
|
#include "StageStats.h"
|
2003-12-28 06:00:27 +00:00
|
|
|
#include "ActorUtil.h"
|
2004-06-07 21:14:03 +00:00
|
|
|
#include "BitmapText.h"
|
2005-08-29 01:23:25 +00:00
|
|
|
#include "XmlFile.h"
|
2003-10-23 06:15:10 +00:00
|
|
|
|
|
|
|
|
const int MinComboSizeToShow = 5;
|
|
|
|
|
|
2005-08-29 01:23:25 +00:00
|
|
|
REGISTER_ACTOR_CLASS( ComboGraph )
|
|
|
|
|
|
|
|
|
|
ComboGraph::ComboGraph()
|
|
|
|
|
{
|
2005-10-10 22:27:09 +00:00
|
|
|
DeleteChildrenWhenDone( true );
|
|
|
|
|
|
2005-08-29 01:23:25 +00:00
|
|
|
m_pNormalCombo = NULL;
|
|
|
|
|
m_pMaxCombo = NULL;
|
2005-10-10 22:27:09 +00:00
|
|
|
m_pMaxComboText = NULL;
|
2005-08-29 01:23:25 +00:00
|
|
|
}
|
|
|
|
|
|
2006-01-22 01:00:06 +00:00
|
|
|
void ComboGraph::LoadFromNode( const RString& sDir, const XNode* pNode )
|
2005-08-29 01:23:25 +00:00
|
|
|
{
|
|
|
|
|
ActorFrame::LoadFromNode( sDir, pNode );
|
|
|
|
|
|
2005-10-10 22:27:09 +00:00
|
|
|
m_pMaxComboText = (BitmapText *) this->GetChild( "MaxComboText" );
|
|
|
|
|
if( m_pMaxComboText == NULL )
|
2006-09-17 01:19:19 +00:00
|
|
|
RageException::Throw( "ComboGraph in \"%s\" must have a child named \"MaxComboText\".", sDir.c_str() );
|
2005-10-10 22:27:09 +00:00
|
|
|
if( !m_pMaxComboText->IsType("BitmapText") )
|
2006-09-17 01:19:19 +00:00
|
|
|
RageException::Throw( "ComboGraph in \"%s\" has a child named \"MaxComboText\" that is not a BitmapText.", sDir.c_str() );
|
2005-08-29 01:23:25 +00:00
|
|
|
|
2005-10-10 22:27:09 +00:00
|
|
|
m_pNormalCombo = this->GetChild( "NormalCombo" );
|
|
|
|
|
if( m_pNormalCombo == NULL )
|
2006-09-17 01:19:19 +00:00
|
|
|
RageException::Throw( "ComboGraph in \"%s\" must have a child named \"NormalCombo\".", sDir.c_str() );
|
2005-08-29 01:23:25 +00:00
|
|
|
|
2005-10-10 22:27:09 +00:00
|
|
|
m_pMaxCombo = this->GetChild( "MaxCombo" );
|
|
|
|
|
if( m_pMaxCombo == NULL )
|
2006-09-17 01:19:19 +00:00
|
|
|
RageException::Throw( "ComboGraph in \"%s\" must have a child named \"MaxCombo\".", sDir.c_str() );
|
2005-08-29 01:23:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ComboGraph::Load( const StageStats &s, const PlayerStageStats &pss )
|
2003-10-23 06:15:10 +00:00
|
|
|
{
|
2005-04-20 06:13:06 +00:00
|
|
|
const float fFirstSecond = 0;
|
2005-04-23 02:50:26 +00:00
|
|
|
const float fLastSecond = s.GetTotalPossibleStepsSeconds();
|
2005-04-20 06:13:06 +00:00
|
|
|
|
2003-10-23 06:15:10 +00:00
|
|
|
/* Find the largest combo. */
|
2005-09-11 21:18:22 +00:00
|
|
|
int iMaxComboSize = 0;
|
2005-04-20 06:13:06 +00:00
|
|
|
for( unsigned i = 0; i < pss.ComboList.size(); ++i )
|
2005-09-11 21:18:22 +00:00
|
|
|
iMaxComboSize = max( iMaxComboSize, pss.ComboList[i].GetStageCnt() );
|
2003-10-23 06:15:10 +00:00
|
|
|
|
2005-04-20 06:13:06 +00:00
|
|
|
for( unsigned i = 0; i < pss.ComboList.size(); ++i )
|
2003-10-23 06:15:10 +00:00
|
|
|
{
|
2005-04-20 06:13:06 +00:00
|
|
|
const PlayerStageStats::Combo_t &combo = pss.ComboList[i];
|
2003-12-22 23:25:33 +00:00
|
|
|
if( combo.GetStageCnt() < MinComboSizeToShow )
|
2003-10-23 06:15:10 +00:00
|
|
|
continue; /* too small */
|
|
|
|
|
|
2005-09-11 21:18:22 +00:00
|
|
|
const bool bIsMax = (combo.GetStageCnt() == iMaxComboSize);
|
2003-10-23 06:15:10 +00:00
|
|
|
|
2005-09-11 21:18:22 +00:00
|
|
|
LOG->Trace( "combo %i is %f+%f of %f", i, combo.fStartSecond, combo.fSizeSeconds, fLastSecond );
|
|
|
|
|
Actor *pSprite = bIsMax? m_pMaxCombo->Copy():m_pNormalCombo->Copy();
|
2003-10-23 06:15:10 +00:00
|
|
|
|
2005-09-11 21:18:22 +00:00
|
|
|
const float fStart = SCALE( combo.fStartSecond, fFirstSecond, fLastSecond, 0.0f, 1.0f );
|
|
|
|
|
const float fSize = SCALE( combo.fSizeSeconds, 0, fLastSecond-fFirstSecond, 0.0f, 1.0f );
|
|
|
|
|
pSprite->SetCropLeft ( SCALE( fSize, 0.0f, 1.0f, 0.5f, 0.0f ) );
|
|
|
|
|
pSprite->SetCropRight( SCALE( fSize, 0.0f, 1.0f, 0.5f, 0.0f ) );
|
2003-10-23 06:15:10 +00:00
|
|
|
|
2005-09-11 21:18:22 +00:00
|
|
|
pSprite->SetCropLeft( fStart );
|
|
|
|
|
pSprite->SetCropRight( 1 - (fSize + fStart) );
|
2003-10-23 06:15:10 +00:00
|
|
|
|
2005-09-11 21:18:22 +00:00
|
|
|
this->AddChild( pSprite );
|
2003-10-23 06:15:10 +00:00
|
|
|
}
|
|
|
|
|
|
2005-04-20 06:13:06 +00:00
|
|
|
for( unsigned i = 0; i < pss.ComboList.size(); ++i )
|
2003-10-23 06:15:10 +00:00
|
|
|
{
|
2005-04-20 06:13:06 +00:00
|
|
|
const PlayerStageStats::Combo_t &combo = pss.ComboList[i];
|
2003-12-22 23:25:33 +00:00
|
|
|
if( combo.GetStageCnt() < MinComboSizeToShow )
|
2003-10-23 06:15:10 +00:00
|
|
|
continue; /* too small */
|
|
|
|
|
|
2005-09-11 21:18:22 +00:00
|
|
|
if( !iMaxComboSize )
|
2003-12-23 04:44:34 +00:00
|
|
|
continue;
|
|
|
|
|
|
2005-09-11 21:18:22 +00:00
|
|
|
const bool bIsMax = (combo.GetStageCnt() == iMaxComboSize);
|
|
|
|
|
if( !bIsMax )
|
2003-10-23 06:15:10 +00:00
|
|
|
continue;
|
|
|
|
|
|
2006-09-03 05:53:53 +00:00
|
|
|
BitmapText *pText = dynamic_cast<BitmapText*>( m_pMaxComboText->Copy() ); // XXX Copy should be covariant
|
2003-10-23 06:15:10 +00:00
|
|
|
|
2005-09-11 23:04:28 +00:00
|
|
|
const float fStart = SCALE( combo.fStartSecond, fFirstSecond, fLastSecond, 0.0f, 1.0f );
|
|
|
|
|
const float fSize = SCALE( combo.fSizeSeconds, 0, fLastSecond-fFirstSecond, 0.0f, 1.0f );
|
2003-12-22 01:55:03 +00:00
|
|
|
|
2005-08-29 01:23:25 +00:00
|
|
|
const float fWidth = m_pNormalCombo->GetUnzoomedWidth();
|
2005-09-11 23:04:28 +00:00
|
|
|
const float fCenterPercent = fStart + fSize/2;
|
|
|
|
|
const float fCenterXPos = SCALE( fCenterPercent, 0.0f, 1.0f, -fWidth/2.0f, fWidth/2.0f );
|
|
|
|
|
pText->SetX( fCenterXPos );
|
2003-10-23 06:15:10 +00:00
|
|
|
|
2005-09-11 21:18:22 +00:00
|
|
|
pText->SetText( ssprintf("%i",combo.GetStageCnt()) );
|
2003-10-23 06:15:10 +00:00
|
|
|
|
2005-09-11 21:18:22 +00:00
|
|
|
this->AddChild( pText );
|
2003-10-23 06:15:10 +00:00
|
|
|
}
|
2005-10-10 22:33:08 +00:00
|
|
|
|
|
|
|
|
/* Hide the templates. */
|
|
|
|
|
m_pNormalCombo->SetHidden( true );
|
|
|
|
|
m_pMaxCombo->SetHidden( true );
|
|
|
|
|
m_pMaxComboText->SetHidden( true );
|
2003-10-23 06:15:10 +00:00
|
|
|
}
|
|
|
|
|
|
2005-08-29 01:23:25 +00:00
|
|
|
// lua start
|
|
|
|
|
#include "LuaBinding.h"
|
2003-12-28 06:00:27 +00:00
|
|
|
|
2005-08-29 01:23:25 +00:00
|
|
|
class LunaComboGraph: public Luna<ComboGraph>
|
2003-10-23 06:15:10 +00:00
|
|
|
{
|
2005-08-29 01:23:25 +00:00
|
|
|
public:
|
|
|
|
|
LunaComboGraph() { LUA->Register( Register ); }
|
2003-10-23 06:15:10 +00:00
|
|
|
|
2005-08-29 01:23:25 +00:00
|
|
|
static int LoadFromStats( T* p, lua_State *L )
|
|
|
|
|
{
|
|
|
|
|
StageStats *pStageStats = Luna<StageStats>::check( L, 1 );
|
|
|
|
|
PlayerStageStats *pPlayerStageStats = Luna<PlayerStageStats>::check( L, 2 );
|
|
|
|
|
p->Load( *pStageStats, *pPlayerStageStats );
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void Register(lua_State *L)
|
|
|
|
|
{
|
2005-09-10 02:47:04 +00:00
|
|
|
ADD_METHOD( LoadFromStats );
|
|
|
|
|
|
2005-08-29 01:23:25 +00:00
|
|
|
Luna<T>::Register( L );
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
LUA_REGISTER_DERIVED_CLASS( ComboGraph, ActorFrame )
|
|
|
|
|
// lua end
|
2003-10-23 06:15:10 +00:00
|
|
|
|
2004-06-07 21:14:03 +00:00
|
|
|
/*
|
|
|
|
|
* (c) 2003 Glenn Maynard
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|