Merge branch 'master' of ssh://mnml-studios/~/SpaceRace

This commit is contained in:
ntr committed 2023-08-21 21:44:29 +10:00
commit 331e811e2d
5 files changed
+1420

No files matched your search

+55
View File
@@ -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;
}
}