Initial commit
This commit is contained in:
commit
262601edb8
2025 files changed
+218754
No files matched your search
@@ -0,0 +1,124 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices.WindowsRuntime;
|
||||
using Unity.VisualScripting;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
|
||||
namespace UITypes
|
||||
{
|
||||
|
||||
public class GameElement : VisualElement
|
||||
{
|
||||
[UnityEngine.Scripting.Preserve]
|
||||
public new class UxmlFactory : UxmlFactory<GameElement> { }
|
||||
|
||||
public Button Left { get; set; }
|
||||
public Button Right { get; set; }
|
||||
public Button Up { get; set; }
|
||||
public Button Down { get; set; }
|
||||
|
||||
private Visualizer leftVisualizer;
|
||||
private Visualizer rightVisualizer;
|
||||
|
||||
|
||||
private VisualElement leftUpcomingColumn;
|
||||
private VisualElement rightUpcomingColumn;
|
||||
private VisualElement upUpcomingColumn;
|
||||
public VisualElement downUpcomingColumn;
|
||||
|
||||
private Label score;
|
||||
private Label songTime;
|
||||
|
||||
private VisualElement leftBackgroundImage;
|
||||
private VisualElement rightBackgroundImage;
|
||||
|
||||
Dictionary<KeyCode, Button> buttonDictionary;
|
||||
|
||||
Game game;
|
||||
|
||||
public void InitGame(Game game)
|
||||
{
|
||||
this.game = game;
|
||||
leftVisualizer = this.Q("LeftVisualizer") as Visualizer;
|
||||
rightVisualizer = this.Q("RightVisualizer") as Visualizer;
|
||||
|
||||
Left = this.Q("GameLeftButton") as Button;
|
||||
Right = this.Q("GameRightButton") as Button;
|
||||
Up = this.Q("GameUpButton") as Button;
|
||||
Down = this.Q("GameDownButton") as Button;
|
||||
|
||||
score = this.Q("Score") as Label;
|
||||
songTime = this.Q("TimeLeft") as Label;
|
||||
|
||||
leftBackgroundImage = this.Q("GameBackgroundImageLeft");
|
||||
rightBackgroundImage = this.Q("GameBackgroundImageRight");
|
||||
|
||||
leftUpcomingColumn = this.Q("LeftArrowUpcomingColumn");
|
||||
rightUpcomingColumn = this.Q("RightArrowUpcomingColumn");
|
||||
upUpcomingColumn = this.Q("UpArrowUpcomingColumn");
|
||||
downUpcomingColumn = this.Q("DownArrowUpcomingColumn");
|
||||
|
||||
RegisterCallback<KeyDownEvent>(OnKeyDown, TrickleDown.TrickleDown);
|
||||
RegisterCallback<KeyUpEvent>(OnKeyUp, TrickleDown.TrickleDown);
|
||||
|
||||
leftVisualizer.InitVisualizer("LeftBar");
|
||||
rightVisualizer.InitVisualizer("RightBar");
|
||||
|
||||
buttonDictionary = new()
|
||||
{
|
||||
{ KeyCode.LeftArrow, Left },
|
||||
{ KeyCode.RightArrow, Right },
|
||||
{ KeyCode.UpArrow, Up },
|
||||
{ KeyCode.DownArrow, Down },
|
||||
};
|
||||
}
|
||||
|
||||
public void SetColumnColor(Color32 color)
|
||||
{
|
||||
leftVisualizer.SetBarColor(color);
|
||||
rightVisualizer.SetBarColor(color);
|
||||
}
|
||||
|
||||
public void UpdateVisualizers(float[] specData, float bassStrength)
|
||||
{
|
||||
leftVisualizer.UpdateBars(specData);
|
||||
rightVisualizer.UpdateBars(specData);
|
||||
|
||||
leftBackgroundImage.style.opacity = new StyleFloat(bassStrength);
|
||||
rightBackgroundImage.style.opacity = new StyleFloat(bassStrength);
|
||||
}
|
||||
|
||||
public void UpdateSongTime(string time)
|
||||
{
|
||||
songTime.text = time;
|
||||
}
|
||||
|
||||
void OnKeyDown(KeyDownEvent ev)
|
||||
{
|
||||
if (ev.keyCode == KeyCode.Escape)
|
||||
{
|
||||
game.EscapeClicked();
|
||||
return;
|
||||
}
|
||||
|
||||
buttonDictionary.TryGetValue(ev.keyCode, out Button button);
|
||||
|
||||
if (button == null) return;
|
||||
|
||||
button.AddToClassList("GameButtonClicked");
|
||||
}
|
||||
|
||||
void OnKeyUp(KeyUpEvent ev)
|
||||
{
|
||||
buttonDictionary.TryGetValue(ev.keyCode, out Button button);
|
||||
|
||||
if (button == null) return;
|
||||
|
||||
button.RemoveFromClassList("GameButtonClicked");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7d2b20ef45d368713a506125f1be0a5b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices.WindowsRuntime;
|
||||
using Unity.VisualScripting;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
|
||||
namespace UITypes
|
||||
{
|
||||
|
||||
public class LevelMaker : VisualElement
|
||||
{
|
||||
[UnityEngine.Scripting.Preserve]
|
||||
public new class UxmlFactory : UxmlFactory<LevelMaker> { }
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d5bedf3116d476781940e77954406f5e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,223 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net.Sockets;
|
||||
using System.Text.RegularExpressions;
|
||||
using TagLib;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
using DiscordPresence;
|
||||
using UnityEditor;
|
||||
using MenuAndSongs;
|
||||
using BangerTypes;
|
||||
using System.Diagnostics;
|
||||
|
||||
|
||||
namespace UITypes
|
||||
{
|
||||
|
||||
public class MainMenu : MonoBehaviour
|
||||
{
|
||||
private UIDocument document;
|
||||
|
||||
private Button play;
|
||||
private Button soon;
|
||||
private Button quit;
|
||||
|
||||
private Button back;
|
||||
private Button open;
|
||||
private Button reload;
|
||||
|
||||
private ScrollView scrollView;
|
||||
|
||||
private VisualElement mainMenu;
|
||||
private VisualElement levelSelect;
|
||||
public GameElement GameElem { get; set; }
|
||||
private LevelMaker makerElem;
|
||||
private Game game;
|
||||
|
||||
public string MusicPath { get; set; }
|
||||
string hintFile = "Hint_place_songs_here.txt";
|
||||
|
||||
public Sprite defaultImage;
|
||||
|
||||
private bool songsLoaded = false;
|
||||
|
||||
List<SongEntry> songs = new();
|
||||
|
||||
const string reloadText = "RELOAD ⟳";
|
||||
const string reloadDone = "RELOAD ✔";
|
||||
|
||||
private void AddSongEntry(Song song)
|
||||
{
|
||||
SongEntry entry = new()
|
||||
{
|
||||
Song = song
|
||||
};
|
||||
|
||||
|
||||
UnityEngine.Debug.Log(song.Clip);
|
||||
|
||||
VisualElement entryToBeAdded = entry.InitEntry();
|
||||
UnityEngine.Debug.Log(song.Clip + " Clip");
|
||||
|
||||
UnityEngine.Debug.Log(entryToBeAdded);
|
||||
songs.Add(entry);
|
||||
scrollView.Add(entryToBeAdded);
|
||||
}
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
MusicPath = Application.persistentDataPath + "/Music/";
|
||||
|
||||
document = GetComponent<UIDocument>();
|
||||
game = GetComponent<Game>();
|
||||
|
||||
play = document.rootVisualElement.Q("Play") as Button;
|
||||
soon = document.rootVisualElement.Q("Soon") as Button;
|
||||
quit = document.rootVisualElement.Q("Quit") as Button;
|
||||
back = document.rootVisualElement.Q("Back") as Button;
|
||||
open = document.rootVisualElement.Q("Open") as Button;
|
||||
reload = document.rootVisualElement.Q("Reload") as Button;
|
||||
|
||||
play.style.backgroundColor = new Color(0, 0, 0, 0);
|
||||
soon.style.backgroundColor = new Color(0, 0, 0, 0);
|
||||
quit.style.backgroundColor = new Color(0, 0, 0, 0);
|
||||
back.style.backgroundColor = new Color(0, 0, 0, 0);
|
||||
open.style.backgroundColor = new Color(0, 0, 0, 0);
|
||||
reload.style.backgroundColor = new Color(0, 0, 0, 0);
|
||||
|
||||
scrollView = document.rootVisualElement.Q("scroll") as ScrollView;
|
||||
|
||||
mainMenu = document.rootVisualElement.Q("menu");
|
||||
levelSelect = document.rootVisualElement.Q("levels");
|
||||
GameElem = document.rootVisualElement.Q("game") as GameElement;
|
||||
|
||||
|
||||
play.RegisterCallback<ClickEvent>(Play);
|
||||
quit.RegisterCallback<ClickEvent>(Quit);
|
||||
|
||||
back.RegisterCallback<ClickEvent>(Back);
|
||||
open.RegisterCallback<ClickEvent>(Open);
|
||||
reload.RegisterCallback<ClickEvent>(Reload);
|
||||
|
||||
// DateTimeOffset dto = new DateTimeOffset(1970, 1, 1, 0, 0, 0, TimeSpan.Zero);
|
||||
|
||||
// PresenceManager.UpdatePresence("In Main Menu", state: "Picking a banger", start: 100000, end: 1000000000);
|
||||
}
|
||||
|
||||
private void Open(ClickEvent evt)
|
||||
{
|
||||
Process.Start(MusicPath);
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
GameElem.InitGame(game);
|
||||
|
||||
mainMenu.style.display = DisplayStyle.Flex;
|
||||
levelSelect.style.display = DisplayStyle.None;
|
||||
GameElem.style.display = DisplayStyle.None;
|
||||
|
||||
}
|
||||
|
||||
private void Play(ClickEvent evt)
|
||||
{
|
||||
mainMenu.style.display = DisplayStyle.None;
|
||||
levelSelect.style.display = DisplayStyle.Flex;
|
||||
|
||||
LoadSongs();
|
||||
}
|
||||
|
||||
public void PlaySong(UITypes.SongEntry song)
|
||||
{
|
||||
GameElem.style.display = DisplayStyle.Flex;
|
||||
levelSelect.style.display = DisplayStyle.None;
|
||||
|
||||
game.LoadSong(song);
|
||||
game.Play();
|
||||
}
|
||||
|
||||
public void Quit(ClickEvent evt)
|
||||
{
|
||||
Application.Quit();
|
||||
}
|
||||
|
||||
public void Escape()
|
||||
{
|
||||
GameElem.style.display = DisplayStyle.None;
|
||||
levelSelect.style.display = DisplayStyle.Flex;
|
||||
}
|
||||
|
||||
public void Back(ClickEvent evt)
|
||||
{
|
||||
mainMenu.style.display = DisplayStyle.Flex;
|
||||
levelSelect.style.display = DisplayStyle.None;
|
||||
}
|
||||
|
||||
public void Reload(ClickEvent evt)
|
||||
{
|
||||
songsLoaded = false;
|
||||
DisposeOldSongs();
|
||||
LoadSongs();
|
||||
StartCoroutine(ChangeReloadButtonText());
|
||||
}
|
||||
|
||||
private void LoadSongs()
|
||||
{
|
||||
if (songsLoaded)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Directory.Exists(MusicPath))
|
||||
{
|
||||
Directory.CreateDirectory(MusicPath);
|
||||
}
|
||||
|
||||
if (!System.IO.File.Exists(MusicPath + "/" + hintFile))
|
||||
{
|
||||
System.IO.File.Create(MusicPath + "/" + hintFile);
|
||||
}
|
||||
|
||||
List<string> ls = Directory
|
||||
.GetFiles(MusicPath)
|
||||
.Where(file => Regex.IsMatch(file, ".*\\.rhys"))
|
||||
.ToList();
|
||||
|
||||
foreach (string file in ls)
|
||||
{
|
||||
Song song = FindSongs.ParseRHYS(file, defaultImage);
|
||||
AddSongEntry(song);
|
||||
}
|
||||
|
||||
songsLoaded = true;
|
||||
}
|
||||
|
||||
private void DisposeOldSongs()
|
||||
{
|
||||
foreach (SongEntry song in songs)
|
||||
{
|
||||
song.RemoveFromHierarchy();
|
||||
}
|
||||
|
||||
songs = new();
|
||||
}
|
||||
|
||||
IEnumerator ChangeReloadButtonText()
|
||||
{
|
||||
float timeoutDuration = 0.5f;
|
||||
|
||||
reload.text = reloadDone;
|
||||
reload.style.color = Color.green;
|
||||
// Wait for the specified timeout duration
|
||||
yield return new WaitForSeconds(timeoutDuration);
|
||||
|
||||
reload.text = reloadText;
|
||||
reload.style.color = Color.white;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ab55de669b89b5585841dd248e952b07
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,100 @@
|
||||
using BangerTypes;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
|
||||
namespace UITypes
|
||||
{
|
||||
public class SongEntry : Button
|
||||
{
|
||||
[UnityEngine.Scripting.Preserve]
|
||||
public new class UxmlFactory : UxmlFactory<SongEntry> { }
|
||||
|
||||
public Song Song { get; set; }
|
||||
|
||||
private MainMenu menu;
|
||||
|
||||
public VisualElement InitEntry()
|
||||
{
|
||||
menu = GameObject.FindWithTag("MenuUI").GetComponent<MainMenu>();
|
||||
|
||||
AddToClassList("songEntry");
|
||||
|
||||
text = "";
|
||||
|
||||
VisualElement contentWrapper = new();
|
||||
|
||||
Image coverImage = new();
|
||||
VisualElement labelWrapper = new();
|
||||
|
||||
Label titleLabel = new(), artistLabel = new(), albumLabel = new(), durationLabel = new();
|
||||
|
||||
titleLabel.AddToClassList("SongEntryLabel");
|
||||
artistLabel.AddToClassList("SongEntryLabel");
|
||||
albumLabel.AddToClassList("SongEntryLabel");
|
||||
durationLabel.AddToClassList("SongEntryLabel");
|
||||
|
||||
contentWrapper.AddToClassList("SongEntryContentWrapper");
|
||||
|
||||
coverImage.AddToClassList("SongEntryCoverImage");
|
||||
coverImage.image = Song.CoverArt.texture;
|
||||
|
||||
Song.AverageColor = GetAverage(Song.CoverArt);
|
||||
|
||||
coverImage.style.backgroundColor = new StyleColor(Song.AverageColor);
|
||||
|
||||
labelWrapper.AddToClassList("SongEntryLabelWrapper");
|
||||
|
||||
titleLabel.text = Song.Title;
|
||||
artistLabel.text = Song.Artist;
|
||||
albumLabel.text = Song.Album;
|
||||
durationLabel.text = Song.Duration;
|
||||
|
||||
this.Add(contentWrapper);
|
||||
|
||||
labelWrapper.Add(titleLabel);
|
||||
labelWrapper.Add(artistLabel);
|
||||
labelWrapper.Add(albumLabel);
|
||||
labelWrapper.Add(durationLabel);
|
||||
|
||||
contentWrapper.Add(coverImage);
|
||||
contentWrapper.Add(labelWrapper);
|
||||
|
||||
RegisterCallback<ClickEvent>(LoadSong);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public void LoadSong(ClickEvent evt)
|
||||
{
|
||||
menu.PlaySong(this);
|
||||
}
|
||||
|
||||
Color32 GetAverage(Sprite image)
|
||||
{
|
||||
Color32[] pixels = image.texture.GetPixels32();
|
||||
|
||||
int totalR = 0;
|
||||
int totalG = 0;
|
||||
int totalB = 0;
|
||||
|
||||
foreach (Color32 pixel in pixels)
|
||||
{
|
||||
totalR += pixel.r;
|
||||
totalG += pixel.g;
|
||||
totalB += pixel.b;
|
||||
}
|
||||
|
||||
int pixelCount = pixels.Length;
|
||||
int averageR = totalR / pixelCount;
|
||||
int averageG = totalG / pixelCount;
|
||||
int averageB = totalB / pixelCount;
|
||||
|
||||
Color averageColor = new Color32((byte)averageR, (byte)averageG, (byte)averageB, 255);
|
||||
|
||||
return averageColor;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2131c7fbe221f7549b1645ea7225740f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace UITypes
|
||||
{
|
||||
|
||||
public class Visualizer : VisualElement
|
||||
{
|
||||
[UnityEngine.Scripting.Preserve]
|
||||
public new class UxmlFactory : UxmlFactory<Visualizer> { }
|
||||
|
||||
private List<VisualElement> bars = new();
|
||||
|
||||
const int barCount = 128;
|
||||
|
||||
public void InitVisualizer(string style)
|
||||
{
|
||||
for (int i = 0; i < barCount; i++)
|
||||
{
|
||||
VisualElement element = new();
|
||||
element.AddToClassList("Bar");
|
||||
element.AddToClassList(style);
|
||||
bars.Add(element);
|
||||
Add(element);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetBarColor(Color32 color)
|
||||
{
|
||||
bars.ForEach(bar => bar.style.backgroundColor = new StyleColor(color));
|
||||
}
|
||||
|
||||
public void UpdateBars(float[] spectrumData)
|
||||
{
|
||||
for (int i = 0; i < barCount; i++)
|
||||
{
|
||||
VisualElement elem = bars[i];
|
||||
|
||||
float width = Math.Min(spectrumData[i] * 50, 50);
|
||||
elem.style.width = Length.Percent(width);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2e3c69f88fdd3084a829ace65442beed
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in new issue
Block a user