diff --git a/stepmania/src/ComboGraph.cpp b/stepmania/src/ComboGraph.cpp new file mode 100644 index 0000000000..8880bb415a --- /dev/null +++ b/stepmania/src/ComboGraph.cpp @@ -0,0 +1,78 @@ +#include "global.h" +#include "ComboGraph.h" +#include "ThemeManager.h" +#include "RageLog.h" + +const int MinComboSizeToShow = 5; + +void ComboGraph::Load( CString Path, const StageStats &s, PlayerNumber pn ) +{ + ASSERT( m_Actors.size() == 0 ); + + /* Find the largest combo. */ + int MaxComboSize = 0; + unsigned i; + for( i = 0; i < s.ComboList[pn].size(); ++i ) + MaxComboSize = max( MaxComboSize, s.ComboList[pn][i].cnt ); + + float width = -1; + for( i = 0; i < s.ComboList[pn].size(); ++i ) + { + const StageStats::Combo_t &combo = s.ComboList[pn][i]; + if( combo.cnt < MinComboSizeToShow ) + continue; /* too small */ + + const bool IsMax = (combo.cnt == MaxComboSize); + + LOG->Trace("combo %i is %f+%f", i, combo.start, combo.size); + Sprite *sprite = new Sprite; + const CString path = ssprintf( "%s %s", Path.c_str(), IsMax? "max":"normal" ); + sprite->Load( THEME->GetPathToG(path) ); + + sprite->SetCropLeft ( SCALE( combo.size, 0.0f, 1.0f, 0.5f, 0.0f ) ); + sprite->SetCropRight( SCALE( combo.size, 0.0f, 1.0f, 0.5f, 0.0f ) ); + + sprite->BeginTweening( .5f ); + sprite->SetCropLeft( combo.start ); + sprite->SetCropRight( 1 - (combo.size + combo.start) ); + + if( width < 0 ) + width = sprite->GetUnzoomedWidth(); + + m_Actors.push_back( sprite ); + this->AddChild( sprite ); + } + + for( i = 0; i < s.ComboList[pn].size(); ++i ) + { + const StageStats::Combo_t &combo = s.ComboList[pn][i]; + if( combo.cnt < MinComboSizeToShow ) + continue; /* too small */ + + const bool IsMax = (combo.cnt == MaxComboSize); + if( !IsMax ) + continue; + + BitmapText *text = new BitmapText; + text->LoadFromFont( THEME->GetPathToF(Path) ); + + const float CenterPercent = combo.start + combo.size/2; + const float CenterXPos = SCALE( CenterPercent, 0.0f, 1.0f, -width/2.0f, width/2.0f ); + text->SetX( CenterXPos ); + + text->SetText( ssprintf("%i",combo.cnt) ); + text->Command( "diffusealpha,0;sleep,.5f;linear,.3;diffusealpha,1" ); + + m_Actors.push_back( text ); + this->AddChild( text ); + } +} + +void ComboGraph::Unload() +{ + for( unsigned i = 0; i < m_Actors.size(); ++i ) + delete m_Actors[i]; + + m_SubActors.clear(); +} + diff --git a/stepmania/src/ComboGraph.h b/stepmania/src/ComboGraph.h new file mode 100644 index 0000000000..b23a1754d2 --- /dev/null +++ b/stepmania/src/ComboGraph.h @@ -0,0 +1,21 @@ +#ifndef COMBO_GRAPH_H +#define COMBO_GRAPH_H + +#include "ActorFrame.h" +#include "PlayerNumber.h" +#include "StageStats.h" +#include "Sprite.h" +#include "BitmapText.h" + +class ComboGraph: public ActorFrame +{ +public: + ~ComboGraph() { Unload(); } + void Load( CString Path, const StageStats &s, PlayerNumber pn ); + void Unload(); + +private: + vector m_Actors; +}; + +#endif