From fa31995d58c7b94269ae4d9c0926b80170ad28a9 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Mon, 17 Nov 2003 04:19:29 +0000 Subject: [PATCH] add DifficultyList --- stepmania/src/DifficultyList.cpp | 212 +++++++++++++++++++++++++++++++ stepmania/src/DifficultyList.h | 38 ++++++ 2 files changed, 250 insertions(+) create mode 100644 stepmania/src/DifficultyList.cpp create mode 100644 stepmania/src/DifficultyList.h diff --git a/stepmania/src/DifficultyList.cpp b/stepmania/src/DifficultyList.cpp new file mode 100644 index 0000000000..3f08f1df91 --- /dev/null +++ b/stepmania/src/DifficultyList.cpp @@ -0,0 +1,212 @@ +#include "global.h" +#include "DifficultyList.h" +#include "GameState.h" +#include "Song.h" +#include "StyleDef.h" +#include "DifficultyMeter.h" +#include "RageLog.h" +#include "BitmapText.h" +#include "SongManager.h" +#include "ThemeManager.h" + +#define ITEMS_SPACING_Y THEME->GetMetricF(m_sName,"ItemsSpacingY") +#define DESCRIPTION_MAX_WIDTH THEME->GetMetricF(m_sName,"DescriptionMaxWidth") +#define TWEEN_ON_STAGGER_SECONDS THEME->GetMetricF(m_sName,"TweenOnStaggerSeconds") + +const int RowsOnScreen=6; + +DifficultyList::DifficultyList() +{ + m_Meters = NULL; // defer alloc to Load + m_Frames = NULL; + m_Descriptions = NULL; +} + +DifficultyList::~DifficultyList() +{ + delete [] m_Meters; + delete [] m_Frames; + delete [] m_Descriptions; +} + +void DifficultyList::Load() +{ + ASSERT( !m_Meters ); + m_Meters = new DifficultyMeter[MAX_METERS]; + m_Frames = new ActorFrame[MAX_METERS]; + m_Descriptions = new BitmapText[MAX_METERS]; + m_CurSong = NULL; + + int pn, m; + for( pn = 0; pn < NUM_PLAYERS; ++pn ) + { + if( !GAMESTATE->IsHumanPlayer(pn) ) + continue; + + m_Cursors[pn].Load( THEME->GetPathToG(ssprintf("%s cursor p%i",m_sName.c_str(), pn+1)) ); + m_Cursors[pn]->SetName( ssprintf("CursorP%i",pn+1) ); + ON_COMMAND( m_Cursors[pn] ); + this->AddChild( m_Cursors[pn] ); + } + + for( m = 0; m < MAX_METERS; ++m ) + { + m_Meters[m].SetName( "DifficultySummaryRow", "Row" ); + m_Meters[m].Load(); + this->AddChild( &m_Meters[m] ); + + m_Descriptions[m].SetName( "Description" ); + m_Descriptions[m].LoadFromFont( THEME->GetPathToF(ssprintf("%s description",m_sName.c_str())) ); + this->AddChild( &m_Descriptions[m] ); + } + + PositionItems(); + + for( pn = 0; pn < NUM_PLAYERS; ++pn ) + if( GAMESTATE->IsHumanPlayer(pn) ) + ON_COMMAND( m_Cursors[pn] ); + + for( m = 0; m < MAX_METERS; ++m ) + { + ON_COMMAND( m_Meters[m] ); + ON_COMMAND( m_Descriptions[m] ); + } +} + +void DifficultyList::PositionItems() +{ + int pos = 0; + for( int m = 0; m < MAX_METERS; ++m ) + { + DifficultyMeter &met = m_Meters[m]; + + float ItemPosition; + if( m < RowsOnScreen ) + ItemPosition = (float) pos++; + else + { + met.SetHidden( true ); +// ItemPosition = ItemPosition = (float) pos++; + continue; + } + const float fY = ITEMS_SPACING_Y*ItemPosition; + LOG->Trace("row %i, pos %f, fY %f", + m, ItemPosition, fY); + + m_Descriptions[m].SetY( fY ); + met.SetY( fY ); + } + + for( int pn = 0;pn < NUM_PLAYERS; ++pn ) + { + if( !GAMESTATE->IsHumanPlayer(pn) ) + continue; + + unsigned ItemPosition; + for( ItemPosition = 0; ItemPosition < m_CurSteps.size(); ++ItemPosition ) + if( GAMESTATE->m_pCurNotes[pn] == m_CurSteps[ItemPosition] ) + break; + + if( ItemPosition == m_CurSteps.size() ) + continue; + + const float fY = ITEMS_SPACING_Y*ItemPosition; + + COMMAND( m_Cursors[pn], "Change" ); + m_Cursors[pn]->SetY( fY ); + } +} + +void DifficultyList::SetFromGameState() +{ + Song *song = GAMESTATE->m_pCurSong; + if( !song ) + return; + + /* If the song has changed, update displays: */ + if( song != m_CurSong ) + { + m_CurSong = song; + m_CurSteps.clear(); + song->GetSteps( m_CurSteps, GAMESTATE->GetCurrentStyleDef()->m_StepsType ); + + /* Should match the sort in ScreenSelectMusic::AfterMusicChange. */ + SortNotesArrayByDifficulty( m_CurSteps ); + + for( int m = 0; m < MAX_METERS; ++m ) + { + DifficultyMeter &met = m_Meters[m]; + if( m >= (int) m_CurSteps.size() ) + { + met.Unset(); + m_Descriptions[m].SetText( "" ); + continue; + } + + met.SetFromNotes( m_CurSteps[m] ); + const CString desc = m_CurSteps[m]->GetDescription(); + m_Descriptions[m].SetZoomX(1); + m_Descriptions[m].SetTextMaxWidth( DESCRIPTION_MAX_WIDTH, SONGMAN->GetDifficultyThemeName(desc) ); + /* Don't mess with alpha; it might be fading on. */ + m_Descriptions[m].SetDiffuseColor( SONGMAN->GetDifficultyColor( m_CurSteps[m]->GetDifficulty() ) ); + } + } + + PositionItems(); +} + +void DifficultyList::TweenOnScreen() +{ + for( int m = 0; m < MAX_METERS; ++m ) + { + m_Descriptions[m].BeginTweening( m * TWEEN_ON_STAGGER_SECONDS ); + COMMAND( m_Descriptions[m], "TweenOn" ); + COMMAND( m_Meters[m], "TweenOn" ); + } + + for( int pn = 0; pn < NUM_PLAYERS; ++pn ) + { + if( !GAMESTATE->IsHumanPlayer(pn) ) + continue; + COMMAND( m_Cursors[pn], "TweenOn" ); + } +} + +void DifficultyList::TweenOffScreen() +{ + +} + +void DifficultyList::Show() +{ + for( int m = 0; m < MAX_METERS; ++m ) + { + // XXX: m_Meters[m].Show + COMMAND( m_Descriptions[m], "Show" ); + COMMAND( m_Meters[m], "Show" ); + } + + for( int pn = 0; pn < NUM_PLAYERS; ++pn ) + { + if( !GAMESTATE->IsHumanPlayer(pn) ) + continue; + COMMAND( m_Cursors[pn], "Show" ); + } +} + +void DifficultyList::Hide() +{ + for( int m = 0; m < MAX_METERS; ++m ) + { + // XXX: m_Meters[m].Hide + COMMAND( m_Descriptions[m], "Hide" ); + COMMAND( m_Meters[m], "Hide" ); + } + + for( int pn = 0; pn < NUM_PLAYERS; ++pn ) + { + if( !GAMESTATE->IsHumanPlayer(pn) ) + continue; + COMMAND( m_Cursors[pn], "Hide" ); + } +} diff --git a/stepmania/src/DifficultyList.h b/stepmania/src/DifficultyList.h new file mode 100644 index 0000000000..44f3947557 --- /dev/null +++ b/stepmania/src/DifficultyList.h @@ -0,0 +1,38 @@ +#ifndef DIFFICULTY_LIST +#define DIFFICULTY_LIST + +#include "ActorFrame.h" +#include "ActorUtil.h" +#include "PlayerNumber.h" +class DifficultyMeter; +class Song; +class Steps; +class BitmapText; + +#define MAX_METERS 16 + +class DifficultyList: public ActorFrame +{ +public: + DifficultyList(); + ~DifficultyList(); + + void Load(); + void SetFromGameState(); + void TweenOnScreen(); + void TweenOffScreen(); + void Hide(); + void Show(); + +private: + void PositionItems(); + + DifficultyMeter *m_Meters; + AutoActor m_Cursors[NUM_PLAYERS]; + BitmapText *m_Descriptions; + ActorFrame *m_Frames; + Song *m_CurSong; + vector m_CurSteps; +}; + +#endif