From 6da92c08b9b6885faf46d8a260f4956c72b6a32a Mon Sep 17 00:00:00 2001 From: tyler staples Date: Mon, 28 Mar 2016 01:13:40 -0700 Subject: Added MenuClosed event which fires when the current menu is closed. --- StardewModdingAPI/Events/EventArgs.cs | 10 ++++++++++ StardewModdingAPI/Events/Menu.cs | 6 ++++++ StardewModdingAPI/Inheritance/SGame.cs | 12 ++++++++++++ 3 files changed, 28 insertions(+) diff --git a/StardewModdingAPI/Events/EventArgs.cs b/StardewModdingAPI/Events/EventArgs.cs index d057796a..2bce964e 100644 --- a/StardewModdingAPI/Events/EventArgs.cs +++ b/StardewModdingAPI/Events/EventArgs.cs @@ -108,6 +108,16 @@ namespace StardewModdingAPI.Events public IClickableMenu PriorMenu { get; private set; } } + public class EventArgsClickableMenuClosed : EventArgs + { + public EventArgsClickableMenuClosed(IClickableMenu priorMenu) + { + PriorMenu = priorMenu; + } + + public IClickableMenu PriorMenu { get; private set; } + } + public class EventArgsGameLocationsChanged : EventArgs { public EventArgsGameLocationsChanged(List newLocations) diff --git a/StardewModdingAPI/Events/Menu.cs b/StardewModdingAPI/Events/Menu.cs index 466a364e..0e043780 100644 --- a/StardewModdingAPI/Events/Menu.cs +++ b/StardewModdingAPI/Events/Menu.cs @@ -6,10 +6,16 @@ namespace StardewModdingAPI.Events public static class MenuEvents { public static event EventHandler MenuChanged = delegate { }; + public static event EventHandler MenuClosed = delegate { }; internal static void InvokeMenuChanged(IClickableMenu priorMenu, IClickableMenu newMenu) { MenuChanged.Invoke(null, new EventArgsClickableMenuChanged(priorMenu, newMenu)); } + + internal static void InvokeMenuClosed(IClickableMenu priorMenu) + { + MenuClosed.Invoke(null, new EventArgsClickableMenuClosed(priorMenu)); + } } } \ No newline at end of file diff --git a/StardewModdingAPI/Inheritance/SGame.cs b/StardewModdingAPI/Inheritance/SGame.cs index 65711507..c6c6b440 100644 --- a/StardewModdingAPI/Inheritance/SGame.cs +++ b/StardewModdingAPI/Inheritance/SGame.cs @@ -143,6 +143,11 @@ namespace StardewModdingAPI.Inheritance /// public IClickableMenu PreviousActiveMenu { get; private set; } + /// + /// Indicates if the MenuClosed event was fired to prevent it from re-firing. + /// + internal bool WasMenuClosedInvoked = false; + /// /// The previous mine level /// @@ -1438,6 +1443,13 @@ namespace StardewModdingAPI.Inheritance { MenuEvents.InvokeMenuChanged(PreviousActiveMenu, activeClickableMenu); PreviousActiveMenu = activeClickableMenu; + WasMenuClosedInvoked = false; + } + + if (!WasMenuClosedInvoked && PreviousActiveMenu != null && activeClickableMenu == null) + { + MenuEvents.InvokeMenuClosed(PreviousActiveMenu); + WasMenuClosedInvoked = true; } if (locations.GetHash() != PreviousGameLocations) -- cgit