recent lap
This commit is contained in:
1 parent
daa84c8a9d
commit
69a97e3c76
6 files changed
+71
-39
No files matched your search
+23
-4
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
@@ -9,6 +10,9 @@ using UnityEditor;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class Timing: MonoBehaviour {
|
||||
[SerializeField]
|
||||
TimingUI ui;
|
||||
|
||||
public List<SectorTime> sectorTimes;
|
||||
public bool timerEnabled;
|
||||
|
||||
@@ -16,7 +20,7 @@ public class Timing: MonoBehaviour {
|
||||
public double sectorTime;
|
||||
public double lapTime;
|
||||
public Sector[] sectors;
|
||||
public LapJSON recentLap;
|
||||
public Lap recentLap = null;
|
||||
|
||||
double sectorStart;
|
||||
double lapStart;
|
||||
@@ -33,6 +37,7 @@ public class Timing: MonoBehaviour {
|
||||
Debug.Log("Track Sector Count - " + sectors.Length);
|
||||
|
||||
LapStorageService.GetPlayerLaps(mapName);
|
||||
recentLap = null;
|
||||
}
|
||||
|
||||
void Update() {
|
||||
@@ -107,7 +112,19 @@ public class Timing: MonoBehaviour {
|
||||
Debug.Log($"Ending lap Sectors={sectorTimes.Count} Name={mapName}");
|
||||
Lap l = new Lap { Map = mapName, Sectors = sectorTimes };
|
||||
Debug.Log($"EndLap {l}");
|
||||
|
||||
LapStorageService.PersistLap(l);
|
||||
StartCoroutine(RecentLapLifecycle(l));
|
||||
}
|
||||
|
||||
IEnumerator RecentLapLifecycle(Lap l) {
|
||||
ui.ShowRecentLap(l);
|
||||
yield return new WaitForSeconds(3);
|
||||
ui.HideRecentLap();
|
||||
}
|
||||
|
||||
public Lap PB() {
|
||||
return LapStorageService.PB(mapName);
|
||||
}
|
||||
|
||||
public double PBSectorDiff(SectorTime s) => PB() switch {
|
||||
@@ -118,8 +135,10 @@ public class Timing: MonoBehaviour {
|
||||
null => -1d,
|
||||
};
|
||||
|
||||
public Lap PB() {
|
||||
return LapStorageService.PB(mapName);
|
||||
}
|
||||
public double PBLapDiff(Lap lap) => PB() switch {
|
||||
Lap pb => lap.TotalTime() - pb.TotalTime(),
|
||||
null => -1d,
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" xsi="http://www.w3.org/2001/XMLSchema-instance" engine="UnityEngine.UIElements" editor="UnityEditor.UIElements" noNamespaceSchemaLocation="../../UIElementsSchema/UIElements.xsd" editor-extension-mode="False">
|
||||
<Style src="project://database/Assets/Src/UI/TimingUi.uss?fileID=7433441132597879392&guid=cf92f075876ddf7ffb4cd5c59633ad7b&type=3#ShipUi" />
|
||||
<ui:VisualElement style="flex-grow: 1; background-color: rgba(0, 0, 0, 0); align-items: center; justify-content: center;">
|
||||
<ui:Label tabindex="-1" text="✛" display-tooltip-when-elided="true" style="opacity: 0.5; position: relative; -unity-text-align: middle-center; -unity-font: url('project://database/Assets/UI%20Toolkit/Fonts/Jura-Medium.otf?fileID=12800000&guid=65648a14640996362a6b0929c723b6e4&type=3#Jura-Medium'); -unity-font-definition: initial;" />
|
||||
<ui:Label tabindex="-1" text="✛" display-tooltip-when-elided="true" style="opacity: 0.5; position: relative; -unity-text-align: middle-center; -unity-font: url('project://database/Assets/UI%20Toolkit/Fonts/Jura-Light.otf?fileID=12800000&guid=54b9163f81dfb0d7baa7fda0d795ceeb&type=3#Jura-Light'); -unity-font-definition: initial; font-size: 16px;" />
|
||||
</ui:VisualElement>
|
||||
</ui:UXML>
|
||||
@@ -1,14 +1,14 @@
|
||||
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" editor-extension-mode="False">
|
||||
<Style src="project://database/Assets/Src/UI/TimingUi.uss?fileID=7433441132597879392&guid=cf92f075876ddf7ffb4cd5c59633ad7b&type=3#ShipUi" />
|
||||
<Style src="project://database/Assets/Src/UI/TimingUi.uss?fileID=7433441132597879392&guid=cf92f075876ddf7ffb4cd5c59633ad7b&type=3#TimingUi" />
|
||||
<ui:VisualElement name="shipUi" style="flex-grow: 1; background-color: rgba(0, 0, 0, 0); color: rgb(255, 255, 255); font-size: 28px; -unity-font: url('project://database/Assets/UI%20Toolkit/Fonts/Jura-Medium.otf?fileID=12800000&guid=65648a14640996362a6b0929c723b6e4&type=3#Jura-Medium'); -unity-font-definition: initial;">
|
||||
<ui:VisualElement name="Top" style="flex-grow: 1;" />
|
||||
<ui:VisualElement name="Middle" style="flex-grow: 1; align-items: center;" />
|
||||
<ui:VisualElement name="Bottom" style="flex-grow: 0; background-color: rgba(0, 0, 0, 0.26); flex-direction: column; align-items: stretch; justify-content: flex-end; color: rgb(255, 255, 255); width: 33%; align-self: center;">
|
||||
<ui:VisualElement name="currentLap" style="flex-grow: 1; background-color: rgba(0, 0, 0, 0); flex-direction: row; justify-content: space-between; align-items: auto; width: auto; align-self: stretch; flex-shrink: 0; visibility: visible; display: flex;">
|
||||
<ui:VisualElement name="currentLap" style="flex-grow: 1; background-color: rgba(0, 0, 0, 0); flex-direction: row; justify-content: space-between; align-items: auto; width: auto; align-self: stretch; flex-shrink: 0;">
|
||||
<ui:Label tabindex="-1" text="Time" display-tooltip-when-elided="true" name="timer" style="align-self: flex-end; align-items: auto;" />
|
||||
<ui:Label tabindex="-1" text="1:28.248" display-tooltip-when-elided="true" name="pb" />
|
||||
</ui:VisualElement>
|
||||
<ui:VisualElement name="pbCompare" style="flex-grow: 1; background-color: rgba(0, 0, 0, 0); flex-direction: row; justify-content: space-between; align-items: auto; width: auto; align-self: stretch; flex-shrink: 0;">
|
||||
<ui:VisualElement name="recentLap" style="flex-grow: 1; background-color: rgba(0, 0, 0, 0); flex-direction: row; justify-content: space-between; align-items: auto; width: auto; align-self: stretch; flex-shrink: 0;">
|
||||
<ui:Label tabindex="-1" text="1:24.248" display-tooltip-when-elided="true" name="recentTime" style="align-self: flex-end; align-items: auto;" />
|
||||
<ui:Label tabindex="-1" text="-0.999" display-tooltip-when-elided="true" name="recentDiff" class="green" />
|
||||
</ui:VisualElement>
|
||||
|
||||
+11
-10
@@ -19,7 +19,7 @@ public class TimingUI : MonoBehaviour {
|
||||
Label recentTime;
|
||||
Label recentDiff;
|
||||
|
||||
VisualElement pbCompare;
|
||||
VisualElement recentLap;
|
||||
VisualElement currentLap;
|
||||
VisualElement sectors;
|
||||
|
||||
@@ -30,7 +30,7 @@ public class TimingUI : MonoBehaviour {
|
||||
void Init() {
|
||||
uiDocument = GetComponent<UIDocument>();
|
||||
|
||||
pbCompare = uiDocument.rootVisualElement.Q<VisualElement>("pbCompare");
|
||||
recentLap = uiDocument.rootVisualElement.Q<VisualElement>("recentLap");
|
||||
currentLap = uiDocument.rootVisualElement.Q<VisualElement>("currentLap");
|
||||
sectors = uiDocument.rootVisualElement.Q<VisualElement>("sectors");
|
||||
|
||||
@@ -41,7 +41,7 @@ public class TimingUI : MonoBehaviour {
|
||||
pb.text = "-";
|
||||
|
||||
|
||||
pbCompare.AddToClassList("hidden");
|
||||
recentLap.AddToClassList("hidden");
|
||||
}
|
||||
|
||||
void FixedUpdate() {
|
||||
@@ -76,17 +76,18 @@ public class TimingUI : MonoBehaviour {
|
||||
|
||||
sectors.Add(l);
|
||||
}
|
||||
|
||||
// if (timing.recentLap != null) ShowRecentLap()
|
||||
}
|
||||
|
||||
// yadad yadad
|
||||
void ShowRecentLap() {
|
||||
public void ShowRecentLap(Lap lap) {
|
||||
currentLap.AddToClassList("hidden");
|
||||
pbCompare.RemoveFromClassList("hidden");
|
||||
recentLap.RemoveFromClassList("hidden");
|
||||
recentTime.text = lap.ToString();
|
||||
recentDiff.text = lap.ToString();
|
||||
}
|
||||
|
||||
recentTime.text = timing.recentLap.ToString();
|
||||
// recentDiff = yadad
|
||||
public void HideRecentLap() {
|
||||
currentLap.RemoveFromClassList("hidden");
|
||||
recentLap.AddToClassList("hidden");
|
||||
}
|
||||
|
||||
Label SectorLabel(SectorTime s) {
|
||||
|
||||
@@ -10,24 +10,6 @@
|
||||
letter-spacing: 24px;
|
||||
}
|
||||
|
||||
#list-entry {
|
||||
height: 41px;
|
||||
align-items: flex-start;
|
||||
justify-content: center;
|
||||
padding-left: 10px;
|
||||
background-color: rgb(170, 89, 57);
|
||||
border-color: rgb(49, 26, 17);
|
||||
border-width: 2px;
|
||||
border-radius: 15px;
|
||||
}
|
||||
|
||||
#character-name {
|
||||
|
||||
-unity-font-style: bold;
|
||||
font-size: 18px;
|
||||
color: rgb(49, 26, 17);
|
||||
}
|
||||
|
||||
.green {
|
||||
color: var(--green);
|
||||
}
|
||||
@@ -46,4 +28,4 @@
|
||||
|
||||
.hidden {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user