middle align diff sectors whatever

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

No files matched your search

+30 -2
View File
@@ -1,12 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
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,
Purple,
White,
+9 -5
View File
@@ -83,14 +83,16 @@ public class Timing: MonoBehaviour {
if (sector != sectorTimes.Count + 1)
return;
// alright they legitimately finished a sector...
double sTime = Time.timeAsDouble - sectorStart;
SectorTime s = new SectorTime { Sector = sector, Seconds = sTime };
sectorTimes.Add(s);
sectorStart = Time.timeAsDouble;
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) {
EndLap();
NextLap();
@@ -111,13 +113,15 @@ public class Timing: MonoBehaviour {
Lap l = new Lap { Map = mapName, Sectors = sectorTimes };
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));
LapStorageService.PersistLap(l);
}
IEnumerator RecentLapLifecycle(Lap l) {
ui.ShowRecentLap(l);
yield return new WaitForSeconds(3);
yield return new WaitForSeconds(5);
ui.HideRecentLap();
}
+20 -11
View File
@@ -4,18 +4,27 @@
<ui:VisualElement name="Top" style="flex-grow: 1;" />
<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="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:Label tabindex="-1" text="Time" display-tooltip-when-elided="true" name="timer" style="align-self: flex-end; align-items: auto;" />
<ui:Label tabindex="-1" text="1:28.248" display-tooltip-when-elided="true" name="pb" />
<ui:VisualElement name="notice" style="flex-grow: 1; background-color: rgba(0, 0, 0, 0);">
<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: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 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:Label tabindex="-1" text="1:24.248" display-tooltip-when-elided="true" name="recentTime" style="align-self: flex-end; align-items: auto;" />
<ui:Label tabindex="-1" text="-0.999" display-tooltip-when-elided="true" name="recentDiff" class="green" />
</ui:VisualElement>
<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:Label tabindex="-1" text="32.0" display-tooltip-when-elided="true" class="yellow" />
<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="1:28.8" display-tooltip-when-elided="true" class="purple" />
<ui:VisualElement name="timer" style="flex-grow: 1; background-color: rgba(0, 0, 0, 0);">
<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="Time" display-tooltip-when-elided="true" name="timerTime" style="align-self: flex-end; align-items: auto;" />
<ui:Label tabindex="-1" text="1:28.248" display-tooltip-when-elided="true" name="timerPb" />
</ui:VisualElement>
<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="32.0" display-tooltip-when-elided="true" class="yellow" />
<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>
+49 -33
View File
@@ -12,13 +12,15 @@ public class TimingUI : MonoBehaviour {
Timing timing;
UIDocument uiDocument;
VisualElement recentLap;
VisualElement currentLap;
VisualElement sectors;
Label timer;
Label pb;
Label recentTime;
Label recentDiff;
VisualElement timer;
VisualElement timerSectors;
Label timerTime;
Label timerPb;
VisualElement notice;
VisualElement noticeSectors;
Label noticeTime;
Label noticeDiff;
void OnEnable() {
Init();
@@ -28,18 +30,21 @@ public class TimingUI : MonoBehaviour {
uiDocument = GetComponent<UIDocument>();
timing = GetComponent<Timing>();
recentLap = uiDocument.rootVisualElement.Q<VisualElement>("recentLap");
currentLap = uiDocument.rootVisualElement.Q<VisualElement>("currentLap");
sectors = uiDocument.rootVisualElement.Q<VisualElement>("sectors");
notice = uiDocument.rootVisualElement.Q<VisualElement>("notice");
noticeSectors = uiDocument.rootVisualElement.Q<VisualElement>("noticeSectors");
recentTime = uiDocument.rootVisualElement.Q<Label>("recentTime");
recentDiff = uiDocument.rootVisualElement.Q<Label>("recentDiff");
timer = uiDocument.rootVisualElement.Q<Label>("timer");
pb = uiDocument.rootVisualElement.Q<Label>("pb");
pb.text = "-";
timer = uiDocument.rootVisualElement.Q<VisualElement>("timer");
timerSectors = uiDocument.rootVisualElement.Q<VisualElement>("timerSectors");
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() {
@@ -49,21 +54,21 @@ public class TimingUI : MonoBehaviour {
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
UpdateUI();
}
public void UpdateUI() {
if (sectors == null)
Debug.LogWarning("null sectors");
if (timerSectors == null)
Debug.LogWarning("null timerSectors");
Lap pbLap = timing.PB();
if (pbLap != null)
pb.text = $"{pbLap.ToString()}";
Lap timerPbLap = timing.PB();
if (timerPbLap != null)
timerPb.text = $"{timerPbLap.ToString()}";
sectors.Clear();
timerSectors.Clear();
foreach (Sector sector in timing.sectors) {
Label l = timing.sectorTimes
@@ -72,20 +77,31 @@ public class TimingUI : MonoBehaviour {
.DefaultIfEmpty(new Label("-"))
.Single();
sectors.Add(l);
timerSectors.Add(l);
}
}
public void ShowRecentLap(Lap lap) {
currentLap.AddToClassList("hidden");
recentLap.RemoveFromClassList("hidden");
recentTime.text = lap.ToString();
recentDiff.text = lap.ToString();
timer.AddToClassList("hidden");
notice.RemoveFromClassList("hidden");
// 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() {
currentLap.RemoveFromClassList("hidden");
recentLap.AddToClassList("hidden");
timer.RemoveFromClassList("hidden");
notice.AddToClassList("hidden");
}
Label SectorLabel(SectorTime s) {
@@ -95,9 +111,9 @@ public class TimingUI : MonoBehaviour {
_ => "+",
};
SectorColour colour = diff switch {
< 0 => SectorColour.Green,
_ => SectorColour.Yellow,
DiffColour colour = diff switch {
< 0 => DiffColour.Green,
_ => DiffColour.Yellow,
};
Label l = new Label($"{sign}{diff:0.000}");
+11
View File
@@ -10,6 +10,17 @@
letter-spacing: 24px;
}
.sectors {
font-size: 20px;
}
.sectors Label {
flex-shrink: 1;
flex-grow: 1;
flex-basis: 0;
-unity-text-align: upper-center;
}
.green {
color: var(--green);
}