using System; using StardewModdingAPI.Framework; using StardewValley.Menus; namespace StardewModdingAPI.Events { /// Events raised when a game menu is opened or closed (including internal menus like the title screen). public static class MenuEvents { /********* ** Events *********/ /// Raised after a game menu is opened or replaced with another menu. This event is not invoked when a menu is closed. public static event EventHandler MenuChanged; /// Raised after a game menu is closed. public static event EventHandler MenuClosed; /********* ** Internal methods *********/ /// Raise a event. /// Encapsulates monitoring and logging. /// The previous menu. /// The current menu. internal static void InvokeMenuChanged(IMonitor monitor, IClickableMenu priorMenu, IClickableMenu newMenu) { monitor.SafelyRaiseGenericEvent($"{nameof(MenuEvents)}.{nameof(MenuEvents.MenuChanged)}", MenuEvents.MenuChanged?.GetInvocationList(), null, new EventArgsClickableMenuChanged(priorMenu, newMenu)); } /// Raise a event. /// Encapsulates monitoring and logging. /// The menu that was closed. internal static void InvokeMenuClosed(IMonitor monitor, IClickableMenu priorMenu) { monitor.SafelyRaiseGenericEvent($"{nameof(MenuEvents)}.{nameof(MenuEvents.MenuClosed)}", MenuEvents.MenuClosed?.GetInvocationList(), null, new EventArgsClickableMenuClosed(priorMenu)); } } }