1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
namespace StardewModdingAPI.Events
{
/// <summary>Events raised when the player uses a controller, keyboard, or mouse.</summary>
public static class ControlEvents
{
/*********
** 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;
/// <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;
/*********
** Internal methods
*********/
/// <summary>Raise a <see cref="KeyboardChanged"/> event.</summary>
/// <param name="priorState">The previous keyboard state.</param>
/// <param name="newState">The current keyboard state.</param>
internal static void InvokeKeyboardChanged(KeyboardState priorState, KeyboardState newState)
{
ControlEvents.KeyboardChanged?.Invoke(null, new EventArgsKeyboardStateChanged(priorState, newState));
}
/// <summary>Raise a <see cref="MouseChanged"/> event.</summary>
/// <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(MouseState priorState, MouseState newState, Point priorPosition, Point newPosition)
{
ControlEvents.MouseChanged?.Invoke(null, new EventArgsMouseStateChanged(priorState, newState, priorPosition, newPosition));
}
/// <summary>Raise a <see cref="KeyPressed"/> event.</summary>
/// <param name="key">The keyboard button that was pressed.</param>
internal static void InvokeKeyPressed(Keys key)
{
ControlEvents.KeyPressed?.Invoke(null, new EventArgsKeyPressed(key));
}
/// <summary>Raise a <see cref="KeyReleased"/> event.</summary>
/// <param name="key">The keyboard button that was released.</param>
internal static void InvokeKeyReleased(Keys key)
{
ControlEvents.KeyReleased?.Invoke(null, new EventArgsKeyPressed(key));
}
/// <summary>Raise a <see cref="ControllerButtonPressed"/> event.</summary>
/// <param name="playerIndex">The player who pressed the button.</param>
/// <param name="button">The controller button that was pressed.</param>
internal static void InvokeButtonPressed(PlayerIndex playerIndex, Buttons button)
{
ControlEvents.ControllerButtonPressed?.Invoke(null, new EventArgsControllerButtonPressed(playerIndex, button));
}
/// <summary>Raise a <see cref="ControllerButtonReleased"/> event.</summary>
/// <param name="playerIndex">The player who released the button.</param>
/// <param name="button">The controller button that was released.</param>
internal static void InvokeButtonReleased(PlayerIndex playerIndex, Buttons button)
{
ControlEvents.ControllerButtonReleased?.Invoke(null, new EventArgsControllerButtonReleased(playerIndex, button));
}
/// <summary>Raise a <see cref="ControllerTriggerPressed"/> event.</summary>
/// <param name="playerIndex">The player who pressed the trigger button.</param>
/// <param name="button">The trigger button that was pressed.</param>
/// <param name="value">The current trigger value.</param>
internal static void InvokeTriggerPressed(PlayerIndex playerIndex, Buttons button, float value)
{
ControlEvents.ControllerTriggerPressed?.Invoke(null, new EventArgsControllerTriggerPressed(playerIndex, button, value));
}
/// <summary>Raise a <see cref="ControllerTriggerReleased"/> event.</summary>
/// <param name="playerIndex">The player who pressed the trigger button.</param>
/// <param name="button">The trigger button that was pressed.</param>
/// <param name="value">The current trigger value.</param>
internal static void InvokeTriggerReleased(PlayerIndex playerIndex, Buttons button, float value)
{
ControlEvents.ControllerTriggerReleased?.Invoke(null, new EventArgsControllerTriggerReleased(playerIndex, button, value));
}
}
}
|