middle align diff sectors whatever

This commit is contained in:
ntr committed 2023-08-04 12:28:23 +10:00
1 parent 6f0ef954d8
commit beeac0ee8d
5 files changed
+119 -51

No files matched your search

+30 -2
View File
@@ -1,12 +1,40 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.IO; using System.IO;
using UnityEngine; using UnityEngine;
public enum SectorColour { public enum NoticeCategory {
Initial,
Slower,
Faster,
Fastest,
}
// public record TimingNotice(
// double Seconds,
// NoticeCategory Category,
// ) {
// Label ToLabel() {
// Label l = Category switch {
// DiffType.Slower => new Label($"+{diff:0.000}"),
// DiffType.Faster => new Label($"-{diff:0.000}"),
// DiffType.Fastest => new Label($"-{diff:0.000}"),
// };
// string colourClass = Category Switch {
// DiffType.Slower => "yellow",
// DiffType.Faster => "green",
// DiffType.Fastest => "purple",
// };
// l.AddToClassList(colourClass);
// return l;
// }
// }
public enum DiffColour {
Green, Green,
Purple, Purple,
White, White,
+9 -5
View File
@@ -83,14 +83,16 @@ public class Timing: MonoBehaviour {
if (sector != sectorTimes.Count + 1) if (sector != sectorTimes.Count + 1)
return; return;
// alright they legitimately finished a sector...
double sTime = Time.timeAsDouble - sectorStart; double sTime = Time.timeAsDouble - sectorStart;
SectorTime s = new SectorTime { Sector = sector, Seconds = sTime }; SectorTime s = new SectorTime { Sector = sector, Seconds = sTime };
sectorTimes.Add(s); sectorTimes.Add(s);
sectorStart = Time.timeAsDouble;
Debug.Log($"{sectorTimes.Count} / {sectors.Length}"); Debug.Log($"{sectorTimes.Count} / {sectors.Length}");
// restart the timer for the next sector
sectorStart = Time.timeAsDouble;
// they finished a lap!
if (sectorTimes.Count == sectors.Length) { if (sectorTimes.Count == sectors.Length) {
EndLap(); EndLap();
NextLap(); NextLap();
@@ -111,13 +113,15 @@ public class Timing: MonoBehaviour {
Lap l = new Lap { Map = mapName, Sectors = sectorTimes }; Lap l = new Lap { Map = mapName, Sectors = sectorTimes };
Debug.Log($"EndLap {l}"); Debug.Log($"EndLap {l}");
LapStorageService.PersistLap(l); // have to show this before we persist the lap in case it is the pb
StartCoroutine(RecentLapLifecycle(l)); StartCoroutine(RecentLapLifecycle(l));
LapStorageService.PersistLap(l);
} }
IEnumerator RecentLapLifecycle(Lap l) { IEnumerator RecentLapLifecycle(Lap l) {
ui.ShowRecentLap(l); ui.ShowRecentLap(l);
yield return new WaitForSeconds(3); yield return new WaitForSeconds(5);
ui.HideRecentLap(); ui.HideRecentLap();
} }
+20 -11
View File
@@ -4,18 +4,27 @@
<ui:VisualElement name="Top" style="flex-grow: 1;" /> <ui:VisualElement name="Top" style="flex-grow: 1;" />
<ui:VisualElement name="Middle" style="flex-grow: 1; align-items: center;" /> <ui:VisualElement name="Middle" style="flex-grow: 1; align-items: center;" />
<ui:VisualElement name="Bottom" style="flex-grow: 0; background-color: rgba(0, 0, 0, 0.26); flex-direction: column; align-items: stretch; justify-content: flex-end; color: rgb(255, 255, 255); width: 33%; align-self: center;"> <ui:VisualElement name="Bottom" style="flex-grow: 0; background-color: rgba(0, 0, 0, 0.26); flex-direction: column; align-items: stretch; justify-content: flex-end; color: rgb(255, 255, 255); width: 33%; align-self: center;">
<ui:VisualElement name="currentLap" style="flex-grow: 1; background-color: rgba(0, 0, 0, 0); flex-direction: row; justify-content: space-between; align-items: auto; width: auto; align-self: stretch; flex-shrink: 0;"> <ui:VisualElement name="notice" style="flex-grow: 1; background-color: rgba(0, 0, 0, 0);">
<ui:Label tabindex="-1" text="Time" display-tooltip-when-elided="true" name="timer" style="align-self: flex-end; align-items: auto;" /> <ui:VisualElement name="noticeLap" style="flex-grow: 1; background-color: rgba(0, 0, 0, 0); flex-direction: row; justify-content: space-between; align-items: auto; width: auto; align-self: stretch; flex-shrink: 0;">
<ui:Label tabindex="-1" text="1:28.248" display-tooltip-when-elided="true" name="pb" /> <ui:Label tabindex="-1" text="1:24.248" display-tooltip-when-elided="true" name="noticeTime" style="align-self: flex-end; align-items: auto;" />
<ui:Label tabindex="-1" text="-0.999" display-tooltip-when-elided="true" name="noticeDiff" />
</ui:VisualElement>
<ui:VisualElement name="noticeSectors" class="sectors" style="flex-grow: 0; background-color: rgba(0, 0, 0, 0); flex-direction: row; align-self: stretch; align-items: stretch; justify-content: space-between; -unity-text-align: upper-left;">
<ui:Label tabindex="-1" text="+2.1" display-tooltip-when-elided="true" class="yellow" />
<ui:Label tabindex="-1" text="-1.9" display-tooltip-when-elided="true" class="green middle" />
<ui:Label tabindex="-1" text="-" display-tooltip-when-elided="true" class="purple" />
</ui:VisualElement>
</ui:VisualElement> </ui:VisualElement>
<ui:VisualElement name="recentLap" style="flex-grow: 1; background-color: rgba(0, 0, 0, 0); flex-direction: row; justify-content: space-between; align-items: auto; width: auto; align-self: stretch; flex-shrink: 0;"> <ui:VisualElement name="timer" style="flex-grow: 1; background-color: rgba(0, 0, 0, 0);">
<ui:Label tabindex="-1" text="1:24.248" display-tooltip-when-elided="true" name="recentTime" style="align-self: flex-end; align-items: auto;" /> <ui:VisualElement name="timerLap" style="flex-grow: 1; background-color: rgba(0, 0, 0, 0); flex-direction: row; justify-content: space-between; align-items: auto; width: auto; align-self: stretch; flex-shrink: 0;">
<ui:Label tabindex="-1" text="-0.999" display-tooltip-when-elided="true" name="recentDiff" class="green" /> <ui:Label tabindex="-1" text="Time" display-tooltip-when-elided="true" name="timerTime" style="align-self: flex-end; align-items: auto;" />
</ui:VisualElement> <ui:Label tabindex="-1" text="1:28.248" display-tooltip-when-elided="true" name="timerPb" />
<ui:VisualElement name="sectors" style="flex-grow: 0; background-color: rgba(0, 0, 0, 0); flex-direction: row; align-self: stretch; align-items: stretch; justify-content: space-between;"> </ui:VisualElement>
<ui:Label tabindex="-1" text="32.0" display-tooltip-when-elided="true" class="yellow" /> <ui:VisualElement name="timerSectors" class="sectors" style="flex-grow: 0; background-color: rgba(0, 0, 0, 0); flex-direction: row; align-self: stretch; align-items: auto;">
<ui:Label tabindex="-1" text="64.0" display-tooltip-when-elided="true" class="green" style="-unity-font-style: normal; -unity-font: url(&apos;project://database/Assets/UI%20Toolkit/Fonts/Jura-Medium.otf?fileID=12800000&amp;guid=65648a14640996362a6b0929c723b6e4&amp;type=3#Jura-Medium&apos;);" /> <ui:Label tabindex="-1" text="32.0" display-tooltip-when-elided="true" class="yellow" />
<ui:Label tabindex="-1" text="1:28.8" display-tooltip-when-elided="true" class="purple" /> <ui:Label tabindex="-1" text="64.0" display-tooltip-when-elided="true" class="green middle" />
<ui:Label tabindex="-1" text="1:28.8" display-tooltip-when-elided="true" class="purple" />
</ui:VisualElement>
</ui:VisualElement> </ui:VisualElement>
</ui:VisualElement> </ui:VisualElement>
</ui:VisualElement> </ui:VisualElement>
+49 -33
View File
@@ -12,13 +12,15 @@ public class TimingUI : MonoBehaviour {
Timing timing; Timing timing;
UIDocument uiDocument; UIDocument uiDocument;
VisualElement recentLap; VisualElement timer;
VisualElement currentLap; VisualElement timerSectors;
VisualElement sectors; Label timerTime;
Label timer; Label timerPb;
Label pb;
Label recentTime; VisualElement notice;
Label recentDiff; VisualElement noticeSectors;
Label noticeTime;
Label noticeDiff;
void OnEnable() { void OnEnable() {
Init(); Init();
@@ -28,18 +30,21 @@ public class TimingUI : MonoBehaviour {
uiDocument = GetComponent<UIDocument>(); uiDocument = GetComponent<UIDocument>();
timing = GetComponent<Timing>(); timing = GetComponent<Timing>();
recentLap = uiDocument.rootVisualElement.Q<VisualElement>("recentLap"); notice = uiDocument.rootVisualElement.Q<VisualElement>("notice");
currentLap = uiDocument.rootVisualElement.Q<VisualElement>("currentLap"); noticeSectors = uiDocument.rootVisualElement.Q<VisualElement>("noticeSectors");
sectors = uiDocument.rootVisualElement.Q<VisualElement>("sectors");
recentTime = uiDocument.rootVisualElement.Q<Label>("recentTime"); timer = uiDocument.rootVisualElement.Q<VisualElement>("timer");
recentDiff = uiDocument.rootVisualElement.Q<Label>("recentDiff"); timerSectors = uiDocument.rootVisualElement.Q<VisualElement>("timerSectors");
timer = uiDocument.rootVisualElement.Q<Label>("timer");
pb = uiDocument.rootVisualElement.Q<Label>("pb");
pb.text = "-";
noticeTime = uiDocument.rootVisualElement.Q<Label>("noticeTime");
noticeDiff = uiDocument.rootVisualElement.Q<Label>("noticeDiff");
recentLap.AddToClassList("hidden"); timerTime = uiDocument.rootVisualElement.Q<Label>("timerTime");
timerPb = uiDocument.rootVisualElement.Q<Label>("timerPb");
timerPb.text = "-";
notice.AddToClassList("hidden");
} }
void FixedUpdate() { void FixedUpdate() {
@@ -49,21 +54,21 @@ public class TimingUI : MonoBehaviour {
return; return;
} }
timer.text = $"{TimeSpan.FromSeconds(timing.lapTime):m\\:ss\\.fff}"; timerTime.text = $"{TimeSpan.FromSeconds(timing.lapTime):m\\:ss\\.fff}";
// clearly this is not ideal but idk atm // clearly this is not ideal but idk atm
UpdateUI(); UpdateUI();
} }
public void UpdateUI() { public void UpdateUI() {
if (sectors == null) if (timerSectors == null)
Debug.LogWarning("null sectors"); Debug.LogWarning("null timerSectors");
Lap pbLap = timing.PB(); Lap timerPbLap = timing.PB();
if (pbLap != null) if (timerPbLap != null)
pb.text = $"{pbLap.ToString()}"; timerPb.text = $"{timerPbLap.ToString()}";
sectors.Clear(); timerSectors.Clear();
foreach (Sector sector in timing.sectors) { foreach (Sector sector in timing.sectors) {
Label l = timing.sectorTimes Label l = timing.sectorTimes
@@ -72,20 +77,31 @@ public class TimingUI : MonoBehaviour {
.DefaultIfEmpty(new Label("-")) .DefaultIfEmpty(new Label("-"))
.Single(); .Single();
sectors.Add(l); timerSectors.Add(l);
} }
} }
public void ShowRecentLap(Lap lap) { public void ShowRecentLap(Lap lap) {
currentLap.AddToClassList("hidden"); timer.AddToClassList("hidden");
recentLap.RemoveFromClassList("hidden"); notice.RemoveFromClassList("hidden");
recentTime.text = lap.ToString();
recentDiff.text = lap.ToString(); // fine
noticeTime.text = lap.ToString();
// should show the diff to the PB
// or - if there is only 1 lap
noticeDiff.text = lap.ToString();
noticeSectors.Clear();
foreach (SectorTime sector in lap.Sectors) {
Label l = SectorLabel(sector);
noticeSectors.Add(l);
}
} }
public void HideRecentLap() { public void HideRecentLap() {
currentLap.RemoveFromClassList("hidden"); timer.RemoveFromClassList("hidden");
recentLap.AddToClassList("hidden"); notice.AddToClassList("hidden");
} }
Label SectorLabel(SectorTime s) { Label SectorLabel(SectorTime s) {
@@ -95,9 +111,9 @@ public class TimingUI : MonoBehaviour {
_ => "+", _ => "+",
}; };
SectorColour colour = diff switch { DiffColour colour = diff switch {
< 0 => SectorColour.Green, < 0 => DiffColour.Green,
_ => SectorColour.Yellow, _ => DiffColour.Yellow,
}; };
Label l = new Label($"{sign}{diff:0.000}"); Label l = new Label($"{sign}{diff:0.000}");
+11
View File
@@ -10,6 +10,17 @@
letter-spacing: 24px; letter-spacing: 24px;
} }
.sectors {
font-size: 20px;
}
.sectors Label {
flex-shrink: 1;
flex-grow: 1;
flex-basis: 0;
-unity-text-align: upper-center;
}
.green { .green {
color: var(--green); color: var(--green);
} }