UI/Controls/InputGlyph.razor
@using Sandbox
@using Sandbox.UI
@namespace Battlebugs
@inherits Sandbox.UI.Panel
@attribute [StyleSheet]
<root />
@code {
private string _inputAction;
private InputGlyphSize _inputGlyphSize;
private GlyphStyle _glyphStyle;
public void SetButton(string inputAction)
{
if (_inputAction == inputAction)
return;
_inputAction = inputAction;
Update();
}
public override void SetProperty(string name, string value)
{
switch (name)
{
case "button":
{
SetButton(value);
Update();
break;
}
case "size":
{
InputGlyphSize.TryParse(value, true, out _inputGlyphSize);
Update();
break;
}
case "style":
{
_glyphStyle = value switch
{
"knockout" => GlyphStyle.Knockout,
"light" => GlyphStyle.Light,
"dark" => GlyphStyle.Dark,
_ => _glyphStyle
};
Update();
break;
}
}
base.SetProperty(name, value);
}
private void Update()
{
var texture = Input.GetGlyph(_inputAction, _inputGlyphSize, _glyphStyle);
Style.BackgroundImage = texture;
Style.Width = texture.Width;
Style.Height = texture.Height;
}
}