diff --git a/MLEM.Ui/Elements/ElementHelper.cs b/MLEM.Ui/Elements/ElementHelper.cs index 3113eb5..bcaecb8 100644 --- a/MLEM.Ui/Elements/ElementHelper.cs +++ b/MLEM.Ui/Elements/ElementHelper.cs @@ -150,7 +150,7 @@ namespace MLEM.Ui.Elements { button.SetData("Active", true); activeNext = false; } else if (button.GetData("Active")) { - if (unbind != null && unbind.IsPressed(inputHandler)) { + if (unbind != null && unbind.TryConsumePressed(inputHandler)) { keybind.Remove((c, i) => i == index); button.Text.Text = unboundPlaceholder; button.SetData("Active", false); diff --git a/MLEM.Ui/Elements/Slider.cs b/MLEM.Ui/Elements/Slider.cs index 5dfe367..7231e4e 100644 --- a/MLEM.Ui/Elements/Slider.cs +++ b/MLEM.Ui/Elements/Slider.cs @@ -30,9 +30,9 @@ namespace MLEM.Ui.Elements { base.Update(time); if (this.IsSelected) { - if (this.Controls.LeftButtons.IsPressed(this.Input, this.Controls.GamepadIndex)) { + if (this.CurrentValue > 0 && this.Controls.LeftButtons.TryConsumePressed(this.Input, this.Controls.GamepadIndex)) { this.CurrentValue -= this.StepPerScroll; - } else if (this.Controls.RightButtons.IsPressed(this.Input, this.Controls.GamepadIndex)) { + } else if (this.CurrentValue < this.MaxValue && this.Controls.RightButtons.TryConsumePressed(this.Input, this.Controls.GamepadIndex)) { this.CurrentValue += this.StepPerScroll; } } diff --git a/MLEM.Ui/Elements/TextField.cs b/MLEM.Ui/Elements/TextField.cs index e2c9d80..6557775 100644 --- a/MLEM.Ui/Elements/TextField.cs +++ b/MLEM.Ui/Elements/TextField.cs @@ -257,24 +257,26 @@ namespace MLEM.Ui.Elements { if (!this.IsSelected || this.IsHidden) return; - if (this.Input.IsKeyPressed(Keys.Left)) { + if (this.CaretPos > 0 && this.Input.TryConsumePressed(Keys.Left)) { this.CaretPos--; - } else if (this.Input.IsKeyPressed(Keys.Right)) { + } else if (this.CaretPos < this.text.Length && this.Input.TryConsumePressed(Keys.Right)) { this.CaretPos++; - } else if (this.Multiline && this.Input.IsKeyPressed(Keys.Up)) { - this.MoveCaretToLine(this.CaretLine - 1); - } else if (this.Multiline && this.Input.IsKeyPressed(Keys.Down)) { - this.MoveCaretToLine(this.CaretLine + 1); - } else if (this.Input.IsKeyPressed(Keys.Home)) { + } else if (this.Multiline && this.Input.IsKeyPressedAvailable(Keys.Up) && this.MoveCaretToLine(this.CaretLine - 1)) { + this.Input.TryConsumeKeyPressed(Keys.Up); + } else if (this.Multiline && this.Input.IsKeyPressedAvailable(Keys.Down) && this.MoveCaretToLine(this.CaretLine + 1)) { + this.Input.TryConsumeKeyPressed(Keys.Down); + } else if (this.CaretPos != 0 && this.Input.TryConsumeKeyPressed(Keys.Home)) { this.CaretPos = 0; - } else if (this.Input.IsKeyPressed(Keys.End)) { + } else if (this.CaretPos != this.text.Length && this.Input.TryConsumeKeyPressed(Keys.End)) { this.CaretPos = this.text.Length; } else if (this.Input.IsModifierKeyDown(ModifierKey.Control)) { - if (this.Input.IsKeyPressed(Keys.V)) { + if (this.Input.IsKeyPressedAvailable(Keys.V)) { var clip = ClipboardService.GetText(); - if (clip != null) + if (clip != null) { this.InsertText(clip, true); - } else if (this.Input.IsKeyPressed(Keys.C)) { + this.Input.TryConsumeKeyPressed(Keys.V); + } + } else if (this.Input.TryConsumeKeyPressed(Keys.C)) { // until there is text selection, just copy the whole content ClipboardService.SetText(this.Text); } diff --git a/MLEM.Ui/UiControls.cs b/MLEM.Ui/UiControls.cs index a53b8cf..c099c3a 100644 --- a/MLEM.Ui/UiControls.cs +++ b/MLEM.Ui/UiControls.cs @@ -192,14 +192,17 @@ namespace MLEM.Ui { } this.KeyboardButtons.TryConsumePressed(this.Input, this.GamepadIndex); } - } else if (this.Input.IsKeyPressed(Keys.Tab)) { + } else if (this.Input.IsKeyPressedAvailable(Keys.Tab)) { this.IsAutoNavMode = true; // tab or shift-tab to next or previous element var backward = this.Input.IsModifierKeyDown(ModifierKey.Shift); var next = this.GetTabNextElement(backward); if (this.SelectedElement?.Root != null) next = this.SelectedElement.GetTabNextElement(backward, next); - this.SelectElement(this.ActiveRoot, next); + if (next != this.SelectedElement) { + this.SelectElement(this.ActiveRoot, next); + this.Input.TryConsumeKeyPressed(Keys.Tab); + } } }