Files
itgmania212121/stepmania/src/ComboGraph.cpp
T

155 lines
5.2 KiB
C++
Raw Normal View History

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()
{
DeleteChildrenWhenDone( true );
2005-08-29 01:23:25 +00:00
m_pNormalCombo = NULL;
m_pMaxCombo = NULL;
m_pMaxComboText = NULL;
2005-08-29 01:23:25 +00:00
}
void ComboGraph::LoadFromNode( const XNode* pNode )
2005-08-29 01:23:25 +00:00
{
ActorFrame::LoadFromNode( pNode );
2005-08-29 01:23:25 +00:00
2006-10-20 09:47:24 +00:00
Actor *pActor = this->GetChild( "MaxComboText" );
if( pActor == NULL )
2006-10-09 08:08:59 +00:00
RageException::Throw( "%s: ComboGraph: must have a child named \"MaxComboText\"", ActorUtil::GetWhere(pNode).c_str() );
2006-10-20 09:47:24 +00:00
m_pMaxComboText = dynamic_cast<BitmapText *>( pActor );
if( m_pMaxComboText == NULL )
2006-10-09 08:08:59 +00:00
RageException::Throw( "%s: ComboGraph: \"MaxComboText\" child is not a BitmapText", ActorUtil::GetWhere(pNode).c_str() );
2005-08-29 01:23:25 +00:00
m_pNormalCombo = this->GetChild( "NormalCombo" );
if( m_pNormalCombo == NULL )
2006-10-09 08:08:59 +00:00
RageException::Throw( "%s: ComboGraph: must have a child named \"NormalCombo\"", ActorUtil::GetWhere(pNode).c_str() );
2005-08-29 01:23:25 +00:00
m_pMaxCombo = this->GetChild( "MaxCombo" );
if( m_pMaxCombo == NULL )
2006-10-09 08:08:59 +00:00
RageException::Throw( "%s: ComboGraph: must have a child named \"MaxCombo\"", ActorUtil::GetWhere(pNode).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
{
const float fFirstSecond = 0;
const float fLastSecond = s.GetTotalPossibleStepsSeconds();
2003-10-23 06:15:10 +00:00
/* Find the largest combo. */
2005-09-11 21:18:22 +00:00
int iMaxComboSize = 0;
for( unsigned i = 0; i < pss.m_ComboList.size(); ++i )
iMaxComboSize = max( iMaxComboSize, pss.m_ComboList[i].GetStageCnt() );
2003-10-23 06:15:10 +00:00
for( unsigned i = 0; i < pss.m_ComboList.size(); ++i )
2003-10-23 06:15:10 +00:00
{
const PlayerStageStats::Combo_t &combo = pss.m_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
LOG->Trace( "combo %i is %f+%f of %f", i, combo.m_fStartSecond, combo.m_fSizeSeconds, fLastSecond );
2005-09-11 21:18:22 +00:00
Actor *pSprite = bIsMax? m_pMaxCombo->Copy():m_pNormalCombo->Copy();
2003-10-23 06:15:10 +00:00
const float fStart = SCALE( combo.m_fStartSecond, fFirstSecond, fLastSecond, 0.0f, 1.0f );
const float fSize = SCALE( combo.m_fSizeSeconds, 0, fLastSecond-fFirstSecond, 0.0f, 1.0f );
2005-09-11 21:18:22 +00:00
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
}
for( unsigned i = 0; i < pss.m_ComboList.size(); ++i )
2003-10-23 06:15:10 +00:00
{
const PlayerStageStats::Combo_t &combo = pss.m_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-10-20 00:22:16 +00:00
BitmapText *pText = m_pMaxComboText->Copy();
2003-10-23 06:15:10 +00:00
const float fStart = SCALE( combo.m_fStartSecond, fFirstSecond, fLastSecond, 0.0f, 1.0f );
const float fSize = SCALE( combo.m_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. */
2007-02-13 06:32:26 +00:00
m_pNormalCombo->SetVisible( false );
m_pMaxCombo->SetVisible( false );
m_pMaxComboText->SetVisible( false );
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:
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;
}
2006-09-27 20:03:31 +00:00
LunaComboGraph()
2005-08-29 01:23:25 +00:00
{
2006-09-27 20:03:31 +00:00
ADD_METHOD( LoadFromStats );
2005-08-29 01:23:25 +00:00
}
};
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.
*/