From 9cf7046a5bfa2678f000c08e8ca9cfb55e5b36cc Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Tue, 25 Mar 2025 13:35:50 +0100 Subject: [PATCH] Add leaderboards to Online interface https://github.com/FlaxEngine/OnlinePlatformSteam/issues/2 --- Source/Engine/Online/IOnlinePlatform.h | 170 ++++++++++++++++++ .../Engine/Platform/GDK/GDKPlatformSettings.h | 8 + 2 files changed, 178 insertions(+) diff --git a/Source/Engine/Online/IOnlinePlatform.h b/Source/Engine/Online/IOnlinePlatform.h index 91dd453ac..724a88d97 100644 --- a/Source/Engine/Online/IOnlinePlatform.h +++ b/Source/Engine/Online/IOnlinePlatform.h @@ -99,6 +99,109 @@ API_STRUCT(Namespace="FlaxEngine.Online") struct FLAXENGINE_API OnlineAchievemen API_FIELD() DateTime UnlockTime = DateTime::MinValue(); }; +/// +/// Online platform leaderboards sorting modes. +/// +API_ENUM(Namespace="FlaxEngine.Online") enum class OnlineLeaderboardSortModes +{ + /// + /// Don't sort stats. + /// + None = 0, + + /// + /// Sort ascending, top-score is the lowest number (lower value is better). + /// + Ascending, + + /// + /// Sort descending, top-score is the highest number (higher value is better). + /// + Descending, +}; + +/// +/// Online platform leaderboards display modes. Defines how leaderboard value should be used. +/// +API_ENUM(Namespace="FlaxEngine.Online") enum class OnlineLeaderboardValueFormats +{ + /// + /// Undefined format. + /// + Undefined = 0, + + /// + /// Raw numerical score. + /// + Numeric, + + /// + /// Time in seconds. + /// + Seconds, + + /// + /// Time in milliseconds. + /// + Milliseconds, +}; + +/// +/// Online platform leaderboard description. +/// +API_STRUCT(Namespace="FlaxEngine.Online") struct FLAXENGINE_API OnlineLeaderboard +{ + DECLARE_SCRIPTING_TYPE_MINIMAL(OnlineLeaderboard); + + /// + /// Unique leaderboard identifier. Specific for a certain online platform. + /// + API_FIELD() String Identifier; + + /// + /// Leaderboard name. Specific for a game. + /// + API_FIELD() String Name; + + /// + /// The leaderboard sorting method. + /// + API_FIELD() OnlineLeaderboardSortModes SortMode; + + /// + /// The leaderboard values formatting. + /// + API_FIELD() OnlineLeaderboardValueFormats ValueFormat; + + /// + /// The leaderboard rows count (amount of entries to access). + /// + API_FIELD() int32 EntriesCount; +}; + +/// +/// Online platform leaderboard entry description. +/// +API_STRUCT(Namespace="FlaxEngine.Online") struct FLAXENGINE_API OnlineLeaderboardEntry +{ + DECLARE_SCRIPTING_TYPE_MINIMAL(OnlineLeaderboardEntry); + + /// + /// The player who holds the entry. + /// + API_FIELD() OnlineUser User; + + /// + /// The entry rank. Placement of the entry in the leaderboard (starts at 1 for the top-score). + /// + API_FIELD() int32 Rank; + + /// + /// The entry score set in the leaderboard. + /// + API_FIELD() int32 Score; +}; + /// /// Interface for online platform providers for communicating with various multiplayer services such as player info, achievements, game lobby or in-game store. /// @@ -216,6 +319,73 @@ public: /// True if failed, otherwise false. API_FUNCTION() virtual bool SetStat(const StringView& name, float value, User* localUser = nullptr) = 0; +public: + /// + /// Gets the online leaderboard. + /// + /// The leaderboard name. + /// The result value. + /// The local user (null if use default one). + /// True if failed, otherwise false. + API_FUNCTION() virtual bool GetLeaderboard(const StringView& name, API_PARAM(Out) OnlineLeaderboard& value, User* localUser = nullptr) = 0; + + /// + /// Gets or creates the online leaderboard. It will not create it if already exists. + /// + /// The leaderboard name. + /// The leaderboard sorting mode. + /// The leaderboard values formatting. + /// The result value. + /// The local user (null if use default one). + /// True if failed, otherwise false. + API_FUNCTION() virtual bool GetOrCreateLeaderboard(const StringView& name, OnlineLeaderboardSortModes sortMode, OnlineLeaderboardValueFormats valueFormat, API_PARAM(Out) OnlineLeaderboard& value, User* localUser = nullptr) = 0; + + /// + /// Gets the online leaderboard entries. Allows to specify the range for ranks to gather. + /// + /// The leaderboard. + /// The list of result entries. + /// The zero-based index to start downloading entries from. For example, to display the top 10 on a leaderboard pass value of 0. + /// The amount of entries to read, starting from the first entry at . + /// True if failed, otherwise false. + API_FUNCTION() virtual bool GetLeaderboardEntries(const OnlineLeaderboard& leaderboard, API_PARAM(Out) Array& entries, int32 start = 0, int32 count = 10) = 0; + + /// + /// Gets the online leaderboard entries around the player. Allows to specify the range for ranks to gather around the user rank. The current user's entry is always included. + /// + /// The leaderboard. + /// The list of result entries. + /// The zero-based index to start downloading entries relative to the user. For example, to display the 4 higher scores on a leaderboard pass value of -4. Value 0 will return current user as the first one. + /// The amount of entries to read, starting from the first entry at . + /// True if failed, otherwise false. + API_FUNCTION() virtual bool GetLeaderboardEntriesAroundUser(const OnlineLeaderboard& leaderboard, API_PARAM(Out) Array& entries, int32 start = -4, int32 count = 10) = 0; + + /// + /// Gets the online leaderboard entries for player friends. + /// + /// The leaderboard. + /// The list of result entries. + /// True if failed, otherwise false. + API_FUNCTION() virtual bool GetLeaderboardEntriesForFriends(const OnlineLeaderboard& leaderboard, API_PARAM(Out) Array& entries) = 0; + + /// + /// Gets the online leaderboard entries for an arbitrary set of users. + /// + /// The leaderboard. + /// The list of result entries. + /// The list of users to read their ranks on the leaderboard. + /// True if failed, otherwise false. + API_FUNCTION() virtual bool GetLeaderboardEntriesForUsers(const OnlineLeaderboard& leaderboard, API_PARAM(Out) Array& entries, const Array& users) = 0; + + /// + /// Sets the online leaderboard entry for the user. + /// + /// The leaderboard. + /// The score value to set. + /// True if store value only if it's better than existing value (if any), otherwise will override any existing score for that user. + /// True if failed, otherwise false. + API_FUNCTION() virtual bool SetLeaderboardEntry(const OnlineLeaderboard& leaderboard, int32 score, bool keepBest = false) = 0; + public: /// /// Gets the online savegame data. Returns empty if savegame slot is unused. diff --git a/Source/Engine/Platform/GDK/GDKPlatformSettings.h b/Source/Engine/Platform/GDK/GDKPlatformSettings.h index 69ba4c7e8..2ac462fdb 100644 --- a/Source/Engine/Platform/GDK/GDKPlatformSettings.h +++ b/Source/Engine/Platform/GDK/GDKPlatformSettings.h @@ -102,6 +102,14 @@ API_CLASS(Namespace="FlaxEditor.Content.Settings") class FLAXENGINE_API GDKPlatf API_FIELD(Attributes="EditorOrder(330), EditorDisplay(\"Xbox Live\")") StringAnsi SCID; +#if !BUILD_RELEASE + /// + /// Enables debugging Xbox Live via verbose tracing. + /// + API_FIELD(Attributes="EditorOrder(370), EditorDisplay(\"Xbox Live\")") + bool DebugXboxLive = false; +#endif + /// /// Specifies if the Game DVR system component is enabled or not. ///