mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-25 14:08:34 +01:00
Compare commits
No commits in common. "4c24284a3f126da7f7319868d37d4887970d4de9" and "46c77d24447ee3c69288a8cbca93d4fc2fb4372b" have entirely different histories.
4c24284a3f
...
46c77d2444
12 changed files with 59 additions and 181 deletions
|
@ -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 and Keybind
|
- Added consuming variants of IsPressed methods to InputHandler
|
||||||
- Added SpriteBatchContext struct and extensions
|
- Added SpriteBatchContext struct and extensions
|
||||||
- Added InputHandler.InvertPressBehavior
|
- Added InputHandler.InvertPressBehavior
|
||||||
|
|
||||||
|
@ -22,7 +22,6 @@ 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
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
using MLEM.Startup;
|
using MLEM.Startup;
|
||||||
|
|
||||||
namespace TemplateNamespace;
|
namespace TemplateNamespace {
|
||||||
|
public class GameImpl : MlemGame {
|
||||||
public class GameImpl : MlemGame {
|
|
||||||
|
|
||||||
public static GameImpl Instance { get; private set; }
|
public static GameImpl Instance { get; private set; }
|
||||||
|
|
||||||
|
@ -10,4 +9,5 @@ public class GameImpl : MlemGame {
|
||||||
Instance = this;
|
Instance = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -1,9 +1,8 @@
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using MLEM.Misc;
|
using MLEM.Misc;
|
||||||
|
|
||||||
namespace TemplateNamespace;
|
namespace TemplateNamespace {
|
||||||
|
public static class Program {
|
||||||
public static class Program {
|
|
||||||
|
|
||||||
public static void Main() {
|
public static void Main() {
|
||||||
MlemPlatform.Current = new MlemPlatform.DesktopGl<TextInputEventArgs>((w, c) => w.TextInput += c);
|
MlemPlatform.Current = new MlemPlatform.DesktopGl<TextInputEventArgs>((w, c) => w.TextInput += c);
|
||||||
|
@ -11,4 +10,5 @@ public static class Program {
|
||||||
game.Run();
|
game.Run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>net6.0</TargetFramework>
|
<TargetFramework>net5.0</TargetFramework>
|
||||||
<PublishReadyToRun>false</PublishReadyToRun>
|
<PublishReadyToRun>false</PublishReadyToRun>
|
||||||
<TieredCompilation>false</TieredCompilation>
|
<TieredCompilation>false</TieredCompilation>
|
||||||
<ApplicationIcon>Icon.ico</ApplicationIcon>
|
<ApplicationIcon>Icon.ico</ApplicationIcon>
|
||||||
|
@ -16,6 +16,8 @@
|
||||||
</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>
|
||||||
|
|
|
@ -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.TryConsumePressed(inputHandler)) {
|
if (unbind != null && unbind.IsPressed(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);
|
||||||
|
|
|
@ -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.WasMouseButtonUp(MouseButton.Left) && this.Input.IsMouseButtonDown(MouseButton.Left)) {
|
if (moused == this && this.Input.IsMouseButtonPressed(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)) {
|
||||||
|
|
|
@ -30,9 +30,9 @@ namespace MLEM.Ui.Elements {
|
||||||
base.Update(time);
|
base.Update(time);
|
||||||
|
|
||||||
if (this.IsSelected) {
|
if (this.IsSelected) {
|
||||||
if (this.CurrentValue > 0 && this.Controls.LeftButtons.TryConsumePressed(this.Input, this.Controls.GamepadIndex)) {
|
if (this.Controls.LeftButtons.IsPressed(this.Input, this.Controls.GamepadIndex)) {
|
||||||
this.CurrentValue -= this.StepPerScroll;
|
this.CurrentValue -= this.StepPerScroll;
|
||||||
} else if (this.CurrentValue < this.MaxValue && this.Controls.RightButtons.TryConsumePressed(this.Input, this.Controls.GamepadIndex)) {
|
} else if (this.Controls.RightButtons.IsPressed(this.Input, this.Controls.GamepadIndex)) {
|
||||||
this.CurrentValue += this.StepPerScroll;
|
this.CurrentValue += this.StepPerScroll;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -257,26 +257,24 @@ namespace MLEM.Ui.Elements {
|
||||||
if (!this.IsSelected || this.IsHidden)
|
if (!this.IsSelected || this.IsHidden)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (this.CaretPos > 0 && this.Input.TryConsumePressed(Keys.Left)) {
|
if (this.Input.IsKeyPressed(Keys.Left)) {
|
||||||
this.CaretPos--;
|
this.CaretPos--;
|
||||||
} else if (this.CaretPos < this.text.Length && this.Input.TryConsumePressed(Keys.Right)) {
|
} else if (this.Input.IsKeyPressed(Keys.Right)) {
|
||||||
this.CaretPos++;
|
this.CaretPos++;
|
||||||
} else if (this.Multiline && this.Input.IsKeyPressedAvailable(Keys.Up) && this.MoveCaretToLine(this.CaretLine - 1)) {
|
} else if (this.Multiline && this.Input.IsKeyPressed(Keys.Up)) {
|
||||||
this.Input.TryConsumeKeyPressed(Keys.Up);
|
this.MoveCaretToLine(this.CaretLine - 1);
|
||||||
} else if (this.Multiline && this.Input.IsKeyPressedAvailable(Keys.Down) && this.MoveCaretToLine(this.CaretLine + 1)) {
|
} else if (this.Multiline && this.Input.IsKeyPressed(Keys.Down)) {
|
||||||
this.Input.TryConsumeKeyPressed(Keys.Down);
|
this.MoveCaretToLine(this.CaretLine + 1);
|
||||||
} else if (this.CaretPos != 0 && this.Input.TryConsumeKeyPressed(Keys.Home)) {
|
} else if (this.Input.IsKeyPressed(Keys.Home)) {
|
||||||
this.CaretPos = 0;
|
this.CaretPos = 0;
|
||||||
} else if (this.CaretPos != this.text.Length && this.Input.TryConsumeKeyPressed(Keys.End)) {
|
} else if (this.Input.IsKeyPressed(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.IsKeyPressedAvailable(Keys.V)) {
|
if (this.Input.IsKeyPressed(Keys.V)) {
|
||||||
var clip = ClipboardService.GetText();
|
var clip = ClipboardService.GetText();
|
||||||
if (clip != null) {
|
if (clip != null)
|
||||||
this.InsertText(clip, true);
|
this.InsertText(clip, true);
|
||||||
this.Input.TryConsumeKeyPressed(Keys.V);
|
} else if (this.Input.IsKeyPressed(Keys.C)) {
|
||||||
}
|
|
||||||
} 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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -162,26 +162,22 @@ 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.IsMouseButtonPressedAvailable(MouseButton.Left)) {
|
if (this.Input.IsMouseButtonPressed(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);
|
||||||
this.Input.TryConsumeMouseButtonPressed(MouseButton.Left);
|
} else if (this.Input.IsMouseButtonPressed(MouseButton.Right)) {
|
||||||
}
|
|
||||||
} 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.IsPressedAvailable(this.Input, this.GamepadIndex)) {
|
if (this.KeyboardButtons.IsPressed(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
|
||||||
|
@ -190,19 +186,15 @@ 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.IsKeyPressedAvailable(Keys.Tab)) {
|
} else if (this.Input.IsKeyPressed(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);
|
||||||
if (next != this.SelectedElement) {
|
|
||||||
this.SelectElement(this.ActiveRoot, next);
|
this.SelectElement(this.ActiveRoot, next);
|
||||||
this.Input.TryConsumeKeyPressed(Keys.Tab);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -238,28 +230,20 @@ namespace MLEM.Ui {
|
||||||
|
|
||||||
// GAMEPAD INPUT
|
// GAMEPAD INPUT
|
||||||
if (this.HandleGamepad) {
|
if (this.HandleGamepad) {
|
||||||
if (this.GamepadButtons.IsPressedAvailable(this.Input, this.GamepadIndex)) {
|
if (this.GamepadButtons.IsPressed(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);
|
||||||
this.GamepadButtons.TryConsumePressed(this.Input, this.GamepadIndex);
|
} else if (this.SecondaryGamepadButtons.IsPressed(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);
|
||||||
this.SecondaryGamepadButtons.TryConsumePressed(this.Input, this.GamepadIndex);
|
} else if (this.DownButtons.IsPressed(this.Input, this.GamepadIndex)) {
|
||||||
}
|
this.HandleGamepadNextElement(Direction2.Down);
|
||||||
} else if (this.DownButtons.IsPressedAvailable(this.Input, this.GamepadIndex)) {
|
} else if (this.LeftButtons.IsPressed(this.Input, this.GamepadIndex)) {
|
||||||
if (this.HandleGamepadNextElement(Direction2.Down))
|
this.HandleGamepadNextElement(Direction2.Left);
|
||||||
this.DownButtons.TryConsumePressed(this.Input, this.GamepadIndex);
|
} else if (this.RightButtons.IsPressed(this.Input, this.GamepadIndex)) {
|
||||||
} else if (this.LeftButtons.IsPressedAvailable(this.Input, this.GamepadIndex)) {
|
this.HandleGamepadNextElement(Direction2.Right);
|
||||||
if (this.HandleGamepadNextElement(Direction2.Left))
|
} else if (this.UpButtons.IsPressed(this.Input, this.GamepadIndex)) {
|
||||||
this.LeftButtons.TryConsumePressed(this.Input, this.GamepadIndex);
|
this.HandleGamepadNextElement(Direction2.Up);
|
||||||
} 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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -429,16 +413,13 @@ namespace MLEM.Ui {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool HandleGamepadNextElement(Direction2 dir) {
|
private void 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -365,15 +365,6 @@ 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.
|
||||||
|
@ -383,7 +374,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.IsKeyPressedAvailable(key)) {
|
if (this.IsKeyPressed(key) && !this.consumedPresses.Contains((key, -1))) {
|
||||||
this.consumedPresses.Add((key, -1));
|
this.consumedPresses.Add((key, -1));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -451,15 +442,6 @@ 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.
|
||||||
|
@ -468,7 +450,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.IsMouseButtonPressedAvailable(button)) {
|
if (this.IsMouseButtonPressed(button) && !this.consumedPresses.Contains((button, -1))) {
|
||||||
this.consumedPresses.Add((button, -1));
|
this.consumedPresses.Add((button, -1));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -560,16 +542,6 @@ 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.
|
||||||
|
@ -580,7 +552,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.IsGamepadButtonPressedAvailable(button, index)) {
|
if (this.IsGamepadButtonPressed(button) && !this.consumedPresses.Contains((button, index))) {
|
||||||
this.consumedPresses.Add((button, index));
|
this.consumedPresses.Add((button, index));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -684,26 +656,7 @@ namespace MLEM.Input {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns if a given control of any kind is pressed, and if the press has not been consumed yet using <see cref="TryConsumePressed"/>.
|
/// Returns if a given control of any kind is pressed, and marks the press as consumed if it is.
|
||||||
/// </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>
|
||||||
|
|
|
@ -131,36 +131,6 @@ 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.
|
||||||
|
@ -254,7 +224,6 @@ 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>
|
||||||
|
@ -264,8 +233,7 @@ 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>
|
||||||
|
@ -274,29 +242,6 @@ 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>
|
||||||
|
|
Loading…
Reference in a new issue