crosshair wip

This commit is contained in:
ntr committed 2023-08-01 16:32:49 +10:00
1 parent 19f26c7ca9
commit 7c6c6902c5
35 files changed
+1331 -1688

No files matched your search

+68
View File
@@ -0,0 +1,68 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.UIElements;
public class TimingUI : MonoBehaviour {
UIDocument uiDocument;
[SerializeField]
ShipControls ship;
[SerializeField]
Timing timing;
Label timer;
Label pb;
VisualElement sectors;
VisualElement timeSheet;
void OnEnable() {
Init();
}
void Init() {
uiDocument = GetComponent<UIDocument>();
timer = uiDocument.rootVisualElement.Q<Label>("timer");
pb = uiDocument.rootVisualElement.Q<Label>("pb");
sectors = uiDocument.rootVisualElement.Q<VisualElement>("sectors");
}
void FixedUpdate() {
if (timer == null) {
Debug.LogWarning("no speed or timer");
Init();
return;
}
timer.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");
pb.text = $"PB: {timing.PB().ToString()}";
sectors.Clear();
foreach (Sector sector in timing.sectors) {
Label l = timing.sectorTimes
.Where(s => s.Sector == sector.sector)
.Select(s => {
Label l = new Label($"{s}");
string colourClass = timing.GetSectorColour(s).ToString().ToLowerInvariant();
l.AddToClassList(colourClass);
return l;
})
.DefaultIfEmpty(new Label("-"))
.Single();
sectors.Add(l);
}
}
}