From 27082a717cd6b7ebd5813cc112a379ccbbbc12a0 Mon Sep 17 00:00:00 2001 From: Thastertyn Date: Sun, 16 Jun 2024 22:07:02 +0200 Subject: [PATCH] Notes now move --- Scripts/Game/Game.cs | 13 +++++++++---- Scripts/UI Types/GameElement.cs | 8 ++++---- Scripts/UI Types/NoteElement.cs | 6 ++++-- UI/Game.uss | 4 ++-- 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/Scripts/Game/Game.cs b/Scripts/Game/Game.cs index 9a65d57..06532ad 100644 --- a/Scripts/Game/Game.cs +++ b/Scripts/Game/Game.cs @@ -51,11 +51,16 @@ public class Game : MonoBehaviour float timestamp = manager.source.time; List newNotes = allNotes.Where(note => note.t >= timestamp && timestamp + 1f <= note.t).ToList(); - newNotes.ForEach(note => activeNotes.Remove(note)); + + foreach (Note note in newNotes) + { + Debug.Log("Removing note"); + Debug.Log(allNotes.Remove(note)); + } - menu.GameElem.CheckNoteSelf(timestamp); - menu.GameElem.UpdateMargin(timestamp); menu.GameElem.UpdateNotes(newNotes); + menu.GameElem.CheckNoteLifetime(timestamp); + menu.GameElem.UpdateMargin(timestamp); } IEnumerator GameLoop() @@ -83,7 +88,7 @@ public class Game : MonoBehaviour { int totalSeconds = (int)manager.source.time; int h = totalSeconds / 3600; - int m = (totalSeconds % 3600) / 60; + int m = totalSeconds % 3600 / 60; int s = totalSeconds % 60; string result = $"{h:D2}:{m:D2}:{s:D2} / {totalDuration}"; diff --git a/Scripts/UI Types/GameElement.cs b/Scripts/UI Types/GameElement.cs index 5a7f348..d6a868e 100644 --- a/Scripts/UI Types/GameElement.cs +++ b/Scripts/UI Types/GameElement.cs @@ -46,7 +46,6 @@ namespace UITypes Game game; - List activeNoteElements = new(); public void InitGame(Game game) @@ -121,7 +120,8 @@ namespace UITypes foreach (var note in notes) { NoteElement el = new(); - el.Init(note); + el.Init(note, leftUpcomingColumn.resolvedStyle.height); + activeNoteElements.Add(el); if (note.a == "left") { @@ -150,9 +150,9 @@ namespace UITypes } } - public void CheckNoteSelf(float timestamp) + public void CheckNoteLifetime(float timestamp) { - foreach (var note in activeNoteElements) + foreach (var note in activeNoteElements.ToList()) { if (note.CheckSelf(timestamp)) { diff --git a/Scripts/UI Types/NoteElement.cs b/Scripts/UI Types/NoteElement.cs index 1f6bf9a..1e6b4de 100644 --- a/Scripts/UI Types/NoteElement.cs +++ b/Scripts/UI Types/NoteElement.cs @@ -14,9 +14,11 @@ namespace UITypes public new class UxmlFactory : UxmlFactory { } public Note note; + public float ColumnHeight; - public void Init(Note note) + public void Init(Note note, float columnHeight) { + this.ColumnHeight = columnHeight; AddToClassList("NoteElement"); AddToClassList(note.a[..1].ToUpper() + note.a[1..] + "Note"); @@ -26,7 +28,7 @@ namespace UITypes public void UpdateMargin(float timestamp) { - style.marginTop = new((note.t - timestamp) / 1000f); + style.marginTop = new(ColumnHeight - (note.t - timestamp) * 1000 - resolvedStyle.height); } public bool CheckSelf(float timestamp) diff --git a/UI/Game.uss b/UI/Game.uss index 5af6ae9..cd64584 100644 --- a/UI/Game.uss +++ b/UI/Game.uss @@ -38,8 +38,8 @@ } .NoteElement { - width: 20%; - height: 20%; + width: 100%; + height: 30%; margin: auto; font-size: 32px; border-radius: 45px;