Panels/InputAnalogHint.razor
@using System;
@using Sandbox;
@using Sandbox.UI;
@inherits Panel
@namespace Sandbox
<style>
InputAnalogHint
{
justify-content: center;
align-items: center;
gap: 32px;
img
{
background-size: contain;
background-repeat: no-repeat;
max-height: 64px;
max-width: 64px;
}
label{
font-family: Arial;
color: white;
font-size: 24px;
text-transform: uppercase;
}
}
</style>
<root>
<img @ref=Glyph />
<label>@( !string.IsNullOrEmpty( Text ) ? Text : Analog.ToString() )</label>
</root>
@code
{
// @ref
public Image Glyph { get; set; }
public InputAnalog Analog { get; set; }
public InputGlyphSize Size { get; set; } = InputGlyphSize.Medium;
public string Text { get; set; }
/// <summary>
/// Checks the current button and updates the glyph.
/// </summary>
void UpdateTexture()
{
var texture = Input.GetGlyph(Analog, Size, true);
if ( texture is null ) return;
if ( !Glyph.IsValid() ) 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(Analog, Input.UsingController);
}
}