add method to suppress active keybindings (#744)

This commit is contained in:
Jesse Plamondon-Willard 2021-01-19 23:50:46 -05:00
parent f251f0d06c
commit e40483aab1
No known key found for this signature in database
GPG Key ID: CF8B1456B3E29F49
3 changed files with 25 additions and 3 deletions

View File

@ -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.

View File

@ -1,5 +1,6 @@
using System;
using StardewModdingAPI.Framework.Input;
using StardewModdingAPI.Utilities;
namespace StardewModdingAPI.Framework.ModHelpers
{
@ -49,6 +50,19 @@ namespace StardewModdingAPI.Framework.ModHelpers
this.CurrentInputState().OverrideButton(button, setDown: false);
}
/// <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)
{

View File

@ -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);