menu
This commit is contained in:
1 parent
6eb7bac08a
commit
6704c3ae59
46 files changed
+5298
-74
No files matched your search
@@ -0,0 +1,66 @@
|
||||
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 = $"{TimeSpan.FromSeconds(timing.lapTime):g}";
|
||||
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}");
|
||||
string colourClass = timing.GetSectorColour(s).ToString().ToLowerInvariant();
|
||||
l.AddToClassList(colourClass);
|
||||
return l;
|
||||
})
|
||||
.DefaultIfEmpty(new Label("-"))
|
||||
.Single();
|
||||
|
||||
sectors.Add(l);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user