minor bugfix and pad support
This commit is contained in:
parent
ce671e7124
commit
6e87be3c77
21 changed files with 574 additions and 85 deletions
|
|
@ -77,6 +77,7 @@ namespace RacesOfValheim
|
|||
/// </summary>
|
||||
public static bool IsDownIgnoringHeldKeys(this KeyboardShortcut shortcut)
|
||||
{
|
||||
if (ConsumePress(shortcut)) return true;
|
||||
if (shortcut.MainKey == KeyCode.None) return false;
|
||||
if (!Input.GetKeyDown(shortcut.MainKey)) return false;
|
||||
|
||||
|
|
@ -100,6 +101,33 @@ namespace RacesOfValheim
|
|||
return true;
|
||||
}
|
||||
|
||||
// A key press that came from somewhere other than the keyboard - the race group in the radial
|
||||
// menu (RaceRadial). Held for a short window rather than one frame, because the radial closes
|
||||
// with an animation and the race reading the key may not run on the very next frame; the
|
||||
// first matching read takes it, so it fires once.
|
||||
private const float PressWindow = 0.5f;
|
||||
private static KeyboardShortcut pressed = KeyboardShortcut.Empty;
|
||||
private static float pressedUntil = -1f;
|
||||
|
||||
public static void Press(KeyboardShortcut shortcut)
|
||||
{
|
||||
pressed = shortcut;
|
||||
pressedUntil = Time.time + PressWindow;
|
||||
}
|
||||
|
||||
/// <summary>True once if <paramref name="shortcut"/> was pressed through <see cref="Press"/>.
|
||||
/// IsDownIgnoringHeldKeys already asks; the two readers still on BepInEx's own IsDown() ask
|
||||
/// directly.</summary>
|
||||
public static bool ConsumePress(KeyboardShortcut shortcut)
|
||||
{
|
||||
if (Time.time > pressedUntil) return false;
|
||||
if (shortcut.MainKey == KeyCode.None || shortcut.MainKey != pressed.MainKey) return false;
|
||||
if (!System.Linq.Enumerable.SequenceEqual(shortcut.Modifiers, pressed.Modifiers)) return false;
|
||||
|
||||
pressedUntil = -1f;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Gamepad counterparts of the three mouse buttons, indexed like Input.GetMouseButton.
|
||||
// Not a free choice: ZInput.ResetKBMButtons binds Attack to Mouse0, Block to Mouse1 and
|
||||
// SecondaryAttack to Mouse2, so each form attack lands on the pad button vanilla already
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue