55 lines
1.4 KiB
C#
55 lines
1.4 KiB
C#
class InterfaceIcon : VisualElement {
|
|
public enum Icon {
|
|
// Outputs
|
|
Acceleration,
|
|
Deceleration,
|
|
Strafing,
|
|
Shield,
|
|
|
|
Crosshair,
|
|
|
|
Logo,
|
|
}
|
|
|
|
public new class UxmlFactory : UxmlFactory<InterfaceIcon, UxmlTraits> {}
|
|
public new class UxmlTraits : VisualElement.UxmlTraits {
|
|
readonly UxmlEnumAttributeDescription<Icon> _iconAttribute = new() { name = "icon" };
|
|
|
|
public override void Init(VisualElement ve, IUxmlAttributes bag, CreationContext cc) {
|
|
base.Init(ve, bag, cc);
|
|
var InterfaceIcon = (InterfaceIcon)ve;
|
|
InterfaceIcon.icon = _iconAttribute.GetValueFromBag(bag, cc);
|
|
}
|
|
}
|
|
|
|
static readonly Dictionary<Icon, char> _iconGlyphMap = new() {
|
|
{ Icon.CandyCane, '\uf786' },
|
|
{ Icon.Sleigh, '\uf7cc' },
|
|
{ Icon.Snowflake, '\uf2dc' },
|
|
};
|
|
|
|
public Icon icon {
|
|
get => _icon;
|
|
set {
|
|
_icon = value;
|
|
_iconLabel.text = _iconGlyphMap[value].ToString();
|
|
}
|
|
}
|
|
|
|
Icon _icon;
|
|
Label _iconLabel;
|
|
|
|
public InterfaceIcon() : this(Icon.CandyCane) {}
|
|
|
|
public InterfaceIcon(Icon icon) {
|
|
_iconLabel = new Label {
|
|
style = {
|
|
unityFont = Resources.Load<Font>("fontawesome-solid"),
|
|
unityFontDefinition = StyleKeyword.None,
|
|
},
|
|
};
|
|
|
|
Add(_iconLabel);
|
|
this.icon = icon;
|
|
}
|
|
} |