shield detail
This commit is contained in:
1 parent
95dacdb595
commit
1c305bb677
18 files changed
+3368
-824
No files matched your search
@@ -75,7 +75,7 @@ namespace BoostComponents {
|
||||
|
||||
var painter = context.painter2D;
|
||||
painter.lineWidth = 4.0f;
|
||||
painter.lineCap = LineCap.Butt;
|
||||
painter.lineCap = LineCap.Round;
|
||||
painter.strokeColor = strokeColor;
|
||||
|
||||
painter.BeginPath();
|
||||
@@ -93,4 +93,70 @@ namespace BoostComponents {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class BoostIndicator : VisualElement {
|
||||
// Need this uxml traits and factory for it to show up in editor
|
||||
public new class UxmlTraits : VisualElement.UxmlTraits {
|
||||
UxmlDoubleAttributeDescription m_ProgressAttribute = new UxmlDoubleAttributeDescription() {
|
||||
name = "progress"
|
||||
};
|
||||
|
||||
public override void Init(VisualElement ve, IUxmlAttributes bag, CreationContext cc) {
|
||||
base.Init(ve, bag, cc);
|
||||
(ve as BoostIndicator).progress = m_ProgressAttribute.GetValueFromBag(bag, cc);
|
||||
}
|
||||
}
|
||||
|
||||
public new class UxmlFactory : UxmlFactory<BoostIndicator, UxmlTraits> { }
|
||||
|
||||
public static readonly string ussClassName = "BoostIndicator";
|
||||
public static readonly string ussLabelClassName = "BoostIndicator";
|
||||
|
||||
double m_Progress = 0f;
|
||||
|
||||
Color strokeColor = Color.white;
|
||||
|
||||
public double progress {
|
||||
get => m_Progress;
|
||||
set {
|
||||
m_Progress = value;
|
||||
MarkDirtyRepaint();
|
||||
}
|
||||
}
|
||||
|
||||
public BoostIndicator() {
|
||||
AddToClassList(ussClassName);
|
||||
RegisterCallback<CustomStyleResolvedEvent>(evt => CustomStylesResolved(evt));
|
||||
generateVisualContent += GenerateVisualContent;
|
||||
}
|
||||
|
||||
void GenerateVisualContent(MeshGenerationContext context) {
|
||||
float width = contentRect.width;
|
||||
float height = contentRect.height;
|
||||
|
||||
double length = width * m_Progress;
|
||||
|
||||
Vector2 left = new Vector2(0f, height / 2);
|
||||
Vector2 end = new Vector2((float)length, height / 2);
|
||||
|
||||
var painter = context.painter2D;
|
||||
painter.lineWidth = 3.0f;
|
||||
painter.lineCap = LineCap.Round;
|
||||
painter.strokeColor = strokeColor;
|
||||
|
||||
painter.BeginPath();
|
||||
painter.MoveTo(left);
|
||||
painter.LineTo(end);
|
||||
painter.Stroke();
|
||||
}
|
||||
|
||||
static void CustomStylesResolved(CustomStyleResolvedEvent evt) {
|
||||
BoostIndicator element = (BoostIndicator)evt.currentTarget;
|
||||
element.UpdateCustomStyles();
|
||||
}
|
||||
|
||||
void UpdateCustomStyles() {
|
||||
MarkDirtyRepaint();
|
||||
}
|
||||
}
|
||||
}
|
||||
File renamed without changes.
@@ -2,7 +2,7 @@
|
||||
<Style src="project://database/Assets/Src/UI/TimingUi.uss?fileID=7433441132597879392&guid=cf92f075876ddf7ffb4cd5c59633ad7b&type=3#TimingUi" />
|
||||
<ui:VisualElement name="VisualElement" style="-unity-font: url('project://database/Assets/UI%20Toolkit/Fonts/Jura-Medium.otf?fileID=12800000&guid=65648a14640996362a6b0929c723b6e4&type=3#Jura-Medium'); -unity-font-definition: initial; flex-direction: row; flex-grow: 1;">
|
||||
<ui:VisualElement name="left" style="flex-grow: 1; background-color: rgba(0, 0, 0, 0); justify-content: center; align-items: center;" />
|
||||
<ui:VisualElement name="middle" style="justify-content: flex-end;">
|
||||
<ui:VisualElement name="middle" style="justify-content: flex-end; width: 20%;">
|
||||
<ui:VisualElement name="speedCtr" style="flex-direction: row; justify-content: center;">
|
||||
<ui:Label tabindex="-1" display-tooltip-when-elided="true" name="speed" style="min-width: 5%; -unity-text-align: upper-right; flex-basis: 10%;" />
|
||||
<ui:Label tabindex="-1" text="u/s" display-tooltip-when-elided="true" name="units" style="flex-basis: 10%; -unity-text-align: upper-left;" />
|
||||
@@ -11,14 +11,27 @@
|
||||
<ui:Label tabindex="-1" display-tooltip-when-elided="true" name="shields" text="100" style="min-width: 5%; -unity-text-align: upper-right; flex-basis: 10%;" />
|
||||
<ui:Label tabindex="-1" text="%" display-tooltip-when-elided="true" name="units" style="flex-basis: 10%; -unity-text-align: upper-left;" />
|
||||
</ui:VisualElement>
|
||||
<ui:VisualElement name="boostBarCtr" style="height: 2.5%;">
|
||||
<BoostComponents.BoostBar progress="0.66" name="boostBar" charges="2" style="height: 100%;" />
|
||||
<ui:VisualElement name="puCtr" style="flex-direction: row; flex-grow: 0; justify-content: space-around;">
|
||||
<ui:VisualElement name="accelCtr" style="flex-grow: 0; background-color: rgba(0, 0, 0, 0);">
|
||||
<InterfaceIcon class="interfaceIcon" style="-unity-text-align: upper-center; -unity-font-style: normal;" />
|
||||
<BoostComponents.BoostIndicator name="BoostIndicator" progress="0.9" style="height: 1%;" />
|
||||
<BoostComponents.BoostIndicator name="BoostIndicator" progress="0.25" style="height: 1%;" />
|
||||
</ui:VisualElement>
|
||||
<ui:VisualElement name="decelCtr" style="flex-grow: 0; background-color: rgba(0, 0, 0, 0);">
|
||||
<InterfaceIcon icon="Deceleration" class="interfaceIcon" style="-unity-text-align: upper-center; -unity-font-style: normal;" />
|
||||
<BoostComponents.BoostIndicator name="BoostIndicator" progress="0.25" style="height: 1%;" />
|
||||
</ui:VisualElement>
|
||||
<ui:VisualElement name="strafeCtr" style="flex-grow: 0; background-color: rgba(0, 0, 0, 0);">
|
||||
<InterfaceIcon icon="Strafing" class="interfaceIcon" style="-unity-text-align: upper-center; -unity-font-style: normal;" />
|
||||
<BoostComponents.BoostIndicator name="BoostIndicator" progress="0.9" style="height: 1%;" />
|
||||
</ui:VisualElement>
|
||||
<ui:VisualElement name="shieldCtr" style="flex-grow: 0; background-color: rgba(0, 0, 0, 0);">
|
||||
<InterfaceIcon icon="Shield" text="88" name="ShieldIcon" class="interfaceIcon" style="-unity-text-align: upper-center; -unity-font-style: normal; align-items: center; justify-content: center;" />
|
||||
<BoostComponents.BoostIndicator name="BoostIndicator" progress="0.5" style="height: 1%;" />
|
||||
</ui:VisualElement>
|
||||
</ui:VisualElement>
|
||||
<ui:VisualElement name="puCtr" style="flex-direction: row; visibility: hidden;">
|
||||
<ui:Label tabindex="-1" display-tooltip-when-elided="true" name="puAccel" text="100" />
|
||||
<ui:Label tabindex="-1" text="100" display-tooltip-when-elided="true" name="puDecel" />
|
||||
<ui:Label tabindex="-1" text="100" display-tooltip-when-elided="true" name="puStrafe" />
|
||||
<ui:Label tabindex="-1" text="100" display-tooltip-when-elided="true" name="puShield" />
|
||||
<ui:VisualElement name="boostBarCtr" class="boostBarCtr">
|
||||
<BoostComponents.BoostBar progress="0.66" name="boostBar" charges="2" style="height: 100%;" />
|
||||
</ui:VisualElement>
|
||||
<ui:VisualElement name="middleBottom" style="flex-grow: 0; background-color: rgba(0, 0, 0, 0); flex-shrink: 0; flex-basis: 20%;" />
|
||||
</ui:VisualElement>
|
||||
|
||||
@@ -14,12 +14,9 @@ public class ControlsUI : MonoBehaviour {
|
||||
UIDocument uiDocument;
|
||||
Label speed;
|
||||
Label shields;
|
||||
Label puAccel;
|
||||
Label puDecel;
|
||||
Label puStrafe;
|
||||
Label puShield;
|
||||
|
||||
BoostBar boostBar;
|
||||
InterfaceIcon shield;
|
||||
|
||||
void OnEnable() {
|
||||
Init();
|
||||
@@ -30,11 +27,7 @@ public class ControlsUI : MonoBehaviour {
|
||||
speed = uiDocument.rootVisualElement.Q<Label>("speed");
|
||||
shields = uiDocument.rootVisualElement.Q<Label>("shields");
|
||||
|
||||
// PowerUnit
|
||||
puAccel = uiDocument.rootVisualElement.Q<Label>("puAccel");
|
||||
puDecel = uiDocument.rootVisualElement.Q<Label>("puDecel");
|
||||
puStrafe = uiDocument.rootVisualElement.Q<Label>("puStrafe");
|
||||
puShield = uiDocument.rootVisualElement.Q<Label>("puShield");
|
||||
shield = uiDocument.rootVisualElement.Q<InterfaceIcon>("ShieldIcon");
|
||||
|
||||
boostBar = uiDocument.rootVisualElement.Q<BoostBar>("boostBar");
|
||||
}
|
||||
@@ -47,12 +40,10 @@ public class ControlsUI : MonoBehaviour {
|
||||
}
|
||||
|
||||
speed.text = $"{ship.Speed():0}";
|
||||
shields.text = ship.powerUnit.ShieldPct;
|
||||
|
||||
puAccel.text = ship.powerUnit.Acceleration.ToString();
|
||||
puDecel.text = ship.powerUnit.Deceleration.ToString();
|
||||
puStrafe.text = ship.powerUnit.Strafing.ToString();
|
||||
puShield.text = ship.powerUnit.ShieldMax.ToString();
|
||||
shield.detail = ship.powerUnit.ShieldPct switch {
|
||||
"100" => "",
|
||||
string pct => pct,
|
||||
};
|
||||
|
||||
boostBar.progress = ship.powerUnit.BoostProgress;
|
||||
boostBar.charges = ship.powerUnit.BoostCharges;
|
||||
|
||||
@@ -89,7 +89,7 @@ namespace CrosshairComponents {
|
||||
|
||||
var painter = context.painter2D;
|
||||
painter.lineWidth = 1.0f;
|
||||
painter.lineCap = LineCap.Butt;
|
||||
painter.lineCap = LineCap.Round;
|
||||
painter.strokeColor = m_TrackColor;
|
||||
|
||||
painter.BeginPath();
|
||||
@@ -190,7 +190,7 @@ namespace CrosshairComponents {
|
||||
|
||||
var painter = context.painter2D;
|
||||
painter.lineWidth = 1.0f;
|
||||
painter.lineCap = LineCap.Butt;
|
||||
painter.lineCap = LineCap.Round;
|
||||
painter.strokeColor = m_TrackColor;
|
||||
|
||||
painter.BeginPath();
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" xsi="http://www.w3.org/2001/XMLSchema-instance" engine="UnityEngine.UIElements" editor="UnityEditor.UIElements" noNamespaceSchemaLocation="../../../UIElementsSchema/UIElements.xsd" editor-extension-mode="False">
|
||||
<InterfaceIcon icon="Logo" style="-unity-font: resource('SpaceRace-Icons'); -unity-font-definition: initial; font-size: 256px; color: rgb(255, 255, 255);" />
|
||||
<InterfaceIcon icon="Logo" style="-unity-font: resource('SpaceRace-Icons'); -unity-font-definition: initial; font-size: 32px; color: rgb(255, 255, 255); -unity-font-style: normal;" />
|
||||
</ui:UXML>
|
||||
@@ -20,21 +20,23 @@ public class InterfaceIcon : VisualElement {
|
||||
public new class UxmlFactory : UxmlFactory<InterfaceIcon, UxmlTraits> {}
|
||||
public new class UxmlTraits : VisualElement.UxmlTraits {
|
||||
readonly UxmlEnumAttributeDescription<Icon> _iconAttribute = new() { name = "icon" };
|
||||
readonly UxmlStringAttributeDescription _detailAttribute = new UxmlStringAttributeDescription() { name = "text" };
|
||||
|
||||
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);
|
||||
InterfaceIcon.detail = _detailAttribute.GetValueFromBag(bag, cc);
|
||||
}
|
||||
}
|
||||
|
||||
static readonly Dictionary<Icon, char> _iconGlyphMap = new() {
|
||||
{ Icon.Acceleration, '\ue901' },
|
||||
{ Icon.Deceleration, '\ue902' },
|
||||
{ Icon.Strafing, '\ue903' },
|
||||
{ Icon.Shield, '\ue904' },
|
||||
{ Icon.Acceleration, '\u25bc' },
|
||||
{ Icon.Deceleration, '\u25b2' },
|
||||
{ Icon.Strafing, '\u2b94' },
|
||||
{ Icon.Shield, '\u26c9' },
|
||||
|
||||
{ Icon.Logo, '\ue900' },
|
||||
{ Icon.Logo, '\u26d0' },
|
||||
};
|
||||
|
||||
public Icon icon {
|
||||
@@ -45,8 +47,19 @@ public class InterfaceIcon : VisualElement {
|
||||
}
|
||||
}
|
||||
|
||||
public string detail {
|
||||
get => _detail;
|
||||
set {
|
||||
_detail = value;
|
||||
_detailLabel.text = value;
|
||||
}
|
||||
}
|
||||
|
||||
Icon _icon;
|
||||
string _detail;
|
||||
|
||||
Label _iconLabel;
|
||||
Label _detailLabel;
|
||||
|
||||
public InterfaceIcon() : this(Icon.Strafing) {}
|
||||
|
||||
@@ -59,6 +72,17 @@ public class InterfaceIcon : VisualElement {
|
||||
};
|
||||
|
||||
Add(_iconLabel);
|
||||
|
||||
_detailLabel = new Label {
|
||||
style = {
|
||||
position = Position.Absolute,
|
||||
},
|
||||
};
|
||||
|
||||
_detailLabel.AddToClassList("detail");
|
||||
|
||||
Add(_detailLabel);
|
||||
|
||||
this.icon = icon;
|
||||
}
|
||||
}
|
||||
@@ -48,3 +48,27 @@
|
||||
margin-top: 20%;
|
||||
-unity-text-align: upper-center;
|
||||
}
|
||||
|
||||
InterfaceIcon {
|
||||
text-align: center;
|
||||
font-size: 40px;
|
||||
}
|
||||
|
||||
InterfaceIcon Label {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
InterfaceIcon .detail {
|
||||
font-size: 24px;
|
||||
}
|
||||
|
||||
BoostIndicator {
|
||||
margin-top: 6px;
|
||||
padding: 3px;
|
||||
}
|
||||
|
||||
.boostBarCtr {
|
||||
height: 1%;
|
||||
margin-top: 12px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
Reference in new issue
Block a user