using System; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Input; 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. /// The previous keyboard state. /// The current keyboard state. internal static void InvokeKeyboardChanged(KeyboardState priorState, KeyboardState newState) { ControlEvents.KeyboardChanged?.Invoke(null, new EventArgsKeyboardStateChanged(priorState, newState)); } /// Raise a event. /// 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(MouseState priorState, MouseState newState, Point priorPosition, Point newPosition) { ControlEvents.MouseChanged?.Invoke(null, new EventArgsMouseStateChanged(priorState, newState, priorPosition, newPosition)); } /// Raise a event. /// The keyboard button that was pressed. internal static void InvokeKeyPressed(Keys key) { ControlEvents.KeyPressed?.Invoke(null, new EventArgsKeyPressed(key)); } /// Raise a event. /// The keyboard button that was released. internal static void InvokeKeyReleased(Keys key) { ControlEvents.KeyReleased?.Invoke(null, new EventArgsKeyPressed(key)); } /// Raise a event. /// The player who pressed the button. /// The controller button that was pressed. internal static void InvokeButtonPressed(PlayerIndex playerIndex, Buttons button) { ControlEvents.ControllerButtonPressed?.Invoke(null, new EventArgsControllerButtonPressed(playerIndex, button)); } /// Raise a event. /// The player who released the button. /// The controller button that was released. internal static void InvokeButtonReleased(PlayerIndex playerIndex, Buttons button) { ControlEvents.ControllerButtonReleased?.Invoke(null, new EventArgsControllerButtonReleased(playerIndex, button)); } /// Raise a event. /// The player who pressed the trigger button. /// The trigger button that was pressed. /// The current trigger value. internal static void InvokeTriggerPressed(PlayerIndex playerIndex, Buttons button, float value) { ControlEvents.ControllerTriggerPressed?.Invoke(null, new EventArgsControllerTriggerPressed(playerIndex, button, value)); } /// Raise a event. /// The player who pressed the trigger button. /// The trigger button that was pressed. /// The current trigger value. internal static void InvokeTriggerReleased(PlayerIndex playerIndex, Buttons button, float value) { ControlEvents.ControllerTriggerReleased?.Invoke(null, new EventArgsControllerTriggerReleased(playerIndex, button, value)); } } }