mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-22 12:58:33 +01:00
also added WasModifierDown and WasDown to Keybind and Combination
This commit is contained in:
parent
797a3b2617
commit
8bb62a2ce5
3 changed files with 101 additions and 2 deletions
|
@ -15,7 +15,7 @@ Jump to version:
|
||||||
Additions
|
Additions
|
||||||
- Added TokenizedString.Realign
|
- Added TokenizedString.Realign
|
||||||
- Added GetFlags and GetUniqueFlags to EnumHelper
|
- 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**
|
- **Added the ability to find paths to one of multiple goals using AStar**
|
||||||
|
|
||||||
Improvements
|
Improvements
|
||||||
|
|
|
@ -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>
|
/// <summary>
|
||||||
/// Returns if a given control of any kind is pressed.
|
/// 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"/>.
|
/// This is a helper function that can be passed a <see cref="Keys"/>, <see cref="Buttons"/> or <see cref="MouseButton"/>.
|
||||||
|
|
|
@ -123,6 +123,21 @@ namespace MLEM.Input {
|
||||||
return false;
|
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>
|
/// <summary>
|
||||||
/// Returns whether this keybind is considered to be pressed.
|
/// Returns whether this keybind is considered to be pressed.
|
||||||
/// See <see cref="InputHandler.IsPressed"/> for more information.
|
/// See <see cref="InputHandler.IsPressed"/> for more information.
|
||||||
|
@ -183,6 +198,21 @@ namespace MLEM.Input {
|
||||||
return false;
|
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>
|
/// <summary>
|
||||||
/// Returns the amount of time that this keybind has been held down for.
|
/// 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"/>.
|
/// If this input isn't currently down, this method returns <see cref="TimeSpan.Zero"/>.
|
||||||
|
@ -320,7 +350,7 @@ 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.
|
/// 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>
|
||||||
|
@ -330,6 +360,17 @@ namespace MLEM.Input {
|
||||||
return this.IsModifierDown(handler, gamepadIndex) && handler.IsDown(this.Key, gamepadIndex);
|
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>
|
/// <summary>
|
||||||
/// Returns whether this combination is currently pressed.
|
/// Returns whether this combination is currently pressed.
|
||||||
/// See <see cref="InputHandler.IsPressed"/> for more information.
|
/// See <see cref="InputHandler.IsPressed"/> for more information.
|
||||||
|
@ -380,6 +421,22 @@ namespace MLEM.Input {
|
||||||
return false;
|
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>
|
/// <summary>
|
||||||
/// Returns the amount of time that this combination has been held down for.
|
/// 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"/>.
|
/// If this input isn't currently down, this method returns <see cref="TimeSpan.Zero"/>.
|
||||||
|
|
Loading…
Reference in a new issue