From 67388c106b91c2604f36e0ebb295adb099972f11 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Thu, 10 Mar 2022 13:08:49 +0100 Subject: [PATCH] allow retrieving a keybind button's active state --- MLEM.Ui/Elements/ElementHelper.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/MLEM.Ui/Elements/ElementHelper.cs b/MLEM.Ui/Elements/ElementHelper.cs index c6dd1f6..d397dc7 100644 --- a/MLEM.Ui/Elements/ElementHelper.cs +++ b/MLEM.Ui/Elements/ElementHelper.cs @@ -119,6 +119,7 @@ namespace MLEM.Ui.Elements { /// Creates a that acts as a way to input a custom value for a . /// Note that only the at index of the given keybind is displayed and edited, all others are ignored. /// Inputting custom keybinds using this element supports -based modifiers and any -based keys. + /// The keybind button's current state can be retrieved using the "Active" key, which stores a bool that indicates whether the button is currently waiting for a new value to be assigned. /// /// The button's anchor /// The button's size @@ -134,7 +135,6 @@ namespace MLEM.Ui.Elements { string GetCurrentName() => keybind.TryGetCombination(index, out var combination) ? combination.ToString(" + ", inputName) : unboundPlaceholder; var button = new Button(anchor, size, GetCurrentName()); - var active = false; var activeNext = false; button.OnPressed = e => { button.Text.Text = activePlaceholder; @@ -142,20 +142,20 @@ namespace MLEM.Ui.Elements { }; button.OnUpdated = (e, time) => { if (activeNext) { - active = true; + button.SetData("Active", true); activeNext = false; - } else if (active) { + } else if (button.GetData("Active")) { if (unbindKey != default && inputHandler.IsPressed(unbindKey)) { keybind.Remove((c, i) => i == index); button.Text.Text = unboundPlaceholder; - active = false; + button.SetData("Active", false); } else if (inputHandler.InputsPressed.Length > 0) { var key = inputHandler.InputsPressed.FirstOrDefault(i => !i.IsModifier()); if (key != default) { var mods = inputHandler.InputsDown.Where(i => i.IsModifier()); keybind.Remove((c, i) => i == index).Insert(index, key, mods.ToArray()); button.Text.Text = GetCurrentName(); - active = false; + button.SetData("Active", false); } } } else {