From f7b1f1b6f7995d9bdb3584b20b01665b5e6b5ff1 Mon Sep 17 00:00:00 2001 From: Matthew <3005344+LeFauxMatt@users.noreply.github.com> Date: Tue, 17 Dec 2024 17:41:18 -0800 Subject: [PATCH 1/3] Adding OpenCheatsMenu to make it more easily accessed using reflection --- CJBCheatsMenu/ModEntry.cs | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/CJBCheatsMenu/ModEntry.cs b/CJBCheatsMenu/ModEntry.cs index f9e0acf5..82f600c4 100644 --- a/CJBCheatsMenu/ModEntry.cs +++ b/CJBCheatsMenu/ModEntry.cs @@ -15,8 +15,8 @@ namespace CJBCheatsMenu; internal class ModEntry : Mod { /********* - ** Fields - *********/ + ** Fields + *********/ /// The relative file to the warps data file. private readonly string WarpsPath = "assets/warps.json"; @@ -34,8 +34,8 @@ internal class ModEntry : Mod /********* - ** Public methods - *********/ + ** Public methods + *********/ /// public override void Entry(IModHelper helper) { @@ -74,8 +74,8 @@ public override void Entry(IModHelper helper) /********* - ** Private methods - *********/ + ** Private methods + *********/ /// private void OnGameLaunched(object? sender, GameLaunchedEventArgs e) { @@ -140,8 +140,9 @@ private void OnButtonsChanged(object? sender, ButtonsChangedEventArgs e) else { this.Monitor.Log("Received menu open key."); - CommonHelper.WarnOnGameMenuKeyConflict(this.Helper.Input, this.Monitor, this.Config.OpenMenuKey, "cheats menu"); - Game1.activeClickableMenu = new CheatsMenu(this.Config.DefaultTab, this.Cheats.Value, this.Monitor, isNewMenu: true); + CommonHelper.WarnOnGameMenuKeyConflict(this.Helper.Input, this.Monitor, this.Config.OpenMenuKey, + "cheats menu"); + this.OpenCheatsMenu(); } } @@ -196,6 +197,11 @@ private void OnMenuChanged(object? sender, MenuChangedEventArgs e) } } + private void OpenCheatsMenu() + { + Game1.activeClickableMenu = new CheatsMenu(this.Config.DefaultTab, this.Cheats.Value, this.Monitor, true); + } + /// Load the default warps from the data file, if it's valid. [SuppressMessage("ReSharper", "ConstantNullCoalescingCondition", Justification = "The warps field is initialized in this method.")] private ModData LoadModData() From f45ffa3f93b827a391c1396197f040d4b7041a0c Mon Sep 17 00:00:00 2001 From: Matthew <3005344+LeFauxMatt@users.noreply.github.com> Date: Tue, 17 Dec 2024 17:44:41 -0800 Subject: [PATCH 2/3] . --- CJBCheatsMenu/ModEntry.cs | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/CJBCheatsMenu/ModEntry.cs b/CJBCheatsMenu/ModEntry.cs index 82f600c4..583dbef6 100644 --- a/CJBCheatsMenu/ModEntry.cs +++ b/CJBCheatsMenu/ModEntry.cs @@ -15,8 +15,8 @@ namespace CJBCheatsMenu; internal class ModEntry : Mod { /********* - ** Fields - *********/ + ** Fields + *********/ /// The relative file to the warps data file. private readonly string WarpsPath = "assets/warps.json"; @@ -34,8 +34,8 @@ internal class ModEntry : Mod /********* - ** Public methods - *********/ + ** Public methods + *********/ /// public override void Entry(IModHelper helper) { @@ -74,8 +74,8 @@ public override void Entry(IModHelper helper) /********* - ** Private methods - *********/ + ** Private methods + *********/ /// private void OnGameLaunched(object? sender, GameLaunchedEventArgs e) { @@ -140,8 +140,7 @@ private void OnButtonsChanged(object? sender, ButtonsChangedEventArgs e) else { this.Monitor.Log("Received menu open key."); - CommonHelper.WarnOnGameMenuKeyConflict(this.Helper.Input, this.Monitor, this.Config.OpenMenuKey, - "cheats menu"); + CommonHelper.WarnOnGameMenuKeyConflict(this.Helper.Input, this.Monitor, this.Config.OpenMenuKey, "cheats menu"); this.OpenCheatsMenu(); } } @@ -197,11 +196,6 @@ private void OnMenuChanged(object? sender, MenuChangedEventArgs e) } } - private void OpenCheatsMenu() - { - Game1.activeClickableMenu = new CheatsMenu(this.Config.DefaultTab, this.Cheats.Value, this.Monitor, true); - } - /// Load the default warps from the data file, if it's valid. [SuppressMessage("ReSharper", "ConstantNullCoalescingCondition", Justification = "The warps field is initialized in this method.")] private ModData LoadModData() @@ -222,6 +216,11 @@ private ModData LoadModData() return new ModData(null, null); } + private void OpenCheatsMenu() + { + Game1.activeClickableMenu = new CheatsMenu(this.Config.DefaultTab, this.Cheats.Value, this.Monitor, true); + } + /// Reset the cached location list. private void ResetLocationCache() { From 7a44e7cd62c5cf7851ca4bf44e5e906a23a92de5 Mon Sep 17 00:00:00 2001 From: Matthew <3005344+LeFauxMatt@users.noreply.github.com> Date: Tue, 17 Dec 2024 18:31:38 -0800 Subject: [PATCH 3/3] draft api to launch cheats menu --- CJBCheatsMenu/Framework/CJBCheatsMenuAPI.cs | 42 +++++++++++++++++++++ CJBCheatsMenu/ICJBCheatsMenuAPI.cs | 14 +++++++ CJBCheatsMenu/{Framework => }/MenuTab.cs | 4 +- CJBCheatsMenu/ModEntry.cs | 5 +++ 4 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 CJBCheatsMenu/Framework/CJBCheatsMenuAPI.cs create mode 100644 CJBCheatsMenu/ICJBCheatsMenuAPI.cs rename CJBCheatsMenu/{Framework => }/MenuTab.cs (91%) diff --git a/CJBCheatsMenu/Framework/CJBCheatsMenuAPI.cs b/CJBCheatsMenu/Framework/CJBCheatsMenuAPI.cs new file mode 100644 index 00000000..b651dfa2 --- /dev/null +++ b/CJBCheatsMenu/Framework/CJBCheatsMenuAPI.cs @@ -0,0 +1,42 @@ +using CJBCheatsMenu.Framework.Models; +using StardewModdingAPI; +using StardewModdingAPI.Utilities; +using StardewValley; + +namespace CJBCheatsMenu.Framework; + +/// +public sealed class CJBCheatsMenuAPI : ICJBCheatsMenuAPI +{ + /********* + ** Fields + *********/ + /// Manages the cheat implementations. + private readonly CheatManager Cheats; + + /// The mod configuration. + private readonly ModConfig Config; + + /// Encapsulates monitoring and logging. + private readonly IMonitor Monitor; + + /********* + ** Public methods + *********/ + /// Construct an instance. + /// The cheats helper. + /// The mod configuration. + /// Encapsulates monitoring and logging. + internal CJBCheatsMenuAPI(CheatManager cheats, ModConfig config, IMonitor monitor) + { + this.Cheats = cheats; + this.Config = config; + this.Monitor = monitor; + } + + /// + public void OpenCheatsMenu(MenuTab? tab) + { + Game1.activeClickableMenu = new CheatsMenu(tab ?? this.Config.DefaultTab, this.Cheats, this.Monitor, true); + } +} diff --git a/CJBCheatsMenu/ICJBCheatsMenuAPI.cs b/CJBCheatsMenu/ICJBCheatsMenuAPI.cs new file mode 100644 index 00000000..ffbe5bd5 --- /dev/null +++ b/CJBCheatsMenu/ICJBCheatsMenuAPI.cs @@ -0,0 +1,14 @@ +using CJBCheatsMenu.Framework; +using StardewValley; + +namespace CJBCheatsMenu; + +/// The API which lets other mods interact with CJB Cheats Menu. +public interface ICJBCheatsMenuAPI +{ + /// + /// Open the cheats menu. + /// + /// The initial tab to display, or opens the default. + void OpenCheatsMenu(MenuTab? tab); +} diff --git a/CJBCheatsMenu/Framework/MenuTab.cs b/CJBCheatsMenu/MenuTab.cs similarity index 91% rename from CJBCheatsMenu/Framework/MenuTab.cs rename to CJBCheatsMenu/MenuTab.cs index 47358d35..4ffdcaad 100644 --- a/CJBCheatsMenu/Framework/MenuTab.cs +++ b/CJBCheatsMenu/MenuTab.cs @@ -1,7 +1,7 @@ -namespace CJBCheatsMenu.Framework; +namespace CJBCheatsMenu; /// A tab in the cheat menu. -internal enum MenuTab +public enum MenuTab { /// The 'player & tools' tab. PlayerAndTools, diff --git a/CJBCheatsMenu/ModEntry.cs b/CJBCheatsMenu/ModEntry.cs index 583dbef6..e66eeceb 100644 --- a/CJBCheatsMenu/ModEntry.cs +++ b/CJBCheatsMenu/ModEntry.cs @@ -72,6 +72,11 @@ public override void Entry(IModHelper helper) helper.Events.World.LocationListChanged += this.OnLocationListChanged; } + /// + public override object GetApi() + { + return new CJBCheatsMenuAPI(this.Cheats.Value, this.Config, this.Monitor); + } /********* ** Private methods