From e40483aab1f6dbcb89f3a1fd1639fc732fe987fc Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Tue, 19 Jan 2021 23:50:46 -0500 Subject: add method to suppress active keybindings (#744) --- src/SMAPI/Framework/ModHelpers/InputHelper.cs | 14 ++++++++++++++ src/SMAPI/IInputHelper.cs | 6 ++++++ 2 files changed, 20 insertions(+) (limited to 'src') 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 { @@ -49,6 +50,19 @@ namespace StardewModdingAPI.Framework.ModHelpers this.CurrentInputState().OverrideButton(button, setDown: false); } + /// + 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); + } + } + /// public SButtonState GetState(SButton 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 { /// Provides an API for checking and changing input state. @@ -18,6 +20,10 @@ namespace StardewModdingAPI /// The button to suppress. void Suppress(SButton button); + /// Suppress the keybinds which are currently down. + /// The keybind list whose active keybinds to suppress. + void SuppressActiveKeybinds(KeybindList keybindList); + /// Get the state of a button. /// The button to check. SButtonState GetState(SButton button); -- cgit