UI/InputDisplay.cs

Static helper that pins input device selection for UI labels. It chooses a device based on whether gamepad is primary and exposes GetOrigin and GetGlyph which run Input lookups inside an Input.PlayerScope so the engine restores input state after the lookup.

Native Interop
using Sandbox;

namespace BlockParty;

/// <summary>Action labels and glyphs follow the gameplay device latch, even after mouse input.</summary>
internal static class InputDisplay
{
	private static Input.PlayerIndex Device => InputState.GamepadIsPrimary
		? Input.PlayerIndex.Controller1 : Input.PlayerIndex.KeyboardAndMouse;

	public static string GetOrigin( string action )
	{
		// GetButtonOrigin ignores ignoreController. A scoped device preserves the engine's
		// rebound/localized keyboard lookup and restores input state when the lookup ends.
		using var scope = Input.PlayerScope( Device );
		return Input.GetButtonOrigin( action );
	}

	public static Texture GetGlyph( string action )
	{
		// Scope the glyph lookup too, so controller vendor artwork follows the same device.
		using var scope = Input.PlayerScope( Device );
		return Input.GetGlyph( action, InputGlyphSize.Small, true );
	}
}