diff --git a/CHANGELOG.md b/CHANGELOG.md index 976b78c..3240ebc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -53,6 +53,7 @@ Improvements - Automatically update all elements when changing a ui system's viewport - Allow setting a default color for clickable links in UiStyle - Allow ElementHelper's KeybindButton to query a combination at a given index +- Allow ElementHelper's KeybindButton to accept a Keybind for clearing a combination - Automatically select the first element when a dropdown is opened in auto nav mode - Improved gamepad navigation by employing angles between elements - Prefer elements that have the same parent as the currently selected element when using gamepad navigation diff --git a/MLEM.Ui/Elements/ElementHelper.cs b/MLEM.Ui/Elements/ElementHelper.cs index d397dc7..f1a7a8f 100644 --- a/MLEM.Ui/Elements/ElementHelper.cs +++ b/MLEM.Ui/Elements/ElementHelper.cs @@ -115,6 +115,11 @@ namespace MLEM.Ui.Elements { return group; } + /// + public static Button KeybindButton(Anchor anchor, Vector2 size, Keybind keybind, InputHandler inputHandler, string activePlaceholder, GenericInput unbindKey = default, string unboundPlaceholder = "", Func inputName = null, int index = 0) { + return KeybindButton(anchor, size, keybind, inputHandler, activePlaceholder, new Keybind(unbindKey), unboundPlaceholder, inputName, index); + } + /// /// 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. @@ -126,12 +131,12 @@ namespace MLEM.Ui.Elements { /// The keybind that this button should represent /// The input handler to query inputs with /// A placeholder text that is displayed while the keybind is being edited - /// An optional generic input that allows the keybind value to be unbound, clearing all combinations + /// An optional keybind to press that allows the keybind value to be unbound, clearing the combination /// A placeholder text that is displayed if the keybind is unbound /// An optional function to give each input a display name that is easier to read. If this is null, is used. /// The index in the that the button should display. Note that, if the index is greater than the amount of combinations, combinations entered using this button will be stored at an earlier index. /// A keybind button with the given settings - public static Button KeybindButton(Anchor anchor, Vector2 size, Keybind keybind, InputHandler inputHandler, string activePlaceholder, GenericInput unbindKey = default, string unboundPlaceholder = "", Func inputName = null, int index = 0) { + public static Button KeybindButton(Anchor anchor, Vector2 size, Keybind keybind, InputHandler inputHandler, string activePlaceholder, Keybind unbind = default, string unboundPlaceholder = "", Func inputName = null, int index = 0) { string GetCurrentName() => keybind.TryGetCombination(index, out var combination) ? combination.ToString(" + ", inputName) : unboundPlaceholder; var button = new Button(anchor, size, GetCurrentName()); @@ -145,7 +150,7 @@ namespace MLEM.Ui.Elements { button.SetData("Active", true); activeNext = false; } else if (button.GetData("Active")) { - if (unbindKey != default && inputHandler.IsPressed(unbindKey)) { + if (unbind != null && unbind.IsPressed(inputHandler)) { keybind.Remove((c, i) => i == index); button.Text.Text = unboundPlaceholder; button.SetData("Active", false);