fix(input): the radial menu no longer swings the form it is opening a menu on
Clicking an entry in the race wheel also fired the transformed form's attack. The click picks the entry AND is read here as a raw mouse button, because the forms read the device directly rather than going through Humanoid.StartAttack. Vanilla attacks never had this: they go through ZInput, which the radial already blocks, so only input read straight off the device got through - which is all of ours. Hud.InRadial() answers it, the same shape of call as the Hud.IsPieceSelectionVisible() already here for the hammer's build panel. That is now the second GUI Player.TakeInput knows nothing about. CHECKED IN AttackDown AND NOT IN Allowed, deliberately. The radial fires an ability by queueing its keybind through Press(), and the ability's own reader picks that up inside an Allowed gate - so blocking Allowed while the wheel is open would risk the wheel swallowing the abilities it exists to trigger. The second half is the same bug one layer down: an ability bound to a mouse BUTTON does not go through AttackDown at all. Skadi's cold spell sits on middle mouse, so middle-clicking an entry in the wheel cast it. IsDownIgnoringHeldKeys now takes the queued press first and without any gate - that one is the radial itself - and ignores a raw mouse button while the wheel is up. Keys at the keyboard are untouched: nothing about an open wheel makes pressing K ambiguous. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
parent
7ad1d6920e
commit
2b900d91e7
1 changed files with 54 additions and 1 deletions
|
|
@ -15,13 +15,16 @@ namespace RacesOfValheim
|
||||||
/// (InventoryGui covers the backpack and chests alike), so mirror that instead of maintaining
|
/// (InventoryGui covers the backpack and chests alike), so mirror that instead of maintaining
|
||||||
/// a parallel list of GUI checks that would drift as the game changes.
|
/// a parallel list of GUI checks that would drift as the game changes.
|
||||||
///
|
///
|
||||||
/// ONE GUI THAT TakeInput DOES NOT COVER: the hammer's piece selection panel. Read off the IL,
|
/// TWO GUIS THAT TakeInput DOES NOT COVER. The first is the hammer's piece selection panel. Read off the IL,
|
||||||
/// TakeInput tests Chat, Console, TextInput, StoreGui, InventoryGui, Menu, TextViewer, the map,
|
/// TakeInput tests Chat, Console, TextInput, StoreGui, InventoryGui, Menu, TextViewer, the map,
|
||||||
/// free-fly and the barber - and nothing else. Vanilla does not need it there because build
|
/// free-fly and the barber - and nothing else. Vanilla does not need it there because build
|
||||||
/// input is handled separately in UpdatePlacement, but a mod ability reading the device
|
/// input is handled separately in UpdatePlacement, but a mod ability reading the device
|
||||||
/// directly does: Skadi's cold spell is bound to middle mouse and kept casting while the build
|
/// directly does: Skadi's cold spell is bound to middle mouse and kept casting while the build
|
||||||
/// menu was open. Hud.IsPieceSelectionVisible is static, public and null-safe on its own
|
/// menu was open. Hud.IsPieceSelectionVisible is static, public and null-safe on its own
|
||||||
/// instance, so it costs one call and no reflection.
|
/// instance, so it costs one call and no reflection.
|
||||||
|
///
|
||||||
|
/// The second is the radial menu, and it is handled in AttackDown rather than here - see
|
||||||
|
/// RadialOpen for why the difference matters.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class RaceInput
|
public static class RaceInput
|
||||||
{
|
{
|
||||||
|
|
@ -77,8 +80,18 @@ namespace RacesOfValheim
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static bool IsDownIgnoringHeldKeys(this KeyboardShortcut shortcut)
|
public static bool IsDownIgnoringHeldKeys(this KeyboardShortcut shortcut)
|
||||||
{
|
{
|
||||||
|
// The queued press is taken FIRST and without any gate, because that is the radial menu
|
||||||
|
// firing this very ability - see Press(). Everything below is the device being read raw.
|
||||||
if (ConsumePress(shortcut)) return true;
|
if (ConsumePress(shortcut)) return true;
|
||||||
if (shortcut.MainKey == KeyCode.None) return false;
|
if (shortcut.MainKey == KeyCode.None) return false;
|
||||||
|
|
||||||
|
// A keybind that sits on a mouse button is the radial's own click as far as the device is
|
||||||
|
// concerned, so the wheel closes this door too. AttackDown covers the forms' attacks;
|
||||||
|
// this covers abilities bound to a button instead - Skadi's cold spell is on middle
|
||||||
|
// mouse, and middle-clicking an entry in the wheel used to cast it. Keys at the keyboard
|
||||||
|
// are left alone: nothing about the wheel makes pressing K ambiguous.
|
||||||
|
if (RadialOpen && IsMouseButton(shortcut.MainKey)) return false;
|
||||||
|
|
||||||
if (!Input.GetKeyDown(shortcut.MainKey)) return false;
|
if (!Input.GetKeyDown(shortcut.MainKey)) return false;
|
||||||
|
|
||||||
foreach (KeyCode modifier in shortcut.Modifiers)
|
foreach (KeyCode modifier in shortcut.Modifiers)
|
||||||
|
|
@ -143,15 +156,55 @@ namespace RacesOfValheim
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static bool AttackDown(int mouseButton)
|
public static bool AttackDown(int mouseButton)
|
||||||
{
|
{
|
||||||
|
if (RadialOpen) return false;
|
||||||
return Input.GetMouseButtonDown(mouseButton) || PadAttackDown(mouseButton);
|
return Input.GetMouseButtonDown(mouseButton) || PadAttackDown(mouseButton);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Held-down counterpart of <see cref="AttackDown"/>.</summary>
|
/// <summary>Held-down counterpart of <see cref="AttackDown"/>.</summary>
|
||||||
public static bool AttackHeld(int mouseButton)
|
public static bool AttackHeld(int mouseButton)
|
||||||
{
|
{
|
||||||
|
if (RadialOpen) return false;
|
||||||
return Input.GetMouseButton(mouseButton) || PadAttackHeld(mouseButton);
|
return Input.GetMouseButton(mouseButton) || PadAttackHeld(mouseButton);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Whether the radial menu is up, which is a third GUI TakeInput knows nothing about.
|
||||||
|
///
|
||||||
|
/// Clicking an entry in the wheel was also swinging the transformed form's attack: the click
|
||||||
|
/// picks the entry AND is read here as a raw mouse button. Vanilla attacks are untouched by
|
||||||
|
/// this because they go through ZInput, which the radial already blocks - only input read
|
||||||
|
/// straight off the device gets through, which is all of ours.
|
||||||
|
///
|
||||||
|
/// CHECKED HERE AND NOT IN <see cref="Allowed"/>, deliberately. The radial fires an ability by
|
||||||
|
/// queueing its keybind through Press(), and the ability's own reader picks that up inside an
|
||||||
|
/// Allowed gate - so blocking Allowed while the wheel is open would risk the wheel swallowing
|
||||||
|
/// the very abilities it exists to trigger. The queued press does survive, since it holds for
|
||||||
|
/// PressWindow rather than a single frame, but there is no reason to lean on that when only
|
||||||
|
/// the mouse reads are the problem. Keybinds pressed at the keyboard while the wheel is open
|
||||||
|
/// are left alone for the same reason.
|
||||||
|
/// </summary>
|
||||||
|
private static bool IsMouseButton(KeyCode key)
|
||||||
|
{
|
||||||
|
return key >= KeyCode.Mouse0 && key <= KeyCode.Mouse6;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool RadialOpen
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return Hud.InRadial();
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
// Fail open, like the TakeInput path above: a game update that moves this must
|
||||||
|
// cost the fix, not every attack in every form.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>The gamepad half of <see cref="AttackDown"/> alone, for attacks whose mouse
|
/// <summary>The gamepad half of <see cref="AttackDown"/> alone, for attacks whose mouse
|
||||||
/// side is a rebindable KeyboardShortcut rather than a fixed button.</summary>
|
/// side is a rebindable KeyboardShortcut rather than a fixed button.</summary>
|
||||||
public static bool PadAttackDown(int mouseButton)
|
public static bool PadAttackDown(int mouseButton)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue