From 929dccb75a1405737975d76648e015a3e7c00177 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 7 Oct 2017 23:07:10 -0400 Subject: reorganise repo structure --- src/SMAPI/Events/ChangeType.cs | 15 +++ src/SMAPI/Events/ContentEvents.cs | 29 +++++ src/SMAPI/Events/ControlEvents.cs | 112 +++++++++++++++++++ src/SMAPI/Events/EventArgsClickableMenuChanged.cs | 31 ++++++ src/SMAPI/Events/EventArgsClickableMenuClosed.cs | 26 +++++ .../Events/EventArgsControllerButtonPressed.cs | 32 ++++++ .../Events/EventArgsControllerButtonReleased.cs | 32 ++++++ .../Events/EventArgsControllerTriggerPressed.cs | 37 ++++++ .../Events/EventArgsControllerTriggerReleased.cs | 37 ++++++ .../Events/EventArgsCurrentLocationChanged.cs | 31 ++++++ src/SMAPI/Events/EventArgsGameLocationsChanged.cs | 27 +++++ src/SMAPI/Events/EventArgsInput.cs | 124 +++++++++++++++++++++ src/SMAPI/Events/EventArgsIntChanged.cs | 29 +++++ src/SMAPI/Events/EventArgsInventoryChanged.cs | 41 +++++++ src/SMAPI/Events/EventArgsKeyPressed.cs | 26 +++++ src/SMAPI/Events/EventArgsKeyboardStateChanged.cs | 31 ++++++ src/SMAPI/Events/EventArgsLevelUp.cs | 52 +++++++++ .../Events/EventArgsLocationObjectsChanged.cs | 28 +++++ src/SMAPI/Events/EventArgsMineLevelChanged.cs | 30 +++++ src/SMAPI/Events/EventArgsMouseStateChanged.cs | 42 +++++++ src/SMAPI/Events/EventArgsValueChanged.cs | 31 ++++++ src/SMAPI/Events/GameEvents.cs | 96 ++++++++++++++++ src/SMAPI/Events/GraphicsEvents.cs | 116 +++++++++++++++++++ src/SMAPI/Events/InputEvents.cs | 43 +++++++ src/SMAPI/Events/ItemStackChange.cs | 20 ++++ src/SMAPI/Events/LocationEvents.cs | 54 +++++++++ src/SMAPI/Events/MenuEvents.cs | 40 +++++++ src/SMAPI/Events/MineEvents.cs | 28 +++++ src/SMAPI/Events/PlayerEvents.cs | 43 +++++++ src/SMAPI/Events/SaveEvents.cs | 56 ++++++++++ src/SMAPI/Events/TimeEvents.cs | 37 ++++++ 31 files changed, 1376 insertions(+) create mode 100644 src/SMAPI/Events/ChangeType.cs create mode 100644 src/SMAPI/Events/ContentEvents.cs create mode 100644 src/SMAPI/Events/ControlEvents.cs create mode 100644 src/SMAPI/Events/EventArgsClickableMenuChanged.cs create mode 100644 src/SMAPI/Events/EventArgsClickableMenuClosed.cs create mode 100644 src/SMAPI/Events/EventArgsControllerButtonPressed.cs create mode 100644 src/SMAPI/Events/EventArgsControllerButtonReleased.cs create mode 100644 src/SMAPI/Events/EventArgsControllerTriggerPressed.cs create mode 100644 src/SMAPI/Events/EventArgsControllerTriggerReleased.cs create mode 100644 src/SMAPI/Events/EventArgsCurrentLocationChanged.cs create mode 100644 src/SMAPI/Events/EventArgsGameLocationsChanged.cs create mode 100644 src/SMAPI/Events/EventArgsInput.cs create mode 100644 src/SMAPI/Events/EventArgsIntChanged.cs create mode 100644 src/SMAPI/Events/EventArgsInventoryChanged.cs create mode 100644 src/SMAPI/Events/EventArgsKeyPressed.cs create mode 100644 src/SMAPI/Events/EventArgsKeyboardStateChanged.cs create mode 100644 src/SMAPI/Events/EventArgsLevelUp.cs create mode 100644 src/SMAPI/Events/EventArgsLocationObjectsChanged.cs create mode 100644 src/SMAPI/Events/EventArgsMineLevelChanged.cs create mode 100644 src/SMAPI/Events/EventArgsMouseStateChanged.cs create mode 100644 src/SMAPI/Events/EventArgsValueChanged.cs create mode 100644 src/SMAPI/Events/GameEvents.cs create mode 100644 src/SMAPI/Events/GraphicsEvents.cs create mode 100644 src/SMAPI/Events/InputEvents.cs create mode 100644 src/SMAPI/Events/ItemStackChange.cs create mode 100644 src/SMAPI/Events/LocationEvents.cs create mode 100644 src/SMAPI/Events/MenuEvents.cs create mode 100644 src/SMAPI/Events/MineEvents.cs create mode 100644 src/SMAPI/Events/PlayerEvents.cs create mode 100644 src/SMAPI/Events/SaveEvents.cs create mode 100644 src/SMAPI/Events/TimeEvents.cs (limited to 'src/SMAPI/Events') diff --git a/src/SMAPI/Events/ChangeType.cs b/src/SMAPI/Events/ChangeType.cs new file mode 100644 index 00000000..4b207f08 --- /dev/null +++ b/src/SMAPI/Events/ChangeType.cs @@ -0,0 +1,15 @@ +namespace StardewModdingAPI.Events +{ + /// Indicates how an inventory item changed. + public enum ChangeType + { + /// The entire stack was removed. + Removed, + + /// The entire stack was added. + Added, + + /// The stack size changed. + StackChange + } +} \ No newline at end of file diff --git a/src/SMAPI/Events/ContentEvents.cs b/src/SMAPI/Events/ContentEvents.cs new file mode 100644 index 00000000..4b4e2ad0 --- /dev/null +++ b/src/SMAPI/Events/ContentEvents.cs @@ -0,0 +1,29 @@ +using System; +using StardewModdingAPI.Framework; + +namespace StardewModdingAPI.Events +{ + /// Events raised when the game loads content. + public static class ContentEvents + { + + /********* + ** Events + *********/ + /// Raised after the content language changes. + public static event EventHandler> AfterLocaleChanged; + + + /********* + ** Internal methods + *********/ + /// Raise an event. + /// Encapsulates monitoring and logging. + /// The previous locale. + /// The current locale. + internal static void InvokeAfterLocaleChanged(IMonitor monitor, string oldLocale, string newLocale) + { + monitor.SafelyRaiseGenericEvent($"{nameof(ContentEvents)}.{nameof(ContentEvents.AfterLocaleChanged)}", ContentEvents.AfterLocaleChanged?.GetInvocationList(), null, new EventArgsValueChanged(oldLocale, newLocale)); + } + } +} diff --git a/src/SMAPI/Events/ControlEvents.cs b/src/SMAPI/Events/ControlEvents.cs new file mode 100644 index 00000000..80d0f547 --- /dev/null +++ b/src/SMAPI/Events/ControlEvents.cs @@ -0,0 +1,112 @@ +using System; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Input; +using StardewModdingAPI.Framework; + +namespace StardewModdingAPI.Events +{ + /// Events raised when the player uses a controller, keyboard, or mouse. + public static class ControlEvents + { + /********* + ** Events + *********/ + /// Raised when the changes. That happens when the player presses or releases a key. + public static event EventHandler KeyboardChanged; + + /// Raised when the player presses a keyboard key. + public static event EventHandler KeyPressed; + + /// Raised when the player releases a keyboard key. + public static event EventHandler KeyReleased; + + /// Raised when the changes. That happens when the player moves the mouse, scrolls the mouse wheel, or presses/releases a button. + public static event EventHandler MouseChanged; + + /// The player pressed a controller button. This event isn't raised for trigger buttons. + public static event EventHandler ControllerButtonPressed; + + /// The player released a controller button. This event isn't raised for trigger buttons. + public static event EventHandler ControllerButtonReleased; + + /// The player pressed a controller trigger button. + public static event EventHandler ControllerTriggerPressed; + + /// The player released a controller trigger button. + public static event EventHandler ControllerTriggerReleased; + + + /********* + ** Internal methods + *********/ + /// Raise a event. + /// Encapsulates monitoring and logging. + /// The previous keyboard state. + /// The current keyboard state. + internal static void InvokeKeyboardChanged(IMonitor monitor, KeyboardState priorState, KeyboardState newState) + { + monitor.SafelyRaiseGenericEvent($"{nameof(ControlEvents)}.{nameof(ControlEvents.KeyboardChanged)}", ControlEvents.KeyboardChanged?.GetInvocationList(), null, new EventArgsKeyboardStateChanged(priorState, newState)); + } + + /// Raise a event. + /// Encapsulates monitoring and logging. + /// The previous mouse state. + /// The current mouse state. + /// The previous mouse position on the screen adjusted for the zoom level. + /// The current mouse position on the screen adjusted for the zoom level. + internal static void InvokeMouseChanged(IMonitor monitor, MouseState priorState, MouseState newState, Point priorPosition, Point newPosition) + { + monitor.SafelyRaiseGenericEvent($"{nameof(ControlEvents)}.{nameof(ControlEvents.MouseChanged)}", ControlEvents.MouseChanged?.GetInvocationList(), null, new EventArgsMouseStateChanged(priorState, newState, priorPosition, newPosition)); + } + + /// Raise a event. + /// Encapsulates monitoring and logging. + /// The keyboard button that was pressed. + internal static void InvokeKeyPressed(IMonitor monitor, Keys key) + { + monitor.SafelyRaiseGenericEvent($"{nameof(ControlEvents)}.{nameof(ControlEvents.KeyPressed)}", ControlEvents.KeyPressed?.GetInvocationList(), null, new EventArgsKeyPressed(key)); + } + + /// Raise a event. + /// Encapsulates monitoring and logging. + /// The keyboard button that was released. + internal static void InvokeKeyReleased(IMonitor monitor, Keys key) + { + monitor.SafelyRaiseGenericEvent($"{nameof(ControlEvents)}.{nameof(ControlEvents.KeyReleased)}", ControlEvents.KeyReleased?.GetInvocationList(), null, new EventArgsKeyPressed(key)); + } + + /// Raise a event. + /// Encapsulates monitoring and logging. + /// The controller button that was pressed. + internal static void InvokeButtonPressed(IMonitor monitor, Buttons button) + { + monitor.SafelyRaiseGenericEvent($"{nameof(ControlEvents)}.{nameof(ControlEvents.ControllerButtonPressed)}", ControlEvents.ControllerButtonPressed?.GetInvocationList(), null, new EventArgsControllerButtonPressed(PlayerIndex.One, button)); + } + + /// Raise a event. + /// Encapsulates monitoring and logging. + /// The controller button that was released. + internal static void InvokeButtonReleased(IMonitor monitor, Buttons button) + { + monitor.SafelyRaiseGenericEvent($"{nameof(ControlEvents)}.{nameof(ControlEvents.ControllerButtonReleased)}", ControlEvents.ControllerButtonReleased?.GetInvocationList(), null, new EventArgsControllerButtonReleased(PlayerIndex.One, button)); + } + + /// Raise a event. + /// Encapsulates monitoring and logging. + /// The trigger button that was pressed. + /// The current trigger value. + internal static void InvokeTriggerPressed(IMonitor monitor, Buttons button, float value) + { + monitor.SafelyRaiseGenericEvent($"{nameof(ControlEvents)}.{nameof(ControlEvents.ControllerTriggerPressed)}", ControlEvents.ControllerTriggerPressed?.GetInvocationList(), null, new EventArgsControllerTriggerPressed(PlayerIndex.One, button, value)); + } + + /// Raise a event. + /// Encapsulates monitoring and logging. + /// The trigger button that was pressed. + /// The current trigger value. + internal static void InvokeTriggerReleased(IMonitor monitor, Buttons button, float value) + { + monitor.SafelyRaiseGenericEvent($"{nameof(ControlEvents)}.{nameof(ControlEvents.ControllerTriggerReleased)}", ControlEvents.ControllerTriggerReleased?.GetInvocationList(), null, new EventArgsControllerTriggerReleased(PlayerIndex.One, button, value)); + } + } +} diff --git a/src/SMAPI/Events/EventArgsClickableMenuChanged.cs b/src/SMAPI/Events/EventArgsClickableMenuChanged.cs new file mode 100644 index 00000000..2a2aa163 --- /dev/null +++ b/src/SMAPI/Events/EventArgsClickableMenuChanged.cs @@ -0,0 +1,31 @@ +using System; +using StardewValley.Menus; + +namespace StardewModdingAPI.Events +{ + /// Event arguments for a event. + public class EventArgsClickableMenuChanged : EventArgs + { + /********* + ** Accessors + *********/ + /// The previous menu. + public IClickableMenu NewMenu { get; } + + /// The current menu. + public IClickableMenu PriorMenu { get; } + + + /********* + ** Public methods + *********/ + /// Construct an instance. + /// The previous menu. + /// The current menu. + public EventArgsClickableMenuChanged(IClickableMenu priorMenu, IClickableMenu newMenu) + { + this.NewMenu = newMenu; + this.PriorMenu = priorMenu; + } + } +} diff --git a/src/SMAPI/Events/EventArgsClickableMenuClosed.cs b/src/SMAPI/Events/EventArgsClickableMenuClosed.cs new file mode 100644 index 00000000..5e6585f0 --- /dev/null +++ b/src/SMAPI/Events/EventArgsClickableMenuClosed.cs @@ -0,0 +1,26 @@ +using System; +using StardewValley.Menus; + +namespace StardewModdingAPI.Events +{ + /// Event arguments for a event. + public class EventArgsClickableMenuClosed : EventArgs + { + /********* + ** Accessors + *********/ + /// The menu that was closed. + public IClickableMenu PriorMenu { get; } + + + /********* + ** Accessors + *********/ + /// Construct an instance. + /// The menu that was closed. + public EventArgsClickableMenuClosed(IClickableMenu priorMenu) + { + this.PriorMenu = priorMenu; + } + } +} diff --git a/src/SMAPI/Events/EventArgsControllerButtonPressed.cs b/src/SMAPI/Events/EventArgsControllerButtonPressed.cs new file mode 100644 index 00000000..3243b80b --- /dev/null +++ b/src/SMAPI/Events/EventArgsControllerButtonPressed.cs @@ -0,0 +1,32 @@ +using System; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Input; + +namespace StardewModdingAPI.Events +{ + /// Event arguments for a event. + public class EventArgsControllerButtonPressed : EventArgs + { + /********* + ** Accessors + *********/ + /// The player who pressed the button. + public PlayerIndex PlayerIndex { get; } + + /// The controller button that was pressed. + public Buttons ButtonPressed { get; } + + + /********* + ** Public methods + *********/ + /// Construct an instance. + /// The player who pressed the button. + /// The controller button that was pressed. + public EventArgsControllerButtonPressed(PlayerIndex playerIndex, Buttons button) + { + this.PlayerIndex = playerIndex; + this.ButtonPressed = button; + } + } +} diff --git a/src/SMAPI/Events/EventArgsControllerButtonReleased.cs b/src/SMAPI/Events/EventArgsControllerButtonReleased.cs new file mode 100644 index 00000000..e05a080b --- /dev/null +++ b/src/SMAPI/Events/EventArgsControllerButtonReleased.cs @@ -0,0 +1,32 @@ +using System; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Input; + +namespace StardewModdingAPI.Events +{ + /// Event arguments for a event. + public class EventArgsControllerButtonReleased : EventArgs + { + /********* + ** Accessors + *********/ + /// The player who pressed the button. + public PlayerIndex PlayerIndex { get; } + + /// The controller button that was pressed. + public Buttons ButtonReleased { get; } + + + /********* + ** Public methods + *********/ + /// Construct an instance. + /// The player who pressed the button. + /// The controller button that was released. + public EventArgsControllerButtonReleased(PlayerIndex playerIndex, Buttons button) + { + this.PlayerIndex = playerIndex; + this.ButtonReleased = button; + } + } +} diff --git a/src/SMAPI/Events/EventArgsControllerTriggerPressed.cs b/src/SMAPI/Events/EventArgsControllerTriggerPressed.cs new file mode 100644 index 00000000..a2087733 --- /dev/null +++ b/src/SMAPI/Events/EventArgsControllerTriggerPressed.cs @@ -0,0 +1,37 @@ +using System; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Input; + +namespace StardewModdingAPI.Events +{ + /// Event arguments for a event. + public class EventArgsControllerTriggerPressed : EventArgs + { + /********* + ** Accessors + *********/ + /// The player who pressed the button. + public PlayerIndex PlayerIndex { get; } + + /// The controller button that was pressed. + public Buttons ButtonPressed { get; } + + /// The current trigger value. + public float Value { get; } + + + /********* + ** Public methods + *********/ + /// Construct an instance. + /// The player who pressed the trigger button. + /// The trigger button that was pressed. + /// The current trigger value. + public EventArgsControllerTriggerPressed(PlayerIndex playerIndex, Buttons button, float value) + { + this.PlayerIndex = playerIndex; + this.ButtonPressed = button; + this.Value = value; + } + } +} diff --git a/src/SMAPI/Events/EventArgsControllerTriggerReleased.cs b/src/SMAPI/Events/EventArgsControllerTriggerReleased.cs new file mode 100644 index 00000000..d2eecbec --- /dev/null +++ b/src/SMAPI/Events/EventArgsControllerTriggerReleased.cs @@ -0,0 +1,37 @@ +using System; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Input; + +namespace StardewModdingAPI.Events +{ + /// Event arguments for a event. + public class EventArgsControllerTriggerReleased : EventArgs + { + /********* + ** Accessors + *********/ + /// The player who pressed the button. + public PlayerIndex PlayerIndex { get; } + + /// The controller button that was released. + public Buttons ButtonReleased { get; } + + /// The current trigger value. + public float Value { get; } + + + /********* + ** Public methods + *********/ + /// Construct an instance. + /// The player who pressed the trigger button. + /// The trigger button that was released. + /// The current trigger value. + public EventArgsControllerTriggerReleased(PlayerIndex playerIndex, Buttons button, float value) + { + this.PlayerIndex = playerIndex; + this.ButtonReleased = button; + this.Value = value; + } + } +} diff --git a/src/SMAPI/Events/EventArgsCurrentLocationChanged.cs b/src/SMAPI/Events/EventArgsCurrentLocationChanged.cs new file mode 100644 index 00000000..25d3ebf3 --- /dev/null +++ b/src/SMAPI/Events/EventArgsCurrentLocationChanged.cs @@ -0,0 +1,31 @@ +using System; +using StardewValley; + +namespace StardewModdingAPI.Events +{ + /// Event arguments for a event. + public class EventArgsCurrentLocationChanged : EventArgs + { + /********* + ** Accessors + *********/ + /// The player's current location. + public GameLocation NewLocation { get; } + + /// The player's previous location. + public GameLocation PriorLocation { get; } + + + /********* + ** Public methods + *********/ + /// Construct an instance. + /// The player's previous location. + /// The player's current location. + public EventArgsCurrentLocationChanged(GameLocation priorLocation, GameLocation newLocation) + { + this.NewLocation = newLocation; + this.PriorLocation = priorLocation; + } + } +} diff --git a/src/SMAPI/Events/EventArgsGameLocationsChanged.cs b/src/SMAPI/Events/EventArgsGameLocationsChanged.cs new file mode 100644 index 00000000..fb8c821e --- /dev/null +++ b/src/SMAPI/Events/EventArgsGameLocationsChanged.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using StardewValley; + +namespace StardewModdingAPI.Events +{ + /// Event arguments for a event. + public class EventArgsGameLocationsChanged : EventArgs + { + /********* + ** Accessors + *********/ + /// The current list of game locations. + public List NewLocations { get; } + + + /********* + ** Public methods + *********/ + /// Construct an instance. + /// The current list of game locations. + public EventArgsGameLocationsChanged(List newLocations) + { + this.NewLocations = newLocations; + } + } +} diff --git a/src/SMAPI/Events/EventArgsInput.cs b/src/SMAPI/Events/EventArgsInput.cs new file mode 100644 index 00000000..66cb19f2 --- /dev/null +++ b/src/SMAPI/Events/EventArgsInput.cs @@ -0,0 +1,124 @@ +using System; +using System.Linq; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Input; +using StardewModdingAPI.Utilities; +using StardewValley; + +namespace StardewModdingAPI.Events +{ + /// Event arguments when a button is pressed or released. + public class EventArgsInput : EventArgs + { + /********* + ** Accessors + *********/ + /// The button on the controller, keyboard, or mouse. + public SButton Button { get; } + + /// The current cursor position. + public ICursorPosition Cursor { get; set; } + + /// Whether the input is considered a 'click' by the game for enabling action. + public bool IsClick { get; } + + + /********* + ** Public methods + *********/ + /// Construct an instance. + /// The button on the controller, keyboard, or mouse. + /// The cursor position. + /// Whether the input is considered a 'click' by the game for enabling action. + public EventArgsInput(SButton button, ICursorPosition cursor, bool isClick) + { + this.Button = button; + this.Cursor = cursor; + this.IsClick = isClick; + } + + /// Prevent the game from handling the vurrent button press. This doesn't prevent other mods from receiving the event. + public void SuppressButton() + { + this.SuppressButton(this.Button); + } + + /// Prevent the game from handling a button press. This doesn't prevent other mods from receiving the event. + /// The button to suppress. + public void SuppressButton(SButton button) + { + // keyboard + if (this.Button.TryGetKeyboard(out Keys key)) + Game1.oldKBState = new KeyboardState(Game1.oldKBState.GetPressedKeys().Except(new[] { key }).ToArray()); + + // controller + else if (this.Button.TryGetController(out Buttons controllerButton)) + { + var newState = GamePad.GetState(PlayerIndex.One); + var thumbsticks = Game1.oldPadState.ThumbSticks; + var triggers = Game1.oldPadState.Triggers; + var buttons = Game1.oldPadState.Buttons; + var dpad = Game1.oldPadState.DPad; + + switch (controllerButton) + { + // d-pad + case Buttons.DPadDown: + dpad = new GamePadDPad(dpad.Up, newState.DPad.Down, dpad.Left, dpad.Right); + break; + case Buttons.DPadLeft: + dpad = new GamePadDPad(dpad.Up, dpad.Down, newState.DPad.Left, dpad.Right); + break; + case Buttons.DPadRight: + dpad = new GamePadDPad(dpad.Up, dpad.Down, dpad.Left, newState.DPad.Right); + break; + case Buttons.DPadUp: + dpad = new GamePadDPad(newState.DPad.Up, dpad.Down, dpad.Left, dpad.Right); + break; + + // trigger + case Buttons.LeftTrigger: + triggers = new GamePadTriggers(newState.Triggers.Left, triggers.Right); + break; + case Buttons.RightTrigger: + triggers = new GamePadTriggers(triggers.Left, newState.Triggers.Right); + break; + + // thumbstick + case Buttons.LeftThumbstickDown: + case Buttons.LeftThumbstickLeft: + case Buttons.LeftThumbstickRight: + case Buttons.LeftThumbstickUp: + thumbsticks = new GamePadThumbSticks(newState.ThumbSticks.Left, thumbsticks.Right); + break; + case Buttons.RightThumbstickDown: + case Buttons.RightThumbstickLeft: + case Buttons.RightThumbstickRight: + case Buttons.RightThumbstickUp: + thumbsticks = new GamePadThumbSticks(newState.ThumbSticks.Right, thumbsticks.Left); + break; + + // buttons + default: + var mask = + (buttons.A == ButtonState.Pressed ? Buttons.A : 0) + | (buttons.B == ButtonState.Pressed ? Buttons.B : 0) + | (buttons.Back == ButtonState.Pressed ? Buttons.Back : 0) + | (buttons.BigButton == ButtonState.Pressed ? Buttons.BigButton : 0) + | (buttons.LeftShoulder == ButtonState.Pressed ? Buttons.LeftShoulder : 0) + | (buttons.LeftStick == ButtonState.Pressed ? Buttons.LeftStick : 0) + | (buttons.RightShoulder == ButtonState.Pressed ? Buttons.RightShoulder : 0) + | (buttons.RightStick == ButtonState.Pressed ? Buttons.RightStick : 0) + | (buttons.Start == ButtonState.Pressed ? Buttons.Start : 0) + | (buttons.X == ButtonState.Pressed ? Buttons.X : 0) + | (buttons.Y == ButtonState.Pressed ? Buttons.Y : 0); + mask = mask ^ controllerButton; + buttons = new GamePadButtons(mask); + break; + } + + Game1.oldPadState = new GamePadState(thumbsticks, triggers, buttons, dpad); + } + } + } +} diff --git a/src/SMAPI/Events/EventArgsIntChanged.cs b/src/SMAPI/Events/EventArgsIntChanged.cs new file mode 100644 index 00000000..0c742d12 --- /dev/null +++ b/src/SMAPI/Events/EventArgsIntChanged.cs @@ -0,0 +1,29 @@ +using System; + +namespace StardewModdingAPI.Events +{ + /// Event arguments for an integer field that changed value. + public class EventArgsIntChanged : EventArgs + { + /********* + ** Accessors + *********/ + /// The previous value. + public int PriorInt { get; } + + /// The current value. + public int NewInt { get; } + + /********* + ** Public methods + *********/ + /// Construct an instance. + /// The previous value. + /// The current value. + public EventArgsIntChanged(int priorInt, int newInt) + { + this.PriorInt = priorInt; + this.NewInt = newInt; + } + } +} diff --git a/src/SMAPI/Events/EventArgsInventoryChanged.cs b/src/SMAPI/Events/EventArgsInventoryChanged.cs new file mode 100644 index 00000000..1ee02842 --- /dev/null +++ b/src/SMAPI/Events/EventArgsInventoryChanged.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using StardewValley; + +namespace StardewModdingAPI.Events +{ + /// Event arguments for a event. + public class EventArgsInventoryChanged : EventArgs + { + /********* + ** Accessors + *********/ + /// The player's inventory. + public List Inventory { get; } + + /// The added items. + public List Added { get; } + + /// The removed items. + public List Removed { get; } + + /// The items whose stack sizes changed. + public List QuantityChanged { get; } + + + /********* + ** Public methods + *********/ + /// Construct an instance. + /// The player's inventory. + /// The inventory changes. + public EventArgsInventoryChanged(List inventory, List changedItems) + { + this.Inventory = inventory; + this.Added = changedItems.Where(n => n.ChangeType == ChangeType.Added).ToList(); + this.Removed = changedItems.Where(n => n.ChangeType == ChangeType.Removed).ToList(); + this.QuantityChanged = changedItems.Where(n => n.ChangeType == ChangeType.StackChange).ToList(); + } + } +} diff --git a/src/SMAPI/Events/EventArgsKeyPressed.cs b/src/SMAPI/Events/EventArgsKeyPressed.cs new file mode 100644 index 00000000..d9d81e10 --- /dev/null +++ b/src/SMAPI/Events/EventArgsKeyPressed.cs @@ -0,0 +1,26 @@ +using System; +using Microsoft.Xna.Framework.Input; + +namespace StardewModdingAPI.Events +{ + /// Event arguments for a event. + public class EventArgsKeyPressed : EventArgs + { + /********* + ** Accessors + *********/ + /// The keyboard button that was pressed. + public Keys KeyPressed { get; } + + + /********* + ** Public methods + *********/ + /// Construct an instance. + /// The keyboard button that was pressed. + public EventArgsKeyPressed(Keys key) + { + this.KeyPressed = key; + } + } +} diff --git a/src/SMAPI/Events/EventArgsKeyboardStateChanged.cs b/src/SMAPI/Events/EventArgsKeyboardStateChanged.cs new file mode 100644 index 00000000..14e397ce --- /dev/null +++ b/src/SMAPI/Events/EventArgsKeyboardStateChanged.cs @@ -0,0 +1,31 @@ +using System; +using Microsoft.Xna.Framework.Input; + +namespace StardewModdingAPI.Events +{ + /// Event arguments for a event. + public class EventArgsKeyboardStateChanged : EventArgs + { + /********* + ** Accessors + *********/ + /// The previous keyboard state. + public KeyboardState NewState { get; } + + /// The current keyboard state. + public KeyboardState PriorState { get; } + + + /********* + ** Public methods + *********/ + /// Construct an instance. + /// The previous keyboard state. + /// The current keyboard state. + public EventArgsKeyboardStateChanged(KeyboardState priorState, KeyboardState newState) + { + this.PriorState = priorState; + this.NewState = newState; + } + } +} diff --git a/src/SMAPI/Events/EventArgsLevelUp.cs b/src/SMAPI/Events/EventArgsLevelUp.cs new file mode 100644 index 00000000..fe6696d4 --- /dev/null +++ b/src/SMAPI/Events/EventArgsLevelUp.cs @@ -0,0 +1,52 @@ +using System; + +namespace StardewModdingAPI.Events +{ + /// Event arguments for a event. + public class EventArgsLevelUp : EventArgs + { + /********* + ** Accessors + *********/ + /// The player skill that leveled up. + public LevelType Type { get; } + + /// The new skill level. + public int NewLevel { get; } + + /// The player skill types. + public enum LevelType + { + /// The combat skill. + Combat, + + /// The farming skill. + Farming, + + /// The fishing skill. + Fishing, + + /// The foraging skill. + Foraging, + + /// The mining skill. + Mining, + + /// The luck skill. + Luck + } + + + /********* + ** Public methods + *********/ + /// Construct an instance. + /// The player skill that leveled up. + /// The new skill level. + public EventArgsLevelUp(LevelType type, int newLevel) + { + this.Type = type; + this.NewLevel = newLevel; + } + } +} diff --git a/src/SMAPI/Events/EventArgsLocationObjectsChanged.cs b/src/SMAPI/Events/EventArgsLocationObjectsChanged.cs new file mode 100644 index 00000000..058999e9 --- /dev/null +++ b/src/SMAPI/Events/EventArgsLocationObjectsChanged.cs @@ -0,0 +1,28 @@ +using System; +using Microsoft.Xna.Framework; +using StardewValley; +using Object = StardewValley.Object; + +namespace StardewModdingAPI.Events +{ + /// Event arguments for a event. + public class EventArgsLocationObjectsChanged : EventArgs + { + /********* + ** Accessors + *********/ + /// The current list of objects in the current location. + public SerializableDictionary NewObjects { get; } + + + /********* + ** Public methods + *********/ + /// Construct an instance. + /// The current list of objects in the current location. + public EventArgsLocationObjectsChanged(SerializableDictionary newObjects) + { + this.NewObjects = newObjects; + } + } +} diff --git a/src/SMAPI/Events/EventArgsMineLevelChanged.cs b/src/SMAPI/Events/EventArgsMineLevelChanged.cs new file mode 100644 index 00000000..c82fed35 --- /dev/null +++ b/src/SMAPI/Events/EventArgsMineLevelChanged.cs @@ -0,0 +1,30 @@ +using System; + +namespace StardewModdingAPI.Events +{ + /// Event arguments for a event. + public class EventArgsMineLevelChanged : EventArgs + { + /********* + ** Accessors + *********/ + /// The previous mine level. + public int PreviousMineLevel { get; } + + /// The current mine level. + public int CurrentMineLevel { get; } + + + /********* + ** Public methods + *********/ + /// Construct an instance. + /// The previous mine level. + /// The current mine level. + public EventArgsMineLevelChanged(int previousMineLevel, int currentMineLevel) + { + this.PreviousMineLevel = previousMineLevel; + this.CurrentMineLevel = currentMineLevel; + } + } +} diff --git a/src/SMAPI/Events/EventArgsMouseStateChanged.cs b/src/SMAPI/Events/EventArgsMouseStateChanged.cs new file mode 100644 index 00000000..57298164 --- /dev/null +++ b/src/SMAPI/Events/EventArgsMouseStateChanged.cs @@ -0,0 +1,42 @@ +using System; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Input; + +namespace StardewModdingAPI.Events +{ + /// Event arguments for a event. + public class EventArgsMouseStateChanged : EventArgs + { + /********* + ** Accessors + *********/ + /// The previous mouse state. + public MouseState PriorState { get; } + + /// The current mouse state. + public MouseState NewState { get; } + + /// The previous mouse position on the screen adjusted for the zoom level. + public Point PriorPosition { get; } + + /// The current mouse position on the screen adjusted for the zoom level. + public Point NewPosition { get; } + + + /********* + ** Public methods + *********/ + /// Construct an instance. + /// The previous mouse state. + /// The current mouse state. + /// The previous mouse position on the screen adjusted for the zoom level. + /// The current mouse position on the screen adjusted for the zoom level. + public EventArgsMouseStateChanged(MouseState priorState, MouseState newState, Point priorPosition, Point newPosition) + { + this.PriorState = priorState; + this.NewState = newState; + this.PriorPosition = priorPosition; + this.NewPosition = newPosition; + } + } +} diff --git a/src/SMAPI/Events/EventArgsValueChanged.cs b/src/SMAPI/Events/EventArgsValueChanged.cs new file mode 100644 index 00000000..1d25af49 --- /dev/null +++ b/src/SMAPI/Events/EventArgsValueChanged.cs @@ -0,0 +1,31 @@ +using System; + +namespace StardewModdingAPI.Events +{ + /// Event arguments for a field that changed value. + /// The value type. + public class EventArgsValueChanged : EventArgs + { + /********* + ** Accessors + *********/ + /// The previous value. + public T PriorValue { get; } + + /// The current value. + public T NewValue { get; } + + + /********* + ** Public methods + *********/ + /// Construct an instance. + /// The previous value. + /// The current value. + public EventArgsValueChanged(T priorValue, T newValue) + { + this.PriorValue = priorValue; + this.NewValue = newValue; + } + } +} \ No newline at end of file diff --git a/src/SMAPI/Events/GameEvents.cs b/src/SMAPI/Events/GameEvents.cs new file mode 100644 index 00000000..b477376e --- /dev/null +++ b/src/SMAPI/Events/GameEvents.cs @@ -0,0 +1,96 @@ +using System; +using StardewModdingAPI.Framework; + +namespace StardewModdingAPI.Events +{ + /// Events raised when the game changes state. + public static class GameEvents + { + /********* + ** Events + *********/ + /// Raised during launch after configuring XNA or MonoGame. The game window hasn't been opened by this point. Called after . + internal static event EventHandler InitializeInternal; + + /// Raised when the game updates its state (≈60 times per second). + public static event EventHandler UpdateTick; + + /// Raised every other tick (≈30 times per second). + public static event EventHandler SecondUpdateTick; + + /// Raised every fourth tick (≈15 times per second). + public static event EventHandler FourthUpdateTick; + + /// Raised every eighth tick (≈8 times per second). + public static event EventHandler EighthUpdateTick; + + /// Raised every 15th tick (≈4 times per second). + public static event EventHandler QuarterSecondTick; + + /// Raised every 30th tick (≈twice per second). + public static event EventHandler HalfSecondTick; + + /// Raised every 60th tick (≈once per second). + public static event EventHandler OneSecondTick; + + + /********* + ** Internal methods + *********/ + /// Raise an event. + /// Encapsulates logging and monitoring. + internal static void InvokeInitialize(IMonitor monitor) + { + monitor.SafelyRaisePlainEvent($"{nameof(GameEvents)}.{nameof(GameEvents.InitializeInternal)}", GameEvents.InitializeInternal?.GetInvocationList()); + } + + /// Raise an event. + /// Encapsulates logging and monitoring. + internal static void InvokeUpdateTick(IMonitor monitor) + { + monitor.SafelyRaisePlainEvent($"{nameof(GameEvents)}.{nameof(GameEvents.UpdateTick)}", GameEvents.UpdateTick?.GetInvocationList()); + } + + /// Raise a event. + /// Encapsulates monitoring and logging. + internal static void InvokeSecondUpdateTick(IMonitor monitor) + { + monitor.SafelyRaisePlainEvent($"{nameof(GameEvents)}.{nameof(GameEvents.SecondUpdateTick)}", GameEvents.SecondUpdateTick?.GetInvocationList()); + } + + /// Raise a event. + /// Encapsulates monitoring and logging. + internal static void InvokeFourthUpdateTick(IMonitor monitor) + { + monitor.SafelyRaisePlainEvent($"{nameof(GameEvents)}.{nameof(GameEvents.FourthUpdateTick)}", GameEvents.FourthUpdateTick?.GetInvocationList()); + } + + /// Raise a event. + /// Encapsulates monitoring and logging. + internal static void InvokeEighthUpdateTick(IMonitor monitor) + { + monitor.SafelyRaisePlainEvent($"{nameof(GameEvents)}.{nameof(GameEvents.EighthUpdateTick)}", GameEvents.EighthUpdateTick?.GetInvocationList()); + } + + /// Raise a event. + /// Encapsulates monitoring and logging. + internal static void InvokeQuarterSecondTick(IMonitor monitor) + { + monitor.SafelyRaisePlainEvent($"{nameof(GameEvents)}.{nameof(GameEvents.QuarterSecondTick)}", GameEvents.QuarterSecondTick?.GetInvocationList()); + } + + /// Raise a event. + /// Encapsulates monitoring and logging. + internal static void InvokeHalfSecondTick(IMonitor monitor) + { + monitor.SafelyRaisePlainEvent($"{nameof(GameEvents)}.{nameof(GameEvents.HalfSecondTick)}", GameEvents.HalfSecondTick?.GetInvocationList()); + } + + /// Raise a event. + /// Encapsulates monitoring and logging. + internal static void InvokeOneSecondTick(IMonitor monitor) + { + monitor.SafelyRaisePlainEvent($"{nameof(GameEvents)}.{nameof(GameEvents.OneSecondTick)}", GameEvents.OneSecondTick?.GetInvocationList()); + } + } +} diff --git a/src/SMAPI/Events/GraphicsEvents.cs b/src/SMAPI/Events/GraphicsEvents.cs new file mode 100644 index 00000000..fff51bed --- /dev/null +++ b/src/SMAPI/Events/GraphicsEvents.cs @@ -0,0 +1,116 @@ +using System; +using StardewModdingAPI.Framework; + +namespace StardewModdingAPI.Events +{ + /// Events raised during the game's draw loop, when the game is rendering content to the window. + public static class GraphicsEvents + { + /********* + ** Events + *********/ + /**** + ** Generic events + ****/ + /// Raised after the game window is resized. + public static event EventHandler Resize; + + /**** + ** Main render events + ****/ + /// Raised before drawing the world to the screen. + public static event EventHandler OnPreRenderEvent; + + /// Raised after drawing the world to the screen. + public static event EventHandler OnPostRenderEvent; + + /**** + ** HUD events + ****/ + /// 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.) + public static event EventHandler OnPreRenderHudEvent; + + /// 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.) + public static event EventHandler OnPostRenderHudEvent; + + /**** + ** GUI events + ****/ + /// Raised before drawing a menu to the screen during a draw loop. This includes the game's internal menus like the title screen. + public static event EventHandler OnPreRenderGuiEvent; + + /// Raised after drawing a menu to the screen during a draw loop. This includes the game's internal menus like the title screen. + public static event EventHandler OnPostRenderGuiEvent; + + + /********* + ** Internal methods + *********/ + /**** + ** Generic events + ****/ + /// Raise a event. + /// Encapsulates monitoring and logging. + internal static void InvokeResize(IMonitor monitor) + { + monitor.SafelyRaisePlainEvent($"{nameof(GraphicsEvents)}.{nameof(GraphicsEvents.Resize)}", GraphicsEvents.Resize?.GetInvocationList()); + } + + /**** + ** Main render events + ****/ + /// Raise an event. + /// Encapsulates monitoring and logging. + internal static void InvokeOnPreRenderEvent(IMonitor monitor) + { + monitor.SafelyRaisePlainEvent($"{nameof(GraphicsEvents)}.{nameof(GraphicsEvents.OnPreRenderEvent)}", GraphicsEvents.OnPreRenderEvent?.GetInvocationList()); + } + + /// Raise an event. + /// Encapsulates monitoring and logging. + internal static void InvokeOnPostRenderEvent(IMonitor monitor) + { + monitor.SafelyRaisePlainEvent($"{nameof(GraphicsEvents)}.{nameof(GraphicsEvents.OnPostRenderEvent)}", GraphicsEvents.OnPostRenderEvent?.GetInvocationList()); + } + + /// Get whether there are any post-render event listeners. + internal static bool HasPostRenderListeners() + { + return GraphicsEvents.OnPostRenderEvent != null; + } + + /**** + ** GUI events + ****/ + /// Raise an event. + /// Encapsulates monitoring and logging. + internal static void InvokeOnPreRenderGuiEvent(IMonitor monitor) + { + monitor.SafelyRaisePlainEvent($"{nameof(GraphicsEvents)}.{nameof(GraphicsEvents.OnPreRenderGuiEvent)}", GraphicsEvents.OnPreRenderGuiEvent?.GetInvocationList()); + } + + /// Raise an event. + /// Encapsulates monitoring and logging. + internal static void InvokeOnPostRenderGuiEvent(IMonitor monitor) + { + monitor.SafelyRaisePlainEvent($"{nameof(GraphicsEvents)}.{nameof(GraphicsEvents.OnPostRenderGuiEvent)}", GraphicsEvents.OnPostRenderGuiEvent?.GetInvocationList()); + } + + /**** + ** HUD events + ****/ + /// Raise an event. + /// Encapsulates monitoring and logging. + internal static void InvokeOnPreRenderHudEvent(IMonitor monitor) + { + monitor.SafelyRaisePlainEvent($"{nameof(GraphicsEvents)}.{nameof(GraphicsEvents.OnPreRenderHudEvent)}", GraphicsEvents.OnPreRenderHudEvent?.GetInvocationList()); + } + + /// Raise an event. + /// Encapsulates monitoring and logging. + internal static void InvokeOnPostRenderHudEvent(IMonitor monitor) + { + monitor.SafelyRaisePlainEvent($"{nameof(GraphicsEvents)}.{nameof(GraphicsEvents.OnPostRenderHudEvent)}", GraphicsEvents.OnPostRenderHudEvent?.GetInvocationList()); + } + } +} diff --git a/src/SMAPI/Events/InputEvents.cs b/src/SMAPI/Events/InputEvents.cs new file mode 100644 index 00000000..c31eb698 --- /dev/null +++ b/src/SMAPI/Events/InputEvents.cs @@ -0,0 +1,43 @@ +using System; +using StardewModdingAPI.Framework; +using StardewModdingAPI.Utilities; + +namespace StardewModdingAPI.Events +{ + /// Events raised when the player uses a controller, keyboard, or mouse button. + public static class InputEvents + { + /********* + ** Events + *********/ + /// Raised when the player presses a button on the keyboard, controller, or mouse. + public static event EventHandler ButtonPressed; + + /// Raised when the player releases a keyboard key on the keyboard, controller, or mouse. + public static event EventHandler ButtonReleased; + + + /********* + ** Internal methods + *********/ + /// Raise a event. + /// Encapsulates monitoring and logging. + /// The button on the controller, keyboard, or mouse. + /// The cursor position. + /// Whether the input is considered a 'click' by the game for enabling action. + internal static void InvokeButtonPressed(IMonitor monitor, SButton button, ICursorPosition cursor, bool isClick) + { + monitor.SafelyRaiseGenericEvent($"{nameof(InputEvents)}.{nameof(InputEvents.ButtonPressed)}", InputEvents.ButtonPressed?.GetInvocationList(), null, new EventArgsInput(button, cursor, isClick)); + } + + /// Raise a event. + /// Encapsulates monitoring and logging. + /// The button on the controller, keyboard, or mouse. + /// The cursor position. + /// Whether the input is considered a 'click' by the game for enabling action. + internal static void InvokeButtonReleased(IMonitor monitor, SButton button, ICursorPosition cursor, bool isClick) + { + monitor.SafelyRaiseGenericEvent($"{nameof(InputEvents)}.{nameof(InputEvents.ButtonReleased)}", InputEvents.ButtonReleased?.GetInvocationList(), null, new EventArgsInput(button, cursor, isClick)); + } + } +} diff --git a/src/SMAPI/Events/ItemStackChange.cs b/src/SMAPI/Events/ItemStackChange.cs new file mode 100644 index 00000000..f9ae6df6 --- /dev/null +++ b/src/SMAPI/Events/ItemStackChange.cs @@ -0,0 +1,20 @@ +using StardewValley; + +namespace StardewModdingAPI.Events +{ + /// Represents an inventory slot that changed. + public class ItemStackChange + { + /********* + ** Accessors + *********/ + /// The item in the slot. + public Item Item { get; set; } + + /// The amount by which the item's stack size changed. + public int StackChange { get; set; } + + /// How the inventory slot changed. + public ChangeType ChangeType { get; set; } + } +} \ No newline at end of file diff --git a/src/SMAPI/Events/LocationEvents.cs b/src/SMAPI/Events/LocationEvents.cs new file mode 100644 index 00000000..b834bc1c --- /dev/null +++ b/src/SMAPI/Events/LocationEvents.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; +using Microsoft.Xna.Framework; +using StardewModdingAPI.Framework; +using StardewValley; +using Object = StardewValley.Object; + +namespace StardewModdingAPI.Events +{ + /// Events raised when the player transitions between game locations, a location is added or removed, or the objects in the current location change. + public static class LocationEvents + { + /********* + ** Events + *********/ + /// Raised after the player warps to a new location. + public static event EventHandler CurrentLocationChanged; + + /// Raised after a game location is added or removed. + public static event EventHandler LocationsChanged; + + /// Raised after the list of objects in the current location changes (e.g. an object is added or removed). + public static event EventHandler LocationObjectsChanged; + + + /********* + ** Internal methods + *********/ + /// Raise a event. + /// Encapsulates monitoring and logging. + /// The player's previous location. + /// The player's current location. + internal static void InvokeCurrentLocationChanged(IMonitor monitor, GameLocation priorLocation, GameLocation newLocation) + { + monitor.SafelyRaiseGenericEvent($"{nameof(LocationEvents)}.{nameof(LocationEvents.CurrentLocationChanged)}", LocationEvents.CurrentLocationChanged?.GetInvocationList(), null, new EventArgsCurrentLocationChanged(priorLocation, newLocation)); + } + + /// Raise a event. + /// Encapsulates monitoring and logging. + /// The current list of game locations. + internal static void InvokeLocationsChanged(IMonitor monitor, List newLocations) + { + monitor.SafelyRaiseGenericEvent($"{nameof(LocationEvents)}.{nameof(LocationEvents.LocationsChanged)}", LocationEvents.LocationsChanged?.GetInvocationList(), null, new EventArgsGameLocationsChanged(newLocations)); + } + + /// Raise a event. + /// Encapsulates monitoring and logging. + /// The current list of objects in the current location. + internal static void InvokeOnNewLocationObject(IMonitor monitor, SerializableDictionary newObjects) + { + monitor.SafelyRaiseGenericEvent($"{nameof(LocationEvents)}.{nameof(LocationEvents.LocationObjectsChanged)}", LocationEvents.LocationObjectsChanged?.GetInvocationList(), null, new EventArgsLocationObjectsChanged(newObjects)); + } + } +} diff --git a/src/SMAPI/Events/MenuEvents.cs b/src/SMAPI/Events/MenuEvents.cs new file mode 100644 index 00000000..bd8d897e --- /dev/null +++ b/src/SMAPI/Events/MenuEvents.cs @@ -0,0 +1,40 @@ +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)); + } + } +} diff --git a/src/SMAPI/Events/MineEvents.cs b/src/SMAPI/Events/MineEvents.cs new file mode 100644 index 00000000..9cf7edac --- /dev/null +++ b/src/SMAPI/Events/MineEvents.cs @@ -0,0 +1,28 @@ +using System; +using StardewModdingAPI.Framework; + +namespace StardewModdingAPI.Events +{ + /// Events raised when something happens in the mines. + public static class MineEvents + { + /********* + ** Events + *********/ + /// Raised after the player warps to a new level of the mine. + public static event EventHandler MineLevelChanged; + + + /********* + ** Internal methods + *********/ + /// Raise a event. + /// Encapsulates monitoring and logging. + /// The previous mine level. + /// The current mine level. + internal static void InvokeMineLevelChanged(IMonitor monitor, int previousMineLevel, int currentMineLevel) + { + monitor.SafelyRaiseGenericEvent($"{nameof(MineEvents)}.{nameof(MineEvents.MineLevelChanged)}", MineEvents.MineLevelChanged?.GetInvocationList(), null, new EventArgsMineLevelChanged(previousMineLevel, currentMineLevel)); + } + } +} diff --git a/src/SMAPI/Events/PlayerEvents.cs b/src/SMAPI/Events/PlayerEvents.cs new file mode 100644 index 00000000..5a9a9d5f --- /dev/null +++ b/src/SMAPI/Events/PlayerEvents.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using StardewModdingAPI.Framework; +using StardewValley; + +namespace StardewModdingAPI.Events +{ + /// Events raised when the player data changes. + public static class PlayerEvents + { + /********* + ** Events + *********/ + /// Raised after the player's inventory changes in any way (added or removed item, sorted, etc). + public static event EventHandler InventoryChanged; + + /// Raised after the player levels up a skill. This happens as soon as they level up, not when the game notifies the player after their character goes to bed. + public static event EventHandler LeveledUp; + + + /********* + ** Internal methods + *********/ + /// Raise an event. + /// Encapsulates monitoring and logging. + /// The player's inventory. + /// The inventory changes. + internal static void InvokeInventoryChanged(IMonitor monitor, List inventory, IEnumerable changedItems) + { + monitor.SafelyRaiseGenericEvent($"{nameof(PlayerEvents)}.{nameof(PlayerEvents.InventoryChanged)}", PlayerEvents.InventoryChanged?.GetInvocationList(), null, new EventArgsInventoryChanged(inventory, changedItems.ToList())); + } + + /// Rase a event. + /// Encapsulates monitoring and logging. + /// The player skill that leveled up. + /// The new skill level. + internal static void InvokeLeveledUp(IMonitor monitor, EventArgsLevelUp.LevelType type, int newLevel) + { + monitor.SafelyRaiseGenericEvent($"{nameof(PlayerEvents)}.{nameof(PlayerEvents.LeveledUp)}", PlayerEvents.LeveledUp?.GetInvocationList(), null, new EventArgsLevelUp(type, newLevel)); + } + } +} diff --git a/src/SMAPI/Events/SaveEvents.cs b/src/SMAPI/Events/SaveEvents.cs new file mode 100644 index 00000000..50e6d729 --- /dev/null +++ b/src/SMAPI/Events/SaveEvents.cs @@ -0,0 +1,56 @@ +using System; +using StardewModdingAPI.Framework; + +namespace StardewModdingAPI.Events +{ + /// Events raised before and after the player saves/loads the game. + public static class SaveEvents + { + /********* + ** Events + *********/ + /// Raised before the game begins writes data to the save file. + public static event EventHandler BeforeSave; + + /// Raised after the game finishes writing data to the save file. + public static event EventHandler AfterSave; + + /// Raised after the player loads a save slot. + public static event EventHandler AfterLoad; + + /// Raised after the game returns to the title screen. + public static event EventHandler AfterReturnToTitle; + + + /********* + ** Internal methods + *********/ + /// Raise a event. + /// Encapsulates monitoring and logging. + internal static void InvokeBeforeSave(IMonitor monitor) + { + monitor.SafelyRaisePlainEvent($"{nameof(SaveEvents)}.{nameof(SaveEvents.BeforeSave)}", SaveEvents.BeforeSave?.GetInvocationList(), null, EventArgs.Empty); + } + + /// Raise a event. + /// Encapsulates monitoring and logging. + internal static void InvokeAfterSave(IMonitor monitor) + { + monitor.SafelyRaisePlainEvent($"{nameof(SaveEvents)}.{nameof(SaveEvents.AfterSave)}", SaveEvents.AfterSave?.GetInvocationList(), null, EventArgs.Empty); + } + + /// Raise a event. + /// Encapsulates monitoring and logging. + internal static void InvokeAfterLoad(IMonitor monitor) + { + monitor.SafelyRaisePlainEvent($"{nameof(SaveEvents)}.{nameof(SaveEvents.AfterLoad)}", SaveEvents.AfterLoad?.GetInvocationList(), null, EventArgs.Empty); + } + + /// Raise a event. + /// Encapsulates monitoring and logging. + internal static void InvokeAfterReturnToTitle(IMonitor monitor) + { + monitor.SafelyRaisePlainEvent($"{nameof(SaveEvents)}.{nameof(SaveEvents.AfterReturnToTitle)}", SaveEvents.AfterReturnToTitle?.GetInvocationList(), null, EventArgs.Empty); + } + } +} diff --git a/src/SMAPI/Events/TimeEvents.cs b/src/SMAPI/Events/TimeEvents.cs new file mode 100644 index 00000000..9aea5e04 --- /dev/null +++ b/src/SMAPI/Events/TimeEvents.cs @@ -0,0 +1,37 @@ +using System; +using StardewModdingAPI.Framework; + +namespace StardewModdingAPI.Events +{ + /// Events raised when the in-game date or time changes. + public static class TimeEvents + { + /********* + ** Events + *********/ + /// Raised after the game begins a new day, including when loading a save. + public static event EventHandler AfterDayStarted; + + /// Raised after the in-game clock changes. + public static event EventHandler TimeOfDayChanged; + + /********* + ** Internal methods + *********/ + /// Raise an event. + /// Encapsulates monitoring and logging. + internal static void InvokeAfterDayStarted(IMonitor monitor) + { + monitor.SafelyRaisePlainEvent($"{nameof(TimeEvents)}.{nameof(TimeEvents.AfterDayStarted)}", TimeEvents.AfterDayStarted?.GetInvocationList(), null, EventArgs.Empty); + } + + /// Raise a event. + /// Encapsulates monitoring and logging. + /// The previous time in military time format (e.g. 6:00pm is 1800). + /// The current time in military time format (e.g. 6:10pm is 1810). + internal static void InvokeTimeOfDayChanged(IMonitor monitor, int priorTime, int newTime) + { + monitor.SafelyRaiseGenericEvent($"{nameof(TimeEvents)}.{nameof(TimeEvents.TimeOfDayChanged)}", TimeEvents.TimeOfDayChanged?.GetInvocationList(), null, new EventArgsIntChanged(priorTime, newTime)); + } + } +} -- cgit