Skip to content

Commit

Permalink
Fix refresh of favorites/experiences, now experiences section works a…
Browse files Browse the repository at this point in the history
…nd adding to favorites doesn't return to favorites
  • Loading branch information
bookdude13 committed Jan 9, 2025
1 parent a2b030d commit 7f3b8a2
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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");
Expand All @@ -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();
Expand Down
32 changes: 16 additions & 16 deletions SRPlaylistManager/MonoBehavior/MainMenuPlaylistMenuMonoBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)");
}
}
}
}
2 changes: 1 addition & 1 deletion SRPlaylistManager/SRPlaylistManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand Down

0 comments on commit 7f3b8a2

Please sign in to comment.