From 664a2a9f11fc271c53c0a8ea2f695671a7dc6918 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Sun, 20 Jun 2021 22:33:24 +0200 Subject: [PATCH] added a way to access a keybind's combinations --- MLEM/Input/Keybind.cs | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/MLEM/Input/Keybind.cs b/MLEM/Input/Keybind.cs index 2f9a001..65718a5 100644 --- a/MLEM/Input/Keybind.cs +++ b/MLEM/Input/Keybind.cs @@ -72,29 +72,50 @@ namespace MLEM.Input { return this.combinations.Any(c => c.IsPressed(handler, gamepadIndex)); } + /// + /// Returns an enumerable of all of the combinations that this keybind currently contains + /// + /// This keybind's combinations + public IEnumerable GetCombinations() { + foreach (var combination in this.combinations) + yield return combination; + } + + /// + /// A key combination is a combination of a set of modifier keys and a key. + /// All of the keys are instances, so they can be keyboard-, mouse- or gamepad-based. + /// [DataContract] - private class Combination { + public class Combination { + /// + /// The inputs that have to be held down for this combination to be valid. + /// If this collection is empty, there are no required modifier keys. + /// [DataMember] - private readonly GenericInput[] modifiers; + public readonly GenericInput[] Modifiers; + /// + /// The input that has to be down (or pressed) for this combination to be considered down (or pressed). + /// Note that needs to be empty, or all of its values need to be down, as well. + /// [DataMember] - private readonly GenericInput key; + public readonly GenericInput Key; - public Combination(GenericInput key, GenericInput[] modifiers) { - this.modifiers = modifiers; - this.key = key; + internal Combination(GenericInput key, GenericInput[] modifiers) { + this.Modifiers = modifiers; + this.Key = key; } internal bool IsDown(InputHandler handler, int gamepadIndex = -1) { - return this.IsModifierDown(handler, gamepadIndex) && handler.IsDown(this.key, gamepadIndex); + return this.IsModifierDown(handler, gamepadIndex) && handler.IsDown(this.Key, gamepadIndex); } internal bool IsPressed(InputHandler handler, int gamepadIndex = -1) { - return this.IsModifierDown(handler, gamepadIndex) && handler.IsPressed(this.key, gamepadIndex); + return this.IsModifierDown(handler, gamepadIndex) && handler.IsPressed(this.Key, gamepadIndex); } private bool IsModifierDown(InputHandler handler, int gamepadIndex = -1) { - return this.modifiers.Length <= 0 || this.modifiers.Any(m => handler.IsDown(m, gamepadIndex)); + return this.Modifiers.Length <= 0 || this.Modifiers.Any(m => handler.IsDown(m, gamepadIndex)); } }