diff options
Diffstat (limited to 'src/SMAPI/Events')
-rw-r--r-- | src/SMAPI/Events/ControlEvents.cs | 28 | ||||
-rw-r--r-- | src/SMAPI/Events/EventArgsInput.cs | 10 | ||||
-rw-r--r-- | src/SMAPI/Events/IInputEvents.cs | 14 | ||||
-rw-r--r-- | src/SMAPI/Events/IModEvents.cs | 3 | ||||
-rw-r--r-- | src/SMAPI/Events/InputButtonPressedEventArgs.cs | 56 | ||||
-rw-r--r-- | src/SMAPI/Events/InputButtonReleasedEventArgs.cs | 56 | ||||
-rw-r--r-- | src/SMAPI/Events/InputEvents.cs | 8 |
7 files changed, 150 insertions, 25 deletions
diff --git a/src/SMAPI/Events/ControlEvents.cs b/src/SMAPI/Events/ControlEvents.cs index 973bb245..77bbf3ab 100644 --- a/src/SMAPI/Events/ControlEvents.cs +++ b/src/SMAPI/Events/ControlEvents.cs @@ -20,22 +20,22 @@ namespace StardewModdingAPI.Events /// <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 { - add => ControlEvents.EventManager.Control_KeyboardChanged.Add(value); - remove => ControlEvents.EventManager.Control_KeyboardChanged.Remove(value); + add => ControlEvents.EventManager.Legacy_Control_KeyboardChanged.Add(value); + remove => ControlEvents.EventManager.Legacy_Control_KeyboardChanged.Remove(value); } /// <summary>Raised when the player presses a keyboard key.</summary> public static event EventHandler<EventArgsKeyPressed> KeyPressed { - add => ControlEvents.EventManager.Control_KeyPressed.Add(value); - remove => ControlEvents.EventManager.Control_KeyPressed.Remove(value); + add => ControlEvents.EventManager.Legacy_Control_KeyPressed.Add(value); + remove => ControlEvents.EventManager.Legacy_Control_KeyPressed.Remove(value); } /// <summary>Raised when the player releases a keyboard key.</summary> public static event EventHandler<EventArgsKeyPressed> KeyReleased { - add => ControlEvents.EventManager.Control_KeyReleased.Add(value); - remove => ControlEvents.EventManager.Control_KeyReleased.Remove(value); + add => ControlEvents.EventManager.Legacy_Control_KeyReleased.Add(value); + remove => ControlEvents.EventManager.Legacy_Control_KeyReleased.Remove(value); } /// <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> @@ -48,29 +48,29 @@ namespace StardewModdingAPI.Events /// <summary>The player pressed a controller button. This event isn't raised for trigger buttons.</summary> public static event EventHandler<EventArgsControllerButtonPressed> ControllerButtonPressed { - add => ControlEvents.EventManager.Control_ControllerButtonPressed.Add(value); - remove => ControlEvents.EventManager.Control_ControllerButtonPressed.Remove(value); + add => ControlEvents.EventManager.Legacy_Control_ControllerButtonPressed.Add(value); + remove => ControlEvents.EventManager.Legacy_Control_ControllerButtonPressed.Remove(value); } /// <summary>The player released a controller button. This event isn't raised for trigger buttons.</summary> public static event EventHandler<EventArgsControllerButtonReleased> ControllerButtonReleased { - add => ControlEvents.EventManager.Control_ControllerButtonReleased.Add(value); - remove => ControlEvents.EventManager.Control_ControllerButtonReleased.Remove(value); + add => ControlEvents.EventManager.Legacy_Control_ControllerButtonReleased.Add(value); + remove => ControlEvents.EventManager.Legacy_Control_ControllerButtonReleased.Remove(value); } /// <summary>The player pressed a controller trigger button.</summary> public static event EventHandler<EventArgsControllerTriggerPressed> ControllerTriggerPressed { - add => ControlEvents.EventManager.Control_ControllerTriggerPressed.Add(value); - remove => ControlEvents.EventManager.Control_ControllerTriggerPressed.Remove(value); + add => ControlEvents.EventManager.Legacy_Control_ControllerTriggerPressed.Add(value); + remove => ControlEvents.EventManager.Legacy_Control_ControllerTriggerPressed.Remove(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); + add => ControlEvents.EventManager.Legacy_Control_ControllerTriggerReleased.Add(value); + remove => ControlEvents.EventManager.Legacy_Control_ControllerTriggerReleased.Remove(value); } diff --git a/src/SMAPI/Events/EventArgsInput.cs b/src/SMAPI/Events/EventArgsInput.cs index d60f4017..0cafdba5 100644 --- a/src/SMAPI/Events/EventArgsInput.cs +++ b/src/SMAPI/Events/EventArgsInput.cs @@ -23,10 +23,10 @@ namespace StardewModdingAPI.Events public ICursorPosition Cursor { get; } /// <summary>Whether the input should trigger actions on the affected tile.</summary> - public bool IsActionButton { get; } + public bool IsActionButton => this.Button.IsActionButton(); /// <summary>Whether the input should use tools on the affected tile.</summary> - public bool IsUseToolButton { get; } + public bool IsUseToolButton => this.Button.IsUseToolButton(); /// <summary>Whether a mod has indicated the key was already handled.</summary> public bool IsSuppressed => this.SuppressButtons.Contains(this.Button); @@ -38,15 +38,11 @@ namespace StardewModdingAPI.Events /// <summary>Construct an instance.</summary> /// <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> /// <param name="suppressButtons">The buttons to suppress.</param> - public EventArgsInput(SButton button, ICursorPosition cursor, bool isActionButton, bool isUseToolButton, HashSet<SButton> suppressButtons) + public EventArgsInput(SButton button, ICursorPosition cursor, HashSet<SButton> suppressButtons) { this.Button = button; this.Cursor = cursor; - this.IsActionButton = isActionButton; - this.IsUseToolButton = isUseToolButton; this.SuppressButtons = suppressButtons; } diff --git a/src/SMAPI/Events/IInputEvents.cs b/src/SMAPI/Events/IInputEvents.cs new file mode 100644 index 00000000..92802fda --- /dev/null +++ b/src/SMAPI/Events/IInputEvents.cs @@ -0,0 +1,14 @@ +using System; + +namespace StardewModdingAPI.Events +{ + /// <summary>Events raised when the player provides input using a controller, keyboard, or mouse.</summary> + public interface IInputEvents + { + /// <summary>Raised when the player presses a button on the keyboard, controller, or mouse.</summary> + event EventHandler<InputButtonPressedArgsInput> ButtonPressed; + + /// <summary>Raised when the player releases a button on the keyboard, controller, or mouse.</summary> + event EventHandler<InputButtonReleasedArgsInput> ButtonReleased; + } +} diff --git a/src/SMAPI/Events/IModEvents.cs b/src/SMAPI/Events/IModEvents.cs index 99e5523f..16ec6557 100644 --- a/src/SMAPI/Events/IModEvents.cs +++ b/src/SMAPI/Events/IModEvents.cs @@ -3,6 +3,9 @@ namespace StardewModdingAPI.Events /// <summary>Manages access to events raised by SMAPI.</summary> public interface IModEvents { + /// <summary>Events raised when the player provides input using a controller, keyboard, or mouse.</summary> + IInputEvents Input { get; } + /// <summary>Events raised when something changes in the world.</summary> IWorldEvents World { get; } } diff --git a/src/SMAPI/Events/InputButtonPressedEventArgs.cs b/src/SMAPI/Events/InputButtonPressedEventArgs.cs new file mode 100644 index 00000000..c8d55cd4 --- /dev/null +++ b/src/SMAPI/Events/InputButtonPressedEventArgs.cs @@ -0,0 +1,56 @@ +using System; +using System.Collections.Generic; + +namespace StardewModdingAPI.Events +{ + /// <summary>Event arguments when a button is pressed.</summary> + public class InputButtonPressedArgsInput : EventArgs + { + /********* + ** Properties + *********/ + /// <summary>The buttons to suppress.</summary> + private readonly HashSet<SButton> SuppressButtons; + + + /********* + ** Accessors + *********/ + /// <summary>The button on the controller, keyboard, or mouse.</summary> + public SButton Button { get; } + + /// <summary>The current cursor position.</summary> + public ICursorPosition Cursor { get; } + + /// <summary>Whether a mod has indicated the key was already handled.</summary> + public bool IsSuppressed => this.SuppressButtons.Contains(this.Button); + + + /********* + ** Public methods + *********/ + /// <summary>Construct an instance.</summary> + /// <param name="button">The button on the controller, keyboard, or mouse.</param> + /// <param name="cursor">The cursor position.</param> + /// <param name="suppressButtons">The buttons to suppress.</param> + public InputButtonPressedArgsInput(SButton button, ICursorPosition cursor, HashSet<SButton> suppressButtons) + { + this.Button = button; + this.Cursor = cursor; + this.SuppressButtons = suppressButtons; + } + + /// <summary>Prevent the game from handling the current button press. This doesn't prevent other mods from receiving the event.</summary> + public void SuppressButton() + { + this.SuppressButton(this.Button); + } + + /// <summary>Prevent the game from handling a button press. This doesn't prevent other mods from receiving the event.</summary> + /// <param name="button">The button to suppress.</param> + public void SuppressButton(SButton button) + { + this.SuppressButtons.Add(button); + } + } +} diff --git a/src/SMAPI/Events/InputButtonReleasedEventArgs.cs b/src/SMAPI/Events/InputButtonReleasedEventArgs.cs new file mode 100644 index 00000000..863fab6a --- /dev/null +++ b/src/SMAPI/Events/InputButtonReleasedEventArgs.cs @@ -0,0 +1,56 @@ +using System; +using System.Collections.Generic; + +namespace StardewModdingAPI.Events +{ + /// <summary>Event arguments when a button is released.</summary> + public class InputButtonReleasedArgsInput : EventArgs + { + /********* + ** Properties + *********/ + /// <summary>The buttons to suppress.</summary> + private readonly HashSet<SButton> SuppressButtons; + + + /********* + ** Accessors + *********/ + /// <summary>The button on the controller, keyboard, or mouse.</summary> + public SButton Button { get; } + + /// <summary>The current cursor position.</summary> + public ICursorPosition Cursor { get; } + + /// <summary>Whether a mod has indicated the key was already handled.</summary> + public bool IsSuppressed => this.SuppressButtons.Contains(this.Button); + + + /********* + ** Public methods + *********/ + /// <summary>Construct an instance.</summary> + /// <param name="button">The button on the controller, keyboard, or mouse.</param> + /// <param name="cursor">The cursor position.</param> + /// <param name="suppressButtons">The buttons to suppress.</param> + public InputButtonReleasedArgsInput(SButton button, ICursorPosition cursor, HashSet<SButton> suppressButtons) + { + this.Button = button; + this.Cursor = cursor; + this.SuppressButtons = suppressButtons; + } + + /// <summary>Prevent the game from handling the current button press. This doesn't prevent other mods from receiving the event.</summary> + public void SuppressButton() + { + this.SuppressButton(this.Button); + } + + /// <summary>Prevent the game from handling a button press. This doesn't prevent other mods from receiving the event.</summary> + /// <param name="button">The button to suppress.</param> + public void SuppressButton(SButton button) + { + this.SuppressButtons.Add(button); + } + } +} diff --git a/src/SMAPI/Events/InputEvents.cs b/src/SMAPI/Events/InputEvents.cs index 84d7ce5d..e62d6ee6 100644 --- a/src/SMAPI/Events/InputEvents.cs +++ b/src/SMAPI/Events/InputEvents.cs @@ -19,15 +19,15 @@ namespace StardewModdingAPI.Events /// <summary>Raised when the player presses a button on the keyboard, controller, or mouse.</summary> public static event EventHandler<EventArgsInput> ButtonPressed { - add => InputEvents.EventManager.Input_ButtonPressed.Add(value); - remove => InputEvents.EventManager.Input_ButtonPressed.Remove(value); + add => InputEvents.EventManager.Legacy_Input_ButtonPressed.Add(value); + remove => InputEvents.EventManager.Legacy_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 { - add => InputEvents.EventManager.Input_ButtonReleased.Add(value); - remove => InputEvents.EventManager.Input_ButtonReleased.Remove(value); + add => InputEvents.EventManager.Legacy_Input_ButtonReleased.Add(value); + remove => InputEvents.EventManager.Legacy_Input_ButtonReleased.Remove(value); } |