66 lines
1.6 KiB
C#
66 lines
1.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
using UnityEngine;
|
|
using UnityEngine.UIElements;
|
|
|
|
public class ShipUi : MonoBehaviour {
|
|
[SerializeField]
|
|
UIDocument uiDocument = null;
|
|
|
|
[SerializeField]
|
|
ShipControls ship;
|
|
|
|
[SerializeField]
|
|
Timing timing;
|
|
|
|
Label speed;
|
|
Label timer;
|
|
VisualElement sectors;
|
|
VisualElement timeSheet;
|
|
|
|
void OnEnable() {
|
|
speed = uiDocument.rootVisualElement.Q<Label>("speed");
|
|
timer = uiDocument.rootVisualElement.Q<Label>("timer");
|
|
sectors = uiDocument.rootVisualElement.Q<VisualElement>("sectors");
|
|
timeSheet = uiDocument.rootVisualElement.Q<VisualElement>("timeSheet");
|
|
}
|
|
|
|
void FixedUpdate() {
|
|
timer.text = $"{timing.lapTime:0.0}";
|
|
speed.text = $"{ship.Speed():0} u/s";
|
|
|
|
// clearly this is not ideal but idk atm
|
|
UpdateTimesheet();
|
|
}
|
|
|
|
public void UpdateTimesheet() {
|
|
if (sectors == null)
|
|
Debug.LogWarning("null sectors");
|
|
|
|
timeSheet.Clear();
|
|
foreach (Lap lap in timing.lapTimes) {
|
|
Label l = new Label();
|
|
l.text = $"{lap}";
|
|
timeSheet.Add(l);
|
|
}
|
|
|
|
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}");
|
|
l.AddToClassList(s.ColourClass());
|
|
return l;
|
|
})
|
|
.DefaultIfEmpty(new Label("-"))
|
|
.Single();
|
|
|
|
sectors.Add(l);
|
|
}
|
|
}
|
|
}
|