diff --git a/Assets/Scenes/MenuScene.unity b/Assets/Scenes/MenuScene.unity index 6eacd5e92..0b56cafa6 100644 --- a/Assets/Scenes/MenuScene.unity +++ b/Assets/Scenes/MenuScene.unity @@ -12427,7 +12427,7 @@ MonoBehaviour: m_Calls: - m_Target: {fileID: 874813134} m_TargetAssemblyTypeName: YARG.UI.MainMenu, Assembly-CSharp - m_MethodName: ShowMainMenu + m_MethodName: ShowSongSelect m_Mode: 1 m_Arguments: m_ObjectArgument: {fileID: 0} @@ -16964,7 +16964,7 @@ MonoBehaviour: m_Calls: - m_Target: {fileID: 874813134} m_TargetAssemblyTypeName: YARG.UI.MainMenu, Assembly-CSharp - m_MethodName: ShowMainMenu + m_MethodName: ShowSongSelect m_Mode: 1 m_Arguments: m_ObjectArgument: {fileID: 0} diff --git a/Assets/Script/GameManager.cs b/Assets/Script/GameManager.cs index 11d9fd8d6..7f379d631 100644 --- a/Assets/Script/GameManager.cs +++ b/Assets/Script/GameManager.cs @@ -37,6 +37,8 @@ public class GameManager : MonoBehaviour { private AudioMixerGroup vocalGroup; public SceneIndex CurrentScene { get; private set; } = SceneIndex.PERSISTANT; + + public SongEntry SelectedSong { get; set; } private void Awake() { Instance = this; diff --git a/Assets/Script/PlayMode/Play.cs b/Assets/Script/PlayMode/Play.cs index 199e5f872..7adb6e15c 100644 --- a/Assets/Script/PlayMode/Play.cs +++ b/Assets/Script/PlayMode/Play.cs @@ -14,7 +14,6 @@ using YARG.Settings; using YARG.Song; using YARG.UI; -using YARG.Util; using YARG.Venue; namespace YARG.PlayMode { @@ -28,8 +27,6 @@ public static Play Instance { public const float SONG_START_OFFSET = -2f; - public static SongEntry song = null; - public delegate void BeatAction(); public static event BeatAction BeatEvent; @@ -41,7 +38,7 @@ public static Play Instance { public static event PauseStateChangeAction OnPauseToggle; [SerializeField] - private RenderTexture backgroundRenderTexture; + private GameObject soundAudioPrefab; public bool SongStarted { get; @@ -89,20 +86,12 @@ public bool Paused { GameManager.AudioManager.Pause(); - if (GameUI.Instance.videoPlayer.enabled) { - GameUI.Instance.videoPlayer.Pause(); - } } else { Time.timeScale = 1f; GameManager.AudioManager.Play(); - - if (GameUI.Instance.videoPlayer.enabled) { - GameUI.Instance.videoPlayer.Play(); - } } - - OnPauseToggle?.Invoke(_paused); + OnPauseToggle(_paused); } } @@ -114,8 +103,6 @@ private void Awake() { ScoreKeeper.Reset(); StarScoreKeeper.Reset(); - backgroundRenderTexture.ClearTexture(); - // Song StartSong(); } @@ -127,10 +114,10 @@ private void StartSong() { bool isSpeedUp = Math.Abs(speed - 1) > float.Epsilon; // Load MOGG if CON, otherwise load stems - if (song is ExtractedConSongEntry rawConSongEntry) { + if (GameManager.Instance.SelectedSong is ExtractedConSongEntry rawConSongEntry) { GameManager.AudioManager.LoadMogg(rawConSongEntry, isSpeedUp); } else { - var stems = AudioHelpers.GetSupportedStems(song.Location); + var stems = AudioHelpers.GetSupportedStems(GameManager.Instance.SelectedSong.Location); GameManager.AudioManager.LoadSong(stems, isSpeedUp); } @@ -172,8 +159,32 @@ private void StartSong() { i++; } - // Load background (venue, video, image, etc.) - LoadBackground(); + // Load Background + string backgroundPath = Path.Combine(GameManager.Instance.SelectedSong.Location, "bg.yarground"); + string mp4Path = Path.Combine(GameManager.Instance.SelectedSong.Location, "bg.mp4"); + string pngPath = Path.Combine(GameManager.Instance.SelectedSong.Location, "bg.png"); + + if (File.Exists(backgroundPath)) { + // First check for a yarground + var bundle = AssetBundle.LoadFromFile(backgroundPath); + var bg = bundle.LoadAsset("Assets/_Background.prefab"); + var bgInstance = Instantiate(bg); + + bgInstance.GetComponent().Bundle = bundle; + } else if (File.Exists(mp4Path)) { + // If not, check for a video + GameUI.Instance.videoPlayer.url = mp4Path; + GameUI.Instance.videoPlayer.enabled = true; + GameUI.Instance.videoPlayer.Play(); + } else if (File.Exists(pngPath)) { + // Otherwise, load an image + var png = ImageHelper.LoadTextureFromFile(pngPath); + + GameUI.Instance.background.texture = png; + } else { + // No background file, we load a random video + // TODO: Add custom videos folder, load here + } SongStarted = true; @@ -192,74 +203,16 @@ private void StartSong() { break; } } - - OnSongStart?.Invoke(song); - } - - private void LoadBackground() { - // Try a yarground first - - string backgroundPath = Path.Combine(song.Location, "bg.yarground"); - if (File.Exists(backgroundPath)) { - var bundle = AssetBundle.LoadFromFile(backgroundPath); - - // KEEP THIS PATH LOWERCASE - // Breaks things for other platforms, because Unity - var bg = bundle.LoadAsset("assets/_background.prefab"); - - var bgInstance = Instantiate(bg); - - bgInstance.GetComponent().Bundle = bundle; - return; - } - - // Next, a video - - string[] videoPaths = { - "bg.mp4", - "bg.mov", - "bg.webm", - }; - - foreach (var file in videoPaths) { - var path = Path.Combine(song.Location, file); - - if (File.Exists(path)) { - GameUI.Instance.videoPlayer.url = path; - GameUI.Instance.videoPlayer.enabled = true; - - return; - } - } - - // Finally, an image - - string[] imagePaths = { - "bg.png", - "bg.jpg", - "bg.jpeg", - }; - - foreach (var file in imagePaths) { - var path = Path.Combine(song.Location, file); - - if (File.Exists(path)) { - var png = ImageHelper.LoadTextureFromFile(path); - - GameUI.Instance.background.texture = png; - return; - } - } } private void LoadChart() { // Add main file var files = new List { - Path.Combine(song.Location, song.NotesFile) + Path.Combine(GameManager.Instance.SelectedSong.Location, GameManager.Instance.SelectedSong.NotesFile) }; // Look for upgrades and add - // var upgradeFolder = new DirectoryInfo(Path.Combine(song.RootFolder, "yarg_upgrade")); + // var upgradeFolder = new DirectoryInfo(Path.Combine(GameManager.Instance.ChosenSong.RootFolder, "yarg_upgrade")); // if (upgradeFolder.Exists) { // foreach (var midi in upgradeFolder.GetFiles("*.mid")) { // files.Add(midi.FullName); @@ -269,18 +222,18 @@ private void LoadChart() { // Parse MoonSong moonSong = null; - if (song.NotesFile.EndsWith(".chart")) { + if (GameManager.Instance.SelectedSong.NotesFile.EndsWith(".chart")) { Debug.Log("Reading .chart file"); moonSong = ChartReader.ReadChart(files[0]); } chart = new YargChart(moonSong); - if (song.NotesFile.EndsWith(".mid")) { + if (GameManager.Instance.SelectedSong.NotesFile.EndsWith(".mid")) { // Parse - var parser = new MidiParser(song, files.ToArray()); + var parser = new MidiParser(GameManager.Instance.SelectedSong, files.ToArray()); chart.InitializeArrays(); parser.Parse(chart); - } else if (song.NotesFile.EndsWith(".chart")) { + } else if (GameManager.Instance.SelectedSong.NotesFile.EndsWith(".chart")) { var handler = new BeatHandler(moonSong); handler.GenerateBeats(); chart.beats = handler.Beats; @@ -298,10 +251,6 @@ private IEnumerator StartAudio() { yield return null; } - if (GameUI.Instance.videoPlayer.enabled) { - GameUI.Instance.videoPlayer.Play(); - } - GameManager.AudioManager.Play(); audioStarted = true; } @@ -427,7 +376,7 @@ private void Update() { } } - // End song + // End GameManager.Instance.ChosenSong if (realSongTime >= SongLength) { MainMenu.isPostSong = true; Exit(); @@ -491,15 +440,13 @@ public void Exit() { GameManager.AudioManager.UnloadSong(); // Call events - OnSongEnd?.Invoke(song); + OnSongEnd?.Invoke(GameManager.Instance.SelectedSong); // Unpause just in case Time.timeScale = 1f; - backgroundRenderTexture.ClearTexture(); _tracks.Clear(); - OnSongEnd?.Invoke(song); GameManager.Instance.LoadScene(SceneIndex.MENU); } diff --git a/Assets/Script/UI/DifficultySelect.cs b/Assets/Script/UI/DifficultySelect.cs index 6c68cd549..8311d7187 100644 --- a/Assets/Script/UI/DifficultySelect.cs +++ b/Assets/Script/UI/DifficultySelect.cs @@ -205,7 +205,6 @@ private void IncreasePlayerIndex() { } // Play song - Play.song = MainMenu.Instance.chosenSong; GameManager.Instance.LoadScene(SceneIndex.PLAY); } else { UpdateInstrument(); @@ -224,7 +223,9 @@ private void UpdateInstrument() { // Get available instruments var availableInstruments = allInstruments - .Where(instrument => MainMenu.Instance.chosenSong.HasInstrument(instrument)).ToList(); + .Where(instrument => GameManager.Instance.SelectedSong.HasInstrument(instrument)).ToList(); + + Debug.Log(GameManager.Instance.SelectedSong.AvailableParts); // Force add pro drums and five lane if (availableInstruments.Contains(Instrument.DRUMS)) { @@ -242,25 +243,16 @@ private void UpdateInstrument() { // Filter out to only allowed instruments availableInstruments.RemoveAll(i => !player.inputStrategy.GetAllowedInstruments().Contains(i)); - bool showSitOut = availableInstruments.Count <= 0 || PlayerManager.players.Count > 1; - - optionCount = availableInstruments.Count + (showSitOut ? 1 : 0); - if (showSitOut) { - optionCount++; - } + optionCount = availableInstruments.Count + 1; // Add to options - var ops = new string[optionCount]; + var ops = new string[availableInstruments.Count + 1]; instruments = new string[availableInstruments.Count]; for (int i = 0; i < instruments.Length; i++) { instruments[i] = availableInstruments[i].ToStringName(); ops[i] = availableInstruments[i].ToLocalizedName(); } - - // Add sit out (only if there are more than 1 player) - if (showSitOut) { - ops[^1] = "Sit Out"; - } + ops[^1] = "Sit Out"; // Set text and sprites for (int i = 0; i < 6; i++) { @@ -294,7 +286,7 @@ private void UpdateDifficulty(string chosenInstrument, bool showExpertPlus) { // Get the available difficulties var availableDifficulties = new List(); for (int i = 0; i < (int) Difficulty.EXPERT_PLUS; i++) { - if (!MainMenu.Instance.chosenSong.HasPart(instrument, (Difficulty) i)) { + if (!GameManager.Instance.SelectedSong.HasPart(instrument, (Difficulty) i)) { continue; } availableDifficulties.Add((Difficulty) i); diff --git a/Assets/Script/UI/GameUI.cs b/Assets/Script/UI/GameUI.cs index be1d0320b..f25133198 100644 --- a/Assets/Script/UI/GameUI.cs +++ b/Assets/Script/UI/GameUI.cs @@ -38,11 +38,11 @@ private void Awake() { private void Start() { if (Play.speed == 1f) { - songTitle.text = $"{Play.song.Name}"; - bandName.text = $"{Play.song.Artist}"; + songTitle.text = $"{GameManager.Instance.SelectedSong.Name}"; + bandName.text = $"{GameManager.Instance.SelectedSong.Artist}"; } else { - songTitle.text = $"{Play.song.Name} ({Play.speed * 100}%)"; - bandName.text = $"{Play.song.Artist}"; + songTitle.text = $"{GameManager.Instance.SelectedSong.Name} ({Play.speed * 100}%)"; + bandName.text = $"{GameManager.Instance.SelectedSong.Artist}"; } } diff --git a/Assets/Script/UI/MainMenu.cs b/Assets/Script/UI/MainMenu.cs index 21bdb13ac..ec0ba671e 100644 --- a/Assets/Script/UI/MainMenu.cs +++ b/Assets/Script/UI/MainMenu.cs @@ -22,8 +22,6 @@ private enum ButtonIndex { EXIT } - public SongEntry chosenSong = null; - [SerializeField] private Canvas mainMenu; [SerializeField] diff --git a/Assets/Script/UI/MusicLibrary/SongSelection.cs b/Assets/Script/UI/MusicLibrary/SongSelection.cs index 93da4f8b6..8a8424518 100644 --- a/Assets/Script/UI/MusicLibrary/SongSelection.cs +++ b/Assets/Script/UI/MusicLibrary/SongSelection.cs @@ -56,6 +56,10 @@ private set { _selectedIndex -= _songs.Count; } + if (_songs[value] is SongViewType song) { + GameManager.Instance.SelectedSong = song.SongEntry; + } + UpdateScrollbar(); UpdateSongViews(); } @@ -301,7 +305,17 @@ public void UpdateSearch() { _songs.Clear(); } - SelectedIndex = 1; + if (GameManager.Instance.SelectedSong == null) { + SelectedIndex = 1; + } else { + var index = _songs.FindIndex(song => { + var songType = song as SongViewType; + return songType != null && songType.SongEntry == GameManager.Instance.SelectedSong; + }); + + SelectedIndex = Mathf.Max(1, index); + } + UpdateSongViews(); UpdateScrollbar(); } diff --git a/Assets/Script/UI/MusicLibrary/ViewTypes/SongViewType.cs b/Assets/Script/UI/MusicLibrary/ViewTypes/SongViewType.cs index 5240b783c..4e3d8c7f1 100644 --- a/Assets/Script/UI/MusicLibrary/ViewTypes/SongViewType.cs +++ b/Assets/Script/UI/MusicLibrary/ViewTypes/SongViewType.cs @@ -54,7 +54,6 @@ public override void SecondaryTextClick() { public override void PrimaryButtonClick() { base.PrimaryButtonClick(); - MainMenu.Instance.chosenSong = SongEntry; MainMenu.Instance.ShowPreSong(); } diff --git a/Assets/Script/UI/PostSong.cs b/Assets/Script/UI/PostSong.cs index 61bea137e..ac4462bd7 100644 --- a/Assets/Script/UI/PostSong.cs +++ b/Assets/Script/UI/PostSong.cs @@ -19,9 +19,9 @@ public class PostSong : MonoBehaviour { private void OnEnable() { if (Play.speed == 1f) { - header.text = $"{Play.song.Name} - {Play.song.Artist}"; + header.text = $"{GameManager.Instance.SelectedSong.Name} - {GameManager.Instance.SelectedSong.Artist}"; } else { - header.text = $"{Play.song.Name} ({Play.speed * 100}% speed) - {Play.song.Artist}"; + header.text = $"{GameManager.Instance.SelectedSong.Name} ({Play.speed * 100}% speed) - {GameManager.Instance.SelectedSong.Artist}"; } // Create a score to push @@ -32,7 +32,7 @@ private void OnEnable() { highestPercent = new(), highestScore = new() }; - var oldScore = ScoreManager.GetScore(Play.song); + var oldScore = ScoreManager.GetScore(GameManager.Instance.SelectedSong); HashSet highScores = new(); HashSet disqualified = new(); @@ -80,7 +80,7 @@ private void OnEnable() { } // Push! - ScoreManager.PushScore(Play.song, songScore); + ScoreManager.PushScore(GameManager.Instance.SelectedSong, songScore); // Show score sections foreach (var player in PlayerManager.players) { @@ -111,7 +111,7 @@ private void OnDisable() { private void Update() { // Enter if (Keyboard.current.enterKey.wasPressedThisFrame) { - MainMenu.Instance.ShowMainMenu(); + MainMenu.Instance.ShowSongSelect(); } } @@ -121,7 +121,7 @@ private void OnGenericNavigation(NavigationType navigationType, bool pressed) { } if (navigationType == NavigationType.PRIMARY) { - MainMenu.Instance.ShowMainMenu(); + MainMenu.Instance.ShowSongSelect(); } } }