summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortyler staples <tyler.a.staples@gmail.com>2016-03-28 01:13:40 -0700
committertyler staples <tyler.a.staples@gmail.com>2016-03-28 01:13:40 -0700
commit6da92c08b9b6885faf46d8a260f4956c72b6a32a (patch)
treebe11b2409237e27ccc71a18e8b325aa2d4664f26
parente6f2825929bc45ea541df46b1baab5d5cbf4dbb1 (diff)
downloadSMAPI-6da92c08b9b6885faf46d8a260f4956c72b6a32a.tar.gz
SMAPI-6da92c08b9b6885faf46d8a260f4956c72b6a32a.tar.bz2
SMAPI-6da92c08b9b6885faf46d8a260f4956c72b6a32a.zip
Added MenuClosed event which fires when the current menu is closed.
-rw-r--r--StardewModdingAPI/Events/EventArgs.cs10
-rw-r--r--StardewModdingAPI/Events/Menu.cs6
-rw-r--r--StardewModdingAPI/Inheritance/SGame.cs12
3 files changed, 28 insertions, 0 deletions
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<GameLocation> 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<EventArgsClickableMenuChanged> MenuChanged = delegate { };
+ public static event EventHandler<EventArgsClickableMenuClosed> 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
@@ -144,6 +144,11 @@ namespace StardewModdingAPI.Inheritance
public IClickableMenu PreviousActiveMenu { get; private set; }
/// <summary>
+ /// Indicates if the MenuClosed event was fired to prevent it from re-firing.
+ /// </summary>
+ internal bool WasMenuClosedInvoked = false;
+
+ /// <summary>
/// The previous mine level
/// </summary>
public int PreviousMineLevel { get; private set; }
@@ -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)