diff options
Diffstat (limited to 'src/SMAPI/Events')
| -rw-r--r-- | src/SMAPI/Events/ContentEvents.cs | 28 | ||||
| -rw-r--r-- | src/SMAPI/Events/ControlEvents.cs | 123 | ||||
| -rw-r--r-- | src/SMAPI/Events/GameEvents.cs | 110 | ||||
| -rw-r--r-- | src/SMAPI/Events/GraphicsEvents.cs | 120 | ||||
| -rw-r--r-- | src/SMAPI/Events/InputEvents.cs | 46 | ||||
| -rw-r--r-- | src/SMAPI/Events/LocationEvents.cs | 61 | ||||
| -rw-r--r-- | src/SMAPI/Events/MenuEvents.cs | 44 | ||||
| -rw-r--r-- | src/SMAPI/Events/MineEvents.cs | 29 | ||||
| -rw-r--r-- | src/SMAPI/Events/PlayerEvents.cs | 45 | ||||
| -rw-r--r-- | src/SMAPI/Events/SaveEvents.cs | 84 | ||||
| -rw-r--r-- | src/SMAPI/Events/SpecialisedEvents.cs | 37 | ||||
| -rw-r--r-- | src/SMAPI/Events/TimeEvents.cs | 41 |
12 files changed, 377 insertions, 391 deletions
diff --git a/src/SMAPI/Events/ContentEvents.cs b/src/SMAPI/Events/ContentEvents.cs index 4b4e2ad0..63645258 100644 --- a/src/SMAPI/Events/ContentEvents.cs +++ b/src/SMAPI/Events/ContentEvents.cs @@ -1,29 +1,37 @@ -using System; -using StardewModdingAPI.Framework; +using System; +using StardewModdingAPI.Framework.Events; namespace StardewModdingAPI.Events { /// <summary>Events raised when the game loads content.</summary> public static class ContentEvents { + /********* + ** Properties + *********/ + /// <summary>The core event manager.</summary> + private static EventManager EventManager; + /********* ** Events *********/ /// <summary>Raised after the content language changes.</summary> - public static event EventHandler<EventArgsValueChanged<string>> AfterLocaleChanged; + public static event EventHandler<EventArgsValueChanged<string>> AfterLocaleChanged + { + add => ContentEvents.EventManager.Content_LocaleChanged.Add(value); + remove => ContentEvents.EventManager.Content_LocaleChanged.Remove(value); + } /********* - ** Internal methods + ** Public methods *********/ - /// <summary>Raise an <see cref="AfterLocaleChanged"/> event.</summary> - /// <param name="monitor">Encapsulates monitoring and logging.</param> - /// <param name="oldLocale">The previous locale.</param> - /// <param name="newLocale">The current locale.</param> - internal static void InvokeAfterLocaleChanged(IMonitor monitor, string oldLocale, string newLocale) + /// <summary>Initialise the events.</summary> + /// <param name="eventManager">The core event manager.</param> + internal static void Init(EventManager eventManager) { - monitor.SafelyRaiseGenericEvent($"{nameof(ContentEvents)}.{nameof(ContentEvents.AfterLocaleChanged)}", ContentEvents.AfterLocaleChanged?.GetInvocationList(), null, new EventArgsValueChanged<string>(oldLocale, newLocale)); + ContentEvents.EventManager = eventManager; } } } diff --git a/src/SMAPI/Events/ControlEvents.cs b/src/SMAPI/Events/ControlEvents.cs index 80d0f547..973bb245 100644 --- a/src/SMAPI/Events/ControlEvents.cs +++ b/src/SMAPI/Events/ControlEvents.cs @@ -1,7 +1,6 @@ -using System; -using Microsoft.Xna.Framework; +using System; using Microsoft.Xna.Framework.Input; -using StardewModdingAPI.Framework; +using StardewModdingAPI.Framework.Events; namespace StardewModdingAPI.Events { @@ -9,104 +8,80 @@ namespace StardewModdingAPI.Events public static class ControlEvents { /********* - ** Events + ** Properties *********/ - /// <summary>Raised when the <see cref="KeyboardState"/> changes. That happens when the player presses or releases a key.</summary> - public static event EventHandler<EventArgsKeyboardStateChanged> KeyboardChanged; - - /// <summary>Raised when the player presses a keyboard key.</summary> - public static event EventHandler<EventArgsKeyPressed> KeyPressed; - - /// <summary>Raised when the player releases a keyboard key.</summary> - public static event EventHandler<EventArgsKeyPressed> KeyReleased; - - /// <summary>Raised when the <see cref="MouseState"/> changes. That happens when the player moves the mouse, scrolls the mouse wheel, or presses/releases a button.</summary> - public static event EventHandler<EventArgsMouseStateChanged> MouseChanged; - - /// <summary>The player pressed a controller button. This event isn't raised for trigger buttons.</summary> - public static event EventHandler<EventArgsControllerButtonPressed> ControllerButtonPressed; - - /// <summary>The player released a controller button. This event isn't raised for trigger buttons.</summary> - public static event EventHandler<EventArgsControllerButtonReleased> ControllerButtonReleased; - - /// <summary>The player pressed a controller trigger button.</summary> - public static event EventHandler<EventArgsControllerTriggerPressed> ControllerTriggerPressed; - - /// <summary>The player released a controller trigger button.</summary> - public static event EventHandler<EventArgsControllerTriggerReleased> ControllerTriggerReleased; + /// <summary>The core event manager.</summary> + private static EventManager EventManager; /********* - ** Internal methods + ** Events *********/ - /// <summary>Raise a <see cref="KeyboardChanged"/> event.</summary> - /// <param name="monitor">Encapsulates monitoring and logging.</param> - /// <param name="priorState">The previous keyboard state.</param> - /// <param name="newState">The current keyboard state.</param> - internal static void InvokeKeyboardChanged(IMonitor monitor, KeyboardState priorState, KeyboardState newState) + /// <summary>Raised when the <see cref="KeyboardState"/> changes. That happens when the player presses or releases a key.</summary> + public static event EventHandler<EventArgsKeyboardStateChanged> KeyboardChanged { - monitor.SafelyRaiseGenericEvent($"{nameof(ControlEvents)}.{nameof(ControlEvents.KeyboardChanged)}", ControlEvents.KeyboardChanged?.GetInvocationList(), null, new EventArgsKeyboardStateChanged(priorState, newState)); + add => ControlEvents.EventManager.Control_KeyboardChanged.Add(value); + remove => ControlEvents.EventManager.Control_KeyboardChanged.Remove(value); } - /// <summary>Raise a <see cref="MouseChanged"/> event.</summary> - /// <param name="monitor">Encapsulates monitoring and logging.</param> - /// <param name="priorState">The previous mouse state.</param> - /// <param name="newState">The current mouse state.</param> - /// <param name="priorPosition">The previous mouse position on the screen adjusted for the zoom level.</param> - /// <param name="newPosition">The current mouse position on the screen adjusted for the zoom level.</param> - internal static void InvokeMouseChanged(IMonitor monitor, MouseState priorState, MouseState newState, Point priorPosition, Point newPosition) + /// <summary>Raised when the player presses a keyboard key.</summary> + public static event EventHandler<EventArgsKeyPressed> KeyPressed { - monitor.SafelyRaiseGenericEvent($"{nameof(ControlEvents)}.{nameof(ControlEvents.MouseChanged)}", ControlEvents.MouseChanged?.GetInvocationList(), null, new EventArgsMouseStateChanged(priorState, newState, priorPosition, newPosition)); + add => ControlEvents.EventManager.Control_KeyPressed.Add(value); + remove => ControlEvents.EventManager.Control_KeyPressed.Remove(value); } - /// <summary>Raise a <see cref="KeyPressed"/> event.</summary> - /// <param name="monitor">Encapsulates monitoring and logging.</param> - /// <param name="key">The keyboard button that was pressed.</param> - internal static void InvokeKeyPressed(IMonitor monitor, Keys key) + /// <summary>Raised when the player releases a keyboard key.</summary> + public static event EventHandler<EventArgsKeyPressed> KeyReleased { - monitor.SafelyRaiseGenericEvent($"{nameof(ControlEvents)}.{nameof(ControlEvents.KeyPressed)}", ControlEvents.KeyPressed?.GetInvocationList(), null, new EventArgsKeyPressed(key)); + add => ControlEvents.EventManager.Control_KeyReleased.Add(value); + remove => ControlEvents.EventManager.Control_KeyReleased.Remove(value); } - /// <summary>Raise a <see cref="KeyReleased"/> event.</summary> - /// <param name="monitor">Encapsulates monitoring and logging.</param> - /// <param name="key">The keyboard button that was released.</param> - internal static void InvokeKeyReleased(IMonitor monitor, Keys key) + /// <summary>Raised when the <see cref="MouseState"/> changes. That happens when the player moves the mouse, scrolls the mouse wheel, or presses/releases a button.</summary> + public static event EventHandler<EventArgsMouseStateChanged> MouseChanged { - monitor.SafelyRaiseGenericEvent($"{nameof(ControlEvents)}.{nameof(ControlEvents.KeyReleased)}", ControlEvents.KeyReleased?.GetInvocationList(), null, new EventArgsKeyPressed(key)); + add => ControlEvents.EventManager.Control_MouseChanged.Add(value); + remove => ControlEvents.EventManager.Control_MouseChanged.Remove(value); } - /// <summary>Raise a <see cref="ControllerButtonPressed"/> event.</summary> - /// <param name="monitor">Encapsulates monitoring and logging.</param> - /// <param name="button">The controller button that was pressed.</param> - internal static void InvokeButtonPressed(IMonitor monitor, Buttons button) + /// <summary>The player pressed a controller button. This event isn't raised for trigger buttons.</summary> + public static event EventHandler<EventArgsControllerButtonPressed> ControllerButtonPressed { - monitor.SafelyRaiseGenericEvent($"{nameof(ControlEvents)}.{nameof(ControlEvents.ControllerButtonPressed)}", ControlEvents.ControllerButtonPressed?.GetInvocationList(), null, new EventArgsControllerButtonPressed(PlayerIndex.One, button)); + add => ControlEvents.EventManager.Control_ControllerButtonPressed.Add(value); + remove => ControlEvents.EventManager.Control_ControllerButtonPressed.Remove(value); } - /// <summary>Raise a <see cref="ControllerButtonReleased"/> event.</summary> - /// <param name="monitor">Encapsulates monitoring and logging.</param> - /// <param name="button">The controller button that was released.</param> - internal static void InvokeButtonReleased(IMonitor monitor, Buttons button) + /// <summary>The player released a controller button. This event isn't raised for trigger buttons.</summary> + public static event EventHandler<EventArgsControllerButtonReleased> ControllerButtonReleased { - monitor.SafelyRaiseGenericEvent($"{nameof(ControlEvents)}.{nameof(ControlEvents.ControllerButtonReleased)}", ControlEvents.ControllerButtonReleased?.GetInvocationList(), null, new EventArgsControllerButtonReleased(PlayerIndex.One, button)); + add => ControlEvents.EventManager.Control_ControllerButtonReleased.Add(value); + remove => ControlEvents.EventManager.Control_ControllerButtonReleased.Remove(value); } - /// <summary>Raise a <see cref="ControllerTriggerPressed"/> event.</summary> - /// <param name="monitor">Encapsulates monitoring and logging.</param> - /// <param name="button">The trigger button that was pressed.</param> - /// <param name="value">The current trigger value.</param> - internal static void InvokeTriggerPressed(IMonitor monitor, Buttons button, float value) + /// <summary>The player pressed a controller trigger button.</summary> + public static event EventHandler<EventArgsControllerTriggerPressed> ControllerTriggerPressed { - monitor.SafelyRaiseGenericEvent($"{nameof(ControlEvents)}.{nameof(ControlEvents.ControllerTriggerPressed)}", ControlEvents.ControllerTriggerPressed?.GetInvocationList(), null, new EventArgsControllerTriggerPressed(PlayerIndex.One, button, value)); + add => ControlEvents.EventManager.Control_ControllerTriggerPressed.Add(value); + remove => ControlEvents.EventManager.Control_ControllerTriggerPressed.Remove(value); } - /// <summary>Raise a <see cref="ControllerTriggerReleased"/> event.</summary> - /// <param name="monitor">Encapsulates monitoring and logging.</param> - /// <param name="button">The trigger button that was pressed.</param> - /// <param name="value">The current trigger value.</param> - internal static void InvokeTriggerReleased(IMonitor monitor, Buttons button, float value) + /// <summary>The player released a controller trigger button.</summary> + public static event EventHandler<EventArgsControllerTriggerReleased> ControllerTriggerReleased + { + add => ControlEvents.EventManager.Control_ControllerTriggerReleased.Add(value); + remove => ControlEvents.EventManager.Control_ControllerTriggerReleased.Remove(value); + } + + + /********* + ** Public methods + *********/ + /// <summary>Initialise the events.</summary> + /// <param name="eventManager">The core event manager.</param> + internal static void Init(EventManager eventManager) { - monitor.SafelyRaiseGenericEvent($"{nameof(ControlEvents)}.{nameof(ControlEvents.ControllerTriggerReleased)}", ControlEvents.ControllerTriggerReleased?.GetInvocationList(), null, new EventArgsControllerTriggerReleased(PlayerIndex.One, button, value)); + ControlEvents.EventManager = eventManager; } } } diff --git a/src/SMAPI/Events/GameEvents.cs b/src/SMAPI/Events/GameEvents.cs index 3466470d..92879280 100644 --- a/src/SMAPI/Events/GameEvents.cs +++ b/src/SMAPI/Events/GameEvents.cs @@ -1,5 +1,5 @@ using System; -using StardewModdingAPI.Framework; +using StardewModdingAPI.Framework.Events; namespace StardewModdingAPI.Events { @@ -7,100 +7,80 @@ namespace StardewModdingAPI.Events public static class GameEvents { /********* - ** Events + ** Properties *********/ - /// <summary>Raised during launch after configuring XNA or MonoGame. The game window hasn't been opened by this point. Called after <see cref="Microsoft.Xna.Framework.Game.Initialize"/>.</summary> - internal static event EventHandler InitializeInternal; - - /// <summary>Raised when the game updates its state (≈60 times per second).</summary> - public static event EventHandler UpdateTick; - - /// <summary>Raised every other tick (≈30 times per second).</summary> - public static event EventHandler SecondUpdateTick; - - /// <summary>Raised every fourth tick (≈15 times per second).</summary> - public static event EventHandler FourthUpdateTick; - - /// <summary>Raised every eighth tick (≈8 times per second).</summary> - public static event EventHandler EighthUpdateTick; - - /// <summary>Raised every 15th tick (≈4 times per second).</summary> - public static event EventHandler QuarterSecondTick; - - /// <summary>Raised every 30th tick (≈twice per second).</summary> - public static event EventHandler HalfSecondTick; - - /// <summary>Raised every 60th tick (≈once per second).</summary> - public static event EventHandler OneSecondTick; - - /// <summary>Raised once after the game initialises and all <see cref="IMod.Entry"/> methods have been called.</summary> - public static event EventHandler FirstUpdateTick; + /// <summary>The core event manager.</summary> + private static EventManager EventManager; /********* - ** Internal methods + ** Events *********/ - /// <summary>Raise an <see cref="InitializeInternal"/> event.</summary> - /// <param name="monitor">Encapsulates logging and monitoring.</param> - internal static void InvokeInitialize(IMonitor monitor) + /// <summary>Raised when the game updates its state (≈60 times per second).</summary> + public static event EventHandler UpdateTick { - monitor.SafelyRaisePlainEvent($"{nameof(GameEvents)}.{nameof(GameEvents.InitializeInternal)}", GameEvents.InitializeInternal?.GetInvocationList()); + add => GameEvents.EventManager.Game_UpdateTick.Add(value); + remove => GameEvents.EventManager.Game_UpdateTick.Remove(value); } - /// <summary>Raise an <see cref="UpdateTick"/> event.</summary> - /// <param name="monitor">Encapsulates logging and monitoring.</param> - internal static void InvokeUpdateTick(IMonitor monitor) + /// <summary>Raised every other tick (≈30 times per second).</summary> + public static event EventHandler SecondUpdateTick { - monitor.SafelyRaisePlainEvent($"{nameof(GameEvents)}.{nameof(GameEvents.UpdateTick)}", GameEvents.UpdateTick?.GetInvocationList()); + add => GameEvents.EventManager.Game_SecondUpdateTick.Add(value); + remove => GameEvents.EventManager.Game_SecondUpdateTick.Remove(value); } - /// <summary>Raise a <see cref="SecondUpdateTick"/> event.</summary> - /// <param name="monitor">Encapsulates monitoring and logging.</param> - internal static void InvokeSecondUpdateTick(IMonitor monitor) + /// <summary>Raised every fourth tick (≈15 times per second).</summary> + public static event EventHandler FourthUpdateTick { - monitor.SafelyRaisePlainEvent($"{nameof(GameEvents)}.{nameof(GameEvents.SecondUpdateTick)}", GameEvents.SecondUpdateTick?.GetInvocationList()); + add => GameEvents.EventManager.Game_FourthUpdateTick.Add(value); + remove => GameEvents.EventManager.Game_FourthUpdateTick.Remove(value); } - /// <summary>Raise a <see cref="FourthUpdateTick"/> event.</summary> - /// <param name="monitor">Encapsulates monitoring and logging.</param> - internal static void InvokeFourthUpdateTick(IMonitor monitor) + /// <summary>Raised every eighth tick (≈8 times per second).</summary> + public static event EventHandler EighthUpdateTick { - monitor.SafelyRaisePlainEvent($"{nameof(GameEvents)}.{nameof(GameEvents.FourthUpdateTick)}", GameEvents.FourthUpdateTick?.GetInvocationList()); + add => GameEvents.EventManager.Game_EighthUpdateTick.Add(value); + remove => GameEvents.EventManager.Game_EighthUpdateTick.Remove(value); } - /// <summary>Raise a <see cref="EighthUpdateTick"/> event.</summary> - /// <param name="monitor">Encapsulates monitoring and logging.</param> - internal static void InvokeEighthUpdateTick(IMonitor monitor) + /// <summary>Raised every 15th tick (≈4 times per second).</summary> + public static event EventHandler QuarterSecondTick { - monitor.SafelyRaisePlainEvent($"{nameof(GameEvents)}.{nameof(GameEvents.EighthUpdateTick)}", GameEvents.EighthUpdateTick?.GetInvocationList()); + add => GameEvents.EventManager.Game_QuarterSecondTick.Add(value); + remove => GameEvents.EventManager.Game_QuarterSecondTick.Remove(value); } - /// <summary>Raise a <see cref="QuarterSecondTick"/> event.</summary> - /// <param name="monitor">Encapsulates monitoring and logging.</param> - internal static void InvokeQuarterSecondTick(IMonitor monitor) + /// <summary>Raised every 30th tick (≈twice per second).</summary> + public static event EventHandler HalfSecondTick { - monitor.SafelyRaisePlainEvent($"{nameof(GameEvents)}.{nameof(GameEvents.QuarterSecondTick)}", GameEvents.QuarterSecondTick?.GetInvocationList()); + add => GameEvents.EventManager.Game_HalfSecondTick.Add(value); + remove => GameEvents.EventManager.Game_HalfSecondTick.Remove(value); } - /// <summary>Raise a <see cref="HalfSecondTick"/> event.</summary> - /// <param name="monitor">Encapsulates monitoring and logging.</param> - internal static void InvokeHalfSecondTick(IMonitor monitor) + /// <summary>Raised every 60th tick (≈once per second).</summary> + public static event EventHandler OneSecondTick { - monitor.SafelyRaisePlainEvent($"{nameof(GameEvents)}.{nameof(GameEvents.HalfSecondTick)}", GameEvents.HalfSecondTick?.GetInvocationList()); + add => GameEvents.EventManager.Game_OneSecondTick.Add(value); + remove => GameEvents.EventManager.Game_OneSecondTick.Remove(value); } - /// <summary>Raise a <see cref="OneSecondTick"/> event.</summary> - /// <param name="monitor">Encapsulates monitoring and logging.</param> - internal static void InvokeOneSecondTick(IMonitor monitor) + /// <summary>Raised once after the game initialises and all <see cref="IMod.Entry"/> methods have been called.</summary> + public static event EventHandler FirstUpdateTick { - monitor.SafelyRaisePlainEvent($"{nameof(GameEvents)}.{nameof(GameEvents.OneSecondTick)}", GameEvents.OneSecondTick?.GetInvocationList()); + add => GameEvents.EventManager.Game_FirstUpdateTick.Add(value); + remove => GameEvents.EventManager.Game_FirstUpdateTick.Remove(value); } - /// <summary>Raise a <see cref="FirstUpdateTick"/> event.</summary> - /// <param name="monitor">Encapsulates monitoring and logging.</param> - internal static void InvokeFirstUpdateTick(IMonitor monitor) + + /********* + ** Public methods + *********/ + /// <summary>Initialise the events.</summary> + /// <param name="eventManager">The core event manager.</param> + internal static void Init(EventManager eventManager) { - monitor.SafelyRaisePlainEvent($"{nameof(GameEvents)}.{nameof(GameEvents.FirstUpdateTick)}", GameEvents.FirstUpdateTick?.GetInvocationList()); + GameEvents.EventManager = eventManager; } } } diff --git a/src/SMAPI/Events/GraphicsEvents.cs b/src/SMAPI/Events/GraphicsEvents.cs index fff51bed..e1ff4ee7 100644 --- a/src/SMAPI/Events/GraphicsEvents.cs +++ b/src/SMAPI/Events/GraphicsEvents.cs @@ -1,5 +1,5 @@ -using System; -using StardewModdingAPI.Framework; +using System; +using StardewModdingAPI.Framework.Events; namespace StardewModdingAPI.Events { @@ -7,110 +7,82 @@ namespace StardewModdingAPI.Events public static class GraphicsEvents { /********* + ** Properties + *********/ + /// <summary>The core event manager.</summary> + private static EventManager EventManager; + + + /********* ** Events *********/ - /**** - ** Generic events - ****/ /// <summary>Raised after the game window is resized.</summary> - public static event EventHandler Resize; + public static event EventHandler Resize + { + add => GraphicsEvents.EventManager.Graphics_Resize.Add(value); + remove => GraphicsEvents.EventManager.Graphics_Resize.Remove(value); + } /**** ** Main render events ****/ /// <summary>Raised before drawing the world to the screen.</summary> - public static event EventHandler OnPreRenderEvent; + public static event EventHandler OnPreRenderEvent + { + add => GraphicsEvents.EventManager.Graphics_OnPreRenderEvent.Add(value); + remove => GraphicsEvents.EventManager.Graphics_OnPreRenderEvent.Remove(value); + } /// <summary>Raised after drawing the world to the screen.</summary> - public static event EventHandler OnPostRenderEvent; - - /**** - ** HUD events - ****/ - /// <summary>Raised before drawing the HUD (item toolbar, clock, etc) to the screen. The HUD is available at this point, but not necessarily visible. (For example, the event is raised even if a menu is open.)</summary> - public static event EventHandler OnPreRenderHudEvent; - - /// <summary>Raised after drawing the HUD (item toolbar, clock, etc) to the screen. The HUD is available at this point, but not necessarily visible. (For example, the event is raised even if a menu is open.)</summary> - public static event EventHandler OnPostRenderHudEvent; - - /**** - ** GUI events - ****/ - /// <summary>Raised before drawing a menu to the screen during a draw loop. This includes the game's internal menus like the title screen.</summary> - public static event EventHandler OnPreRenderGuiEvent; - - /// <summary>Raised after drawing a menu to the screen during a draw loop. This includes the game's internal menus like the title screen.</summary> - public static event EventHandler OnPostRenderGuiEvent; - - - /********* - ** Internal methods - *********/ - /**** - ** Generic events - ****/ - /// <summary>Raise a <see cref="Resize"/> event.</summary> - /// <param name="monitor">Encapsulates monitoring and logging.</param> - internal static void InvokeResize(IMonitor monitor) + public static event EventHandler OnPostRenderEvent { - monitor.SafelyRaisePlainEvent($"{nameof(GraphicsEvents)}.{nameof(GraphicsEvents.Resize)}", GraphicsEvents.Resize?.GetInvocationList()); + add => GraphicsEvents.EventManager.Graphics_OnPostRenderEvent.Add(value); + remove => GraphicsEvents.EventManager.Graphics_OnPostRenderEvent.Remove(value); } /**** - ** Main render events + ** HUD events ****/ - /// <summary>Raise an <see cref="OnPreRenderEvent"/> event.</summary> - /// <param name="monitor">Encapsulates monitoring and logging.</param> - internal static void InvokeOnPreRenderEvent(IMonitor monitor) - { - monitor.SafelyRaisePlainEvent($"{nameof(GraphicsEvents)}.{nameof(GraphicsEvents.OnPreRenderEvent)}", GraphicsEvents.OnPreRenderEvent?.GetInvocationList()); - } - - /// <summary>Raise an <see cref="OnPostRenderEvent"/> event.</summary> - /// <param name="monitor">Encapsulates monitoring and logging.</param> - internal static void InvokeOnPostRenderEvent(IMonitor monitor) + /// <summary>Raised before drawing the HUD (item toolbar, clock, etc) to the screen. The HUD is available at this point, but not necessarily visible. (For example, the event is raised even if a menu is open.)</summary> + public static event EventHandler OnPreRenderHudEvent { - monitor.SafelyRaisePlainEvent($"{nameof(GraphicsEvents)}.{nameof(GraphicsEvents.OnPostRenderEvent)}", GraphicsEvents.OnPostRenderEvent?.GetInvocationList()); + add => GraphicsEvents.EventManager.Graphics_OnPreRenderHudEvent.Add(value); + remove => GraphicsEvents.EventManager.Graphics_OnPreRenderHudEvent.Remove(value); } - /// <summary>Get whether there are any post-render event listeners.</summary> - internal static bool HasPostRenderListeners() + /// <summary>Raised after drawing the HUD (item toolbar, clock, etc) to the screen. The HUD is available at this point, but not necessarily visible. (For example, the event is raised even if a menu is open.)</summary> + public static event EventHandler OnPostRenderHudEvent { - return GraphicsEvents.OnPostRenderEvent != null; + add => GraphicsEvents.EventManager.Graphics_OnPostRenderHudEvent.Add(value); + remove => GraphicsEvents.EventManager.Graphics_OnPostRenderHudEvent.Remove(value); } /**** ** GUI events ****/ - /// <summary>Raise an <see cref="OnPreRenderGuiEvent"/> event.</summary> - /// <param name="monitor">Encapsulates monitoring and logging.</param> - internal static void InvokeOnPreRenderGuiEvent(IMonitor monitor) + /// <summary>Raised before drawing a menu to the screen during a draw loop. This includes the game's internal menus like the title screen.</summary> + public static event EventHandler OnPreRenderGuiEvent { - monitor.SafelyRaisePlainEvent($"{nameof(GraphicsEvents)}.{nameof(GraphicsEvents.OnPreRenderGuiEvent)}", GraphicsEvents.OnPreRenderGuiEvent?.GetInvocationList()); + add => GraphicsEvents.EventManager.Graphics_OnPreRenderGuiEvent.Add(value); + remove => GraphicsEvents.EventManager.Graphics_OnPreRenderGuiEvent.Remove(value); } - /// <summary>Raise an <see cref="OnPostRenderGuiEvent"/> event.</summary> - /// <param name="monitor">Encapsulates monitoring and logging.</param> - internal static void InvokeOnPostRenderGuiEvent(IMonitor monitor) + /// <summary>Raised after drawing a menu to the screen during a draw loop. This includes the game's internal menus like the title screen.</summary> + public static event EventHandler OnPostRenderGuiEvent { - monitor.SafelyRaisePlainEvent($"{nameof(GraphicsEvents)}.{nameof(GraphicsEvents.OnPostRenderGuiEvent)}", GraphicsEvents.OnPostRenderGuiEvent?.GetInvocationList()); + add => GraphicsEvents.EventManager.Graphics_OnPostRenderGuiEvent.Add(value); + remove => GraphicsEvents.EventManager.Graphics_OnPostRenderGuiEvent.Remove(value); } - /**** - ** HUD events - ****/ - /// <summary>Raise an <see cref="OnPreRenderHudEvent"/> event.</summary> - /// <param name="monitor">Encapsulates monitoring and logging.</param> - internal static void InvokeOnPreRenderHudEvent(IMonitor monitor) - { - monitor.SafelyRaisePlainEvent($"{nameof(GraphicsEvents)}.{nameof(GraphicsEvents.OnPreRenderHudEvent)}", GraphicsEvents.OnPreRenderHudEvent?.GetInvocationList()); - } - /// <summary>Raise an <see cref="OnPostRenderHudEvent"/> event.</summary> - /// <param name="monitor">Encapsulates monitoring and logging.</param> - internal static void InvokeOnPostRenderHudEvent(IMonitor monitor) + /********* + ** Public methods + *********/ + /// <summary>Initialise the events.</summary> + /// <param name="eventManager">The core event manager.</param> + internal static void Init(EventManager eventManager) { - monitor.SafelyRaisePlainEvent($"{nameof(GraphicsEvents)}.{nameof(GraphicsEvents.OnPostRenderHudEvent)}", GraphicsEvents.OnPostRenderHudEvent?.GetInvocationList()); + GraphicsEvents.EventManager = eventManager; } } } diff --git a/src/SMAPI/Events/InputEvents.cs b/src/SMAPI/Events/InputEvents.cs index 985aed99..84d7ce5d 100644 --- a/src/SMAPI/Events/InputEvents.cs +++ b/src/SMAPI/Events/InputEvents.cs @@ -1,5 +1,5 @@ using System; -using StardewModdingAPI.Framework; +using StardewModdingAPI.Framework.Events; namespace StardewModdingAPI.Events { @@ -7,38 +7,38 @@ namespace StardewModdingAPI.Events public static class InputEvents { /********* + ** Properties + *********/ + /// <summary>The core event manager.</summary> + private static EventManager EventManager; + + + /********* ** Events *********/ /// <summary>Raised when the player presses a button on the keyboard, controller, or mouse.</summary> - public static event EventHandler<EventArgsInput> ButtonPressed; + public static event EventHandler<EventArgsInput> ButtonPressed + { + add => InputEvents.EventManager.Input_ButtonPressed.Add(value); + remove => InputEvents.EventManager.Input_ButtonPressed.Remove(value); + } /// <summary>Raised when the player releases a keyboard key on the keyboard, controller, or mouse.</summary> - public static event EventHandler<EventArgsInput> ButtonReleased; + public static event EventHandler<EventArgsInput> ButtonReleased + { + add => InputEvents.EventManager.Input_ButtonReleased.Add(value); + remove => InputEvents.EventManager.Input_ButtonReleased.Remove(value); + } /********* - ** Internal methods + ** Public methods *********/ - /// <summary>Raise a <see cref="ButtonPressed"/> event.</summary> - /// <param name="monitor">Encapsulates monitoring and logging.</param> - /// <param name="button">The button on the controller, keyboard, or mouse.</param> - /// <param name="cursor">The cursor position.</param> - /// <param name="isActionButton">Whether the input should trigger actions on the affected tile.</param> - /// <param name="isUseToolButton">Whether the input should use tools on the affected tile.</param> - internal static void InvokeButtonPressed(IMonitor monitor, SButton button, ICursorPosition cursor, bool isActionButton, bool isUseToolButton) - { - monitor.SafelyRaiseGenericEvent($"{nameof(InputEvents)}.{nameof(InputEvents.ButtonPressed)}", InputEvents.ButtonPressed?.GetInvocationList(), null, new EventArgsInput(button, cursor, isActionButton, isUseToolButton)); - } - - /// <summary>Raise a <see cref="ButtonReleased"/> event.</summary> - /// <param name="monitor">Encapsulates monitoring and logging.</param> - /// <param name="button">The button on the controller, keyboard, or mouse.</param> - /// <param name="cursor">The cursor position.</param> - /// <param name="isActionButton">Whether the input should trigger actions on the affected tile.</param> - /// <param name="isUseToolButton">Whether the input should use tools on the affected tile.</param> - internal static void InvokeButtonReleased(IMonitor monitor, SButton button, ICursorPosition cursor, bool isActionButton, bool isUseToolButton) + /// <summary>Initialise the events.</summary> + /// <param name="eventManager">The core event manager.</param> + internal static void Init(EventManager eventManager) { - monitor.SafelyRaiseGenericEvent($"{nameof(InputEvents)}.{nameof(InputEvents.ButtonReleased)}", InputEvents.ButtonReleased?.GetInvocationList(), null, new EventArgsInput(button, cursor, isActionButton, isUseToolButton)); + InputEvents.EventManager = eventManager; } } } diff --git a/src/SMAPI/Events/LocationEvents.cs b/src/SMAPI/Events/LocationEvents.cs index b834bc1c..81d13e9f 100644 --- a/src/SMAPI/Events/LocationEvents.cs +++ b/src/SMAPI/Events/LocationEvents.cs @@ -1,9 +1,5 @@ -using System; -using System.Collections.Generic; -using Microsoft.Xna.Framework; -using StardewModdingAPI.Framework; -using StardewValley; -using Object = StardewValley.Object; +using System; +using StardewModdingAPI.Framework.Events; namespace StardewModdingAPI.Events { @@ -11,44 +7,45 @@ namespace StardewModdingAPI.Events public static class LocationEvents { /********* - ** Events + ** Properties *********/ - /// <summary>Raised after the player warps to a new location.</summary> - public static event EventHandler<EventArgsCurrentLocationChanged> CurrentLocationChanged; - - /// <summary>Raised after a game location is added or removed.</summary> - public static event EventHandler<EventArgsGameLocationsChanged> LocationsChanged; - - /// <summary>Raised after the list of objects in the current location changes (e.g. an object is added or removed).</summary> - public static event EventHandler<EventArgsLocationObjectsChanged> LocationObjectsChanged; + /// <summary>The core event manager.</summary> + private static EventManager EventManager; /********* - ** Internal methods + ** Events *********/ - /// <summary>Raise a <see cref="CurrentLocationChanged"/> event.</summary> - /// <param name="monitor">Encapsulates monitoring and logging.</param> - /// <param name="priorLocation">The player's previous location.</param> - /// <param name="newLocation">The player's current location.</param> - internal static void InvokeCurrentLocationChanged(IMonitor monitor, GameLocation priorLocation, GameLocation newLocation) + /// <summary>Raised after the player warps to a new location.</summary> + public static event EventHandler<EventArgsCurrentLocationChanged> CurrentLocationChanged { - monitor.SafelyRaiseGenericEvent($"{nameof(LocationEvents)}.{nameof(LocationEvents.CurrentLocationChanged)}", LocationEvents.CurrentLocationChanged?.GetInvocationList(), null, new EventArgsCurrentLocationChanged(priorLocation, newLocation)); + add => LocationEvents.EventManager.Location_CurrentLocationChanged.Add(value); + remove => LocationEvents.EventManager.Location_CurrentLocationChanged.Remove(value); } - /// <summary>Raise a <see cref="LocationsChanged"/> event.</summary> - /// <param name="monitor">Encapsulates monitoring and logging.</param> - /// <param name="newLocations">The current list of game locations.</param> - internal static void InvokeLocationsChanged(IMonitor monitor, List<GameLocation> newLocations) + /// <summary>Raised after a game location is added or removed.</summary> + public static event EventHandler<EventArgsGameLocationsChanged> LocationsChanged + { |
