From beeac0ee8df0b127b0d757747a576a38ab235cec Mon Sep 17 00:00:00 2001 From: ntr Date: Fri, 4 Aug 2023 12:28:23 +1000 Subject: [PATCH] middle align diff sectors whatever --- Assets/Src/Laps.cs | 32 ++++++++++++++- Assets/Src/Timing.cs | 14 ++++--- Assets/Src/UI/Timing.uxml | 31 +++++++++----- Assets/Src/UI/TimingUI.cs | 82 +++++++++++++++++++++++--------------- Assets/Src/UI/TimingUi.uss | 11 +++++ 5 files changed, 119 insertions(+), 51 deletions(-) diff --git a/Assets/Src/Laps.cs b/Assets/Src/Laps.cs index 9fb9018..10efb2b 100644 --- a/Assets/Src/Laps.cs +++ b/Assets/Src/Laps.cs @@ -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, diff --git a/Assets/Src/Timing.cs b/Assets/Src/Timing.cs index fe15137..45f58a4 100644 --- a/Assets/Src/Timing.cs +++ b/Assets/Src/Timing.cs @@ -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(); } diff --git a/Assets/Src/UI/Timing.uxml b/Assets/Src/UI/Timing.uxml index 7d1e0d9..71fb61b 100644 --- a/Assets/Src/UI/Timing.uxml +++ b/Assets/Src/UI/Timing.uxml @@ -4,18 +4,27 @@ - - - + + + + + + + + + + - - - - - - - - + + + + + + + + + + diff --git a/Assets/Src/UI/TimingUI.cs b/Assets/Src/UI/TimingUI.cs index 9d2aa84..925f5c2 100644 --- a/Assets/Src/UI/TimingUI.cs +++ b/Assets/Src/UI/TimingUI.cs @@ -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(); timing = GetComponent(); - recentLap = uiDocument.rootVisualElement.Q("recentLap"); - currentLap = uiDocument.rootVisualElement.Q("currentLap"); - sectors = uiDocument.rootVisualElement.Q("sectors"); + notice = uiDocument.rootVisualElement.Q("notice"); + noticeSectors = uiDocument.rootVisualElement.Q("noticeSectors"); - recentTime = uiDocument.rootVisualElement.Q