diff options
author | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2021-01-19 23:50:46 -0500 |
---|---|---|
committer | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2021-01-19 23:50:46 -0500 |
commit | e40483aab1f6dbcb89f3a1fd1639fc732fe987fc (patch) | |
tree | 4c9cb86e9fba7216fbb50eae6052154845ce5215 | |
parent | f251f0d06c2942b53dfd69bb79bf12b16a227503 (diff) | |
download | SMAPI-e40483aab1f6dbcb89f3a1fd1639fc732fe987fc.tar.gz SMAPI-e40483aab1f6dbcb89f3a1fd1639fc732fe987fc.tar.bz2 SMAPI-e40483aab1f6dbcb89f3a1fd1639fc732fe987fc.zip |
add method to suppress active keybindings (#744)
-rw-r--r-- | docs/release-notes.md | 8 | ||||
-rw-r--r-- | src/SMAPI/Framework/ModHelpers/InputHelper.cs | 14 | ||||
-rw-r--r-- | src/SMAPI/IInputHelper.cs | 6 |
3 files changed, 25 insertions, 3 deletions
diff --git a/docs/release-notes.md b/docs/release-notes.md index 5f67641b..83de68e4 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -12,9 +12,11 @@ * Improved game path detection in the installer. The installer now prefers the path registered by Steam or GOG Galaxy, and can also now detect the default install path for manual GOG installs. * For modders: - * Added [API for multi-key bindings](https://stardewcommunitywiki.com/Modding:Modder_Guide/APIs/Input#KeybindList). - * Added a new [`Input.ButtonsChanged` event](https://stardewcommunitywiki.com/Modding:Modder_Guide/APIs/Events#Input.ButtonsChanged). - * Added a `buttonState.IsDown()` extension. + * Added new input APIs: + * Added [API for multi-key bindings](https://stardewcommunitywiki.com/Modding:Modder_Guide/APIs/Input#KeybindList). + * Added a new [`Input.ButtonsChanged` event](https://stardewcommunitywiki.com/Modding:Modder_Guide/APIs/Events#Input.ButtonsChanged). + * Added a `buttonState.IsDown()` extension. + * Added a `helper.Input.SuppressActiveKeybindings` method which suppresses the active buttons in a keybind list. * Improved multiplayer APIs: * `PerScreen<T>` now lets you get/set the value for any screen, get all active values, or clear all values. * Peer data for the multiplayer API/events now includes `IsSplitScreen` and `ScreenID` fields. diff --git a/src/SMAPI/Framework/ModHelpers/InputHelper.cs b/src/SMAPI/Framework/ModHelpers/InputHelper.cs index e1317544..88caf4c3 100644 --- a/src/SMAPI/Framework/ModHelpers/InputHelper.cs +++ b/src/SMAPI/Framework/ModHelpers/InputHelper.cs @@ -1,5 +1,6 @@ using System; using StardewModdingAPI.Framework.Input; +using StardewModdingAPI.Utilities; namespace StardewModdingAPI.Framework.ModHelpers { @@ -50,6 +51,19 @@ namespace StardewModdingAPI.Framework.ModHelpers } /// <inheritdoc /> + public void SuppressActiveKeybinds(KeybindList keybindList) + { + foreach (Keybind keybind in keybindList.Keybinds) + { + if (!keybind.GetState().IsDown()) + continue; + + foreach (SButton button in keybind.Buttons) + this.Suppress(button); + } + } + + /// <inheritdoc /> public SButtonState GetState(SButton button) { return this.CurrentInputState().GetState(button); diff --git a/src/SMAPI/IInputHelper.cs b/src/SMAPI/IInputHelper.cs index e9768c24..2b907b0d 100644 --- a/src/SMAPI/IInputHelper.cs +++ b/src/SMAPI/IInputHelper.cs @@ -1,3 +1,5 @@ +using StardewModdingAPI.Utilities; + namespace StardewModdingAPI { /// <summary>Provides an API for checking and changing input state.</summary> @@ -18,6 +20,10 @@ namespace StardewModdingAPI /// <param name="button">The button to suppress.</param> void Suppress(SButton button); + /// <summary>Suppress the keybinds which are currently down.</summary> + /// <param name="keybindList">The keybind list whose active keybinds to suppress.</param> + void SuppressActiveKeybinds(KeybindList keybindList); + /// <summary>Get the state of a button.</summary> /// <param name="button">The button to check.</param> SButtonState GetState(SButton button); |