From 804cc8b2bc1465d46d433723af4e58dad25fdafd Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Fri, 5 Aug 2005 04:20:46 +0000 Subject: [PATCH] working on profile management screen --- stepmania/src/Profile.cpp | 78 ++++++++++++++++++++++ stepmania/src/Profile.h | 4 ++ stepmania/src/ProfileManager.cpp | 8 +++ stepmania/src/ProfileManager.h | 1 + stepmania/src/ScreenOptionsEditProfile.cpp | 5 ++ 5 files changed, 96 insertions(+) diff --git a/stepmania/src/Profile.cpp b/stepmania/src/Profile.cpp index a9986e5ea8..46c3d55ab0 100644 --- a/stepmania/src/Profile.cpp +++ b/stepmania/src/Profile.cpp @@ -53,6 +53,27 @@ const unsigned int DEFAULT_WEIGHT_POUNDS = 120; #endif +int Profile::HighScoresForASong::GetNumTimesPlayed() const +{ + int iCount = 0; + FOREACHM_CONST( StepsID, HighScoresForASteps, m_StepsHighScores, i ) + { + iCount += i->second.hsl.GetNumTimesPlayed(); + } + return iCount; +} + +int Profile::HighScoresForACourse::GetNumTimesPlayed() const +{ + int iCount = 0; + FOREACHM_CONST( TrailID, HighScoresForATrail, m_TrailHighScores, i ) + { + iCount += i->second.hsl.GetNumTimesPlayed(); + } + return iCount; +} + + void Profile::InitEditableData() { m_sDisplayName = ""; @@ -517,6 +538,41 @@ bool Profile::IsCodeUnlocked( int iCode ) const return m_UnlockedSongs.find( iCode ) != m_UnlockedSongs.end(); } + +Song *Profile::GetMostPopularSong() const +{ + int iMaxNumTimesPlayed = 0; + SongID id; + FOREACHM_CONST( SongID, HighScoresForASong, m_SongHighScores, i ) + { + int iNumTimesPlayed = i->second.GetNumTimesPlayed(); + if( iNumTimesPlayed > iMaxNumTimesPlayed ) + { + id = i->first; + iMaxNumTimesPlayed = iNumTimesPlayed; + } + } + + return id.ToSong(); +} + +Course *Profile::GetMostPopularCourse() const +{ + int iMaxNumTimesPlayed = 0; + CourseID id; + FOREACHM_CONST( CourseID, HighScoresForACourse, m_CourseHighScores, i ) + { + int iNumTimesPlayed = i->second.GetNumTimesPlayed(); + if( iNumTimesPlayed > iMaxNumTimesPlayed ) + { + id = i->first; + iMaxNumTimesPlayed = iNumTimesPlayed; + } + } + + return id.ToCourse(); +} + // // Steps high scores // @@ -1875,6 +1931,25 @@ public: static int GetNumTotalSongsPlayed( T* p, lua_State *L ) { lua_pushnumber(L, p->m_iNumTotalSongsPlayed ); return 1; } static int GetLastPlayedStepsType( T* p, lua_State *L ) { lua_pushnumber(L, p->GetLastPlayedStepsType() ); return 1; } static int GetSongsAndCoursesPercentCompleteAllDifficulties( T* p, lua_State *L ) { lua_pushnumber(L, p->GetSongsAndCoursesPercentCompleteAllDifficulties((StepsType)IArg(1)) ); return 1; } + static int GetDisplayTotalCaloriesBurned( T* p, lua_State *L ) { lua_pushstring(L, p->GetDisplayTotalCaloriesBurned() ); return 1; } + static int GetMostPopularSong( T* p, lua_State *L ) + { + Song *p2 = p->GetMostPopularSong(); + if( p2 ) + p2->PushSelf(L); + else + lua_pushnil( L ); + return 1; + } + static int GetMostPopularCourse( T* p, lua_State *L ) + { + Course *p2 = p->GetMostPopularCourse(); + if( p2 ) + p2->PushSelf(L); + else + lua_pushnil( L ); + return 1; + } static void Register(lua_State *L) { @@ -1903,6 +1978,9 @@ public: ADD_METHOD( GetNumTotalSongsPlayed ) ADD_METHOD( GetLastPlayedStepsType ) ADD_METHOD( GetSongsAndCoursesPercentCompleteAllDifficulties ) + ADD_METHOD( GetDisplayTotalCaloriesBurned ) + ADD_METHOD( GetMostPopularSong ) + ADD_METHOD( GetMostPopularCourse ) Luna::Register( L ); } diff --git a/stepmania/src/Profile.h b/stepmania/src/Profile.h index 3507074894..c69613ff57 100644 --- a/stepmania/src/Profile.h +++ b/stepmania/src/Profile.h @@ -87,6 +87,8 @@ public: bool GetDefaultModifiers( const Game* pGameType, CString &sModifiersOut ) const; void SetDefaultModifiers( const Game* pGameType, const CString &sModifiers ); bool IsCodeUnlocked( int iCode ) const; + Song *GetMostPopularSong() const; + Course *GetMostPopularCourse() const; void AddStepTotals( int iNumTapsAndHolds, int iNumJumps, int iNumHolds, int iNumRolls, int iNumMines, int iNumHands, float fCaloriesBurned ); @@ -154,6 +156,7 @@ public: struct HighScoresForASong { std::map m_StepsHighScores; + int GetNumTimesPlayed() const; }; std::map m_SongHighScores; @@ -179,6 +182,7 @@ public: struct HighScoresForACourse { std::map m_TrailHighScores; + int GetNumTimesPlayed() const; }; std::map m_CourseHighScores; diff --git a/stepmania/src/ProfileManager.cpp b/stepmania/src/ProfileManager.cpp index 9591ba2383..7bd609f14e 100644 --- a/stepmania/src/ProfileManager.cpp +++ b/stepmania/src/ProfileManager.cpp @@ -269,6 +269,14 @@ bool ProfileManager::SaveProfile( PlayerNumber pn ) const return b; } +bool ProfileManager::SaveLocalProfile( CString sProfileID ) +{ + Profile &profile = GetLocalProfile( sProfileID ); + CString sDir = LocalProfileIdToDir( sProfileID ); + bool b = profile.SaveAllToDir( sDir, PREFSMAN->m_bSignProfileData ); + return b; +} + void ProfileManager::UnloadProfile( PlayerNumber pn ) { m_sProfileDir[pn] = ""; diff --git a/stepmania/src/ProfileManager.h b/stepmania/src/ProfileManager.h index 8c572066f3..15956cb292 100644 --- a/stepmania/src/ProfileManager.h +++ b/stepmania/src/ProfileManager.h @@ -43,6 +43,7 @@ public: bool FastLoadProfileNameFromMemoryCard( CString sRootDir, CString &sName ) const; void SaveAllProfiles() const; bool SaveProfile( PlayerNumber pn ) const; + bool SaveLocalProfile( CString sProfileID ); void UnloadProfile( PlayerNumber pn ); // diff --git a/stepmania/src/ScreenOptionsEditProfile.cpp b/stepmania/src/ScreenOptionsEditProfile.cpp index dc8c6db0a6..6ed2af3e38 100644 --- a/stepmania/src/ScreenOptionsEditProfile.cpp +++ b/stepmania/src/ScreenOptionsEditProfile.cpp @@ -100,6 +100,11 @@ void ScreenOptionsEditProfile::GoToPrevScreen() void ScreenOptionsEditProfile::HandleScreenMessage( const ScreenMessage SM ) { + if( SM == SM_GoToNextScreen ) + { + PROFILEMAN->SaveLocalProfile( GAMESTATE->m_sEditLocalProfileID ); + } + ScreenOptions::HandleScreenMessage( SM ); }