From c292f4e4a8b85122398bb6957813c7e964b9d4c7 Mon Sep 17 00:00:00 2001 From: "NGnius (Graham)" Date: Sat, 25 Jul 2020 19:42:55 -0400 Subject: [PATCH] Improve popup and add lobby list command --- GameSDKcraft/CallbackUtility.cs | 1 + GameSDKcraft/GameSDKcraft.csproj | 6 +-- GameSDKcraft/Plugin.cs | 73 +++++++++++++++++++++++++------- 3 files changed, 60 insertions(+), 20 deletions(-) diff --git a/GameSDKcraft/CallbackUtility.cs b/GameSDKcraft/CallbackUtility.cs index 30ffcea..f48d619 100644 --- a/GameSDKcraft/CallbackUtility.cs +++ b/GameSDKcraft/CallbackUtility.cs @@ -96,6 +96,7 @@ namespace GamecraftRPC Discord.LobbyManager lm = Plugin.DiscordRPC.GetLobbyManager(); Discord.LobbyTransaction lt = lm.GetLobbyCreateTransaction(); lt.SetMetadata("steamid", PresenceUtility.SteamId.ToString()); + lt.SetMetadata("name", Steamworks.SteamClient.Name); lt.SetType(Discord.LobbyType.Public); lt.SetCapacity(2); lm.CreateLobby(lt, SyncActivityLobby); diff --git a/GameSDKcraft/GameSDKcraft.csproj b/GameSDKcraft/GameSDKcraft.csproj index 2c1f97a..e0df8d8 100644 --- a/GameSDKcraft/GameSDKcraft.csproj +++ b/GameSDKcraft/GameSDKcraft.csproj @@ -3,7 +3,7 @@ net472 true - 1.0.1 + 1.1.0 Me MIT https://git.exmods.org/???/??? @@ -72,10 +72,6 @@ ..\ref\Gamecraft_Data\Managed\Blocks.HUDFeedbackBlocks.dll ..\..\ref\Gamecraft_Data\Managed\Blocks.HUDFeedbackBlocks.dll - - ..\ref\Gamecraft_Data\Managed\ClusterToWireConversion.Mock.dll - ..\..\ref\Gamecraft_Data\Managed\ClusterToWireConversion.Mock.dll - ..\ref\Gamecraft_Data\Managed\CommandLine.dll ..\..\ref\Gamecraft_Data\Managed\CommandLine.dll diff --git a/GameSDKcraft/Plugin.cs b/GameSDKcraft/Plugin.cs index 3359ee0..f1ec486 100644 --- a/GameSDKcraft/Plugin.cs +++ b/GameSDKcraft/Plugin.cs @@ -1,5 +1,7 @@ using System; +using System.IO; using System.Reflection; +using System.Text; //using Microsoft.Win32; using IllusionPlugin; @@ -94,6 +96,8 @@ namespace GamecraftRPC Client.EnterMenu += CallbackUtility.MenuEnter; GamecraftModdingAPI.Utility.GameEngineManager.AddGameEngine(new Engines.PlayerCountEngine()); + + Client client = new Client(); CommandBuilder.Builder() .Name("JoinDiscord") @@ -136,7 +140,6 @@ namespace GamecraftRPC if (DiscordRPC != null) { Game game = Game.CurrentGame(); - Client client = new Client(); GamecraftModdingAPI.Utility.Logging.CommandLog($"Gamecraft {client.Version}\nUnity {client.UnityVersion}\n{PluginInfo()}\nSDK {DiscordRPC.ToString()}\nGame {game.Name}"); } else @@ -174,25 +177,65 @@ namespace GamecraftRPC } }) .Build(); -#if !RELEASE - bool alreadyWarned = false; + + CommandBuilder.Builder() + .Name("ListDiscordLobbies") + .Description($"View a list of public multiplayer lobbies available through {Name}") + .Action(() => + { + LobbySearchQuery query = lm.GetSearchQuery(); + query.Sort("slots", LobbySearchCast.Number, "999"); + query.Limit(100); + lm.Search(query, result => + { + if (result == Result.Ok) + { + StringBuilder sb = new StringBuilder("~ Lobby List [ID | Username (players/max)] ~\n"); + int lobbyCount = lm.LobbyCount(); + for (int i = 0; i < lobbyCount; i++) + { + long id = lm.GetLobbyId(i); + Lobby lobby = lm.GetLobby(id); + sb.AppendFormat("{3} | {0} ({1}/{2})\n", lm.GetLobbyMetadataValue(id, "name"), + lm.MemberCount(id), lobby.Capacity.ToString(), lm.GetLobbyMetadataValue(id, "steamid")); + } + GamecraftModdingAPI.Utility.Logging.CommandLog(sb.ToString().TrimEnd()); + } + }); + }) + .Build(); + + string popupFileName = "." + Name + "_startuppopup"; + bool alreadyWarned = File.Exists(popupFileName); Client.EnterMenu += (_, args) => { if (alreadyWarned) return; - //GamecraftModdingAPI.Utility.Logging.LogDebug($"Displaying {Name} {Version} DEBUG warning"); - /* - RobocraftX.Services.ErrorBuilder.DisplayCustomError( - $"THIS IS NOT ACTUALLY AN ERROR! {Name} v{Version} is a pre-release. If you encounter a bug or other issue, please report it to NGnius or Exmods on Discord.", - "Discord", () => { UnityEngine.Application.OpenURL("https://discord.exmods.org"); }, - "Ok!", () => { GamecraftModdingAPI.Utility.Logging.LogDebug($"Dismissed {Name} {Version} DEBUG warning"); } - ); - */ - RobocraftX.Services.ErrorBuilder.DisplayWarning($"{Name} v{Version} is a pre-release. If you encounter a bug or other issue, please report it to NGnius or Exmods on Discord."); alreadyWarned = true; - }; + client.PromptUser(new DualChoicePrompt( +#if !RELEASE + $"Version {Version} of {Name} is a pre-release. If you encounter a bug or other issue, please report it on the Exmods Discord.", +#else + $"Congrats, you've installed the {Name} mod! If you encounter a bug or other issue, please report it on the Exmods Discord.", #endif - - GamecraftModdingAPI.Utility.Logging.LogDebug($"{Name} has started up"); + Name, + "Discord", + () => + { + if (DiscordRPC == null) + { + UnityEngine.Application.OpenURL("https://discord.exmods.org"); + } + else + { + DiscordRPC.GetOverlayManager().OpenGuildInvite("2CtWzZT", result => { GamecraftModdingAPI.Utility.Logging.MetaLog($"Open Discord server invite through GameSDK {result}"); }); + } + File.WriteAllText(popupFileName, Version); + }, + "Ok", + () => { File.WriteAllText(popupFileName, Version); })); + }; + + GamecraftModdingAPI.Utility.Logging.MetaLog($"{Name} has started up"); } public void OnFixedUpdate() { } // called once per physics update