interface icons
This commit is contained in:
1 parent
2c44839c80
commit
b475ad8bea
5 files changed
+1420
No files matched your search
@@ -0,0 +1,55 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user