mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-25 14:08:34 +01:00
Compare commits
5 commits
46c77d2444
...
4c24284a3f
Author | SHA1 | Date | |
---|---|---|---|
4c24284a3f | |||
bc0f9d5c0c | |||
610527374e | |||
4a88cca8bf | |||
8adee49e55 |
12 changed files with 181 additions and 59 deletions
|
@ -11,7 +11,7 @@ Jump to version:
|
|||
## 5.4.0 (Unreleased)
|
||||
### MLEM
|
||||
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 InputHandler.InvertPressBehavior
|
||||
|
||||
|
@ -22,6 +22,7 @@ Additions
|
|||
Improvements
|
||||
- Ensure that Element.IsMouseOver is always accurate by making it an auto-property
|
||||
- Started using SpriteBatchContext for Draw and DrawTransformed methods
|
||||
- Make use of the new consuming variants in InputHandler and Keybind to consume UiControls inputs
|
||||
|
||||
Fixes
|
||||
- Fixed auto-nav tooltip displaying on the selected element even when not in auto-nav mode
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
using MLEM.Startup;
|
||||
|
||||
namespace TemplateNamespace {
|
||||
public class GameImpl : MlemGame {
|
||||
namespace TemplateNamespace;
|
||||
|
||||
public static GameImpl Instance { get; private set; }
|
||||
public class GameImpl : MlemGame {
|
||||
|
||||
public GameImpl() {
|
||||
Instance = this;
|
||||
}
|
||||
public static GameImpl Instance { get; private set; }
|
||||
|
||||
public GameImpl() {
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,14 +1,14 @@
|
|||
using Microsoft.Xna.Framework;
|
||||
using MLEM.Misc;
|
||||
|
||||
namespace TemplateNamespace {
|
||||
public static class Program {
|
||||
namespace TemplateNamespace;
|
||||
|
||||
public static void Main() {
|
||||
MlemPlatform.Current = new MlemPlatform.DesktopGl<TextInputEventArgs>((w, c) => w.TextInput += c);
|
||||
using var game = new GameImpl();
|
||||
game.Run();
|
||||
}
|
||||
public static class Program {
|
||||
|
||||
public static void Main() {
|
||||
MlemPlatform.Current = new MlemPlatform.DesktopGl<TextInputEventArgs>((w, c) => w.TextInput += c);
|
||||
using var game = new GameImpl();
|
||||
game.Run();
|
||||
}
|
||||
|
||||
}
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<PublishReadyToRun>false</PublishReadyToRun>
|
||||
<TieredCompilation>false</TieredCompilation>
|
||||
<ApplicationIcon>Icon.ico</ApplicationIcon>
|
||||
|
@ -16,8 +16,6 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<MonoGameContentReference Include="Content\Content.mgcb" />
|
||||
<Content Include="Content\*\**" />
|
||||
<EmbeddedResource Include="Icon.ico" />
|
||||
<EmbeddedResource Include="Icon.bmp" />
|
||||
</ItemGroup>
|
||||
|
|
|
@ -8,6 +8,6 @@ namespace TemplateNamespace {
|
|||
public GameImpl() {
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
|
|
|
@ -138,7 +138,7 @@ namespace MLEM.Ui.Elements {
|
|||
|
||||
// MOUSE INPUT
|
||||
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.scrollStartOffset = this.TransformInverseAll(this.Input.ViewportMousePosition.ToVector2()) - this.ScrollerPosition;
|
||||
} else if (this.isMouseHeld && !this.Input.IsMouseButtonDown(MouseButton.Left)) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -162,22 +162,26 @@ namespace MLEM.Ui {
|
|||
var mousedNow = this.GetElementUnderPos(this.Input.ViewportMousePosition.ToVector2());
|
||||
this.SetMousedElement(mousedNow);
|
||||
|
||||
if (this.Input.IsMouseButtonPressed(MouseButton.Left)) {
|
||||
if (this.Input.IsMouseButtonPressedAvailable(MouseButton.Left)) {
|
||||
this.IsAutoNavMode = false;
|
||||
var selectedNow = mousedNow != null && mousedNow.CanBeSelected ? mousedNow : null;
|
||||
this.SelectElement(this.ActiveRoot, selectedNow);
|
||||
if (mousedNow != null && mousedNow.CanBePressed)
|
||||
if (mousedNow != null && mousedNow.CanBePressed) {
|
||||
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;
|
||||
if (mousedNow != null && mousedNow.CanBePressed)
|
||||
if (mousedNow != null && mousedNow.CanBePressed) {
|
||||
this.System.InvokeOnElementSecondaryPressed(mousedNow);
|
||||
this.Input.TryConsumeMouseButtonPressed(MouseButton.Right);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// KEYBOARD INPUT
|
||||
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.Input.IsModifierKeyDown(ModifierKey.Shift)) {
|
||||
// secondary action on element using space or enter
|
||||
|
@ -186,15 +190,19 @@ namespace MLEM.Ui {
|
|||
// first action on element using space or enter
|
||||
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;
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -230,20 +238,28 @@ namespace MLEM.Ui {
|
|||
|
||||
// GAMEPAD INPUT
|
||||
if (this.HandleGamepad) {
|
||||
if (this.GamepadButtons.IsPressed(this.Input, this.GamepadIndex)) {
|
||||
if (this.SelectedElement?.Root != null && this.SelectedElement.CanBePressed)
|
||||
if (this.GamepadButtons.IsPressedAvailable(this.Input, this.GamepadIndex)) {
|
||||
if (this.SelectedElement?.Root != null && this.SelectedElement.CanBePressed) {
|
||||
this.System.InvokeOnElementPressed(this.SelectedElement);
|
||||
} else if (this.SecondaryGamepadButtons.IsPressed(this.Input, this.GamepadIndex)) {
|
||||
if (this.SelectedElement?.Root != null && this.SelectedElement.CanBePressed)
|
||||
this.GamepadButtons.TryConsumePressed(this.Input, this.GamepadIndex);
|
||||
}
|
||||
} else if (this.SecondaryGamepadButtons.IsPressedAvailable(this.Input, this.GamepadIndex)) {
|
||||
if (this.SelectedElement?.Root != null && this.SelectedElement.CanBePressed) {
|
||||
this.System.InvokeOnElementSecondaryPressed(this.SelectedElement);
|
||||
} else if (this.DownButtons.IsPressed(this.Input, this.GamepadIndex)) {
|
||||
this.HandleGamepadNextElement(Direction2.Down);
|
||||
} else if (this.LeftButtons.IsPressed(this.Input, this.GamepadIndex)) {
|
||||
this.HandleGamepadNextElement(Direction2.Left);
|
||||
} else if (this.RightButtons.IsPressed(this.Input, this.GamepadIndex)) {
|
||||
this.HandleGamepadNextElement(Direction2.Right);
|
||||
} else if (this.UpButtons.IsPressed(this.Input, this.GamepadIndex)) {
|
||||
this.HandleGamepadNextElement(Direction2.Up);
|
||||
this.SecondaryGamepadButtons.TryConsumePressed(this.Input, this.GamepadIndex);
|
||||
}
|
||||
} else if (this.DownButtons.IsPressedAvailable(this.Input, this.GamepadIndex)) {
|
||||
if (this.HandleGamepadNextElement(Direction2.Down))
|
||||
this.DownButtons.TryConsumePressed(this.Input, this.GamepadIndex);
|
||||
} else if (this.LeftButtons.IsPressedAvailable(this.Input, this.GamepadIndex)) {
|
||||
if (this.HandleGamepadNextElement(Direction2.Left))
|
||||
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;
|
||||
var next = this.GetGamepadNextElement(dir);
|
||||
if (this.SelectedElement != null)
|
||||
next = this.SelectedElement.GetGamepadNextElement(dir, next);
|
||||
if (next != null)
|
||||
if (next != null) {
|
||||
this.SelectElement(this.ActiveRoot, next);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -365,6 +365,15 @@ namespace MLEM.Input {
|
|||
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>
|
||||
/// 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.
|
||||
|
@ -374,7 +383,7 @@ namespace MLEM.Input {
|
|||
/// <param name="key">The key to query.</param>
|
||||
/// <returns>If the key is pressed and the press is not consumed yet.</returns>
|
||||
public bool TryConsumeKeyPressed(Keys key) {
|
||||
if (this.IsKeyPressed(key) && !this.consumedPresses.Contains((key, -1))) {
|
||||
if (this.IsKeyPressedAvailable(key)) {
|
||||
this.consumedPresses.Add((key, -1));
|
||||
return true;
|
||||
}
|
||||
|
@ -442,6 +451,15 @@ namespace MLEM.Input {
|
|||
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>
|
||||
/// 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.
|
||||
|
@ -450,7 +468,7 @@ namespace MLEM.Input {
|
|||
/// <param name="button">The button to query.</param>
|
||||
/// <returns>If the button is pressed and the press is not consumed yet.</returns>
|
||||
public bool TryConsumeMouseButtonPressed(MouseButton button) {
|
||||
if (this.IsMouseButtonPressed(button) && !this.consumedPresses.Contains((button, -1))) {
|
||||
if (this.IsMouseButtonPressedAvailable(button)) {
|
||||
this.consumedPresses.Add((button, -1));
|
||||
return true;
|
||||
}
|
||||
|
@ -542,6 +560,16 @@ namespace MLEM.Input {
|
|||
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>
|
||||
/// 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.
|
||||
|
@ -552,7 +580,7 @@ namespace MLEM.Input {
|
|||
/// <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 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));
|
||||
return true;
|
||||
}
|
||||
|
@ -656,7 +684,26 @@ namespace MLEM.Input {
|
|||
}
|
||||
|
||||
/// <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"/>.
|
||||
/// </summary>
|
||||
/// <param name="control">The control whose pressed state to query.</param>
|
||||
|
|
|
@ -131,6 +131,36 @@ namespace MLEM.Input {
|
|||
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>
|
||||
/// Returns whether any of this keybind's modifier keys are currently down.
|
||||
/// See <see cref="InputHandler.IsDown"/> for more information.
|
||||
|
@ -224,6 +254,7 @@ namespace MLEM.Input {
|
|||
|
||||
/// <summary>
|
||||
/// Returns whether this combination is currently down
|
||||
/// See <see cref="InputHandler.IsDown"/> 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>
|
||||
|
@ -233,7 +264,8 @@ namespace MLEM.Input {
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns whether this combination is currently pressed
|
||||
/// Returns whether this combination is currently pressed.
|
||||
/// See <see cref="InputHandler.IsPressed"/> 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>
|
||||
|
@ -242,6 +274,29 @@ namespace MLEM.Input {
|
|||
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>
|
||||
/// Returns whether this combination's modifier keys are currently down
|
||||
/// </summary>
|
||||
|
|
Loading…
Reference in a new issue