diff --git a/targets/Minecraft.Client/Common/src/Leaderboards/LeaderboardInterface.cpp b/targets/Minecraft.Client/Common/src/Leaderboards/LeaderboardInterface.cpp index f530c9234..843ac7277 100644 --- a/targets/Minecraft.Client/Common/src/Leaderboards/LeaderboardInterface.cpp +++ b/targets/Minecraft.Client/Common/src/Leaderboards/LeaderboardInterface.cpp @@ -4,14 +4,14 @@ #include "Minecraft.Client/Common/src/Leaderboards/LeaderboardManager.h" -LeaderboardInterface::LeaderboardInterface(LeaderboardManager* man) { +LeaderboardInterface::LeaderboardInterface(IPlatformLeaderboard* man) { m_manager = man; m_pending = false; - m_filter = (LeaderboardManager::EFilterMode)-1; + m_filter = (IPlatformLeaderboard::EFilterMode)-1; m_callback = nullptr; m_difficulty = 0; - m_type = LeaderboardManager::eStatsType_UNDEFINED; + m_type = IPlatformLeaderboard::eStatsType_UNDEFINED; m_startIndex = 0; m_readCount = 0; @@ -25,9 +25,9 @@ LeaderboardInterface::~LeaderboardInterface() { void LeaderboardInterface::ReadStats_Friends( LeaderboardReadListener* callback, int difficulty, - LeaderboardManager::EStatsType type, PlayerUID myUID, + IPlatformLeaderboard::EStatsType type, PlayerUID myUID, unsigned int startIndex, unsigned int readCount) { - m_filter = LeaderboardManager::eFM_Friends; + m_filter = IPlatformLeaderboard::eFM_Friends; m_pending = true; m_callback = callback; @@ -42,9 +42,9 @@ void LeaderboardInterface::ReadStats_Friends( void LeaderboardInterface::ReadStats_MyScore( LeaderboardReadListener* callback, int difficulty, - LeaderboardManager::EStatsType type, PlayerUID myUID, + IPlatformLeaderboard::EStatsType type, PlayerUID myUID, unsigned int readCount) { - m_filter = LeaderboardManager::eFM_MyScore; + m_filter = IPlatformLeaderboard::eFM_MyScore; m_pending = true; m_callback = callback; @@ -58,9 +58,9 @@ void LeaderboardInterface::ReadStats_MyScore( void LeaderboardInterface::ReadStats_TopRank( LeaderboardReadListener* callback, int difficulty, - LeaderboardManager::EStatsType type, unsigned int startIndex, + IPlatformLeaderboard::EStatsType type, unsigned int startIndex, unsigned int readCount) { - m_filter = LeaderboardManager::eFM_TopRank; + m_filter = IPlatformLeaderboard::eFM_TopRank; m_pending = true; m_callback = callback; @@ -83,14 +83,14 @@ void LeaderboardInterface::tick() { bool LeaderboardInterface::callManager() { switch (m_filter) { - case LeaderboardManager::eFM_Friends: + case IPlatformLeaderboard::eFM_Friends: return m_manager->ReadStats_Friends(m_callback, m_difficulty, m_type, m_myUID, m_startIndex, m_readCount); - case LeaderboardManager::eFM_MyScore: + case IPlatformLeaderboard::eFM_MyScore: return m_manager->ReadStats_MyScore(m_callback, m_difficulty, m_type, m_myUID, m_readCount); - case LeaderboardManager::eFM_TopRank: + case IPlatformLeaderboard::eFM_TopRank: return m_manager->ReadStats_TopRank( m_callback, m_difficulty, m_type, m_startIndex, m_readCount); default: diff --git a/targets/Minecraft.Client/Common/src/Leaderboards/LeaderboardInterface.h b/targets/Minecraft.Client/Common/src/Leaderboards/LeaderboardInterface.h index 53ac5133a..fcdb1df8e 100644 --- a/targets/Minecraft.Client/Common/src/Leaderboards/LeaderboardInterface.h +++ b/targets/Minecraft.Client/Common/src/Leaderboards/LeaderboardInterface.h @@ -6,30 +6,30 @@ // 4J-JEV: Simple interface for handling ReadStat failures. class LeaderboardInterface { private: - LeaderboardManager* m_manager; + IPlatformLeaderboard* m_manager; bool m_pending; // Arguments. - LeaderboardManager::EFilterMode m_filter; + IPlatformLeaderboard::EFilterMode m_filter; LeaderboardReadListener* m_callback; int m_difficulty; - LeaderboardManager::EStatsType m_type; + IPlatformLeaderboard::EStatsType m_type; PlayerUID m_myUID; unsigned int m_startIndex; unsigned int m_readCount; public: - LeaderboardInterface(LeaderboardManager* man); + LeaderboardInterface(IPlatformLeaderboard* man); ~LeaderboardInterface(); void ReadStats_Friends(LeaderboardReadListener* callback, int difficulty, - LeaderboardManager::EStatsType type, PlayerUID myUID, + IPlatformLeaderboard::EStatsType type, PlayerUID myUID, unsigned int startIndex, unsigned int readCount); void ReadStats_MyScore(LeaderboardReadListener* callback, int difficulty, - LeaderboardManager::EStatsType type, PlayerUID myUID, + IPlatformLeaderboard::EStatsType type, PlayerUID myUID, unsigned int readCount); void ReadStats_TopRank(LeaderboardReadListener* callback, int difficulty, - LeaderboardManager::EStatsType type, + IPlatformLeaderboard::EStatsType type, unsigned int startIndex, unsigned int readCount); void CancelOperation(); diff --git a/targets/Minecraft.Client/Common/src/Leaderboards/LeaderboardManager.cpp b/targets/Minecraft.Client/Common/src/Leaderboards/LeaderboardManager.cpp index 625792e8c..4f54dadea 100644 --- a/targets/Minecraft.Client/Common/src/Leaderboards/LeaderboardManager.cpp +++ b/targets/Minecraft.Client/Common/src/Leaderboards/LeaderboardManager.cpp @@ -80,7 +80,7 @@ void LeaderboardManager::printStats(ReadView& view) { "\tnumQueries=%i\n", view.m_numQueries); - for (int i = 0; i < view.m_numQueries; i++) { + for (unsigned int i = 0; i < view.m_numQueries; i++) { ReadScore score = view.m_queries[i]; app.DebugPrintf("\tname='%s'\n", @@ -95,8 +95,8 @@ void LeaderboardManager::printStats(ReadView& view) { } bool DebugReadListener::OnStatsReadComplete( - LeaderboardManager::eStatsReturn success, int numResults, - LeaderboardManager::ViewOut results) { + IPlatformLeaderboard::eStatsReturn success, int numResults, + IPlatformLeaderboard::ViewOut results) { app.DebugPrintf("[DebugReadListener] OnStatsReadComplete, %s:\n", (success ? "success" : "FAILED")); LeaderboardManager::printStats(results); diff --git a/targets/Minecraft.Client/Common/src/Leaderboards/LeaderboardManager.h b/targets/Minecraft.Client/Common/src/Leaderboards/LeaderboardManager.h index 09ded58c3..2031cacfb 100644 --- a/targets/Minecraft.Client/Common/src/Leaderboards/LeaderboardManager.h +++ b/targets/Minecraft.Client/Common/src/Leaderboards/LeaderboardManager.h @@ -2,187 +2,41 @@ #include -#include "4J.Common/4J_Compat.h" +#include "platform/IPlatformLeaderboard.h" -// Forward Declarations. -class LeaderboardManager; -// READ LISTENTER // -class LeaderboardReadListener; - -// ABSTRACT CLASS // -class LeaderboardManager { +class LeaderboardManager : public IPlatformLeaderboard { public: - enum eStatsReturn { - eStatsReturn_Success = 0, - eStatsReturn_NoResults, - eStatsReturn_NetworkError - }; - - enum eProperty_Kills { - eProperty_Kills_Zombie = 0, - eProperty_Kills_Skeleton, - eProperty_Kills_Creeper, - eProperty_Kills_Spider, - eProperty_Kills_SpiderJockey, - eProperty_Kills_ZombiePigman, - eProperty_Kills_Slime, - eProperty_Kills_Rating, - eProperty_Kills_Max, - }; - - enum eProperty_Mining { - eProperty_Mining_Dirt = 0, - eProperty_Mining_Stone, - eProperty_Mining_Sand, - eProperty_Mining_Cobblestone, - eProperty_Mining_Gravel, - eProperty_Mining_Clay, - eProperty_Mining_Obsidian, - eProperty_Mining_Rating, - eProperty_Mining_Max, - }; - - enum eProperty_Farming { - eProperty_Farming_Egg = 0, - eProperty_Farming_Wheat, - eProperty_Farming_Mushroom, - eProperty_Farming_Sugarcane, - eProperty_Farming_Milk, - eProperty_Farming_Pumpkin, - eProperty_Farming_Rating, - eProperty_Farming_Max, - }; - - enum eProperty_Travelling { - eProperty_Travelling_Walked = 0, - eProperty_Travelling_Fallen, - eProperty_Travelling_Minecart, - eProperty_Travelling_Boat, - eProperty_Travelling_Rating, - eProperty_Travelling_Max, - }; - - enum EStatsType { - eStatsType_Travelling = 0, - eStatsType_Mining, - eStatsType_Farming, - eStatsType_Kills, - eStatsType_MAX, - eStatsType_UNDEFINED - }; - - enum EFilterMode { - eFM_Friends = 0, // Stats belonging to current user's friends - eFM_MyScore, // Stats around the current user's rank - eFM_TopRank, // Stats at the top of the leaderboard - eNumFilterModes, - eFM_UNDEFINED - }; - static const std::wstring filterNames[eNumFilterModes]; - typedef struct KillsRecord { - public: - unsigned short m_zombie; - unsigned short m_skeleton; - unsigned short m_creeper; - unsigned short m_spider; - unsigned short m_spiderJockey; - unsigned short m_zombiePigman; - unsigned short m_slime; - } KillsRecord; - - typedef struct MiningRecord { - public: - unsigned short m_dirt; - unsigned short m_stone; - unsigned short m_sand; - unsigned short m_cobblestone; - unsigned short m_gravel; - unsigned short m_clay; - unsigned short m_obsidian; - } MiningRecord; - - typedef struct FarmingRecord { - public: - unsigned short m_eggs; - unsigned short m_wheat; - unsigned short m_mushroom; - unsigned short m_sugarcane; - unsigned short m_milk; - unsigned short m_pumpkin; - } FarmingRecord; - - typedef struct TravellingRecord { - public: - unsigned int m_walked; - unsigned int m_fallen; - unsigned int m_minecart; - unsigned int m_boat; - } TravellingRecord; - -public: - static const int RECORD_SIZE = 40; // base32 - - typedef struct StatsData { - EStatsType m_statsType; - union { - LeaderboardManager::KillsRecord m_kills; - LeaderboardManager::MiningRecord m_mining; - LeaderboardManager::FarmingRecord m_farming; - LeaderboardManager::TravellingRecord m_travelling; - unsigned char m_padding[RECORD_SIZE]; - }; - } StatsData; - - typedef struct RegisterScore { - int m_iPad; - int m_score; - int m_difficulty; - StatsData m_commentData; - } RegisterScore; - - typedef struct ReadScore { - // Maximum number of columns in a scoreboard. - static const unsigned int STATSDATA_MAX = 8; - - PlayerUID m_uid; // Player's unique identifier. - unsigned long m_rank; // Rank of the player on this scoreboard. - std::wstring m_name; // Player's display name. - - unsigned long m_totalScore; // Sum of all the player's scores on this - // leaderboard. - - unsigned short m_statsSize; // Iff (m_hasResults): Number of columns on - // this leaderboard. - unsigned long - m_statsData[STATSDATA_MAX]; // Iff (m_hasResults): Player's score - // for each appropriate column. - - int m_idsErrorMessage; // Iff (not m_hasResults): error message - // explaining what went wrong. - - } ReadScore; - - typedef struct ReadView { - unsigned int m_numQueries; - ReadScore* m_queries; - - } ReadView; - - typedef ReadView ViewOut; - typedef RegisterScore* ViewIn; - -public: LeaderboardManager(); virtual ~LeaderboardManager() {} + // Singleton + static IPlatformLeaderboard* Instance() { return m_instance; } + static void DeleteInstance(); + + // IPlatformLeaderboard pure virtuals — subclasses must implement: + // Tick, OpenSession, CloseSession, DeleteSession, WriteStats, + // FlushStats, CancelOperation, isIdle + + // Base implementations for read operations + bool ReadStats_Friends(LeaderboardReadListener* callback, int difficulty, + EStatsType type, PlayerUID myUID, + unsigned int startIndex, + unsigned int readCount) override; + bool ReadStats_MyScore(LeaderboardReadListener* callback, int difficulty, + EStatsType type, PlayerUID myUID, + unsigned int readCount) override; + bool ReadStats_TopRank(LeaderboardReadListener* callback, int difficulty, + EStatsType type, unsigned int startIndex, + unsigned int readCount) override; + + static void printStats(ReadView& view); + protected: virtual void zeroReadParameters(); EFilterMode m_eFilterMode; - - // Parameters for reading. int m_difficulty; EStatsType m_statsType; LeaderboardReadListener* m_readListener; @@ -190,66 +44,13 @@ protected: unsigned int m_startIndex, m_readCount; private: - static LeaderboardManager* - m_instance; // Singleton instance of the LeaderboardManager - -public: - static LeaderboardManager* Instance() { return m_instance; } - static void DeleteInstance(); - - virtual void Tick() = 0; - - // Open a session - virtual bool OpenSession() = 0; - - // Close a session - virtual void CloseSession() = 0; - - // Delete a session - virtual void DeleteSession() = 0; - - // Write the given stats - // This is called synchronously and will not free any memory allocated for - // views when it is done - - virtual bool WriteStats(unsigned int viewCount, ViewIn views) = 0; - - virtual bool ReadStats_Friends(LeaderboardReadListener* callback, - int difficulty, EStatsType type, - PlayerUID myUID, unsigned int startIndex, - unsigned int readCount); - virtual bool ReadStats_MyScore(LeaderboardReadListener* callback, - int difficulty, EStatsType type, - PlayerUID myUID, unsigned int readCount); - virtual bool ReadStats_TopRank(LeaderboardReadListener* callback, - int difficulty, EStatsType type, - unsigned int startIndex, - unsigned int readCount); - - // Perform a flush of the stats - virtual void FlushStats() = 0; - - // Cancel the current operation - virtual void CancelOperation() = 0; - - // Is the leaderboard manager idle. - virtual bool isIdle() = 0; - -public: - static void printStats(ReadView& view); -}; - -class LeaderboardReadListener { -public: - virtual bool OnStatsReadComplete(LeaderboardManager::eStatsReturn ret, - int numResults, - LeaderboardManager::ViewOut results) = 0; + static LeaderboardManager* m_instance; }; class DebugReadListener : public LeaderboardReadListener { public: - virtual bool OnStatsReadComplete(LeaderboardManager::eStatsReturn ret, - int numResults, - LeaderboardManager::ViewOut results); + bool OnStatsReadComplete(IPlatformLeaderboard::eStatsReturn ret, + int numResults, + IPlatformLeaderboard::ViewOut results) override; static DebugReadListener* m_instance; }; diff --git a/targets/Minecraft.Client/Common/src/UI/Scenes/Frontend Menu screens/UIScene_LeaderboardsMenu.cpp b/targets/Minecraft.Client/Common/src/UI/Scenes/Frontend Menu screens/UIScene_LeaderboardsMenu.cpp index b40ccb204..4ba4c2ad5 100644 --- a/targets/Minecraft.Client/Common/src/UI/Scenes/Frontend Menu screens/UIScene_LeaderboardsMenu.cpp +++ b/targets/Minecraft.Client/Common/src/UI/Scenes/Frontend Menu screens/UIScene_LeaderboardsMenu.cpp @@ -120,7 +120,7 @@ UIScene_LeaderboardsMenu::UIScene_LeaderboardsMenu(int iPad, void* initData, m_currentLeaderboard = 0; m_currentDifficulty = 2; SetLeaderboardHeader(); - m_currentFilter = LeaderboardManager::eFM_Friends; + m_currentFilter = IPlatformLeaderboard::eFM_Friends; wchar_t filterBuffer[40]; swprintf(filterBuffer, 40, L"%ls%ls", app.GetString(IDS_LEADERBOARD_FILTER), @@ -293,24 +293,24 @@ void UIScene_LeaderboardsMenu::handleInput(int iPad, int key, bool repeat, ui.PlayUISFX(eSFX_Scroll); switch (m_currentFilter) { - case LeaderboardManager::eFM_Friends: { - m_currentFilter = LeaderboardManager::eFM_MyScore; + case IPlatformLeaderboard::eFM_Friends: { + m_currentFilter = IPlatformLeaderboard::eFM_MyScore; wchar_t filterBuffer[40]; swprintf(filterBuffer, 40, L"%ls%ls", app.GetString(IDS_LEADERBOARD_FILTER), app.GetString(IDS_LEADERBOARD_FILTER_MYSCORE)); m_labelFilter.setLabel(filterBuffer); } break; - case LeaderboardManager::eFM_MyScore: { - m_currentFilter = LeaderboardManager::eFM_TopRank; + case IPlatformLeaderboard::eFM_MyScore: { + m_currentFilter = IPlatformLeaderboard::eFM_TopRank; wchar_t filterBuffer[40]; swprintf(filterBuffer, 40, L"%ls%ls", app.GetString(IDS_LEADERBOARD_FILTER), app.GetString(IDS_LEADERBOARD_FILTER_OVERALL)); m_labelFilter.setLabel(filterBuffer); } break; - case LeaderboardManager::eFM_TopRank: { - m_currentFilter = LeaderboardManager::eFM_Friends; + case IPlatformLeaderboard::eFM_TopRank: { + m_currentFilter = IPlatformLeaderboard::eFM_Friends; wchar_t filterBuffer[40]; swprintf(filterBuffer, 40, L"%ls%ls", app.GetString(IDS_LEADERBOARD_FILTER), @@ -354,39 +354,39 @@ void UIScene_LeaderboardsMenu::ReadStats(int startIndex) { // app.DebugPrintf("Requesting stats read %d - %d - %d\n", // m_currentLeaderboard, startIndex == -1 ? m_currentFilter : - // LeaderboardManager::eFM_TopRank, m_currentDifficulty); + // IPlatformLeaderboard::eFM_TopRank, m_currentDifficulty); - LeaderboardManager::EFilterMode filtermode; - if (m_currentFilter == LeaderboardManager::eFM_MyScore || - m_currentFilter == LeaderboardManager::eFM_TopRank) { + IPlatformLeaderboard::EFilterMode filtermode; + if (m_currentFilter == IPlatformLeaderboard::eFM_MyScore || + m_currentFilter == IPlatformLeaderboard::eFM_TopRank) { filtermode = (startIndex == -1 ? m_currentFilter - : LeaderboardManager::eFM_TopRank); + : IPlatformLeaderboard::eFM_TopRank); } else { // 4J-JEV: Friends filter shouldn't switch to toprank. filtermode = m_currentFilter; } switch (filtermode) { - case LeaderboardManager::eFM_TopRank: { + case IPlatformLeaderboard::eFM_TopRank: { m_interface.ReadStats_TopRank( this, m_currentDifficulty, - (LeaderboardManager::EStatsType)m_currentLeaderboard, + (IPlatformLeaderboard::EStatsType)m_currentLeaderboard, m_newEntryIndex, m_newReadSize); } break; - case LeaderboardManager::eFM_MyScore: { + case IPlatformLeaderboard::eFM_MyScore: { PlayerUID uid; ProfileManager.GetXUID(ProfileManager.GetPrimaryPad(), &uid, true); m_interface.ReadStats_MyScore( this, m_currentDifficulty, - (LeaderboardManager::EStatsType)m_currentLeaderboard, + (IPlatformLeaderboard::EStatsType)m_currentLeaderboard, uid /*ignored on PS3*/, m_newReadSize); } break; - case LeaderboardManager::eFM_Friends: { + case IPlatformLeaderboard::eFM_Friends: { PlayerUID uid; ProfileManager.GetXUID(ProfileManager.GetPrimaryPad(), &uid, true); m_interface.ReadStats_Friends( this, m_currentDifficulty, - (LeaderboardManager::EStatsType)m_currentLeaderboard, + (IPlatformLeaderboard::EStatsType)m_currentLeaderboard, uid /*ignored on PS3*/, m_newEntryIndex, m_newReadSize); } break; default: @@ -399,15 +399,15 @@ void UIScene_LeaderboardsMenu::ReadStats(int startIndex) { } bool UIScene_LeaderboardsMenu::OnStatsReadComplete( - LeaderboardManager::eStatsReturn retIn, int numResults, - LeaderboardManager::ViewOut results) { + IPlatformLeaderboard::eStatsReturn retIn, int numResults, + IPlatformLeaderboard::ViewOut results) { // CScene_Leaderboards* scene = // reinterpret_cast(userdata); m_isProcessingStatsRead = true; // bool noResults = LeaderboardManager::Instance()->GetStatsState() != - // XboxLeaderboardManager::eStatsState_Ready; + // XboxIPlatformLeaderboard::eStatsState_Ready; bool ret; // app.DebugPrintf("Leaderboards read %d stats\n", numResults); @@ -495,7 +495,7 @@ bool UIScene_LeaderboardsMenu::RetrieveStats() { // assert( LeaderboardManager::Instance()->GetStats() != nullptr ); // PXUSER_STATS_READ_RESULTS stats = // LeaderboardManager::Instance()->GetStats(); if( m_currentFilter == - // LeaderboardManager::eFM_Friends ) + // IPlatformLeaderboard::eFM_Friends ) // LeaderboardManager::Instance()->SortFriendStats(); bool isDistanceLeaderboard = @@ -509,7 +509,7 @@ bool UIScene_LeaderboardsMenu::RetrieveStats() { m_leaderboard.m_entries.clear(); m_leaderboard.m_totalEntryCount = - (m_currentFilter == LeaderboardManager::eFM_Friends) + (m_currentFilter == IPlatformLeaderboard::eFM_Friends) ? m_newEntriesCount : m_numStats; @@ -536,7 +536,7 @@ bool UIScene_LeaderboardsMenu::RetrieveStats() { // If the filter mode is "My Score" then centre the list around the // entries and select the player's score - if (m_currentFilter == LeaderboardManager::eFM_MyScore) { + if (m_currentFilter == IPlatformLeaderboard::eFM_MyScore) { // Centre the leaderboard list on the entries m_newTop = GetEntryStartIndex(); @@ -615,7 +615,7 @@ bool UIScene_LeaderboardsMenu::RetrieveStats() { } void UIScene_LeaderboardsMenu::CopyLeaderboardEntry( - LeaderboardManager::ReadScore* statsRow, int leaderboardEntryIndex, + IPlatformLeaderboard::ReadScore* statsRow, int leaderboardEntryIndex, bool isDistanceLeaderboard) { LeaderboardEntry* leaderboardEntry = &(m_leaderboard.m_entries[leaderboardEntryIndex]); @@ -632,7 +632,7 @@ void UIScene_LeaderboardsMenu::CopyLeaderboardEntry( leaderboardEntry->m_idsErrorMessage = statsRow->m_idsErrorMessage; // Build a row ID - if (m_currentFilter == LeaderboardManager::eFM_Friends) { + if (m_currentFilter == IPlatformLeaderboard::eFM_Friends) { // If friends don't ID rows by rank leaderboardEntry->m_row = leaderboardEntryIndex; } else { @@ -690,9 +690,9 @@ void UIScene_LeaderboardsMenu::CopyLeaderboardEntry( } void UIScene_LeaderboardsMenu::PopulateLeaderboard( - LeaderboardManager::eStatsReturn ret) { + IPlatformLeaderboard::eStatsReturn ret) { int iValidSlots = SetLeaderboardTitleIcons(); - if (ret == LeaderboardManager::eStatsReturn_Success && + if (ret == IPlatformLeaderboard::eStatsReturn_Success && m_leaderboard.m_totalEntryCount > 0) { m_listEntries.setupTitles(app.GetString(IDS_LEADERBOARD_RANK), app.GetString(IDS_LEADERBOARD_GAMERTAG)); @@ -771,7 +771,7 @@ void UIScene_LeaderboardsMenu::PopulateLeaderboard( // Show the no results message #if !defined(_WINDOWS64) // so we check this for other platforms - if (ret == LeaderboardManager::eStatsReturn_NetworkError) + if (ret == IPlatformLeaderboard::eStatsReturn_NetworkError) m_labelInfo.setLabel(app.GetString(IDS_ERROR_NETWORK)); else #endif diff --git a/targets/Minecraft.Client/Common/src/UI/Scenes/Frontend Menu screens/UIScene_LeaderboardsMenu.h b/targets/Minecraft.Client/Common/src/UI/Scenes/Frontend Menu screens/UIScene_LeaderboardsMenu.h index 6e49a472b..a6e915ae4 100644 --- a/targets/Minecraft.Client/Common/src/UI/Scenes/Frontend Menu screens/UIScene_LeaderboardsMenu.h +++ b/targets/Minecraft.Client/Common/src/UI/Scenes/Frontend Menu screens/UIScene_LeaderboardsMenu.h @@ -78,7 +78,7 @@ private: unsigned int m_currentLeaderboard; // The current leaderboard selected for view - LeaderboardManager::EFilterMode + IPlatformLeaderboard::EFilterMode m_currentFilter; // The current filter selected unsigned int m_currentDifficulty; // The current difficulty selected @@ -146,16 +146,16 @@ private: // Copy the stats from the raw m_stats structure into the m_leaderboards // structure int m_numStats; - LeaderboardManager::ViewOut m_stats; + IPlatformLeaderboard::ViewOut m_stats; bool RetrieveStats(); // Copy a leaderboard entry from the stats row - void CopyLeaderboardEntry(LeaderboardManager::ReadScore* statsRow, + void CopyLeaderboardEntry(IPlatformLeaderboard::ReadScore* statsRow, int leaderboardEntryIndex, bool isDistanceLeaderboard); // Populate the XUI leaderboard with the contents of m_leaderboards - void PopulateLeaderboard(LeaderboardManager::eStatsReturn ret); + void PopulateLeaderboard(IPlatformLeaderboard::eStatsReturn ret); // Set the header text of the leaderboard void SetLeaderboardHeader(); @@ -165,9 +165,9 @@ private: // Callback function called when stats read completes, userdata contains // pointer to instance of CScene_Leaderboards - virtual bool OnStatsReadComplete(LeaderboardManager::eStatsReturn ret, + virtual bool OnStatsReadComplete(IPlatformLeaderboard::eStatsReturn ret, int numResults, - LeaderboardManager::ViewOut results); + IPlatformLeaderboard::ViewOut results); virtual void customDraw(IggyCustomDrawCallbackRegion* region); diff --git a/targets/platform/IPlatformLeaderboard.h b/targets/platform/IPlatformLeaderboard.h new file mode 100644 index 000000000..38ad17f12 --- /dev/null +++ b/targets/platform/IPlatformLeaderboard.h @@ -0,0 +1,186 @@ +#pragma once + +#include +#include + +#include "../4J.Common/4J_Compat.h" + +class LeaderboardReadListener; + +class IPlatformLeaderboard { +public: + enum eStatsReturn { + eStatsReturn_Success = 0, + eStatsReturn_NoResults, + eStatsReturn_NetworkError + }; + + enum eProperty_Kills { + eProperty_Kills_Zombie = 0, + eProperty_Kills_Skeleton, + eProperty_Kills_Creeper, + eProperty_Kills_Spider, + eProperty_Kills_SpiderJockey, + eProperty_Kills_ZombiePigman, + eProperty_Kills_Slime, + eProperty_Kills_Rating, + eProperty_Kills_Max, + }; + + enum eProperty_Mining { + eProperty_Mining_Dirt = 0, + eProperty_Mining_Stone, + eProperty_Mining_Sand, + eProperty_Mining_Cobblestone, + eProperty_Mining_Gravel, + eProperty_Mining_Clay, + eProperty_Mining_Obsidian, + eProperty_Mining_Rating, + eProperty_Mining_Max, + }; + + enum eProperty_Farming { + eProperty_Farming_Egg = 0, + eProperty_Farming_Wheat, + eProperty_Farming_Mushroom, + eProperty_Farming_Sugarcane, + eProperty_Farming_Milk, + eProperty_Farming_Pumpkin, + eProperty_Farming_Rating, + eProperty_Farming_Max, + }; + + enum eProperty_Travelling { + eProperty_Travelling_Walked = 0, + eProperty_Travelling_Fallen, + eProperty_Travelling_Minecart, + eProperty_Travelling_Boat, + eProperty_Travelling_Rating, + eProperty_Travelling_Max, + }; + + enum EStatsType { + eStatsType_Travelling = 0, + eStatsType_Mining, + eStatsType_Farming, + eStatsType_Kills, + eStatsType_MAX, + eStatsType_UNDEFINED + }; + + enum EFilterMode { + eFM_Friends = 0, + eFM_MyScore, + eFM_TopRank, + eNumFilterModes, + eFM_UNDEFINED + }; + + struct KillsRecord { + unsigned short m_zombie; + unsigned short m_skeleton; + unsigned short m_creeper; + unsigned short m_spider; + unsigned short m_spiderJockey; + unsigned short m_zombiePigman; + unsigned short m_slime; + }; + + struct MiningRecord { + unsigned short m_dirt; + unsigned short m_stone; + unsigned short m_sand; + unsigned short m_cobblestone; + unsigned short m_gravel; + unsigned short m_clay; + unsigned short m_obsidian; + }; + + struct FarmingRecord { + unsigned short m_eggs; + unsigned short m_wheat; + unsigned short m_mushroom; + unsigned short m_sugarcane; + unsigned short m_milk; + unsigned short m_pumpkin; + }; + + struct TravellingRecord { + unsigned int m_walked; + unsigned int m_fallen; + unsigned int m_minecart; + unsigned int m_boat; + }; + + static constexpr int RECORD_SIZE = 40; + + struct StatsData { + EStatsType m_statsType; + union { + KillsRecord m_kills; + MiningRecord m_mining; + FarmingRecord m_farming; + TravellingRecord m_travelling; + unsigned char m_padding[RECORD_SIZE]; + }; + }; + + struct RegisterScore { + int m_iPad; + int m_score; + int m_difficulty; + StatsData m_commentData; + }; + + struct ReadScore { + static constexpr unsigned int STATSDATA_MAX = 8; + + PlayerUID m_uid; + unsigned long m_rank; + std::wstring m_name; + unsigned long m_totalScore; + unsigned short m_statsSize; + unsigned long m_statsData[STATSDATA_MAX]; + int m_idsErrorMessage; + }; + + struct ReadView { + unsigned int m_numQueries; + ReadScore* m_queries; + }; + + using ViewOut = ReadView; + using ViewIn = RegisterScore*; + + virtual ~IPlatformLeaderboard() = default; + + virtual void Tick() = 0; + [[nodiscard]] virtual bool OpenSession() = 0; + virtual void CloseSession() = 0; + virtual void DeleteSession() = 0; + [[nodiscard]] virtual bool WriteStats(unsigned int viewCount, + ViewIn views) = 0; + virtual bool ReadStats_Friends(LeaderboardReadListener* callback, + int difficulty, EStatsType type, + PlayerUID myUID, unsigned int startIndex, + unsigned int readCount) = 0; + virtual bool ReadStats_MyScore(LeaderboardReadListener* callback, + int difficulty, EStatsType type, + PlayerUID myUID, + unsigned int readCount) = 0; + virtual bool ReadStats_TopRank(LeaderboardReadListener* callback, + int difficulty, EStatsType type, + unsigned int startIndex, + unsigned int readCount) = 0; + virtual void FlushStats() = 0; + virtual void CancelOperation() = 0; + [[nodiscard]] virtual bool isIdle() = 0; +}; + +class LeaderboardReadListener { +public: + virtual ~LeaderboardReadListener() = default; + virtual bool OnStatsReadComplete(IPlatformLeaderboard::eStatsReturn ret, + int numResults, + IPlatformLeaderboard::ViewOut results) = 0; +}; diff --git a/targets/platform/Platform.h b/targets/platform/Platform.h index a5ea61108..af16b57ee 100644 --- a/targets/platform/Platform.h +++ b/targets/platform/Platform.h @@ -1,6 +1,7 @@ #pragma once #include "IPlatformInput.h" +#include "IPlatformLeaderboard.h" #include "IPlatformNetwork.h" #include "IPlatformProfile.h" #include "IPlatformRenderer.h"