middle align diff sectors whatever
This commit is contained in:
1 parent
6f0ef954d8
commit
beeac0ee8d
5 files changed
+119
-51
No files matched your search
+49
-33
@@ -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}");
|
||||
|
||||
Reference in new issue
Block a user