UI/KeyboardFocusGuard.cs
using Sandbox.UI;
namespace BlockParty;
/// <summary>Keeps engine keyboard focus off panels that don't type. Since engine #5702 (Sep 2026) every
/// Button/Checkbox takes focus on mouse-down, and any focused panel flips the keyboard into UI mode: new
/// action presses (Input.Down, so InputState too) stop arriving until that panel is blurred or destroyed.
/// A clicked footer/HUD button that stays on screen therefore silently froze map navigation and player
/// input. BlockParty drives all navigation from game actions, so only panels that consume typed keys may
/// hold focus; everything else is blurred the frame after it grabs it.</summary>
public static class KeyboardFocusGuard
{
/// <summary>Text fields and the level editor's shortcut sink are the only legitimate focus holders.</summary>
public static bool MayHoldFocus( Panel panel ) => panel is TextEntry or LevelEditorShortcutInput;
/// <summary>Once per rendered frame, before input is sampled.</summary>
public static void Tick()
{
var focused = InputFocus.Next ?? InputFocus.Current;
if ( focused is null || MayHoldFocus( focused ) ) return;
focused.Blur();
}
}