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

Added InputHandler.WasPressedForLess and related methods

This commit is contained in:
Ell 2022-12-26 18:44:46 +01:00
parent 10bea0f820
commit 79a2eaa8d2
2 changed files with 38 additions and 0 deletions

View file

@ -20,6 +20,7 @@ Additions
- Added UniformTextureAtlas methods ToList and ToDictionary - Added UniformTextureAtlas methods ToList and ToDictionary
- Added SingleRandom and SeedSource - Added SingleRandom and SeedSource
- Added TokenizedString.GetArea - Added TokenizedString.GetArea
- Added InputHandler.WasPressedForLess and related methods
- **Added the ability to find paths to one of multiple goals using AStar** - **Added the ability to find paths to one of multiple goals using AStar**
Improvements Improvements

View file

@ -859,6 +859,43 @@ namespace MLEM.Input {
} }
} }
/// <summary>
/// Returns if a given control of any kind was just let go this frame, and had been down for less than the given <paramref name="time"/> before that. Essentially, this action signifies a short press action.
/// </summary>
/// <param name="control">The control whose pressed state to query.</param>
/// <param name="time">The maximum time that the control should have been down for.</param>
/// <param name="index">The index of the gamepad to query (if applicable), or -1 for any gamepad.</param>
/// <returns>Whether the given control was pressed for less than the given time.</returns>
public bool WasPressedForLess(GenericInput control, TimeSpan time, int index = -1) {
return this.WasDown(control, index) && this.IsUp(control, index) && this.GetDownTime(control, index) < time;
}
/// <summary>
/// Returns if a given control of any kind was just let go this frame, and had been down for less than the given <paramref name="time"/> before that, and if the press has not been consumed yet using <see cref="TryConsumePressedForLess"/>. Essentially, this action signifies a short press action.
/// </summary>
/// <param name="control">The control whose pressed state to query.</param>
/// <param name="time">The maximum time that the control should have been down for.</param>
/// <param name="index">The index of the gamepad to query (if applicable), or -1 for any gamepad.</param>
/// <returns>Whether the given control was pressed for less than the given time, and the press has not been consumed yet.</returns>
public bool WasPressedForLessAvailable(GenericInput control, TimeSpan time, int index = -1) {
return this.WasPressedForLess(control, time, index) && !this.IsPressConsumed(control, index);
}
/// <summary>
/// Returns if a given control of any kind was just let go this frame, and had been down for less than the given <paramref name="time"/> before that, and if the press has not been consumed yet using <see cref="TryConsumePressedForLess"/>, and marks the press as consumed if it is. Essentially, this action signifies a short press action.
/// </summary>
/// <param name="control">The control whose pressed state to query.</param>
/// <param name="time">The maximum time that the control should have been down for.</param>
/// <param name="index">The index of the gamepad to query (if applicable), or -1 for any gamepad.</param>
/// <returns>Whether the given control was pressed for less than the given time, and the press was successfully consumed.</returns>
public bool TryConsumePressedForLess(GenericInput control, TimeSpan time, int index = -1) {
if (this.WasPressedForLessAvailable(control, time, index)) {
this.consumedPresses.Add((control, index));
return true;
}
return false;
}
/// <inheritdoc cref="IsDown"/> /// <inheritdoc cref="IsDown"/>
public bool IsAnyDown(params GenericInput[] controls) { public bool IsAnyDown(params GenericInput[] controls) {
foreach (var control in controls) { foreach (var control in controls) {