Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions CJBCheatsMenu/Framework/CJBCheatsMenuAPI.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using CJBCheatsMenu.Framework.Models;
using StardewModdingAPI;
using StardewModdingAPI.Utilities;
using StardewValley;

namespace CJBCheatsMenu.Framework;

/// <inheritdoc />
public sealed class CJBCheatsMenuAPI : ICJBCheatsMenuAPI
{
/*********
** Fields
*********/
/// <summary>Manages the cheat implementations.</summary>
private readonly CheatManager Cheats;

/// <summary>The mod configuration.</summary>
private readonly ModConfig Config;

/// <summary>Encapsulates monitoring and logging.</summary>
private readonly IMonitor Monitor;

/*********
** Public methods
*********/
/// <summary>Construct an instance.</summary>
/// <param name="cheats">The cheats helper.</param>
/// <param name="config">The mod configuration.</param>
/// <param name="monitor">Encapsulates monitoring and logging.</param>
internal CJBCheatsMenuAPI(CheatManager cheats, ModConfig config, IMonitor monitor)
{
this.Cheats = cheats;
this.Config = config;
this.Monitor = monitor;
}

/// <inheritdoc />
public void OpenCheatsMenu(MenuTab? tab)
{
Game1.activeClickableMenu = new CheatsMenu(tab ?? this.Config.DefaultTab, this.Cheats, this.Monitor, true);
}
}
14 changes: 14 additions & 0 deletions CJBCheatsMenu/ICJBCheatsMenuAPI.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using CJBCheatsMenu.Framework;
using StardewValley;

namespace CJBCheatsMenu;

/// <summary>The API which lets other mods interact with CJB Cheats Menu.</summary>
public interface ICJBCheatsMenuAPI
{
/// <summary>
/// Open the cheats menu.
/// </summary>
/// <param name="tab">The initial tab to display, or opens the default.</param>
void OpenCheatsMenu(MenuTab? tab);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace CJBCheatsMenu.Framework;
namespace CJBCheatsMenu;

/// <summary>A tab in the cheat menu.</summary>
internal enum MenuTab
public enum MenuTab
{
/// <summary>The 'player &amp; tools' tab.</summary>
PlayerAndTools,
Expand Down
12 changes: 11 additions & 1 deletion CJBCheatsMenu/ModEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ public override void Entry(IModHelper helper)
helper.Events.World.LocationListChanged += this.OnLocationListChanged;
}

/// <inheritdoc />
public override object GetApi()
{
return new CJBCheatsMenuAPI(this.Cheats.Value, this.Config, this.Monitor);
}

/*********
** Private methods
Expand Down Expand Up @@ -141,7 +146,7 @@ private void OnButtonsChanged(object? sender, ButtonsChangedEventArgs e)
{
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);
this.OpenCheatsMenu();
}
}

Expand Down Expand Up @@ -216,6 +221,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);
}

/// <summary>Reset the cached location list.</summary>
private void ResetLocationCache()
{
Expand Down