Files
itgmania212121/stepmania/src/ComboGraph.cpp
T

123 lines
4.1 KiB
C++
Raw Normal View History

2003-10-23 06:15:10 +00:00
#include "global.h"
#include "ComboGraph.h"
#include "ThemeManager.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"
2003-10-23 06:15:10 +00:00
const int MinComboSizeToShow = 5;
void ComboGraph::Load( CString Path, const StageStats &s, PlayerNumber pn )
{
2003-12-28 06:00:27 +00:00
ASSERT( m_SubActors.size() == 0 );
2003-10-23 06:15:10 +00:00
/* Find the largest combo. */
int MaxComboSize = 0;
2004-09-21 07:53:39 +00:00
for( unsigned i = 0; i < s.ComboList[pn].size(); ++i )
2003-12-22 23:25:33 +00:00
MaxComboSize = max( MaxComboSize, s.ComboList[pn][i].GetStageCnt() );
2003-10-23 06:15:10 +00:00
float width = -1;
2004-09-21 07:53:39 +00:00
for( unsigned i = 0; i < s.ComboList[pn].size(); ++i )
2003-10-23 06:15:10 +00:00
{
const StageStats::Combo_t &combo = s.ComboList[pn][i];
2003-12-22 23:25:33 +00:00
if( combo.GetStageCnt() < MinComboSizeToShow )
2003-10-23 06:15:10 +00:00
continue; /* too small */
2003-12-22 23:25:33 +00:00
const bool IsMax = (combo.GetStageCnt() == MaxComboSize);
2003-10-23 06:15:10 +00:00
LOG->Trace("combo %i is %f+%f", i, combo.fStartSecond, combo.fSizeSeconds);
2003-10-23 06:15:10 +00:00
Sprite *sprite = new Sprite;
2003-12-28 06:00:27 +00:00
sprite->SetName( "ComboBar" );
2003-10-23 06:15:10 +00:00
const CString path = ssprintf( "%s %s", Path.c_str(), IsMax? "max":"normal" );
sprite->Load( THEME->GetPathToG(path) );
const float start = SCALE( combo.fStartSecond, s.fFirstSecond[pn], s.fLastSecond[pn], 0.0f, 1.0f );
const float size = SCALE( combo.fSizeSeconds, 0, s.fLastSecond[pn]-s.fFirstSecond[pn], 0.0f, 1.0f );
2003-12-22 01:55:03 +00:00
sprite->SetCropLeft ( SCALE( size, 0.0f, 1.0f, 0.5f, 0.0f ) );
sprite->SetCropRight( SCALE( size, 0.0f, 1.0f, 0.5f, 0.0f ) );
2003-10-23 06:15:10 +00:00
sprite->BeginTweening( .5f );
2003-12-22 01:55:03 +00:00
sprite->SetCropLeft( start );
sprite->SetCropRight( 1 - (size + start) );
2003-10-23 06:15:10 +00:00
if( width < 0 )
width = sprite->GetUnzoomedWidth();
2003-12-28 06:00:27 +00:00
m_Sprites.push_back( sprite );
2003-10-23 06:15:10 +00:00
this->AddChild( sprite );
}
2004-09-21 07:53:39 +00:00
for( unsigned i = 0; i < s.ComboList[pn].size(); ++i )
2003-10-23 06:15:10 +00:00
{
const StageStats::Combo_t &combo = s.ComboList[pn][i];
2003-12-22 23:25:33 +00:00
if( combo.GetStageCnt() < MinComboSizeToShow )
2003-10-23 06:15:10 +00:00
continue; /* too small */
2003-12-23 04:44:34 +00:00
if( !MaxComboSize )
continue;
2003-12-22 23:25:33 +00:00
const bool IsMax = (combo.GetStageCnt() == MaxComboSize);
2003-10-23 06:15:10 +00:00
if( !IsMax )
continue;
BitmapText *text = new BitmapText;
2003-12-28 06:00:27 +00:00
text->SetName( "ComboMaxNumber" );
2003-10-23 06:15:10 +00:00
text->LoadFromFont( THEME->GetPathToF(Path) );
const float start = SCALE( combo.fStartSecond, s.fFirstSecond[pn], s.fLastSecond[pn], 0.0f, 1.0f );
const float size = SCALE( combo.fSizeSeconds, 0, s.fLastSecond[pn]-s.fFirstSecond[pn], 0.0f, 1.0f );
2003-12-22 01:55:03 +00:00
const float CenterPercent = start + size/2;
2003-10-23 06:15:10 +00:00
const float CenterXPos = SCALE( CenterPercent, 0.0f, 1.0f, -width/2.0f, width/2.0f );
text->SetX( CenterXPos );
2003-12-22 23:25:33 +00:00
text->SetText( ssprintf("%i",combo.GetStageCnt()) );
2003-12-28 06:00:27 +00:00
ON_COMMAND( text );
2003-10-23 06:15:10 +00:00
2003-12-28 06:00:27 +00:00
m_Numbers.push_back( text );
2003-10-23 06:15:10 +00:00
this->AddChild( text );
}
}
2003-12-28 06:00:27 +00:00
void ComboGraph::TweenOffScreen()
{
for( unsigned i = 0; i < m_SubActors.size(); ++i )
OFF_COMMAND( m_SubActors[i] );
}
2003-10-23 06:15:10 +00:00
void ComboGraph::Unload()
{
2003-12-28 06:00:27 +00:00
for( unsigned i = 0; i < m_SubActors.size(); ++i )
delete m_SubActors[i];
2003-10-23 06:15:10 +00:00
2003-12-28 06:00:27 +00:00
m_Sprites.clear();
m_Numbers.clear();
2003-10-23 06:15:10 +00:00
m_SubActors.clear();
}
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.
*/