mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-25 22:18:34 +01:00
also added consuming variants of IsPressed to Keybind
This commit is contained in:
parent
8adee49e55
commit
4a88cca8bf
2 changed files with 27 additions and 1 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
|
||||
|
||||
|
|
|
@ -131,6 +131,21 @@ namespace MLEM.Input {
|
|||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns whether this keybind is considered to be 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>
|
||||
/// <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.
|
||||
|
@ -242,6 +257,17 @@ namespace MLEM.Input {
|
|||
return this.IsModifierDown(handler, gamepadIndex) && handler.IsPressed(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.
|
||||
/// </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