diff --git a/stepmania/src/ScreenRanking.cpp b/stepmania/src/ScreenRanking.cpp index 5d8c0e8795..f0e3cdfad4 100644 --- a/stepmania/src/ScreenRanking.cpp +++ b/stepmania/src/ScreenRanking.cpp @@ -25,15 +25,11 @@ static const char *PageTypeNames[] = { "SurvivalCourses", "AllCourses", }; -XToString( PageType ); StringToX( PageType ); #define TYPE THEME->GetMetric(m_sName,"Type") #define COURSES_TO_SHOW THEME->GetMetric(m_sName,"CoursesToShow") -#define DIFFICULTY_X(col) (DIFFICULTY_START_X+COL_SPACING_X*col) -#define SCORE_OFFSET_X(col) (SCORE_OFFSET_START_X+COL_SPACING_X*col) - AutoScreenMessage( SM_ShowNextPage ) AutoScreenMessage( SM_HidePage ) @@ -101,14 +97,8 @@ void ScreenRanking::Init() // watch out: ThemeMetricStepsTypesToShow inverts the results STEPS_TYPES_TO_SHOW.Load ( m_sName,"StepsTypesToHide" ); - ROW_SPACING_X.Load ( m_sName,"RowSpacingX" ); - ROW_SPACING_Y.Load ( m_sName,"RowSpacingY" ); - - STEPS_TYPE_COLOR.Load ( m_sName,STEPS_TYPE_COLOR_NAME,5 ); - SHOW_ONLY_MOST_RECENT_SCORES.Load ( m_sName,"ShowOnlyMostRecentScores" ); SECONDS_PER_PAGE.Load ( m_sName,"SecondsPerPage" ); PAGE_FADE_SECONDS.Load ( m_sName,"PageFadeSeconds" ); - NO_SCORE_NAME.Load ( m_sName,"NoScoreName" ); MANUAL_SCROLLING.Load ( m_sName, "ManualScrolling" ); ScreenAttract::Init(); @@ -196,17 +186,18 @@ float ScreenRanking::SetPage( const PageToShow &pts ) // // init page // - m_textStepsType.SetText( GameManager::StepsTypeToLocalizedString(pts.st) ); + m_textStepsType.SetText( GameManager::StepsTypeToLocalizedString(pts.aTypes.front().second) ); return 0; } void ScreenRankingScroller::DoScroll( int iDir ) { - if( m_ListScoreRowItems.Scroll(iDir) ) - m_soundChange.Play(); - else - SCREENMAN->PlayInvalidSound(); + if( !m_ListScoreRowItems.Scroll(iDir) ) + iDir = 0; + Message msg("Scrolled"); + msg.SetParam( "Dir", iDir ); + this->HandleMessage( msg ); } ///////////////////////////////////////////// @@ -216,31 +207,22 @@ ScoreScroller::ScoreScroller() this->DeleteChildrenWhenDone(); } -void ScoreScroller::SetStepsType( StepsType st, RageColor color ) +void ScoreScroller::SetDisplay( const vector &DifficultiesToShow ) { - m_StepsType = st; - - for( unsigned s=0; sm_textScore[*cd].SetDiffuse( color ); - } - + m_DifficultiesToShow = DifficultiesToShow; ShiftSubActors( INT_MAX ); } bool ScoreScroller::Scroll( int iDir ) { - if( (int)m_vScoreRowItemData.size() <= m_metricSongScoreRowsToDraw ) + if( (int)m_vScoreRowItemData.size() <= SONG_SCORE_ROWS_TO_DRAW ) return false; float fDest = GetDestinationItem(); float fOldDest = fDest; fDest += iDir; - float fLowClamp = (m_metricSongScoreRowsToDraw-1)/2.0f; - float fHighClamp = m_vScoreRowItemData.size()-(m_metricSongScoreRowsToDraw-1)/2.0f-1; + 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 ) { @@ -255,75 +237,57 @@ bool ScoreScroller::Scroll( int iDir ) void ScoreScroller::ScrollTop() { - SetCurrentAndDestinationItem( (m_metricSongScoreRowsToDraw-1)/2.0f ); + SetCurrentAndDestinationItem( (SONG_SCORE_ROWS_TO_DRAW-1)/2.0f ); } void ScoreScroller::ConfigureActor( Actor *pActor, int iItem ) { - ScoreRowItemData &data = m_vScoreRowItemData[iItem]; + Actor &item = *dynamic_cast(pActor); + const ScoreRowItemData &data = m_vScoreRowItemData[iItem]; + + Message msg("Set"); if( data.m_pSong != NULL ) - { - ScoreRowItem &item = *(ScoreRowItem *) pActor; - const Song* pSong = data.m_pSong; + msg.SetParam( "Song", data.m_pSong ); + if( data.m_pCourse != NULL ) + msg.SetParam( "Course", data.m_pCourse ); - item.m_textTitle.SetText( pSong->GetDisplayFullTitle() ); - item.m_textTitle.SetDiffuse( SONGMAN->GetSongColor(pSong) ); + Lua *L = LUA->Get(); + lua_newtable( L ); + lua_pushvalue( L, -1 ); + msg.SetParamFromStack( L, "Entries" ); - FOREACH_CONST( Difficulty, m_DifficultiesToShow, iter ) - { - const Steps* pSteps = SongUtil::GetStepsByDifficulty( pSong, m_StepsType, *iter, false ); - if( pSteps && UNLOCKMAN->StepsIsLocked(pSong, pSteps) ) - pSteps = NULL; - BitmapText* pTextStepsScore = &item.m_textScore[*iter]; - pTextStepsScore->SetVisible( pSteps != NULL ); - if( pSteps == NULL ) - continue; + FOREACH( DifficultyAndStepsType, m_DifficultiesToShow, iter ) + { + Difficulty dc = iter->first; + StepsType st = iter->second; - const HighScoreList &hsl = PROFILEMAN->GetMachineProfile()->GetStepsHighScoreList(pSong,pSteps); - SetScoreFromHighScoreList( pTextStepsScore, hsl ); - } - } - else if( data.m_pCourse != NULL ) - { - const Course* pCourse = data.m_pCourse; - - ScoreRowItem &item = *(ScoreRowItem *) pActor; - item.m_textTitle.SetText( pCourse->GetDisplayFullTitle() ); - item.m_textTitle.SetDiffuse( SONGMAN->GetCourseColor(pCourse) ); - - FOREACH_CONST( Difficulty, m_DifficultiesToShow, cd ) + if( data.m_pSong != NULL ) { - BitmapText* pTextStepsScore = &item.m_textScore[*cd]; + const Song* pSong = data.m_pSong; - const Trail *pTrail = pCourse->GetTrail( m_StepsType, *cd ); - if( UNLOCKMAN->CourseIsLocked(pCourse) ) - pTrail = NULL; - pTextStepsScore->SetVisible( pTrail != NULL ); - if( pTrail == NULL ) + Steps *pSteps = SongUtil::GetStepsByDifficulty( pSong, st, dc, false ); + if( pSteps && UNLOCKMAN->StepsIsLocked(pSong, pSteps) ) continue; - const HighScoreList &hsl = PROFILEMAN->GetMachineProfile()->GetCourseHighScoreList( pCourse, pTrail ); - SetScoreFromHighScoreList( pTextStepsScore, hsl ); + 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 ); -ScoreScroller::ScoreRowItem::ScoreRowItem() -{ - this->AddChild( &m_textTitle ); -} - -ScoreScroller::ScoreRowItem::ScoreRowItem( const ScoreRowItem &cpy ): - ActorFrame( cpy ), - m_sprFrame( cpy.m_sprFrame ), - m_textTitle( cpy.m_textTitle ), - m_textScore( cpy.m_textScore ) -{ - if( m_sprFrame.IsLoaded() ) - this->AddChild( m_sprFrame ); - this->AddChild( &m_textTitle ); - FOREACH( BitmapText, m_textScore, bt ) - this->AddChild( &*bt ); + item.HandleMessage( msg ); } void ScoreScroller::LoadSongs( bool bOnlyRecentScores, int iNumRecentScores ) @@ -344,76 +308,34 @@ void ScoreScroller::LoadCourses( CourseType ct, bool bOnlyRecentScores, int iNum m_vScoreRowItemData[i].m_pCourse = vpCourses[i]; } -void ScoreScroller::Load( - RString sClassName, - const vector &DifficultiesToShow, - float fItemHeight ) +void ScoreScroller::Load( RString sClassName ) { - SCORE_OFFSET_START_X.Load (sClassName, "ScoreOffsetStartX"); - SCORE_OFFSET_Y.Load (sClassName, "ScoreOffsetY"); - NO_SCORE_NAME.Load (sClassName, "NoScoreName"); - COL_SPACING_X.Load (sClassName, "ColSpacingX"); - SONG_SCORE_SECONDS_PER_ROW.Load (sClassName, "SongScoreSecondsPerRow"); - m_metricSongScoreRowsToDraw.Load(sClassName, "SongScoreRowsToDraw"); + SONG_SCORE_ROWS_TO_DRAW.Load(sClassName, "SongScoreRowsToDraw"); - m_DifficultiesToShow = DifficultiesToShow; - - ScoreScroller::ScoreRowItem ItemTemplate; + int iNumCopies = SONG_SCORE_ROWS_TO_DRAW+1; + for( int i=0; iGetPathG(sClassName,"list frame") ); - ItemTemplate.m_sprFrame->SetName( "Frame" ); - ActorUtil::LoadAllCommands( *ItemTemplate.m_sprFrame, sClassName ); - - ItemTemplate.m_textTitle.SetName( "Title" ); - ItemTemplate.m_textTitle.LoadFromFont( THEME->GetPathF(sClassName,"list title") ); - ActorUtil::LoadAllCommands( ItemTemplate.m_textTitle, sClassName ); - - ItemTemplate.m_textScore.resize( NUM_Difficulty ); - FOREACH_CONST( Difficulty, m_DifficultiesToShow, d ) - { - ItemTemplate.m_textScore[*d].SetName( "Score" ); - ItemTemplate.m_textScore[*d].LoadFromFont( THEME->GetPathF(sClassName,"list score") ); - ItemTemplate.m_textScore[*d].SetXY( SCORE_OFFSET_X(*d), SCORE_OFFSET_Y ); - ActorUtil::LoadAllCommands( ItemTemplate.m_textScore[*d], sClassName ); - } + Actor *pActor = ActorUtil::MakeActor( THEME->GetPathG(sClassName,"list item") ); + this->AddChild( pActor ); } - int iNumCopies = m_metricSongScoreRowsToDraw+1; - for( int i=0; iAddChild( new ScoreRowItem(ItemTemplate) ); - - DynamicActorScroller::SetNumItemsToDraw( (float) m_metricSongScoreRowsToDraw ); + DynamicActorScroller::SetNumItemsToDraw( (float) SONG_SCORE_ROWS_TO_DRAW ); DynamicActorScroller::Load2(); - DynamicActorScroller::SetTransformFromHeight( fItemHeight ); - DynamicActorScroller::SetSecondsPerItem( SONG_SCORE_SECONDS_PER_ROW ); - DynamicActorScroller::EnableMask( SCREEN_WIDTH, fItemHeight ); - DynamicActorScroller::ScrollThroughAllItems(); 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" ); - - COL_SPACING_X.Load( m_sName, "ColSpacingX" ); - DIFFICULTY_START_X.Load( m_sName, "DifficultyStartX" ); - DIFFICULTY_Y.Load( m_sName, "DifficultyY" ); NUM_MOST_RECENT_SCORES_TO_SHOW.Load( m_sName, "NumMostRecentScoresToShow" ); ScreenRanking::Init(); - FOREACH_CONST( Difficulty, DIFFICULTIES_TO_SHOW.GetValue(), d ) - { - if( m_PageType == PageType_AllSteps ) - m_sprDifficulty[*d].Load( THEME->GetPathG(m_sName,"difficulty "+DifficultyToString(*d)) ); - else - m_sprDifficulty[*d].Load( THEME->GetPathG(m_sName,"CourseDifficulty "+DifficultyToString(*d)) ); - m_sprDifficulty[*d]->SetName( "Difficulty"+DifficultyToString(*d) ); - m_sprDifficulty[*d]->SetXY( DIFFICULTY_X(*d), DIFFICULTY_Y ); - this->AddChild( m_sprDifficulty[*d] ); - } - m_ListScoreRowItems.SetName( "ListScoreRowItems" ); LOAD_ALL_COMMANDS( m_ListScoreRowItems ); switch( m_PageType ) @@ -442,40 +364,37 @@ void ScreenRankingScroller::Init() break; } - m_ListScoreRowItems.Load( m_sName, DIFFICULTIES_TO_SHOW.GetValue(), ROW_SPACING_Y ); + m_ListScoreRowItems.Load( m_sName ); this->AddChild( &m_ListScoreRowItems ); for( unsigned i=0; i asDifficulties; + split( DIFFICULTIES_TO_SHOW, ",", asDifficulties ); + PageToShow pts; - pts.colorIndex = i; - pts.st = STEPS_TYPES_TO_SHOW.GetValue()[i]; + 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 = GAMEMAN->StringToStepsType( asBits[1] ); + + pts.aTypes.push_back( make_pair(dc, st) ); + } m_vPagesToShow.push_back( pts ); } - - m_soundChange.Load( THEME->GetPathS(m_sName,"change") ); -} - -void ScreenRankingScroller::BeginScreen() -{ - ScreenRanking::BeginScreen(); -} - -void ScoreScroller::SetScoreFromHighScoreList( BitmapText *pTextStepsScore, const HighScoreList &hsl ) -{ - HighScore hs = hsl.GetTopScore(); - if( hsl.vHighScores.empty() ) - hs.SetName( NO_SCORE_NAME ); - - RString s = hs.GetDisplayName() + "\n" + PercentageDisplay::FormatPercentScore( hs.GetPercentDP() ); - pTextStepsScore->SetText( s ); } float ScreenRankingScroller::SetPage( const PageToShow &pts ) { ScreenRanking::SetPage( pts ); - m_ListScoreRowItems.SetStepsType( pts.st, STEPS_TYPE_COLOR.GetValue(pts.colorIndex) ); + m_ListScoreRowItems.SetDisplay( pts.aTypes ); if( (bool)MANUAL_SCROLLING ) m_ListScoreRowItems.ScrollTop(); @@ -500,6 +419,9 @@ float ScreenRankingScroller::SetPage( const PageToShow &pts ) void ScreenRankingLines::Init() { + NO_SCORE_NAME.Load( m_sName,"NoScoreName" ); + ROW_SPACING_X.Load( m_sName,"RowSpacingX" ); + ROW_SPACING_Y.Load( m_sName,"RowSpacingY" ); BULLET_START_X.Load( m_sName, "BulletStartX" ); BULLET_START_Y.Load( m_sName, "BulletStartY" ); NAME_START_X.Load( m_sName, "NameStartX" ); @@ -510,6 +432,7 @@ void ScreenRankingLines::Init() POINTS_START_Y.Load( m_sName, "PointsStartY" ); TIME_START_X.Load( m_sName, "TimeStartX" ); TIME_START_Y.Load( m_sName, "TimeStartY" ); + STEPS_TYPE_COLOR.Load( m_sName,STEPS_TYPE_COLOR_NAME,5 ); ScreenRanking::Init(); @@ -528,7 +451,8 @@ void ScreenRankingLines::Init() PageToShow pts; pts.colorIndex = i; pts.category = (RankingCategory)c; - pts.st = STEPS_TYPES_TO_SHOW.GetValue()[i]; + StepsType st = STEPS_TYPES_TO_SHOW.GetValue()[i]; + pts.aTypes.push_back( make_pair(Difficulty_Invalid, st) ); m_vPagesToShow.push_back( pts ); } } @@ -554,12 +478,13 @@ void ScreenRankingLines::Init() { PageToShow pts; pts.colorIndex = i; - pts.st = STEPS_TYPES_TO_SHOW.GetValue()[i]; + StepsType st = STEPS_TYPES_TO_SHOW.GetValue()[i]; + pts.aTypes.push_back( make_pair(Difficulty_Invalid, st) ); pts.pCourse = SONGMAN->GetCourseFromPath( asCoursePaths[c] ); if( pts.pCourse == NULL ) continue; - pts.pTrail = pts.pCourse->GetTrail( pts.st ); + pts.pTrail = pts.pCourse->GetTrail( st ); if( pts.pTrail == NULL ) continue; @@ -647,7 +572,8 @@ float ScreenRankingLines::SetPage( const PageToShow &pts ) for( int l=0; lGetMachineProfile()->GetCategoryHighScoreList(pts.st,pts.category); + StepsType st = pts.aTypes.front().second; + HighScoreList& hsl = PROFILEMAN->GetMachineProfile()->GetCategoryHighScoreList(st, pts.category); HighScore hs; bool bRecentHighScore = false; if( l < (int)hsl.vHighScores.size() ) @@ -742,7 +668,7 @@ void ScreenRankingLines::BeginScreen() } /* - * (c) 2001-2005 Chris Danford, Glenn Maynard + * (c) 2001-2007 Chris Danford, Glenn Maynard * All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a diff --git a/stepmania/src/ScreenRanking.h b/stepmania/src/ScreenRanking.h index 5b8dbea9fe..00d7e961a1 100644 --- a/stepmania/src/ScreenRanking.h +++ b/stepmania/src/ScreenRanking.h @@ -12,12 +12,12 @@ #include "Difficulty.h" #include "ThemeMetric.h" #include "CommonMetrics.h" -#include "RageSound.h" class Course; class Song; class Trail; struct HighScoreList; +typedef pair DifficultyAndStepsType; enum PageType { @@ -31,8 +31,6 @@ enum PageType NUM_PageType, PageType_Invalid }; -#define FOREACH_PageType( pt ) FOREACH_ENUM( PageType, pt ) -const RString& PageTypeToString( PageType pt ); PageType StringToPageType( const RString& s ); class ScreenRanking : public ScreenAttract @@ -60,7 +58,7 @@ protected: } int colorIndex; - StepsType st; + vector aTypes; RankingCategory category; Course* pCourse; Trail* pTrail; @@ -78,14 +76,8 @@ protected: // 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 ROW_SPACING_X; - ThemeMetric ROW_SPACING_Y; - ThemeMetric1D STEPS_TYPE_COLOR; - - ThemeMetric SHOW_ONLY_MOST_RECENT_SCORES; ThemeMetric SECONDS_PER_PAGE; ThemeMetric PAGE_FADE_SECONDS; - LocalizedString NO_SCORE_NAME; ThemeMetric MANUAL_SCROLLING; }; @@ -95,28 +87,14 @@ public: ScoreScroller(); void LoadSongs( bool bOnlyRecentScores, int iNumRecentScores ); void LoadCourses( CourseType ct, bool bOnlyRecentScores, int iNumRecentScores ); - void Load( - RString sClassName, - const vector &DifficultiesToShow, - float fItemHeight ); - void SetStepsType( StepsType st, RageColor color ); + void Load( RString sClassName ); + void SetDisplay( const vector &DifficultiesToShow ); bool Scroll( int iDir ); void ScrollTop(); protected: virtual void ConfigureActor( Actor *pActor, int iItem ); - void SetScoreFromHighScoreList( BitmapText *pTextStepsScore, const HighScoreList &hsl ); - StepsType m_StepsType; - vector m_DifficultiesToShow; - - struct ScoreRowItem: public ActorFrame - { - ScoreRowItem(); - ScoreRowItem( const ScoreRowItem &cpy ); - AutoActor m_sprFrame; - BitmapText m_textTitle; - vector m_textScore; - }; + vector m_DifficultiesToShow; struct ScoreRowItemData // for all_steps and all_courses { @@ -127,19 +105,13 @@ protected: }; vector m_vScoreRowItemData; - ThemeMetric SCORE_OFFSET_START_X; - ThemeMetric SCORE_OFFSET_Y; - LocalizedString NO_SCORE_NAME; - ThemeMetric COL_SPACING_X; - ThemeMetric SONG_SCORE_SECONDS_PER_ROW; - ThemeMetric m_metricSongScoreRowsToDraw; + ThemeMetric SONG_SCORE_ROWS_TO_DRAW; }; class ScreenRankingScroller: public ScreenRanking { public: virtual void Init(); - virtual void BeginScreen(); virtual void MenuLeft( const InputEventPlus &input ) { DoScroll(-1); } virtual void MenuRight( const InputEventPlus &input ) { DoScroll(+1); } @@ -151,16 +123,6 @@ private: virtual float SetPage( const PageToShow &pts ); ScoreScroller m_ListScoreRowItems; - - AutoActor m_sprDifficulty[NUM_Difficulty]; // for all_steps - - ThemeMetricDifficultiesToShow DIFFICULTIES_TO_SHOW; - ThemeMetric COL_SPACING_X; - ThemeMetric DIFFICULTY_START_X; - ThemeMetric DIFFICULTY_Y; - ThemeMetric NUM_MOST_RECENT_SCORES_TO_SHOW; - - RageSound m_soundChange; }; static const int NUM_RANKING_LINES = 5; @@ -183,7 +145,11 @@ private: BitmapText m_textScores[NUM_RANKING_LINES]; // for category and course BitmapText m_textPoints[NUM_RANKING_LINES]; // for course BitmapText m_textTime[NUM_RANKING_LINES]; // for course + ThemeMetric1D STEPS_TYPE_COLOR; + LocalizedString NO_SCORE_NAME; + ThemeMetric ROW_SPACING_X; + ThemeMetric ROW_SPACING_Y; ThemeMetric BULLET_START_X; ThemeMetric BULLET_START_Y; ThemeMetric NAME_START_X; @@ -199,7 +165,7 @@ private: #endif /* - * (c) 2001-2005 Chris Danford, Ben Nordstrom, Glenn Maynard + * (c) 2001-2007 Chris Danford, Ben Nordstrom, Glenn Maynard * All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a