From 4d2b0355f612004f53cf0fb220b447cb339ee463 Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Thu, 27 Nov 2008 02:58:50 +0000 Subject: [PATCH] split ScreenHighScores from ScreenRanking. These two things lived in the same file and shared enums, but shared almost no code. --- stepmania/src/ScreenHighScores.cpp | 351 ++++++++++++++++++ stepmania/src/ScreenHighScores.h | 115 ++++++ stepmania/src/ScreenRanking.cpp | 485 +++++-------------------- stepmania/src/ScreenRanking.h | 108 ++---- stepmania/src/StepMania-net2008.vcproj | 12 +- 5 files changed, 584 insertions(+), 487 deletions(-) create mode 100644 stepmania/src/ScreenHighScores.cpp create mode 100644 stepmania/src/ScreenHighScores.h diff --git a/stepmania/src/ScreenHighScores.cpp b/stepmania/src/ScreenHighScores.cpp new file mode 100644 index 0000000000..ab1acc5012 --- /dev/null +++ b/stepmania/src/ScreenHighScores.cpp @@ -0,0 +1,351 @@ +#include "global.h" +#include "ScreenHighScores.h" +#include "ScreenManager.h" +//#include "ThemeManager.h" +#include "SongManager.h" +//#include "GameState.h" +//#include "GameManager.h" +//#include "Course.h" +#include "Song.h" +//#include "Steps.h" +//#include "ActorUtil.h" +//#include "ProfileManager.h" +//#include "Profile.h" +#include "RageLog.h" +#include "UnlockManager.h" +//#include "ScreenDimensions.h" +//#include "PercentageDisplay.h" + +static const char *HighScoresTypeNames[] = { + "AllSteps", + "NonstopCourses", + "OniCourses", + "SurvivalCourses", + "AllCourses", +}; +XToString( HighScoresType ); +LuaXType( HighScoresType ); + +REGISTER_SCREEN_CLASS( ScreenHighScores ); + +static void GetAllSongsToShow( vector &vpOut, int iNumMostRecentScoresToShow ) +{ + vpOut.clear(); + FOREACH_CONST( Song*, SONGMAN->GetSongs(), s ) + { + if( !(*s)->NormallyDisplayed() ) + continue; // skip + if( !(*s)->ShowInDemonstrationAndRanking() ) + continue; // skip + vpOut.push_back( *s ); + } + + if( (int)vpOut.size() > iNumMostRecentScoresToShow ) + { + SongUtil::SortSongPointerArrayByTitle( vpOut ); + SongUtil::SortByMostRecentlyPlayedForMachine( vpOut ); + if( (int) vpOut.size() > iNumMostRecentScoresToShow ) + vpOut.erase( vpOut.begin()+iNumMostRecentScoresToShow, vpOut.end() ); + } +} + +static void GetAllCoursesToShow( vector &vpOut, CourseType ct, int iNumMostRecentScoresToShow ) +{ + vpOut.clear(); + vector vpCourses; + if( ct == CourseType_Invalid ) + SONGMAN->GetAllCourses( vpCourses, false ); + else + SONGMAN->GetCourses( ct, vpCourses, false ); + + FOREACH_CONST( Course*, vpCourses, c) + { + if( UNLOCKMAN->CourseIsLocked(*c) ) + continue; // skip + if( !(*c)->ShowInDemonstrationAndRanking() ) + continue; // skip + vpOut.push_back( *c ); + } + if( (int)vpOut.size() > iNumMostRecentScoresToShow ) + { + CourseUtil::SortCoursePointerArrayByTitle( vpOut ); + CourseUtil::SortByMostRecentlyPlayedForMachine( vpOut ); + if( (int) vpOut.size() > iNumMostRecentScoresToShow ) + vpOut.erase( vpOut.begin()+iNumMostRecentScoresToShow, vpOut.end() ); + } +} + +///////////////////////////////////////////// + +ScoreScroller::ScoreScroller() +{ + this->DeleteChildrenWhenDone(); +} + +void ScoreScroller::SetDisplay( const vector &DifficultiesToShow ) +{ + m_DifficultiesToShow = DifficultiesToShow; + ShiftSubActors( INT_MAX ); +} + +bool ScoreScroller::Scroll( int iDir ) +{ + if( (int)m_vScoreRowItemData.size() <= SCROLLER_ITEMS_TO_DRAW ) + return false; + + float fDest = GetDestinationItem(); + float fOldDest = fDest; + fDest += iDir; + float fLowClamp = (SCROLLER_ITEMS_TO_DRAW-1)/2.0f; + float fHighClamp = m_vScoreRowItemData.size()-(SCROLLER_ITEMS_TO_DRAW-1)/2.0f-1; + CLAMP( fDest, fLowClamp, fHighClamp ); + if( fOldDest != fDest ) + { + SetDestinationItem( fDest ); + return true; + } + else + { + return false; + } +} + +void ScoreScroller::ScrollTop() +{ + SetCurrentAndDestinationItem( (SCROLLER_ITEMS_TO_DRAW-1)/2.0f ); +} + +void ScoreScroller::ConfigureActor( Actor *pActor, int iItem ) +{ + LOG->Trace("ScoreScroller::ConfigureActor"); + + Actor &item = *dynamic_cast(pActor); + const ScoreRowItemData &data = m_vScoreRowItemData[iItem]; + + Message msg("Set"); + if( data.m_pSong != NULL ) + msg.SetParam( "Song", data.m_pSong ); + if( data.m_pCourse != NULL ) + msg.SetParam( "Course", data.m_pCourse ); + + + Lua *L = LUA->Get(); + lua_newtable( L ); + lua_pushvalue( L, -1 ); + msg.SetParamFromStack( L, "Entries" ); + + FOREACH( DifficultyAndStepsType, m_DifficultiesToShow, iter ) + { + int i = iter-m_DifficultiesToShow.begin(); + Difficulty dc = iter->first; + StepsType st = iter->second; + + if( data.m_pSong != NULL ) + { + const Song* pSong = data.m_pSong; + Steps *pSteps = SongUtil::GetStepsByDifficulty( pSong, st, dc, false ); + if( pSteps && UNLOCKMAN->StepsIsLocked(pSong, pSteps) ) + pSteps = NULL; + LuaHelpers::Push( L, pSteps ); + } + else if( data.m_pCourse != NULL ) + { + const Course* pCourse = data.m_pCourse; + Trail *pTrail = pCourse->GetTrail( st, dc ); + LuaHelpers::Push( L, pTrail ); + } + // Because pSteps or pTrail can be NULL, what we're creating in Lua is not an array. + // It must be iterated using pairs(), not ipairs(). + lua_setfield( L, -2, ssprintf("%d",i+1) ); + } + lua_pop( L, 1 ); + LUA->Release( L ); + + + item.HandleMessage( msg ); + LOG->Trace("end ScoreScroller::ConfigureActor"); +} + +void ScoreScroller::LoadSongs( int iNumRecentScores ) +{ + vector vpSongs; + GetAllSongsToShow( vpSongs, iNumRecentScores ); + m_vScoreRowItemData.resize( vpSongs.size() ); + for( unsigned i=0; i vpCourses; + GetAllCoursesToShow( vpCourses, ct, iNumRecentScores ); + m_vScoreRowItemData.resize( vpCourses.size() ); + for( unsigned i=0; iGetPathG(sMetricsGroup,"ScrollerItem") ); + this->AddChild( pActor ); + } + + DynamicActorScroller::SetTransformFromReference( THEME->GetMetricR(sMetricsGroup,"ScrollerItemTransformFunction") ); + DynamicActorScroller::SetNumItemsToDraw( (float) SCROLLER_ITEMS_TO_DRAW ); + DynamicActorScroller::SetSecondsPerItem( SCROLLER_SECONDS_PER_ITEM ); + DynamicActorScroller::Load2(); + + m_iNumItems = m_vScoreRowItemData.size(); +} + +///////////////////////////////////////////// + +RString COLUMN_DIFFICULTY_NAME( size_t i ) { return ssprintf("ColumnDifficulty%d",int(i+1)); } +RString COLUMN_STEPS_TYPE_NAME( size_t i ) { return ssprintf("ColumnStepsType%d",int(i+1)); } + +void ScreenHighScores::Init() +{ + ScreenAttract::Init(); + + MANUAL_SCROLLING.Load( m_sName,"ManualScrolling"); + HIGH_SCORES_TYPE.Load( m_sName,"HighScoresType"); + NUM_COLUMNS.Load( m_sName, "NumColumns" ); + COLUMN_DIFFICULTY.Load( m_sName, COLUMN_DIFFICULTY_NAME, NUM_COLUMNS ); + COLUMN_STEPS_TYPE.Load( m_sName, COLUMN_STEPS_TYPE_NAME, NUM_COLUMNS ); + MAX_ITEMS_TO_SHOW.Load( m_sName, "MaxItemsToShow" ); + + m_Scroller.SetName( "Scroller" ); + LOAD_ALL_COMMANDS( m_Scroller ); + switch( HIGH_SCORES_TYPE ) + { + DEFAULT_FAIL( HIGH_SCORES_TYPE.GetValue() ); + case HighScoresType_AllSteps: + m_Scroller.LoadSongs( MAX_ITEMS_TO_SHOW ); + break; + case HighScoresType_NonstopCourses: + case HighScoresType_OniCourses: + case HighScoresType_SurvivalCourses: + case HighScoresType_AllCourses: + { + CourseType ct; + switch( HIGH_SCORES_TYPE ) + { + default: ASSERT(0); + case HighScoresType_NonstopCourses: ct = COURSE_TYPE_NONSTOP; break; + case HighScoresType_OniCourses: ct = COURSE_TYPE_ONI; break; + case HighScoresType_SurvivalCourses: ct = COURSE_TYPE_SURVIVAL; break; + case HighScoresType_AllCourses: ct = CourseType_Invalid; break; + } + + m_Scroller.LoadCourses( ct, MAX_ITEMS_TO_SHOW ); + } + break; + } + + m_Scroller.Load( m_sName ); + this->AddChild( &m_Scroller ); +} + +void ScreenHighScores::BeginScreen() +{ + ScreenAttract::BeginScreen(); + + vector vdast; + for( int i=0; iPostScreenMessage( SM_BeginFadingOut, fSecs ); +} + +void ScreenHighScores::Input( const InputEventPlus &input ) +{ + //LOG->Trace( "ScreenRanking::Input()" ); + if( IsTransitioning() ) + return; + + // If manually scrolling, then pass the input to Scree::Input so it will call Menu* + if( (bool)MANUAL_SCROLLING ) + Screen::Input( input ); + else + ScreenAttract::Input( input ); +} + +void ScreenHighScores::HandleScreenMessage( const ScreenMessage SM ) +{ + if( SM == SM_BeginFadingOut ) /* Screen is starting to tween out. */ + { + StartTransitioningScreen( SM_GoToNextScreen ); + } + + ScreenAttract::HandleScreenMessage( SM ); +} + +void ScreenHighScores::MenuStart( const InputEventPlus &input ) +{ + if( !MANUAL_SCROLLING ) + return; + if( !IsTransitioning() ) + StartTransitioningScreen( SM_GoToNextScreen ); + SCREENMAN->PlayStartSound(); +} + +void ScreenHighScores::MenuBack( const InputEventPlus &input ) +{ + if( !MANUAL_SCROLLING ) + return; + if( !IsTransitioning() ) + StartTransitioningScreen( SM_GoToNextScreen ); + SCREENMAN->PlayStartSound(); +} + +void ScreenHighScores::DoScroll( int iDir ) +{ + if( !m_Scroller.Scroll(iDir) ) + iDir = 0; + Message msg("Scrolled"); + msg.SetParam( "Dir", iDir ); + this->HandleMessage( msg ); +} + +/* + * (c) 2001-2007 Chris Danford, 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. + */ diff --git a/stepmania/src/ScreenHighScores.h b/stepmania/src/ScreenHighScores.h new file mode 100644 index 0000000000..848f0357c6 --- /dev/null +++ b/stepmania/src/ScreenHighScores.h @@ -0,0 +1,115 @@ +#ifndef ScreenHighScores_H +#define ScreenHighScores_H + +#include "ScreenAttract.h" +//#include "GameConstantsAndTypes.h" // for NUM_RANKING_CLASSIC_LINES +#include "Course.h" +//#include "BitmapText.h" +//#include "Banner.h" +//#include "ActorScroller.h" +#include "DynamicActorScroller.h" +//#include "ActorUtil.h" +//#include "Difficulty.h" +//#include "ThemeMetric.h" +//#include "CommonMetrics.h" + +//class Course; +//class Song; +//class Trail; +//struct HighScoreList; +typedef pair DifficultyAndStepsType; + +enum HighScoresType +{ + HighScoresType_AllSteps, // Top 1 HighScore for N Steps in each Song + HighScoresType_NonstopCourses, // Top 1 HighScore for N Trails in each Course + HighScoresType_OniCourses, + HighScoresType_SurvivalCourses, + HighScoresType_AllCourses, + NUM_HighScoresType, + HighScoresType_Invalid +}; +LuaDeclareType( HighScoresType ); + + +class ScoreScroller: public DynamicActorScroller +{ +public: + ScoreScroller(); + void LoadSongs( int iNumRecentScores ); + void LoadCourses( CourseType ct, int iNumRecentScores ); + void Load( RString sClassName ); + void SetDisplay( const vector &DifficultiesToShow ); + bool Scroll( int iDir ); + void ScrollTop(); + +protected: + virtual void ConfigureActor( Actor *pActor, int iItem ); + vector m_DifficultiesToShow; + + struct ScoreRowItemData // for all_steps and all_courses + { + ScoreRowItemData() { m_pSong = NULL; m_pCourse = NULL; } + + Song *m_pSong; + Course *m_pCourse; + }; + vector m_vScoreRowItemData; + + ThemeMetric SCROLLER_ITEMS_TO_DRAW; + ThemeMetric SCROLLER_SECONDS_PER_ITEM; +}; + +class ScreenHighScores: public ScreenAttract +{ +public: + virtual void Init(); + virtual void BeginScreen(); + + void HandleScreenMessage( const ScreenMessage SM ); + virtual void Input( const InputEventPlus &input ); + virtual void MenuStart( const InputEventPlus &input ); + virtual void MenuBack( const InputEventPlus &input ); + virtual void MenuLeft( const InputEventPlus &input ) { DoScroll(-1); } + virtual void MenuRight( const InputEventPlus &input ) { DoScroll(+1); } + virtual void MenuUp( const InputEventPlus &input ) { DoScroll(-1); } + virtual void MenuDown( const InputEventPlus &input ) { DoScroll(+1); } + +private: + void DoScroll( int iDir ); + + ThemeMetric MANUAL_SCROLLING; + ThemeMetric HIGH_SCORES_TYPE; + ThemeMetric NUM_COLUMNS; + ThemeMetric1D COLUMN_DIFFICULTY; + ThemeMetric1D COLUMN_STEPS_TYPE; + ThemeMetric MAX_ITEMS_TO_SHOW; + ScoreScroller m_Scroller; +}; + +#endif + +/* + * (c) 2001-2007 Chris Danford, Ben Nordstrom, 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. + */ diff --git a/stepmania/src/ScreenRanking.cpp b/stepmania/src/ScreenRanking.cpp index d92a68d37f..f2bde617c7 100644 --- a/stepmania/src/ScreenRanking.cpp +++ b/stepmania/src/ScreenRanking.cpp @@ -1,421 +1,65 @@ #include "global.h" #include "ScreenRanking.h" #include "ScreenManager.h" -#include "ThemeManager.h" +//#include "ThemeManager.h" #include "SongManager.h" #include "GameState.h" #include "GameManager.h" -#include "Course.h" -#include "Song.h" -#include "Steps.h" -#include "ActorUtil.h" +//#include "Course.h" +//#include "Song.h" +//#include "Steps.h" +//#include "ActorUtil.h" #include "ProfileManager.h" #include "Profile.h" -#include "RageLog.h" -#include "UnlockManager.h" -#include "ScreenDimensions.h" -#include "PercentageDisplay.h" +//#include "RageLog.h" +//#include "UnlockManager.h" +//#include "ScreenDimensions.h" +//#include "PercentageDisplay.h" -static const char *RankingPageTypeNames[] = { + +static const char *RankingTypeNames[] = { "Category", "Course", - "AllSteps", - "NonstopCourses", - "OniCourses", - "SurvivalCourses", - "AllCourses", }; -StringToX( RankingPageType ); +XToString( RankingType ); +LuaXType( RankingType ); AutoScreenMessage( SM_ShowNextPage ) AutoScreenMessage( SM_HidePage ) +REGISTER_SCREEN_CLASS( ScreenRanking ); -static void GetAllSongsToShow( vector &vpOut, bool bShowOnlyMostRecentScores, int iNumMostRecentScoresToShow ) -{ - vpOut.clear(); - FOREACH_CONST( Song*, SONGMAN->GetSongs(), s ) - { - if( !(*s)->NormallyDisplayed() ) - continue; // skip - if( !(*s)->ShowInDemonstrationAndRanking() ) - continue; // skip - vpOut.push_back( *s ); - } - - if( bShowOnlyMostRecentScores ) - { - SongUtil::SortSongPointerArrayByTitle( vpOut ); - SongUtil::SortByMostRecentlyPlayedForMachine( vpOut ); - if( (int) vpOut.size() > iNumMostRecentScoresToShow ) - vpOut.erase( vpOut.begin()+iNumMostRecentScoresToShow, vpOut.end() ); - } -} - -static void GetAllCoursesToShow( vector &vpOut, CourseType ct, bool bShowOnlyMostRecentScores, int iNumMostRecentScoresToShow ) -{ - vpOut.clear(); - vector vpCourses; - if( ct == CourseType_Invalid ) - SONGMAN->GetAllCourses( vpCourses, false ); - else - SONGMAN->GetCourses( ct, vpCourses, false ); - - FOREACH_CONST( Course*, vpCourses, c) - { - if( UNLOCKMAN->CourseIsLocked(*c) ) - continue; // skip - if( !(*c)->ShowInDemonstrationAndRanking() ) - continue; // skip - vpOut.push_back( *c ); - } - if( bShowOnlyMostRecentScores ) - { - CourseUtil::SortCoursePointerArrayByTitle( vpOut ); - CourseUtil::SortByMostRecentlyPlayedForMachine( vpOut ); - if( (int) vpOut.size() > iNumMostRecentScoresToShow ) - vpOut.erase( vpOut.begin()+iNumMostRecentScoresToShow, vpOut.end() ); - } -} +#define BULLET_X(row) (BULLET_START_X+ROW_SPACING_X*row) +#define BULLET_Y(row) (BULLET_START_Y+ROW_SPACING_Y*row) +#define NAME_X(row) (NAME_START_X+ROW_SPACING_X*row) +#define NAME_Y(row) (NAME_START_Y+ROW_SPACING_Y*row) +#define SCORE_X(row) (SCORE_START_X+ROW_SPACING_X*row) +#define SCORE_Y(row) (SCORE_START_Y+ROW_SPACING_Y*row) +#define POINTS_X(row) (POINTS_START_X+ROW_SPACING_X*row) +#define POINTS_Y(row) (POINTS_START_Y+ROW_SPACING_Y*row) +#define TIME_X(row) (TIME_START_X+ROW_SPACING_X*row) +#define TIME_Y(row) (TIME_START_Y+ROW_SPACING_Y*row) static RString STEPS_TYPE_COLOR_NAME( size_t i ) { return ssprintf("StepsTypeColor%d",int(i+1)); } -REGISTER_SCREEN_CLASS( ScreenRanking ); -REGISTER_SCREEN_CLASS( ScreenRankingScroller ); -REGISTER_SCREEN_CLASS( ScreenRankingLines ); - void ScreenRanking::Init() { - RANKING_PAGE_TYPE.Load ( m_sName,"RankingPageType"); - COURSES_TO_SHOW.Load ( m_sName,"CoursesToShow"); STEPS_TYPES_TO_SHOW.Load( m_sName,"StepsTypesToHide" ); // tricky: The metric name is "hide" because ThemeMetricStepsTypesToShow takes a list of what to hide and returns what StepsTypes to show - SECONDS_PER_PAGE.Load ( m_sName,"SecondsPerPage" ); PAGE_FADE_SECONDS.Load ( m_sName,"PageFadeSeconds" ); - MANUAL_SCROLLING.Load ( m_sName, "ManualScrolling" ); ScreenAttract::Init(); - m_RankingPageType = StringToRankingPageType( RANKING_PAGE_TYPE ); - m_textStepsType.SetName( "StepsType" ); - m_textStepsType.LoadFromFont( THEME->GetPathF(m_sName,"steps type") ); + m_textStepsType.LoadFromFont( THEME->GetPathF(m_sName,"StepsType") ); m_textStepsType.SetShadowLength( 0 ); this->AddChild( &m_textStepsType ); LOAD_ALL_COMMANDS( m_textStepsType ); -} -void ScreenRanking::BeginScreen() -{ - m_iNextPageToShow = 0; - ScreenAttract::BeginScreen(); + RANKING_TYPE.Load ( m_sName,"RankingType"); + COURSES_TO_SHOW.Load ( m_sName,"CoursesToShow"); + SECONDS_PER_PAGE.Load ( m_sName,"SecondsPerPage" ); - this->HandleScreenMessage( SM_ShowNextPage ); -} - -void ScreenRanking::Input( const InputEventPlus &input ) -{ - LOG->Trace( "ScreenRanking::Input()" ); - - if( IsTransitioning() ) - return; - - // If manually scrolling, then pass the input to Scree::Input so it will call Menu* - if( (bool)MANUAL_SCROLLING ) - Screen::Input( input ); - else - ScreenAttract::Input( input ); -} - -void ScreenRanking::MenuStart( const InputEventPlus &input ) -{ - if( !MANUAL_SCROLLING ) - return; - if( !IsTransitioning() ) - StartTransitioningScreen( SM_GoToNextScreen ); - SCREENMAN->PlayStartSound(); -} - -void ScreenRanking::MenuBack( const InputEventPlus &input ) -{ - if( !MANUAL_SCROLLING ) - return; - if( !IsTransitioning() ) - StartTransitioningScreen( SM_GoToNextScreen ); - SCREENMAN->PlayStartSound(); -} - -void ScreenRanking::HandleScreenMessage( const ScreenMessage SM ) -{ - if( SM == SM_ShowNextPage ) - { - if( m_iNextPageToShow < m_vPagesToShow.size() ) - { - float fSecsToShow = SetPage( m_vPagesToShow[m_iNextPageToShow] ); - ++m_iNextPageToShow; - this->SortByDrawOrder(); - - // If manually scrolling, don't automatically change pages. - if( !(bool)MANUAL_SCROLLING ) - this->PostScreenMessage( SM_HidePage, fSecsToShow-PAGE_FADE_SECONDS ); - } - else - { - StartTransitioningScreen(SM_GoToNextScreen); - } - } - else if( SM == SM_HidePage ) - { - this->PlayCommand( "SwitchPage" ); - this->PostScreenMessage( SM_ShowNextPage, PAGE_FADE_SECONDS ); - } - - ScreenAttract::HandleScreenMessage( SM ); -} - -float ScreenRanking::SetPage( const PageToShow &pts ) -{ - // This is going to take a while to load. Possibly longer than one frame. - // So, zero the next update so we don't skip. - SCREENMAN->ZeroNextUpdate(); - - // - // init page - // - StepsType st = pts.aTypes.front().second; - m_textStepsType.SetText( GameManager::GetStepsTypeInfo(st).GetLocalizedString() ); - - return 0; -} - -void ScreenRankingScroller::DoScroll( int iDir ) -{ - if( !m_ListScoreRowItems.Scroll(iDir) ) - iDir = 0; - Message msg("Scrolled"); - msg.SetParam( "Dir", iDir ); - this->HandleMessage( msg ); -} - -///////////////////////////////////////////// - -ScoreScroller::ScoreScroller() -{ - this->DeleteChildrenWhenDone(); -} - -void ScoreScroller::SetDisplay( const vector &DifficultiesToShow ) -{ - m_DifficultiesToShow = DifficultiesToShow; - ShiftSubActors( INT_MAX ); -} - -bool ScoreScroller::Scroll( int iDir ) -{ - if( (int)m_vScoreRowItemData.size() <= SONG_SCORE_ROWS_TO_DRAW ) - return false; - - float fDest = GetDestinationItem(); - float fOldDest = fDest; - fDest += iDir; - float fLowClamp = (SONG_SCORE_ROWS_TO_DRAW-1)/2.0f; - float fHighClamp = m_vScoreRowItemData.size()-(SONG_SCORE_ROWS_TO_DRAW-1)/2.0f-1; - CLAMP( fDest, fLowClamp, fHighClamp ); - if( fOldDest != fDest ) - { - SetDestinationItem( fDest ); - return true; - } - else - { - return false; - } -} - -void ScoreScroller::ScrollTop() -{ - SetCurrentAndDestinationItem( (SONG_SCORE_ROWS_TO_DRAW-1)/2.0f ); -} - -void ScoreScroller::ConfigureActor( Actor *pActor, int iItem ) -{ - Actor &item = *dynamic_cast(pActor); - const ScoreRowItemData &data = m_vScoreRowItemData[iItem]; - - Message msg("Set"); - if( data.m_pSong != NULL ) - msg.SetParam( "Song", data.m_pSong ); - if( data.m_pCourse != NULL ) - msg.SetParam( "Course", data.m_pCourse ); - - Lua *L = LUA->Get(); - lua_newtable( L ); - lua_pushvalue( L, -1 ); - msg.SetParamFromStack( L, "Entries" ); - - FOREACH( DifficultyAndStepsType, m_DifficultiesToShow, iter ) - { - Difficulty dc = iter->first; - StepsType st = iter->second; - - if( data.m_pSong != NULL ) - { - const Song* pSong = data.m_pSong; - - Steps *pSteps = SongUtil::GetStepsByDifficulty( pSong, st, dc, false ); - if( pSteps && UNLOCKMAN->StepsIsLocked(pSong, pSteps) ) - continue; - - LuaHelpers::Push( L, pSteps ); - lua_rawseti( L, -2, lua_objlen(L, -2)+1 ); - } - else if( data.m_pCourse != NULL ) - { - const Course* pCourse = data.m_pCourse; - - Trail *pTrail = pCourse->GetTrail( st, dc ); - if( UNLOCKMAN->CourseIsLocked(pCourse) ) - continue; - - LuaHelpers::Push( L, pTrail ); - lua_rawseti( L, -2, lua_objlen(L, -2)+1 ); - } - } - lua_pop( L, 1 ); - LUA->Release( L ); - - item.HandleMessage( msg ); -} - -void ScoreScroller::LoadSongs( bool bOnlyRecentScores, int iNumRecentScores ) -{ - vector vpSongs; - GetAllSongsToShow( vpSongs, bOnlyRecentScores, iNumRecentScores ); - m_vScoreRowItemData.resize( vpSongs.size() ); - for( unsigned i=0; i vpCourses; - GetAllCoursesToShow( vpCourses, ct, bOnlyRecentScores, iNumRecentScores ); - m_vScoreRowItemData.resize( vpCourses.size() ); - for( unsigned i=0; iGetPathG(sClassName,"list item") ); - this->AddChild( pActor ); - } - - DynamicActorScroller::SetNumItemsToDraw( (float) SONG_SCORE_ROWS_TO_DRAW ); - DynamicActorScroller::Load2(); - - m_iNumItems = m_vScoreRowItemData.size(); -} - -void ScreenRankingScroller::Init() -{ - ThemeMetric SHOW_ONLY_MOST_RECENT_SCORES; - ThemeMetric DIFFICULTIES_TO_SHOW; - ThemeMetric NUM_MOST_RECENT_SCORES_TO_SHOW; - SHOW_ONLY_MOST_RECENT_SCORES.Load ( m_sName,"ShowOnlyMostRecentScores" ); - DIFFICULTIES_TO_SHOW.Load( m_sName, "DifficultiesToShow" ); - NUM_MOST_RECENT_SCORES_TO_SHOW.Load( m_sName, "NumMostRecentScoresToShow" ); - - ScreenRanking::Init(); - - m_ListScoreRowItems.SetName( "ListScoreRowItems" ); - LOAD_ALL_COMMANDS( m_ListScoreRowItems ); - switch( m_RankingPageType ) - { - default: ASSERT(0); - case RankingPageType_AllSteps: - m_ListScoreRowItems.LoadSongs( SHOW_ONLY_MOST_RECENT_SCORES, NUM_MOST_RECENT_SCORES_TO_SHOW ); - break; - case RankingPageType_NonstopCourses: - case RankingPageType_OniCourses: - case RankingPageType_SurvivalCourses: - case RankingPageType_AllCourses: - { - CourseType ct; - switch( m_RankingPageType ) - { - default: ASSERT(0); - case RankingPageType_NonstopCourses: ct = COURSE_TYPE_NONSTOP; break; - case RankingPageType_OniCourses: ct = COURSE_TYPE_ONI; break; - case RankingPageType_SurvivalCourses: ct = COURSE_TYPE_SURVIVAL; break; - case RankingPageType_AllCourses: ct = CourseType_Invalid; break; - } - - m_ListScoreRowItems.LoadCourses( ct, SHOW_ONLY_MOST_RECENT_SCORES, NUM_MOST_RECENT_SCORES_TO_SHOW ); - } - break; - } - - m_ListScoreRowItems.Load( m_sName ); - this->AddChild( &m_ListScoreRowItems ); - - for( unsigned i=0; i asDifficulties; - split( DIFFICULTIES_TO_SHOW, ",", asDifficulties ); - - PageToShow pts; - for( unsigned d=0; d asBits; - split( asDifficulties[d], ":", asBits, false ); - ASSERT( !asBits.empty() ); - Difficulty dc = StringToDifficulty(asBits[0]); - - StepsType st = STEPS_TYPES_TO_SHOW.GetValue()[i]; - if( asBits.size() > 1 ) - st = GameManager::StringToStepsType( asBits[1] ); - - pts.aTypes.push_back( make_pair(dc, st) ); - } - m_vPagesToShow.push_back( pts ); - } -} - -float ScreenRankingScroller::SetPage( const PageToShow &pts ) -{ - ScreenRanking::SetPage( pts ); - - m_ListScoreRowItems.SetDisplay( pts.aTypes ); - - if( (bool)MANUAL_SCROLLING ) - m_ListScoreRowItems.ScrollTop(); - else - m_ListScoreRowItems.ScrollThroughAllItems(); - - return m_ListScoreRowItems.GetSecondsForCompleteScrollThrough(); -} - -// RankingPageType_Category: -// RankingPageType_OneCourse: -#define BULLET_X(row) (BULLET_START_X+ROW_SPACING_X*row) -#define BULLET_Y(row) (BULLET_START_Y+ROW_SPACING_Y*row) -#define NAME_X(row) (NAME_START_X+ROW_SPACING_X*row) -#define NAME_Y(row) (NAME_START_Y+ROW_SPACING_Y*row) -#define SCORE_X(row) (SCORE_START_X+ROW_SPACING_X*row) -#define SCORE_Y(row) (SCORE_START_Y+ROW_SPACING_Y*row) -#define POINTS_X(row) (POINTS_START_X+ROW_SPACING_X*row) -#define POINTS_Y(row) (POINTS_START_Y+ROW_SPACING_Y*row) -#define TIME_X(row) (TIME_START_X+ROW_SPACING_X*row) -#define TIME_Y(row) (TIME_START_Y+ROW_SPACING_Y*row) - -void ScreenRankingLines::Init() -{ NO_SCORE_NAME.Load( m_sName,"NoScoreName" ); ROW_SPACING_X.Load( m_sName,"RowSpacingX" ); ROW_SPACING_Y.Load( m_sName,"RowSpacingY" ); @@ -431,9 +75,7 @@ void ScreenRankingLines::Init() TIME_START_Y.Load( m_sName, "TimeStartY" ); STEPS_TYPE_COLOR.Load( m_sName,STEPS_TYPE_COLOR_NAME,5 ); - ScreenRanking::Init(); - - if( m_RankingPageType == RankingPageType_Category ) + if( RANKING_TYPE == RankingType_Category ) { m_textCategory.SetName( "Category" ); m_textCategory.LoadFromFont( THEME->GetPathF(m_sName,"category") ); @@ -455,7 +97,7 @@ void ScreenRankingLines::Init() } } - if( m_RankingPageType == RankingPageType_OneCourse ) + if( RANKING_TYPE == RankingType_SpecificTrail ) { m_Banner.SetName( "Banner" ); this->AddChild( &m_Banner ); @@ -528,19 +170,63 @@ void ScreenRankingLines::Init() } } -float ScreenRankingLines::SetPage( const PageToShow &pts ) +void ScreenRanking::BeginScreen() { - ScreenRanking::SetPage( pts ); + m_iNextPageToShow = 0; + + ScreenAttract::BeginScreen(); + + this->HandleScreenMessage( SM_ShowNextPage ); +} + +void ScreenRanking::HandleScreenMessage( const ScreenMessage SM ) +{ + if( SM == SM_ShowNextPage ) + { + if( m_iNextPageToShow < m_vPagesToShow.size() ) + { + float fSecsToShow = SetPage( m_vPagesToShow[m_iNextPageToShow] ); + ++m_iNextPageToShow; + this->SortByDrawOrder(); + + this->PostScreenMessage( SM_HidePage, fSecsToShow-PAGE_FADE_SECONDS ); + } + else + { + StartTransitioningScreen(SM_GoToNextScreen); + } + } + else if( SM == SM_HidePage ) + { + this->PlayCommand( "SwitchPage" ); + this->PostScreenMessage( SM_ShowNextPage, PAGE_FADE_SECONDS ); + } + + ScreenAttract::HandleScreenMessage( SM ); +} + +float ScreenRanking::SetPage( const PageToShow &pts ) +{ + // This is going to take a while to load. Possibly longer than one frame. + // So, zero the next update so we don't skip. + SCREENMAN->ZeroNextUpdate(); + + // + // init page + // + StepsType st = pts.aTypes.front().second; + m_textStepsType.SetText( GameManager::GetStepsTypeInfo(st).GetLocalizedString() ); + bool bShowScores = false; bool bShowPoints = false; bool bShowTime = false; - switch( m_RankingPageType ) + switch( RANKING_TYPE ) { - case RankingPageType_Category: + case RankingType_Category: bShowScores = true; break; - case RankingPageType_OneCourse: + case RankingType_SpecificTrail: bShowScores = !pts.pCourse->IsOni(); bShowPoints = pts.pCourse->IsOni(); bShowTime = pts.pCourse->IsOni(); @@ -561,16 +247,16 @@ float ScreenRankingLines::SetPage( const PageToShow &pts ) m_textTime[l].SetDiffuse( STEPS_TYPE_COLOR.GetValue(pts.colorIndex) ); } - switch( m_RankingPageType ) + switch( RANKING_TYPE ) { - case RankingPageType_Category: + case RankingType_Category: { m_textCategory.SetText( ssprintf("Type %c", 'A'+pts.category) ); for( int l=0; lGetMachineProfile()->GetCategoryHighScoreList(st, pts.category); + HighScoreList &hsl = PROFILEMAN->GetMachineProfile()->GetCategoryHighScoreList(st, pts.category); HighScore hs; bool bRecentHighScore = false; if( l < (int)hsl.vHighScores.size() ) @@ -602,7 +288,7 @@ float ScreenRankingLines::SetPage( const PageToShow &pts ) } } return SECONDS_PER_PAGE; - case RankingPageType_OneCourse: + case RankingType_SpecificTrail: { m_textCourseTitle.SetText( pts.pCourse->GetDisplayFullTitle() ); @@ -659,11 +345,6 @@ float ScreenRankingLines::SetPage( const PageToShow &pts ) } } -void ScreenRankingLines::BeginScreen() -{ - ScreenRanking::BeginScreen(); -} - /* * (c) 2001-2007 Chris Danford, Glenn Maynard * All rights reserved. diff --git a/stepmania/src/ScreenRanking.h b/stepmania/src/ScreenRanking.h index a235168ae2..161e8ce69a 100644 --- a/stepmania/src/ScreenRanking.h +++ b/stepmania/src/ScreenRanking.h @@ -1,36 +1,34 @@ -#ifndef SCREEN_RANKING_H -#define SCREEN_RANKING_H +#ifndef ScreenRanking_H +#define ScreenRanking_H #include "ScreenAttract.h" -#include "GameConstantsAndTypes.h" // for NUM_RANKING_LINES -#include "Course.h" +//#include "GameConstantsAndTypes.h" // for NUM_RANKING_LINES +//#include "Course.h" #include "BitmapText.h" #include "Banner.h" -#include "ActorScroller.h" -#include "DynamicActorScroller.h" -#include "ActorUtil.h" +//#include "ActorScroller.h" +//#include "DynamicActorScroller.h" +//#include "ActorUtil.h" #include "Difficulty.h" -#include "ThemeMetric.h" +//#include "ThemeMetric.h" #include "CommonMetrics.h" class Course; -class Song; +//class Song; class Trail; -struct HighScoreList; +//struct HighScoreList; typedef pair DifficultyAndStepsType; -enum RankingPageType +const int NUM_RANKING_LINES = 5; + +enum RankingType { - RankingPageType_Category, // Top N for one Category - RankingPageType_OneCourse, // Top N for one Course - RankingPageType_AllSteps, // Top 1 for N Steps in each Song - RankingPageType_NonstopCourses, // Top 1 for N Trails in each Course - RankingPageType_OniCourses, - RankingPageType_SurvivalCourses, - RankingPageType_AllCourses, - NUM_RankingPageType, - RankingPageType_Invalid + RankingType_Category, // Top N HighScores for one Category + RankingType_SpecificTrail, // Top N HighScores for one Course and Trail + NUM_RankingType, + RankingType_Invalid }; +LuaDeclareType( RankingType ); class ScreenRanking : public ScreenAttract { @@ -38,10 +36,6 @@ public: virtual void Init(); virtual void BeginScreen(); - virtual void Input( const InputEventPlus &input ); - virtual void MenuStart( const InputEventPlus &input ); - virtual void MenuBack( const InputEventPlus &input ); - void HandleScreenMessage( const ScreenMessage SM ); protected: @@ -55,7 +49,11 @@ protected: int colorIndex; vector aTypes; + + // RankingPageType_Category RankingCategory category; + + // RankingPageType_SpecificCourses Course* pCourse; Trail* pTrail; }; @@ -67,71 +65,15 @@ protected: vector m_vPagesToShow; unsigned m_iNextPageToShow; - RankingPageType m_RankingPageType; - ThemeMetric RANKING_PAGE_TYPE; - ThemeMetric COURSES_TO_SHOW; // Don't use the version in CommonMetrics because we may have multiple // ranking screens that want to show different types and difficulties. ThemeMetricStepsTypesToShow STEPS_TYPES_TO_SHOW; - ThemeMetric SECONDS_PER_PAGE; ThemeMetric PAGE_FADE_SECONDS; - ThemeMetric MANUAL_SCROLLING; -}; -class ScoreScroller: public DynamicActorScroller -{ -public: - ScoreScroller(); - void LoadSongs( bool bOnlyRecentScores, int iNumRecentScores ); - void LoadCourses( CourseType ct, bool bOnlyRecentScores, int iNumRecentScores ); - void Load( RString sClassName ); - void SetDisplay( const vector &DifficultiesToShow ); - bool Scroll( int iDir ); - void ScrollTop(); -protected: - virtual void ConfigureActor( Actor *pActor, int iItem ); - vector m_DifficultiesToShow; - - struct ScoreRowItemData // for all_steps and all_courses - { - ScoreRowItemData() { m_pSong = NULL; m_pCourse = NULL; } - - Song *m_pSong; - Course *m_pCourse; - }; - vector m_vScoreRowItemData; - - ThemeMetric SONG_SCORE_ROWS_TO_DRAW; -}; - -class ScreenRankingScroller: public ScreenRanking -{ -public: - virtual void Init(); - - virtual void MenuLeft( const InputEventPlus &input ) { DoScroll(-1); } - virtual void MenuRight( const InputEventPlus &input ) { DoScroll(+1); } - virtual void MenuUp( const InputEventPlus &input ) { DoScroll(-1); } - virtual void MenuDown( const InputEventPlus &input ) { DoScroll(+1); } - -private: - void DoScroll( int iDir ); - virtual float SetPage( const PageToShow &pts ); - - ScoreScroller m_ListScoreRowItems; -}; - -static const int NUM_RANKING_LINES = 5; - -class ScreenRankingLines: public ScreenRanking -{ -public: - virtual void Init(); - virtual void BeginScreen(); - -private: - virtual float SetPage( const PageToShow &pts ); + ThemeMetric RANKING_TYPE; + ThemeMetric COURSES_TO_SHOW; + ThemeMetric SECONDS_PER_PAGE; Banner m_Banner; // for course BitmapText m_textCategory; // for category diff --git a/stepmania/src/StepMania-net2008.vcproj b/stepmania/src/StepMania-net2008.vcproj index 723a52c265..6a63abc167 100644 --- a/stepmania/src/StepMania-net2008.vcproj +++ b/stepmania/src/StepMania-net2008.vcproj @@ -461,6 +461,14 @@ RelativePath=".\ScreenGameplayShared.h" > + + + + @@ -726,11 +734,11 @@ >