UI/Components/InputHint.razor
@using System;
@using Sandbox;
@using Sandbox.UI;

@namespace Opium

<style>
    InputHint
    {
        justify-content: center;
        align-items: center;
        
        img
        {
            background-size: contain;
            background-repeat: no-repeat;
            height: 100%;
        }

        label{
            font-family: Resident Evil Directors Cut;
            color: white;
            font-size: 32px;
            text-transform: uppercase;
        }
    }
</style>

<root>
    @if ( Input.UsingController )
    {
        <img @ref=Glyph />
    }
    else
    {
        <label>@Input.GetButtonOrigin( Action )</label>
    }
</root>

@code
{
    // @ref
    public Image Glyph { get; set; }
    public GlyphStyle GlyphStyle { get; set; } = GlyphStyle.Dark.WithSolidABXY().WithNeutralColorABXY();
    public string Action { get; set; } = "Use";

    /// <summary>
    /// Checks the current button and updates the glyph.
    /// </summary>
    void UpdateTexture()
    {
        var texture = Input.GetGlyph( Action, InputGlyphSize.Small, GlyphStyle );
        if ( texture is null ) return;
        if ( Glyph is null ) return;
        Glyph.Texture = texture;
    }

    protected override void OnAfterTreeRender( bool firstTime )
    {
        UpdateTexture();

        SetClass("keyboard", !Input.UsingController);
    }

    protected override int BuildHash()
    {
        // If we switch input device, rebuild the tree.
        return HashCode.Combine( Action, Input.UsingController );
    }
}