From 7f3b8a2d13a98b0ff8a192e023525f9900336417 Mon Sep 17 00:00:00 2001 From: bookdude13 Date: Thu, 9 Jan 2025 15:53:58 -0600 Subject: [PATCH] Fix refresh of favorites/experiences, now experiences section works and adding to favorites doesn't return to favorites --- .../AbstractPlaylistMenuMonoBehavior.cs | 7 ++-- .../MainMenuPlaylistMenuMonoBehavior.cs | 32 +++++++++---------- .../MultiplayerPlaylistMenuMonoBehavior.cs | 10 +++++- SRPlaylistManager/SRPlaylistManager.cs | 2 +- 4 files changed, 30 insertions(+), 21 deletions(-) diff --git a/SRPlaylistManager/MonoBehavior/AbstractPlaylistMenuMonoBehavior.cs b/SRPlaylistManager/MonoBehavior/AbstractPlaylistMenuMonoBehavior.cs index 6fd9e6a..5c3050a 100644 --- a/SRPlaylistManager/MonoBehavior/AbstractPlaylistMenuMonoBehavior.cs +++ b/SRPlaylistManager/MonoBehavior/AbstractPlaylistMenuMonoBehavior.cs @@ -35,7 +35,7 @@ protected virtual void OnMenuClose(GameObject toHide) toHide.SetActive(true); } - private void LogVerbose(string message) + protected void LogVerbose(string message) { if (SRPlaylistManager.VERBOSE_LOGS) { @@ -126,10 +126,11 @@ public bool RefreshCurrentPlaylistView() LogVerbose("Current playlist idx: " + controller.CurrentPlaylistIndex); LogVerbose("Current selected playlist: " + controller.CurrentSelectedPlaylist?.Name); LogVerbose("Current selection type: " + controller.CurrentSongSelectionType); + // Refresh currently selected playlist view if (controller.CurrentPlaylistIndex >= 0) { - if (controller.CurrentSelectedPlaylist.ShowFavorites) + if (controller.CurrentSongSelectionType == Il2CppUtil.Data.SongSelectionType.FAVORITES) { // Favorites playlist logic LogVerbose("ShowFavorites"); @@ -144,7 +145,7 @@ public bool RefreshCurrentPlaylistView() controller.Interface__OnPlaylistScrollItemClick(0); return true; } - else if (controller.CurrentSelectedPlaylist.ShowAllExperiences) + else if (controller.CurrentSongSelectionType == Il2CppUtil.Data.SongSelectionType.EXPERIENCES) { LogVerbose("ShowAllExperiences"); controller.Interface__ShowExperiencesShelf(); diff --git a/SRPlaylistManager/MonoBehavior/MainMenuPlaylistMenuMonoBehavior.cs b/SRPlaylistManager/MonoBehavior/MainMenuPlaylistMenuMonoBehavior.cs index 82975a2..79a096a 100644 --- a/SRPlaylistManager/MonoBehavior/MainMenuPlaylistMenuMonoBehavior.cs +++ b/SRPlaylistManager/MonoBehavior/MainMenuPlaylistMenuMonoBehavior.cs @@ -23,24 +23,24 @@ protected override GameObject GetToggledView() protected override void OnMenuClose(GameObject toHide) { // Try to open center view again - _logger.Msg("Menu close, showing center view again"); + LogVerbose("Menu close, showing center view again"); toHide.SetActive(true); // Now that we're visible again, refresh the playlist view's visuals if needed - _logger.Msg("Refreshing playlist view"); + LogVerbose("Refreshing playlist view"); bool isFixedRefresh = RefreshCurrentPlaylistView(); // Select at the current index, if any // Different checks for fixed playlists/views var currentPlist = PlaylistManagementController.GetInstance?.CurrentSelectedPlaylist; - _logger.Msg($"Current plist {currentPlist.Name}, fixed reset? {isFixedRefresh}"); - _logger.Msg($"Current plist idx {PlaylistManagementController.GetInstance.CurrentPlaylistIndex}"); - _logger.Msg($"Current plist song idx {PlaylistManagementController.GetInstance.CurrentPlaylistSongIndex}"); - _logger.Msg($"Current plist current song idx {PlaylistManagementController.GetInstance.CurrentSelectedPlaylist.CurrentIndex}"); + LogVerbose($"Current plist {currentPlist.Name}, fixed reset? {isFixedRefresh}"); + LogVerbose($"Current plist idx {PlaylistManagementController.GetInstance.CurrentPlaylistIndex}"); + LogVerbose($"Current plist song idx {PlaylistManagementController.GetInstance.CurrentPlaylistSongIndex}"); + LogVerbose($"Current plist current song idx {PlaylistManagementController.GetInstance.CurrentSelectedPlaylist.CurrentIndex}"); if (isFixedRefresh) { // No easy way to check bounds, so just try and hope - _logger.Msg("Fixed playlist, selecting song idx " + songPlaylistIndexBeforeOpen); + LogVerbose("Fixed playlist, selecting song idx " + songPlaylistIndexBeforeOpen); if (songPlaylistIndexBeforeOpen >= 0) { try @@ -63,33 +63,33 @@ protected override void OnMenuClose(GameObject toHide) if (songPlaylistIndexBeforeOpen > currPlaylistSongCount - 1) { songPlaylistIndexBeforeOpen = currPlaylistSongCount - 1; - _logger.Msg("Index too big, changed to " + songPlaylistIndexBeforeOpen); + LogVerbose("Index too big, changed to " + songPlaylistIndexBeforeOpen); } if (songPlaylistIndexBeforeOpen < 0) { - _logger.Msg("Index out of range, not clicking song"); + LogVerbose("Index out of range, not clicking song"); } else { - _logger.Msg($"Non-fixed playlist, clicking song at index {songPlaylistIndexBeforeOpen}, count is {currPlaylistSongCount}"); - foreach (var song in currentPlist.Songs) - { - _logger.Msg($" Playlist song {song.name} {song.author} {song.hash} {song.trackDuration} {song.addedTime}"); - } + LogVerbose($"Non-fixed playlist, clicking song at index {songPlaylistIndexBeforeOpen}, count is {currPlaylistSongCount}"); + //foreach (var song in currentPlist.Songs) + //{ + // LogVerbose($" Playlist song {song.name} {song.author} {song.hash} {song.trackDuration} {song.addedTime}"); + //} SongSelectionManager.GetInstance?.OnSongItemClicked(songPlaylistIndexBeforeOpen); } } // Now that the extra click has happened, make sure the center view is still visible - _logger.Msg("Second check for center view visible"); + LogVerbose("Second check for center view visible"); toHide.SetActive(true); // Resume audio // Sometimes throws error when song in current playlist is removed in other playlists. // Not sure why, so leaving it as-is for now - _logger.Msg($"Selected song: {SongSelectionManager.GetInstance?.SelectedGameTrack?.TrackName}"); + LogVerbose($"Selected song: {SongSelectionManager.GetInstance?.SelectedGameTrack?.TrackName}"); try { SongSelectionManager.GetInstance?.PlayPreviewAudio(true); diff --git a/SRPlaylistManager/MonoBehavior/MultiplayerPlaylistMenuMonoBehavior.cs b/SRPlaylistManager/MonoBehavior/MultiplayerPlaylistMenuMonoBehavior.cs index d5b0daa..26f6de9 100644 --- a/SRPlaylistManager/MonoBehavior/MultiplayerPlaylistMenuMonoBehavior.cs +++ b/SRPlaylistManager/MonoBehavior/MultiplayerPlaylistMenuMonoBehavior.cs @@ -29,7 +29,15 @@ protected override void OnMenuClose(GameObject toHide) // Resume audio _logger.Msg($"Selected song: {SongSelectionManager.GetInstance?.SelectedGameTrack?.name}"); - SongSelectionManager.GetInstance?.PlayPreviewAudio(true); + + try + { + SongSelectionManager.GetInstance?.PlayPreviewAudio(true); + } + catch (Exception) + { + _logger.Error("Failed to play preview audio (happens sometimes)"); + } } } } diff --git a/SRPlaylistManager/SRPlaylistManager.cs b/SRPlaylistManager/SRPlaylistManager.cs index 7bc25f7..20d6f4e 100644 --- a/SRPlaylistManager/SRPlaylistManager.cs +++ b/SRPlaylistManager/SRPlaylistManager.cs @@ -12,7 +12,7 @@ namespace SRPlaylistManager public class SRPlaylistManager : MelonMod { // If set, adds a ton more logs to debug issues - public static bool VERBOSE_LOGS = false; + public static bool VERBOSE_LOGS = true; public static SRPlaylistManager Instance { get; private set; }