bars work dgaf
This commit is contained in:
1 parent
56ed2a4e89
commit
a065c09e47
3 files changed
+108
-20
No files matched your search
+12
-12
@@ -37,30 +37,30 @@ public class PowerUnit {
|
|||||||
public float Shield => shieldCurrent;
|
public float Shield => shieldCurrent;
|
||||||
public float ShieldMax => shieldMax;
|
public float ShieldMax => shieldMax;
|
||||||
public string ShieldPct => $"{((shieldCurrent / shieldMax) * 100f):0}";
|
public string ShieldPct => $"{((shieldCurrent / shieldMax) * 100f):0}";
|
||||||
float ShieldRegen => boostActive.Count switch {
|
float ShieldRegen => BoostActive.Count switch {
|
||||||
0 => (shieldMax / 5f) * Time.fixedDeltaTime,
|
0 => (shieldMax / 5f) * Time.fixedDeltaTime,
|
||||||
_ => 0f,
|
_ => 0f,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Boost
|
// Boost
|
||||||
List<(Output output, double expiresAt)> boostActive = new();
|
|
||||||
static double boostFullChargeSeconds = 10f;
|
static double boostFullChargeSeconds = 10f;
|
||||||
static double boostDurationSeconds = 2f;
|
public static double boostDurationSeconds = 2f;
|
||||||
double boostMax = 2f * boostDurationSeconds;
|
double boostMax = 2f * boostDurationSeconds;
|
||||||
double boostProgress = 0f;
|
double boostProgress = 0f;
|
||||||
double boostAvailable = 0f;
|
double boostAvailable = 0f;
|
||||||
|
|
||||||
|
public List<(Output output, double expiresAt)> BoostActive = new();
|
||||||
public double BoostProgress => boostProgress / boostMax;
|
public double BoostProgress => boostProgress / boostMax;
|
||||||
public int BoostCharges => (int)(boostMax / boostDurationSeconds);
|
public int BoostCharges => (int)(boostMax / boostDurationSeconds);
|
||||||
|
|
||||||
public float Acceleration =>
|
public float Acceleration =>
|
||||||
acceleration + boostActive.Count(b => b.output == Output.Acceleration) * baseOutput;
|
acceleration + BoostActive.Count(b => b.output == Output.Acceleration) * baseOutput;
|
||||||
|
|
||||||
public float Deceleration =>
|
public float Deceleration =>
|
||||||
deceleration + boostActive.Count(b => b.output == Output.Deceleration) * baseOutput;
|
deceleration + BoostActive.Count(b => b.output == Output.Deceleration) * baseOutput;
|
||||||
|
|
||||||
public float Strafing =>
|
public float Strafing =>
|
||||||
strafing + boostActive.Count(b => b.output == Output.Strafing) * baseOutput;
|
strafing + BoostActive.Count(b => b.output == Output.Strafing) * baseOutput;
|
||||||
|
|
||||||
double BoostRegen => (boostMax / boostFullChargeSeconds) * Time.fixedDeltaTime;
|
double BoostRegen => (boostMax / boostFullChargeSeconds) * Time.fixedDeltaTime;
|
||||||
|
|
||||||
@@ -69,7 +69,7 @@ public class PowerUnit {
|
|||||||
deceleration = initialDeceleration;
|
deceleration = initialDeceleration;
|
||||||
strafing = initialStrafing;
|
strafing = initialStrafing;
|
||||||
|
|
||||||
boostActive = new();
|
BoostActive = new();
|
||||||
boostProgress = 0f;
|
boostProgress = 0f;
|
||||||
|
|
||||||
shieldMax = initialShieldMax;
|
shieldMax = initialShieldMax;
|
||||||
@@ -78,17 +78,17 @@ public class PowerUnit {
|
|||||||
|
|
||||||
public void Deploy(Output output) {
|
public void Deploy(Output output) {
|
||||||
if (boostAvailable < boostDurationSeconds) return;
|
if (boostAvailable < boostDurationSeconds) return;
|
||||||
boostActive.Add((output, Time.timeAsDouble + boostDurationSeconds));
|
BoostActive.Add((output, Time.timeAsDouble + boostDurationSeconds));
|
||||||
boostAvailable -= boostDurationSeconds;
|
boostAvailable -= boostDurationSeconds;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Tick() {
|
public void Tick() {
|
||||||
if (boostProgress <= 0f) boostActive.Clear();
|
if (boostProgress <= 0f) BoostActive.Clear();
|
||||||
|
|
||||||
// remove expired boosts
|
// remove expired boosts
|
||||||
boostActive = boostActive.Where(b => b.expiresAt > Time.timeAsDouble).ToList();
|
BoostActive = BoostActive.Where(b => b.expiresAt > Time.timeAsDouble).ToList();
|
||||||
|
|
||||||
double delta = boostActive.Count switch {
|
double delta = BoostActive.Count switch {
|
||||||
// if there are no boosts active we can increase the store
|
// if there are no boosts active we can increase the store
|
||||||
0 => BoostRegen,
|
0 => BoostRegen,
|
||||||
// if there are active boosts we deplete it
|
// if there are active boosts we deplete it
|
||||||
@@ -104,7 +104,7 @@ public class PowerUnit {
|
|||||||
boostProgress = Math.Max(0f, next);
|
boostProgress = Math.Max(0f, next);
|
||||||
if (delta > 0f) boostAvailable = boostProgress;
|
if (delta > 0f) boostAvailable = boostProgress;
|
||||||
|
|
||||||
shieldMax = initialShieldMax + boostActive.Count(b => b.output == Output.Shield) * 1000f;
|
shieldMax = initialShieldMax + BoostActive.Count(b => b.output == Output.Shield) * 1000f;
|
||||||
shieldCurrent = Math.Min(shieldCurrent + ShieldRegen, shieldMax);
|
shieldCurrent = Math.Min(shieldCurrent + ShieldRegen, shieldMax);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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" 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: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>
|
||||||
<ui:VisualElement name="shieldCtr" style="align-items: center; flex-direction: row; justify-content: center;">
|
<ui:VisualElement name="boostBarCtr" class="boostBarCtr">
|
||||||
<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%;" />
|
<BoostComponents.BoostBar progress="0.66" name="boostBar" charges="2" style="height: 100%;" />
|
||||||
<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>
|
||||||
<ui:VisualElement name="puCtr" style="flex-direction: row; flex-grow: 0; justify-content: space-around;">
|
<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);">
|
<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%;" />
|
<BoostComponents.BoostIndicator name="BoostIndicator" progress="0.5" style="height: 1%;" />
|
||||||
</ui:VisualElement>
|
</ui:VisualElement>
|
||||||
</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 name="middleBottom" style="flex-grow: 0; background-color: rgba(0, 0, 0, 0); flex-shrink: 0; flex-basis: 20%;" />
|
||||||
</ui:VisualElement>
|
</ui:VisualElement>
|
||||||
<ui:VisualElement name="right" style="flex-grow: 1; background-color: rgba(0, 0, 0, 0); justify-content: center; align-items: center;" />
|
<ui:VisualElement name="right" style="flex-grow: 1; background-color: rgba(0, 0, 0, 0); justify-content: center; align-items: center;" />
|
||||||
|
|||||||
@@ -18,18 +18,72 @@ public class ControlsUI : MonoBehaviour {
|
|||||||
BoostBar boostBar;
|
BoostBar boostBar;
|
||||||
InterfaceIcon shield;
|
InterfaceIcon shield;
|
||||||
|
|
||||||
|
VisualElement accelCtr;
|
||||||
|
VisualElement decelCtr;
|
||||||
|
VisualElement strafeCtr;
|
||||||
|
VisualElement shieldCtr;
|
||||||
|
|
||||||
|
BoostIndicator[] accelBoosts;
|
||||||
|
BoostIndicator[] decelBoosts;
|
||||||
|
BoostIndicator[] strafeBoosts;
|
||||||
|
BoostIndicator[] shieldBoosts;
|
||||||
|
|
||||||
|
void Awake() {
|
||||||
|
Init();
|
||||||
|
}
|
||||||
|
|
||||||
void OnEnable() {
|
void OnEnable() {
|
||||||
Init();
|
Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
void 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>();
|
uiDocument = GetComponent<UIDocument>();
|
||||||
speed = uiDocument.rootVisualElement.Q<Label>("speed");
|
speed = uiDocument.rootVisualElement.Q<Label>("speed");
|
||||||
shields = uiDocument.rootVisualElement.Q<Label>("shields");
|
shields = uiDocument.rootVisualElement.Q<Label>("shields");
|
||||||
|
|
||||||
shield = uiDocument.rootVisualElement.Q<InterfaceIcon>("ShieldIcon");
|
shield = uiDocument.rootVisualElement.Q<InterfaceIcon>("ShieldIcon");
|
||||||
|
|
||||||
boostBar = uiDocument.rootVisualElement.Q<BoostBar>("boostBar");
|
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() {
|
void FixedUpdate() {
|
||||||
@@ -47,5 +101,43 @@ public class ControlsUI : MonoBehaviour {
|
|||||||
|
|
||||||
boostBar.progress = ship.powerUnit.BoostProgress;
|
boostBar.progress = ship.powerUnit.BoostProgress;
|
||||||
boostBar.charges = ship.powerUnit.BoostCharges;
|
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,
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user