bars work dgaf

This commit is contained in:
ntr committed 2023-08-22 19:53:03 +10:00
1 parent 56ed2a4e89
commit a065c09e47
3 files changed
+108 -20

No files matched your search

+2 -6
View File
@@ -7,9 +7,8 @@
<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;" />
</ui:VisualElement>
<ui:VisualElement name="shieldCtr" style="align-items: center; flex-direction: row; justify-content: center;">
<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 name="boostBarCtr" class="boostBarCtr">
<BoostComponents.BoostBar progress="0.66" name="boostBar" charges="2" style="height: 100%;" />
</ui:VisualElement>
<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);">
@@ -30,9 +29,6 @@
<BoostComponents.BoostIndicator name="BoostIndicator" progress="0.5" style="height: 1%;" />
</ui:VisualElement>
</ui:VisualElement>
<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>
<ui:VisualElement name="right" style="flex-grow: 1; background-color: rgba(0, 0, 0, 0); justify-content: center; align-items: center;" />
+94 -2
View File
@@ -18,18 +18,72 @@ public class ControlsUI : MonoBehaviour {
BoostBar boostBar;
InterfaceIcon shield;
VisualElement accelCtr;
VisualElement decelCtr;
VisualElement strafeCtr;
VisualElement shieldCtr;
BoostIndicator[] accelBoosts;
BoostIndicator[] decelBoosts;
BoostIndicator[] strafeBoosts;
BoostIndicator[] shieldBoosts;
void Awake() {
Init();
}
void OnEnable() {
Init();
}
void Init() {
accelBoosts = new BoostIndicator[ship.powerUnit.BoostCharges];
decelBoosts = new BoostIndicator[ship.powerUnit.BoostCharges];
strafeBoosts = new BoostIndicator[ship.powerUnit.BoostCharges];
shieldBoosts = new BoostIndicator[ship.powerUnit.BoostCharges];
uiDocument = GetComponent<UIDocument>();
speed = uiDocument.rootVisualElement.Q<Label>("speed");
shields = uiDocument.rootVisualElement.Q<Label>("shields");
shield = uiDocument.rootVisualElement.Q<InterfaceIcon>("ShieldIcon");
boostBar = uiDocument.rootVisualElement.Q<BoostBar>("boostBar");
accelCtr = uiDocument.rootVisualElement.Q<VisualElement>("accelCtr");
decelCtr = uiDocument.rootVisualElement.Q<VisualElement>("decelCtr");
strafeCtr = uiDocument.rootVisualElement.Q<VisualElement>("strafeCtr");
shieldCtr = uiDocument.rootVisualElement.Q<VisualElement>("shieldCtr");
SetupBars();
}
void SetupBars() {
// remove the test elements
accelCtr.Query<BoostIndicator>()
.ForEach(i => accelCtr.Remove(i));
decelCtr.Query<BoostIndicator>()
.ForEach(i => decelCtr.Remove(i));
strafeCtr.Query<BoostIndicator>()
.ForEach(i => strafeCtr.Remove(i));
shieldCtr.Query<BoostIndicator>()
.ForEach(i => shieldCtr.Remove(i));
// add a bar for the capacity of charges to each output icon ctr
for (int i = 0; i < ship.powerUnit.BoostCharges; i++) {
BoostIndicator a = new BoostIndicator();
BoostIndicator d = new BoostIndicator();
BoostIndicator s = new BoostIndicator();
BoostIndicator l = new BoostIndicator();
accelBoosts[i] = a;
decelBoosts[i] = d;
strafeBoosts[i] = s;
shieldBoosts[i] = l;
accelCtr.Add(a);
decelCtr.Add(d);
strafeCtr.Add(s);
shieldCtr.Add(l);
}
}
void FixedUpdate() {
@@ -47,5 +101,43 @@ public class ControlsUI : MonoBehaviour {
boostBar.progress = ship.powerUnit.BoostProgress;
boostBar.charges = ship.powerUnit.BoostCharges;
BarNasty();
}
// yolo looping
void BarNasty() {
var boosts = ship.powerUnit.BoostActive.OrderByDescending(b => b.expiresAt);
var aB = boosts.Where(b => b.output == Output.Acceleration);
var dB = boosts.Where(b => b.output == Output.Deceleration);
var sB = boosts.Where(b => b.output == Output.Strafing);
var lB = boosts.Where(b => b.output == Output.Shield);
for (int i = 0; i < ship.powerUnit.BoostCharges; i++) {
var accelBoost = aB.ElementAtOrDefault(i);
accelBoosts[i].progress = (accelBoost == default((Output, double))) switch {
true => 0f,
false => (accelBoost.expiresAt - Time.timeAsDouble) / PowerUnit.boostDurationSeconds,
};
var decelBoost = dB.ElementAtOrDefault(i);
decelBoosts[i].progress = (decelBoost == default((Output, double))) switch {
true => 0f,
false => (decelBoost.expiresAt - Time.timeAsDouble) / PowerUnit.boostDurationSeconds,
};
var strafeBoost = sB.ElementAtOrDefault(i);
strafeBoosts[i].progress = (strafeBoost == default((Output, double))) switch {
true => 0f,
false => (strafeBoost.expiresAt - Time.timeAsDouble) / PowerUnit.boostDurationSeconds,
};
var shieldBoost = lB.ElementAtOrDefault(i);
shieldBoosts[i].progress = (shieldBoost == default((Output, double))) switch {
true => 0f,
false => (shieldBoost.expiresAt - Time.timeAsDouble) / PowerUnit.boostDurationSeconds,
};
}
}
}