1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-22 12:58:33 +01:00

consume other UI inputs too

This commit is contained in:
Ell 2022-04-30 12:26:40 +02:00
parent 610527374e
commit bc0f9d5c0c
4 changed files with 21 additions and 16 deletions

View file

@ -150,7 +150,7 @@ namespace MLEM.Ui.Elements {
button.SetData("Active", true);
activeNext = false;
} else if (button.GetData<bool>("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);

View file

@ -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;
}
}

View file

@ -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);
}

View file

@ -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);
if (next != this.SelectedElement) {
this.SelectElement(this.ActiveRoot, next);
this.Input.TryConsumeKeyPressed(Keys.Tab);
}
}
}