split ScreenHighScores from ScreenRanking. These two things lived in the same file and shared enums, but shared almost no code.

This commit is contained in:
Chris Danford
2008-11-27 02:58:50 +00:00
parent 5764db221b
commit 4d2b0355f6
5 changed files with 584 additions and 487 deletions
+351
View File
@@ -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<Song*> &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<Course*> &vpOut, CourseType ct, int iNumMostRecentScoresToShow )
{
vpOut.clear();
vector<Course*> 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<DifficultyAndStepsType> &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<Actor *>(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<Song*> vpSongs;
GetAllSongsToShow( vpSongs, iNumRecentScores );
m_vScoreRowItemData.resize( vpSongs.size() );
for( unsigned i=0; i<m_vScoreRowItemData.size(); ++i )
m_vScoreRowItemData[i].m_pSong = vpSongs[i];
}
void ScoreScroller::LoadCourses( CourseType ct, int iNumRecentScores )
{
vector<Course*> vpCourses;
GetAllCoursesToShow( vpCourses, ct, iNumRecentScores );
m_vScoreRowItemData.resize( vpCourses.size() );
for( unsigned i=0; i<m_vScoreRowItemData.size(); ++i )
m_vScoreRowItemData[i].m_pCourse = vpCourses[i];
}
void ScoreScroller::Load( RString sMetricsGroup )
{
SCROLLER_ITEMS_TO_DRAW.Load(sMetricsGroup, "ScrollerItemsToDraw");
SCROLLER_SECONDS_PER_ITEM.Load(sMetricsGroup, "ScrollerSecondsPerItem");
int iNumCopies = SCROLLER_ITEMS_TO_DRAW+1;
for( int i=0; i<iNumCopies; ++i )
{
Actor *pActor = ActorUtil::MakeActor( THEME->GetPathG(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<DifficultyAndStepsType> vdast;
for( int i=0; i<NUM_COLUMNS; i++ )
{
DifficultyAndStepsType dast( COLUMN_DIFFICULTY.GetValue(i), COLUMN_STEPS_TYPE.GetValue(i) );
vdast.push_back( dast );
}
m_Scroller.SetDisplay( vdast );
if( (bool)MANUAL_SCROLLING )
m_Scroller.ScrollTop();
else
m_Scroller.ScrollThroughAllItems();
float fSecs = m_Scroller.GetSecondsForCompleteScrollThrough();
this->PostScreenMessage( 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.
*/
+115
View File
@@ -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<Difficulty, StepsType> 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<DifficultyAndStepsType> &DifficultiesToShow );
bool Scroll( int iDir );
void ScrollTop();
protected:
virtual void ConfigureActor( Actor *pActor, int iItem );
vector<DifficultyAndStepsType> m_DifficultiesToShow;
struct ScoreRowItemData // for all_steps and all_courses
{
ScoreRowItemData() { m_pSong = NULL; m_pCourse = NULL; }
Song *m_pSong;
Course *m_pCourse;
};
vector<ScoreRowItemData> m_vScoreRowItemData;
ThemeMetric<int> SCROLLER_ITEMS_TO_DRAW;
ThemeMetric<float> 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<bool> MANUAL_SCROLLING;
ThemeMetric<HighScoresType> HIGH_SCORES_TYPE;
ThemeMetric<int> NUM_COLUMNS;
ThemeMetric1D<Difficulty> COLUMN_DIFFICULTY;
ThemeMetric1D<StepsType> COLUMN_STEPS_TYPE;
ThemeMetric<int> 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.
*/
+83 -402
View File
@@ -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<Song*> &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<Course*> &vpOut, CourseType ct, bool bShowOnlyMostRecentScores, int iNumMostRecentScoresToShow )
{
vpOut.clear();
vector<Course*> 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<DifficultyAndStepsType> &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<Actor *>(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<Song*> vpSongs;
GetAllSongsToShow( vpSongs, bOnlyRecentScores, iNumRecentScores );
m_vScoreRowItemData.resize( vpSongs.size() );
for( unsigned i=0; i<m_vScoreRowItemData.size(); ++i )
m_vScoreRowItemData[i].m_pSong = vpSongs[i];
}
void ScoreScroller::LoadCourses( CourseType ct, bool bOnlyRecentScores, int iNumRecentScores )
{
vector<Course*> vpCourses;
GetAllCoursesToShow( vpCourses, ct, bOnlyRecentScores, iNumRecentScores );
m_vScoreRowItemData.resize( vpCourses.size() );
for( unsigned i=0; i<m_vScoreRowItemData.size(); ++i )
m_vScoreRowItemData[i].m_pCourse = vpCourses[i];
}
void ScoreScroller::Load( RString sClassName )
{
SONG_SCORE_ROWS_TO_DRAW.Load(sClassName, "SongScoreRowsToDraw");
int iNumCopies = SONG_SCORE_ROWS_TO_DRAW+1;
for( int i=0; i<iNumCopies; ++i )
{
Actor *pActor = ActorUtil::MakeActor( THEME->GetPathG(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<bool> SHOW_ONLY_MOST_RECENT_SCORES;
ThemeMetric<RString> DIFFICULTIES_TO_SHOW;
ThemeMetric<int> 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<STEPS_TYPES_TO_SHOW.GetValue().size(); i++ )
{
vector<RString> asDifficulties;
split( DIFFICULTIES_TO_SHOW, ",", asDifficulties );
PageToShow pts;
for( unsigned d=0; d<asDifficulties.size(); ++d )
{
vector<RString> 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; l<NUM_RANKING_LINES; l++ )
{
StepsType st = pts.aTypes.front().second;
HighScoreList& hsl = PROFILEMAN->GetMachineProfile()->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.
+25 -83
View File
@@ -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<Difficulty, StepsType> 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<DifficultyAndStepsType> aTypes;
// RankingPageType_Category
RankingCategory category;
// RankingPageType_SpecificCourses
Course* pCourse;
Trail* pTrail;
};
@@ -67,71 +65,15 @@ protected:
vector<PageToShow> m_vPagesToShow;
unsigned m_iNextPageToShow;
RankingPageType m_RankingPageType;
ThemeMetric<RString> RANKING_PAGE_TYPE;
ThemeMetric<RString> 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<float> SECONDS_PER_PAGE;
ThemeMetric<float> PAGE_FADE_SECONDS;
ThemeMetric<bool> 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<DifficultyAndStepsType> &DifficultiesToShow );
bool Scroll( int iDir );
void ScrollTop();
protected:
virtual void ConfigureActor( Actor *pActor, int iItem );
vector<DifficultyAndStepsType> m_DifficultiesToShow;
struct ScoreRowItemData // for all_steps and all_courses
{
ScoreRowItemData() { m_pSong = NULL; m_pCourse = NULL; }
Song *m_pSong;
Course *m_pCourse;
};
vector<ScoreRowItemData> m_vScoreRowItemData;
ThemeMetric<int> 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<RankingType> RANKING_TYPE;
ThemeMetric<RString> COURSES_TO_SHOW;
ThemeMetric<float> SECONDS_PER_PAGE;
Banner m_Banner; // for course
BitmapText m_textCategory; // for category
+10 -2
View File
@@ -461,6 +461,14 @@
RelativePath=".\ScreenGameplayShared.h"
>
</File>
<File
RelativePath=".\ScreenHighScores.cpp"
>
</File>
<File
RelativePath=".\ScreenHighScores.h"
>
</File>
<File
RelativePath="ScreenHowToPlay.cpp"
>
@@ -726,11 +734,11 @@
>
</File>
<File
RelativePath="ScreenRanking.cpp"
RelativePath=".\ScreenRanking.cpp"
>
</File>
<File
RelativePath="ScreenRanking.h"
RelativePath=".\ScreenRanking.h"
>
</File>
<File