1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-25 14:08:34 +01:00

Compare commits

..

5 commits

12 changed files with 181 additions and 59 deletions

View file

@ -11,7 +11,7 @@ Jump to version:
## 5.4.0 (Unreleased) ## 5.4.0 (Unreleased)
### MLEM ### MLEM
Additions Additions
- Added consuming variants of IsPressed methods to InputHandler - Added consuming variants of IsPressed methods to InputHandler and Keybind
- Added SpriteBatchContext struct and extensions - Added SpriteBatchContext struct and extensions
- Added InputHandler.InvertPressBehavior - Added InputHandler.InvertPressBehavior
@ -22,6 +22,7 @@ Additions
Improvements Improvements
- Ensure that Element.IsMouseOver is always accurate by making it an auto-property - Ensure that Element.IsMouseOver is always accurate by making it an auto-property
- Started using SpriteBatchContext for Draw and DrawTransformed methods - Started using SpriteBatchContext for Draw and DrawTransformed methods
- Make use of the new consuming variants in InputHandler and Keybind to consume UiControls inputs
Fixes Fixes
- Fixed auto-nav tooltip displaying on the selected element even when not in auto-nav mode - Fixed auto-nav tooltip displaying on the selected element even when not in auto-nav mode

View file

@ -1,13 +1,13 @@
using MLEM.Startup; using MLEM.Startup;
namespace TemplateNamespace { namespace TemplateNamespace;
public class GameImpl : MlemGame {
public static GameImpl Instance { get; private set; } public class GameImpl : MlemGame {
public GameImpl() { public static GameImpl Instance { get; private set; }
Instance = this;
}
public GameImpl() {
Instance = this;
} }
} }

View file

@ -1,14 +1,14 @@
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using MLEM.Misc; using MLEM.Misc;
namespace TemplateNamespace { namespace TemplateNamespace;
public static class Program {
public static void Main() { public static class Program {
MlemPlatform.Current = new MlemPlatform.DesktopGl<TextInputEventArgs>((w, c) => w.TextInput += c);
using var game = new GameImpl();
game.Run();
}
public static void Main() {
MlemPlatform.Current = new MlemPlatform.DesktopGl<TextInputEventArgs>((w, c) => w.TextInput += c);
using var game = new GameImpl();
game.Run();
} }
} }

View file

@ -2,7 +2,7 @@
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework> <TargetFramework>net6.0</TargetFramework>
<PublishReadyToRun>false</PublishReadyToRun> <PublishReadyToRun>false</PublishReadyToRun>
<TieredCompilation>false</TieredCompilation> <TieredCompilation>false</TieredCompilation>
<ApplicationIcon>Icon.ico</ApplicationIcon> <ApplicationIcon>Icon.ico</ApplicationIcon>
@ -16,8 +16,6 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<MonoGameContentReference Include="Content\Content.mgcb" />
<Content Include="Content\*\**" />
<EmbeddedResource Include="Icon.ico" /> <EmbeddedResource Include="Icon.ico" />
<EmbeddedResource Include="Icon.bmp" /> <EmbeddedResource Include="Icon.bmp" />
</ItemGroup> </ItemGroup>

View file

@ -150,7 +150,7 @@ namespace MLEM.Ui.Elements {
button.SetData("Active", true); button.SetData("Active", true);
activeNext = false; activeNext = false;
} else if (button.GetData<bool>("Active")) { } else if (button.GetData<bool>("Active")) {
if (unbind != null && unbind.IsPressed(inputHandler)) { if (unbind != null && unbind.TryConsumePressed(inputHandler)) {
keybind.Remove((c, i) => i == index); keybind.Remove((c, i) => i == index);
button.Text.Text = unboundPlaceholder; button.Text.Text = unboundPlaceholder;
button.SetData("Active", false); button.SetData("Active", false);

View file

@ -138,7 +138,7 @@ namespace MLEM.Ui.Elements {
// MOUSE INPUT // MOUSE INPUT
var moused = this.Controls.MousedElement; var moused = this.Controls.MousedElement;
if (moused == this && this.Input.IsMouseButtonPressed(MouseButton.Left)) { if (moused == this && this.Input.WasMouseButtonUp(MouseButton.Left) && this.Input.IsMouseButtonDown(MouseButton.Left)) {
this.isMouseHeld = true; this.isMouseHeld = true;
this.scrollStartOffset = this.TransformInverseAll(this.Input.ViewportMousePosition.ToVector2()) - this.ScrollerPosition; this.scrollStartOffset = this.TransformInverseAll(this.Input.ViewportMousePosition.ToVector2()) - this.ScrollerPosition;
} else if (this.isMouseHeld && !this.Input.IsMouseButtonDown(MouseButton.Left)) { } else if (this.isMouseHeld && !this.Input.IsMouseButtonDown(MouseButton.Left)) {

View file

@ -30,9 +30,9 @@ namespace MLEM.Ui.Elements {
base.Update(time); base.Update(time);
if (this.IsSelected) { 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; 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; this.CurrentValue += this.StepPerScroll;
} }
} }

View file

@ -257,24 +257,26 @@ namespace MLEM.Ui.Elements {
if (!this.IsSelected || this.IsHidden) if (!this.IsSelected || this.IsHidden)
return; return;
if (this.Input.IsKeyPressed(Keys.Left)) { if (this.CaretPos > 0 && this.Input.TryConsumePressed(Keys.Left)) {
this.CaretPos--; this.CaretPos--;
} else if (this.Input.IsKeyPressed(Keys.Right)) { } else if (this.CaretPos < this.text.Length && this.Input.TryConsumePressed(Keys.Right)) {
this.CaretPos++; this.CaretPos++;
} else if (this.Multiline && this.Input.IsKeyPressed(Keys.Up)) { } else if (this.Multiline && this.Input.IsKeyPressedAvailable(Keys.Up) && this.MoveCaretToLine(this.CaretLine - 1)) {
this.MoveCaretToLine(this.CaretLine - 1); this.Input.TryConsumeKeyPressed(Keys.Up);
} else if (this.Multiline && this.Input.IsKeyPressed(Keys.Down)) { } else if (this.Multiline && this.Input.IsKeyPressedAvailable(Keys.Down) && this.MoveCaretToLine(this.CaretLine + 1)) {
this.MoveCaretToLine(this.CaretLine + 1); this.Input.TryConsumeKeyPressed(Keys.Down);
} else if (this.Input.IsKeyPressed(Keys.Home)) { } else if (this.CaretPos != 0 && this.Input.TryConsumeKeyPressed(Keys.Home)) {
this.CaretPos = 0; 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; this.CaretPos = this.text.Length;
} else if (this.Input.IsModifierKeyDown(ModifierKey.Control)) { } else if (this.Input.IsModifierKeyDown(ModifierKey.Control)) {
if (this.Input.IsKeyPressed(Keys.V)) { if (this.Input.IsKeyPressedAvailable(Keys.V)) {
var clip = ClipboardService.GetText(); var clip = ClipboardService.GetText();
if (clip != null) if (clip != null) {
this.InsertText(clip, true); 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 // until there is text selection, just copy the whole content
ClipboardService.SetText(this.Text); ClipboardService.SetText(this.Text);
} }

View file

@ -162,22 +162,26 @@ namespace MLEM.Ui {
var mousedNow = this.GetElementUnderPos(this.Input.ViewportMousePosition.ToVector2()); var mousedNow = this.GetElementUnderPos(this.Input.ViewportMousePosition.ToVector2());
this.SetMousedElement(mousedNow); this.SetMousedElement(mousedNow);
if (this.Input.IsMouseButtonPressed(MouseButton.Left)) { if (this.Input.IsMouseButtonPressedAvailable(MouseButton.Left)) {
this.IsAutoNavMode = false; this.IsAutoNavMode = false;
var selectedNow = mousedNow != null && mousedNow.CanBeSelected ? mousedNow : null; var selectedNow = mousedNow != null && mousedNow.CanBeSelected ? mousedNow : null;
this.SelectElement(this.ActiveRoot, selectedNow); this.SelectElement(this.ActiveRoot, selectedNow);
if (mousedNow != null && mousedNow.CanBePressed) if (mousedNow != null && mousedNow.CanBePressed) {
this.System.InvokeOnElementPressed(mousedNow); this.System.InvokeOnElementPressed(mousedNow);
} else if (this.Input.IsMouseButtonPressed(MouseButton.Right)) { this.Input.TryConsumeMouseButtonPressed(MouseButton.Left);
}
} else if (this.Input.IsMouseButtonPressedAvailable(MouseButton.Right)) {
this.IsAutoNavMode = false; this.IsAutoNavMode = false;
if (mousedNow != null && mousedNow.CanBePressed) if (mousedNow != null && mousedNow.CanBePressed) {
this.System.InvokeOnElementSecondaryPressed(mousedNow); this.System.InvokeOnElementSecondaryPressed(mousedNow);
this.Input.TryConsumeMouseButtonPressed(MouseButton.Right);
}
} }
} }
// KEYBOARD INPUT // KEYBOARD INPUT
if (this.HandleKeyboard) { if (this.HandleKeyboard) {
if (this.KeyboardButtons.IsPressed(this.Input, this.GamepadIndex)) { if (this.KeyboardButtons.IsPressedAvailable(this.Input, this.GamepadIndex)) {
if (this.SelectedElement?.Root != null && this.SelectedElement.CanBePressed) { if (this.SelectedElement?.Root != null && this.SelectedElement.CanBePressed) {
if (this.Input.IsModifierKeyDown(ModifierKey.Shift)) { if (this.Input.IsModifierKeyDown(ModifierKey.Shift)) {
// secondary action on element using space or enter // secondary action on element using space or enter
@ -186,15 +190,19 @@ namespace MLEM.Ui {
// first action on element using space or enter // first action on element using space or enter
this.System.InvokeOnElementPressed(this.SelectedElement); this.System.InvokeOnElementPressed(this.SelectedElement);
} }
this.KeyboardButtons.TryConsumePressed(this.Input, this.GamepadIndex);
} }
} else if (this.Input.IsKeyPressed(Keys.Tab)) { } else if (this.Input.IsKeyPressedAvailable(Keys.Tab)) {
this.IsAutoNavMode = true; this.IsAutoNavMode = true;
// tab or shift-tab to next or previous element // tab or shift-tab to next or previous element
var backward = this.Input.IsModifierKeyDown(ModifierKey.Shift); var backward = this.Input.IsModifierKeyDown(ModifierKey.Shift);
var next = this.GetTabNextElement(backward); var next = this.GetTabNextElement(backward);
if (this.SelectedElement?.Root != null) if (this.SelectedElement?.Root != null)
next = this.SelectedElement.GetTabNextElement(backward, next); 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);
}
} }
} }
@ -230,20 +238,28 @@ namespace MLEM.Ui {
// GAMEPAD INPUT // GAMEPAD INPUT
if (this.HandleGamepad) { if (this.HandleGamepad) {
if (this.GamepadButtons.IsPressed(this.Input, this.GamepadIndex)) { if (this.GamepadButtons.IsPressedAvailable(this.Input, this.GamepadIndex)) {
if (this.SelectedElement?.Root != null && this.SelectedElement.CanBePressed) if (this.SelectedElement?.Root != null && this.SelectedElement.CanBePressed) {
this.System.InvokeOnElementPressed(this.SelectedElement); this.System.InvokeOnElementPressed(this.SelectedElement);
} else if (this.SecondaryGamepadButtons.IsPressed(this.Input, this.GamepadIndex)) { this.GamepadButtons.TryConsumePressed(this.Input, this.GamepadIndex);
if (this.SelectedElement?.Root != null && this.SelectedElement.CanBePressed) }
} else if (this.SecondaryGamepadButtons.IsPressedAvailable(this.Input, this.GamepadIndex)) {
if (this.SelectedElement?.Root != null && this.SelectedElement.CanBePressed) {
this.System.InvokeOnElementSecondaryPressed(this.SelectedElement); this.System.InvokeOnElementSecondaryPressed(this.SelectedElement);
} else if (this.DownButtons.IsPressed(this.Input, this.GamepadIndex)) { this.SecondaryGamepadButtons.TryConsumePressed(this.Input, this.GamepadIndex);
this.HandleGamepadNextElement(Direction2.Down); }
} else if (this.LeftButtons.IsPressed(this.Input, this.GamepadIndex)) { } else if (this.DownButtons.IsPressedAvailable(this.Input, this.GamepadIndex)) {
this.HandleGamepadNextElement(Direction2.Left); if (this.HandleGamepadNextElement(Direction2.Down))
} else if (this.RightButtons.IsPressed(this.Input, this.GamepadIndex)) { this.DownButtons.TryConsumePressed(this.Input, this.GamepadIndex);
this.HandleGamepadNextElement(Direction2.Right); } else if (this.LeftButtons.IsPressedAvailable(this.Input, this.GamepadIndex)) {
} else if (this.UpButtons.IsPressed(this.Input, this.GamepadIndex)) { if (this.HandleGamepadNextElement(Direction2.Left))
this.HandleGamepadNextElement(Direction2.Up); this.LeftButtons.TryConsumePressed(this.Input, this.GamepadIndex);
} else if (this.RightButtons.IsPressedAvailable(this.Input, this.GamepadIndex)) {
if (this.HandleGamepadNextElement(Direction2.Right))
this.RightButtons.TryConsumePressed(this.Input, this.GamepadIndex);
} else if (this.UpButtons.IsPressedAvailable(this.Input, this.GamepadIndex)) {
if (this.HandleGamepadNextElement(Direction2.Up))
this.UpButtons.TryConsumePressed(this.Input, this.GamepadIndex);
} }
} }
} }
@ -413,13 +429,16 @@ namespace MLEM.Ui {
} }
} }
private void HandleGamepadNextElement(Direction2 dir) { private bool HandleGamepadNextElement(Direction2 dir) {
this.IsAutoNavMode = true; this.IsAutoNavMode = true;
var next = this.GetGamepadNextElement(dir); var next = this.GetGamepadNextElement(dir);
if (this.SelectedElement != null) if (this.SelectedElement != null)
next = this.SelectedElement.GetGamepadNextElement(dir, next); next = this.SelectedElement.GetGamepadNextElement(dir, next);
if (next != null) if (next != null) {
this.SelectElement(this.ActiveRoot, next); this.SelectElement(this.ActiveRoot, next);
return true;
}
return false;
} }
} }

View file

@ -365,6 +365,15 @@ namespace MLEM.Input {
return this.WasKeyUp(key) && this.IsKeyDown(key); return this.WasKeyUp(key) && this.IsKeyDown(key);
} }
/// <summary>
/// Returns if the given key is considered pressed, and if the press has not been consumed yet using <see cref="TryConsumeKeyPressed"/>.
/// </summary>
/// <param name="key">The key to query.</param>
/// <returns>If the key is pressed and the press is not consumed yet.</returns>
public bool IsKeyPressedAvailable(Keys key) {
return this.IsKeyPressed(key) && !this.consumedPresses.Contains((key, -1));
}
/// <summary> /// <summary>
/// Returns whether the given key is considered pressed, and marks the press as consumed if it is. /// Returns whether the given key is considered pressed, and marks the press as consumed if it is.
/// A key is considered pressed if it was not down the last update call, but is down the current update call. /// A key is considered pressed if it was not down the last update call, but is down the current update call.
@ -374,7 +383,7 @@ namespace MLEM.Input {
/// <param name="key">The key to query.</param> /// <param name="key">The key to query.</param>
/// <returns>If the key is pressed and the press is not consumed yet.</returns> /// <returns>If the key is pressed and the press is not consumed yet.</returns>
public bool TryConsumeKeyPressed(Keys key) { public bool TryConsumeKeyPressed(Keys key) {
if (this.IsKeyPressed(key) && !this.consumedPresses.Contains((key, -1))) { if (this.IsKeyPressedAvailable(key)) {
this.consumedPresses.Add((key, -1)); this.consumedPresses.Add((key, -1));
return true; return true;
} }
@ -442,6 +451,15 @@ namespace MLEM.Input {
return this.WasMouseButtonUp(button) && this.IsMouseButtonDown(button); return this.WasMouseButtonUp(button) && this.IsMouseButtonDown(button);
} }
/// <summary>
/// Returns if the given mouse button is considered pressed, and if the press has not been consumed yet using <see cref="TryConsumeMouseButtonPressed"/>.
/// </summary>
/// <param name="button">The button to query.</param>
/// <returns>If the button is pressed and the press is not consumed yet.</returns>
public bool IsMouseButtonPressedAvailable(MouseButton button) {
return this.IsMouseButtonPressed(button) && !this.consumedPresses.Contains((button, -1));
}
/// <summary> /// <summary>
/// Returns whether the given mouse button is considered pressed, and marks the press as consumed if it is. /// Returns whether the given mouse button is considered pressed, and marks the press as consumed if it is.
/// A mouse button is considered pressed if it was up the last update call, and is down the current update call. /// A mouse button is considered pressed if it was up the last update call, and is down the current update call.
@ -450,7 +468,7 @@ namespace MLEM.Input {
/// <param name="button">The button to query.</param> /// <param name="button">The button to query.</param>
/// <returns>If the button is pressed and the press is not consumed yet.</returns> /// <returns>If the button is pressed and the press is not consumed yet.</returns>
public bool TryConsumeMouseButtonPressed(MouseButton button) { public bool TryConsumeMouseButtonPressed(MouseButton button) {
if (this.IsMouseButtonPressed(button) && !this.consumedPresses.Contains((button, -1))) { if (this.IsMouseButtonPressedAvailable(button)) {
this.consumedPresses.Add((button, -1)); this.consumedPresses.Add((button, -1));
return true; return true;
} }
@ -542,6 +560,16 @@ namespace MLEM.Input {
return this.WasGamepadButtonUp(button, index) && this.IsGamepadButtonDown(button, index); return this.WasGamepadButtonUp(button, index) && this.IsGamepadButtonDown(button, index);
} }
/// <summary>
/// Returns if the given gamepad button is considered pressed, and if the press has not been consumed yet using <see cref="TryConsumeMouseButtonPressed"/>.
/// </summary>
/// <param name="button">The button to query.</param>
/// <param name="index">The zero-based index of the gamepad, or -1 for any gamepad.</param>
/// <returns>Whether the given button is pressed and the press is not consumed yet.</returns>
public bool IsGamepadButtonPressedAvailable(Buttons button, int index = -1) {
return this.IsGamepadButtonPressed(button) && !this.consumedPresses.Contains((button, index)) && (index < 0 || !this.consumedPresses.Contains((button, -1)));
}
/// <summary> /// <summary>
/// Returns whether the given gamepad button on the given index is considered pressed, and marks the press as consumed if it is. /// Returns whether the given gamepad button on the given index is considered pressed, and marks the press as consumed if it is.
/// A gamepad button is considered pressed if it was down the last update call, and is up the current update call. /// A gamepad button is considered pressed if it was down the last update call, and is up the current update call.
@ -552,7 +580,7 @@ namespace MLEM.Input {
/// <param name="index">The zero-based index of the gamepad, or -1 for any gamepad.</param> /// <param name="index">The zero-based index of the gamepad, or -1 for any gamepad.</param>
/// <returns>Whether the given button is pressed and the press is not consumed yet.</returns> /// <returns>Whether the given button is pressed and the press is not consumed yet.</returns>
public bool TryConsumeGamepadButtonPressed(Buttons button, int index = -1) { public bool TryConsumeGamepadButtonPressed(Buttons button, int index = -1) {
if (this.IsGamepadButtonPressed(button) && !this.consumedPresses.Contains((button, index))) { if (this.IsGamepadButtonPressedAvailable(button, index)) {
this.consumedPresses.Add((button, index)); this.consumedPresses.Add((button, index));
return true; return true;
} }
@ -656,7 +684,26 @@ namespace MLEM.Input {
} }
/// <summary> /// <summary>
/// Returns if a given control of any kind is pressed, and marks the press as consumed if it is. /// Returns if a given control of any kind is pressed, and if the press has not been consumed yet using <see cref="TryConsumePressed"/>.
/// </summary>
/// <param name="control">The control whose pressed state to query.</param>
/// <param name="index">The index of the gamepad to query (if applicable), or -1 for any gamepad.</param>
/// <returns>Whether the given control is pressed and the press is not consumed yet.</returns>
public bool IsPressedAvailable(GenericInput control, int index = -1) {
switch (control.Type) {
case GenericInput.InputType.Keyboard:
return this.IsKeyPressedAvailable(control);
case GenericInput.InputType.Gamepad:
return this.IsGamepadButtonPressedAvailable(control, index);
case GenericInput.InputType.Mouse:
return this.IsMouseButtonPressedAvailable(control);
default:
return false;
}
}
/// <summary>
/// Returns if a given control of any kind is pressed and available, and marks the press as consumed if it is.
/// This is a helper function that can be passed a <see cref="Keys"/>, <see cref="Buttons"/> or <see cref="MouseButton"/>. /// This is a helper function that can be passed a <see cref="Keys"/>, <see cref="Buttons"/> or <see cref="MouseButton"/>.
/// </summary> /// </summary>
/// <param name="control">The control whose pressed state to query.</param> /// <param name="control">The control whose pressed state to query.</param>

View file

@ -131,6 +131,36 @@ namespace MLEM.Input {
return false; return false;
} }
/// <summary>
/// Returns whether this keybind is considered to be pressed and has not been consumed yet using<see cref="TryConsumePressed"/>.
/// See <see cref="InputHandler.IsPressedAvailable"/> for more information.
/// </summary>
/// <param name="handler">The input handler to query the keys with</param>
/// <param name="gamepadIndex">The index of the gamepad to query, or -1 to query all gamepads</param>
/// <returns>Whether this keybind is considered to be pressed</returns>
public bool IsPressedAvailable(InputHandler handler, int gamepadIndex = -1) {
foreach (var combination in this.combinations) {
if (combination.IsPressedAvailable(handler, gamepadIndex))
return true;
}
return false;
}
/// <summary>
/// Returns whether this keybind is considered to be pressed.
/// See <see cref="InputHandler.TryConsumePressed"/> for more information.
/// </summary>
/// <param name="handler">The input handler to query the keys with</param>
/// <param name="gamepadIndex">The index of the gamepad to query, or -1 to query all gamepads</param>
/// <returns>Whether this keybind is considered to be pressed</returns>
public bool TryConsumePressed(InputHandler handler, int gamepadIndex = -1) {
foreach (var combination in this.combinations) {
if (combination.TryConsumePressed(handler, gamepadIndex))
return true;
}
return false;
}
/// <summary> /// <summary>
/// Returns whether any of this keybind's modifier keys are currently down. /// Returns whether any of this keybind's modifier keys are currently down.
/// See <see cref="InputHandler.IsDown"/> for more information. /// See <see cref="InputHandler.IsDown"/> for more information.
@ -224,6 +254,7 @@ namespace MLEM.Input {
/// <summary> /// <summary>
/// Returns whether this combination is currently down /// Returns whether this combination is currently down
/// See <see cref="InputHandler.IsDown"/> for more information.
/// </summary> /// </summary>
/// <param name="handler">The input handler to query the keys with</param> /// <param name="handler">The input handler to query the keys with</param>
/// <param name="gamepadIndex">The index of the gamepad to query, or -1 to query all gamepads</param> /// <param name="gamepadIndex">The index of the gamepad to query, or -1 to query all gamepads</param>
@ -233,7 +264,8 @@ namespace MLEM.Input {
} }
/// <summary> /// <summary>
/// Returns whether this combination is currently pressed /// Returns whether this combination is currently pressed.
/// See <see cref="InputHandler.IsPressed"/> for more information.
/// </summary> /// </summary>
/// <param name="handler">The input handler to query the keys with</param> /// <param name="handler">The input handler to query the keys with</param>
/// <param name="gamepadIndex">The index of the gamepad to query, or -1 to query all gamepads</param> /// <param name="gamepadIndex">The index of the gamepad to query, or -1 to query all gamepads</param>
@ -242,6 +274,29 @@ namespace MLEM.Input {
return this.IsModifierDown(handler, gamepadIndex) && handler.IsPressed(this.Key, gamepadIndex); return this.IsModifierDown(handler, gamepadIndex) && handler.IsPressed(this.Key, gamepadIndex);
} }
/// <summary>
/// Returns whether this combination is currently pressed and has not been consumed yet using <see cref="TryConsumePressed"/>.
/// See <see cref="InputHandler.IsPressedAvailable"/> for more information.
/// </summary>
/// <param name="handler">The input handler to query the keys with</param>
/// <param name="gamepadIndex">The index of the gamepad to query, or -1 to query all gamepads</param>
/// <returns>Whether this combination is pressed</returns>
public bool IsPressedAvailable(InputHandler handler, int gamepadIndex = -1) {
return this.IsModifierDown(handler, gamepadIndex) && handler.IsPressedAvailable(this.Key, gamepadIndex);
}
/// <summary>
/// Returns whether this combination is currently pressed and the press has not been consumed yet.
/// A combination is considered consumed if this method has already returned true previously since the last <see cref="InputHandler.Update()"/> call.
/// See <see cref="InputHandler.TryConsumePressed"/> for more information.
/// </summary>
/// <param name="handler">The input handler to query the keys with</param>
/// <param name="gamepadIndex">The index of the gamepad to query, or -1 to query all gamepads</param>
/// <returns>Whether this combination is pressed</returns>
public bool TryConsumePressed(InputHandler handler, int gamepadIndex = -1) {
return this.IsModifierDown(handler, gamepadIndex) && handler.TryConsumePressed(this.Key, gamepadIndex);
}
/// <summary> /// <summary>
/// Returns whether this combination's modifier keys are currently down /// Returns whether this combination's modifier keys are currently down
/// </summary> /// </summary>