summaryrefslogtreecommitdiff
path: root/src/SMAPI/Framework
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2021-01-19 21:47:05 -0500
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2021-01-19 21:47:05 -0500
commit7e280a066db92c74e957e2a694c922d4c3eae017 (patch)
tree1b4c927afe92dd155ff3a379574afa3fd095e21a /src/SMAPI/Framework
parentff16a6567b6137b1aafed3470406d5f5884a5bdc (diff)
downloadSMAPI-7e280a066db92c74e957e2a694c922d4c3eae017.tar.gz
SMAPI-7e280a066db92c74e957e2a694c922d4c3eae017.tar.bz2
SMAPI-7e280a066db92c74e957e2a694c922d4c3eae017.zip
add Input.ButtonsChanged event (#744)
Diffstat (limited to 'src/SMAPI/Framework')
-rw-r--r--src/SMAPI/Framework/Events/EventManager.cs4
-rw-r--r--src/SMAPI/Framework/Events/ModInputEvents.cs7
-rw-r--r--src/SMAPI/Framework/SCore.cs31
3 files changed, 29 insertions, 13 deletions
diff --git a/src/SMAPI/Framework/Events/EventManager.cs b/src/SMAPI/Framework/Events/EventManager.cs
index 665dbfe3..f4abfffe 100644
--- a/src/SMAPI/Framework/Events/EventManager.cs
+++ b/src/SMAPI/Framework/Events/EventManager.cs
@@ -93,6 +93,9 @@ namespace StardewModdingAPI.Framework.Events
/****
** Input
****/
+ /// <summary>Raised after the player presses or releases any buttons on the keyboard, controller, or mouse.</summary>
+ public readonly ManagedEvent<ButtonsChangedEventArgs> ButtonsChanged;
+
/// <summary>Raised after the player presses a button on the keyboard, controller, or mouse.</summary>
public readonly ManagedEvent<ButtonPressedEventArgs> ButtonPressed;
@@ -212,6 +215,7 @@ namespace StardewModdingAPI.Framework.Events
this.TimeChanged = ManageEventOf<TimeChangedEventArgs>(nameof(IModEvents.GameLoop), nameof(IGameLoopEvents.TimeChanged));
this.ReturnedToTitle = ManageEventOf<ReturnedToTitleEventArgs>(nameof(IModEvents.GameLoop), nameof(IGameLoopEvents.ReturnedToTitle));
+ this.ButtonsChanged = ManageEventOf<ButtonsChangedEventArgs>(nameof(IModEvents.Input), nameof(IInputEvents.ButtonsChanged));
this.ButtonPressed = ManageEventOf<ButtonPressedEventArgs>(nameof(IModEvents.Input), nameof(IInputEvents.ButtonPressed));
this.ButtonReleased = ManageEventOf<ButtonReleasedEventArgs>(nameof(IModEvents.Input), nameof(IInputEvents.ButtonReleased));
this.CursorMoved = ManageEventOf<CursorMovedEventArgs>(nameof(IModEvents.Input), nameof(IInputEvents.CursorMoved), isPerformanceCritical: true);
diff --git a/src/SMAPI/Framework/Events/ModInputEvents.cs b/src/SMAPI/Framework/Events/ModInputEvents.cs
index ab26ab3e..6f423e5d 100644
--- a/src/SMAPI/Framework/Events/ModInputEvents.cs
+++ b/src/SMAPI/Framework/Events/ModInputEvents.cs
@@ -9,6 +9,13 @@ namespace StardewModdingAPI.Framework.Events
/*********
** Accessors
*********/
+ /// <summary>Raised after the player presses or releases any buttons on the keyboard, controller, or mouse.</summary>
+ public event EventHandler<ButtonsChangedEventArgs> ButtonsChanged
+ {
+ add => this.EventManager.ButtonsChanged.Add(value, this.Mod);
+ remove => this.EventManager.ButtonsChanged.Remove(value);
+ }
+
/// <summary>Raised after the player presses a button on the keyboard, controller, or mouse.</summary>
public event EventHandler<ButtonPressedEventArgs> ButtonPressed
{
diff --git a/src/SMAPI/Framework/SCore.cs b/src/SMAPI/Framework/SCore.cs
index 0c55164c..1ac361cd 100644
--- a/src/SMAPI/Framework/SCore.cs
+++ b/src/SMAPI/Framework/SCore.cs
@@ -817,24 +817,29 @@ namespace StardewModdingAPI.Framework
}
// raise input button events
- foreach (var pair in inputState.ButtonStates)
+ if (inputState.ButtonStates.Count > 0)
{
- SButton button = pair.Key;
- SButtonState status = pair.Value;
+ events.ButtonsChanged.Raise(new ButtonsChangedEventArgs(cursor, inputState));
- if (status == SButtonState.Pressed)
+ foreach (var pair in inputState.ButtonStates)
{
- if (this.Monitor.IsVerbose)
- this.Monitor.Log($"Events: button {button} pressed.");
+ SButton button = pair.Key;
+ SButtonState status = pair.Value;
- events.ButtonPressed.Raise(new ButtonPressedEventArgs(button, cursor, inputState));
- }
- else if (status == SButtonState.Released)
- {
- if (this.Monitor.IsVerbose)
- this.Monitor.Log($"Events: button {button} released.");
+ if (status == SButtonState.Pressed)
+ {
+ if (this.Monitor.IsVerbose)
+ this.Monitor.Log($"Events: button {button} pressed.");
- events.ButtonReleased.Raise(new ButtonReleasedEventArgs(button, cursor, inputState));
+ events.ButtonPressed.Raise(new ButtonPressedEventArgs(button, cursor, inputState));
+ }
+ else if (status == SButtonState.Released)
+ {
+ if (this.Monitor.IsVerbose)
+ this.Monitor.Log($"Events: button {button} released.");
+
+ events.ButtonReleased.Raise(new ButtonReleasedEventArgs(button, cursor, inputState));
+ }
}
}
}