Work on upcoming notes, reworked active notes a bit

This commit is contained in:
Thastertyn committed 2024-06-15 21:03:21 +02:00
1 parent e56da61974
commit e1dbbafe99
5 files changed
+139 -16

No files matched your search

+53 -8
View File
@@ -46,6 +46,9 @@ namespace UITypes
Game game;
List<NoteElement> activeNoteElements = new();
public void InitGame(Game game)
{
this.game = game;
@@ -62,7 +65,7 @@ namespace UITypes
leftBackgroundImage = this.Q("GameBackgroundImageLeft");
rightBackgroundImage = this.Q("GameBackgroundImageRight");
leftUpcomingColumn = this.Q("LeftArrowUpcomingColumn");
rightUpcomingColumn = this.Q("RightArrowUpcomingColumn");
upUpcomingColumn = this.Q("UpArrowUpcomingColumn");
@@ -75,12 +78,12 @@ namespace UITypes
rightVisualizer.InitVisualizer("RightBar");
buttonDictionary = new()
{
{ KeyCode.LeftArrow, Left },
{ KeyCode.RightArrow, Right },
{ KeyCode.UpArrow, Up },
{ KeyCode.DownArrow, Down },
};
{
{ KeyCode.LeftArrow, Left },
{ KeyCode.RightArrow, Right },
{ KeyCode.UpArrow, Up },
{ KeyCode.DownArrow, Down },
};
}
public void SetColumnColor(Color32 color)
@@ -103,7 +106,7 @@ namespace UITypes
songTime.text = time;
}
public void UpdateNotes(Note[] notes)
public void UpdateNotes(List<Note> notes)
{
leftActive = notes.Where(note => note.a == "left").Count() > 0;
rightActive = notes.Where(note => note.a == "right").Count() > 0;
@@ -114,6 +117,48 @@ namespace UITypes
rightUpcomingColumn.EnableInClassList("ColumnActive", rightActive);
downUpcomingColumn.EnableInClassList("ColumnActive", downActive);
upUpcomingColumn.EnableInClassList("ColumnActive", upActive);
foreach (var note in notes)
{
NoteElement el = new();
el.Init(note);
if (note.a == "left")
{
leftUpcomingColumn.Add(el);
}
else if (note.a == "right")
{
rightUpcomingColumn.Add(el);
}
else if (note.a == "up")
{
upUpcomingColumn.Add(el);
}
else if (note.a == "down")
{
downUpcomingColumn.Add(el);
}
}
}
public void UpdateMargin(float timestamp)
{
foreach (var note in activeNoteElements)
{
note.UpdateMargin(timestamp);
}
}
public void CheckNoteSelf(float timestamp)
{
foreach (var note in activeNoteElements)
{
if (note.CheckSelf(timestamp))
{
activeNoteElements.Remove(note);
}
}
}
void OnKeyDown(KeyDownEvent ev)
+37
View File
@@ -0,0 +1,37 @@
using System;
using System.Collections;
using System.Collections.Generic;
using BangerTypes;
using UnityEngine;
using UnityEngine.UIElements;
namespace UITypes
{
public class NoteElement : VisualElement
{
[UnityEngine.Scripting.Preserve]
public new class UxmlFactory : UxmlFactory<NoteElement> { }
public Note note;
public void Init(Note note)
{
AddToClassList("NoteElement");
AddToClassList(note.a[..1].ToUpper() + note.a[1..] + "Note");
this.note = note;
}
public void UpdateMargin(float timestamp)
{
style.marginTop = new((note.t - timestamp) / 1000f);
}
public bool CheckSelf(float timestamp)
{
return note.t - timestamp < 0;
}
}
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0faf98c2edf4306b9a433b5d75c9ffa0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: