1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-12-26 02:09:24 +01:00

also added WasModifierDown and WasDown to Keybind and Combination

This commit is contained in:
Ell 2022-11-08 17:43:34 +01:00
parent 797a3b2617
commit 8bb62a2ce5
3 changed files with 101 additions and 2 deletions

View file

@ -15,7 +15,7 @@ Jump to version:
Additions
- Added TokenizedString.Realign
- Added GetFlags and GetUniqueFlags to EnumHelper
- Added GetDownTime, GetUpTime and GetTimeSincePress to Keybind and Combination
- Added GetDownTime, GetUpTime, GetTimeSincePress, WasModifierDown and WasDown to Keybind and Combination
- **Added the ability to find paths to one of multiple goals using AStar**
Improvements

View file

@ -757,6 +757,48 @@ namespace MLEM.Input {
}
}
/// <summary>
/// Returns if a given control of any kind was down in the last update call.
/// 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 down 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 was down</returns>
/// <exception cref="ArgumentException">If the passed control isn't of a supported type</exception>
public bool WasDown(GenericInput control, int index = -1) {
switch (control.Type) {
case GenericInput.InputType.Keyboard:
return this.WasKeyDown(control);
case GenericInput.InputType.Gamepad:
return this.WasGamepadButtonDown(control, index);
case GenericInput.InputType.Mouse:
return this.WasMouseButtonDown(control);
default:
return false;
}
}
/// <summary>
/// Returns if a given control of any kind was up in the last update call.
/// 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 up 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 was up.</returns>
/// <exception cref="ArgumentException">If the passed control isn't of a supported type</exception>
public bool WasUp(GenericInput control, int index = -1) {
switch (control.Type) {
case GenericInput.InputType.Keyboard:
return this.WasKeyUp(control);
case GenericInput.InputType.Gamepad:
return this.WasGamepadButtonUp(control, index);
case GenericInput.InputType.Mouse:
return this.WasMouseButtonUp(control);
default:
return true;
}
}
/// <summary>
/// Returns if a given control of any kind is pressed.
/// This is a helper function that can be passed a <see cref="Keys"/>, <see cref="Buttons"/> or <see cref="MouseButton"/>.

View file

@ -123,6 +123,21 @@ namespace MLEM.Input {
return false;
}
/// <summary>
/// Returns whether this keybind was considered to be down in the last update call.
/// See <see cref="InputHandler.WasDown"/> 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 was considered to be down</returns>
public bool WasDown(InputHandler handler, int gamepadIndex = -1) {
foreach (var combination in this.combinations) {
if (combination.WasDown(handler, gamepadIndex))
return true;
}
return false;
}
/// <summary>
/// Returns whether this keybind is considered to be pressed.
/// See <see cref="InputHandler.IsPressed"/> for more information.
@ -183,6 +198,21 @@ namespace MLEM.Input {
return false;
}
/// <summary>
/// Returns whether any of this keybind's modifier keys were down in the last update call.
/// See <see cref="InputHandler.WasDown"/> 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 any of this keyboard's modifier keys were down</returns>
public bool WasModifierDown(InputHandler handler, int gamepadIndex = -1) {
foreach (var combination in this.combinations) {
if (combination.WasModifierDown(handler, gamepadIndex))
return true;
}
return false;
}
/// <summary>
/// Returns the amount of time that this keybind has been held down for.
/// If this input isn't currently down, this method returns <see cref="TimeSpan.Zero"/>.
@ -320,7 +350,7 @@ namespace MLEM.Input {
}
/// <summary>
/// Returns whether this combination is currently down
/// 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>
@ -330,6 +360,17 @@ namespace MLEM.Input {
return this.IsModifierDown(handler, gamepadIndex) && handler.IsDown(this.Key, gamepadIndex);
}
/// <summary>
/// Returns whether this combination was down in the last upate call.
/// See <see cref="InputHandler.WasDown"/> 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 was down</returns>
public bool WasDown(InputHandler handler, int gamepadIndex = -1) {
return this.WasModifierDown(handler, gamepadIndex) && handler.WasDown(this.Key, gamepadIndex);
}
/// <summary>
/// Returns whether this combination is currently pressed.
/// See <see cref="InputHandler.IsPressed"/> for more information.
@ -380,6 +421,22 @@ namespace MLEM.Input {
return false;
}
/// <summary>
/// Returns whether this combination's modifier keys were down in the last 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's modifiers were down</returns>
public bool WasModifierDown(InputHandler handler, int gamepadIndex = -1) {
if (this.Modifiers.Length <= 0)
return true;
foreach (var modifier in this.Modifiers) {
if (handler.WasDown(modifier, gamepadIndex))
return true;
}
return false;
}
/// <summary>
/// Returns the amount of time that this combination has been held down for.
/// If this input isn't currently down, this method returns <see cref="TimeSpan.Zero"/>.