Skip to content

Commit

Permalink
Bump to 2.1.0, fixes for UI changes for main menu, better handling of…
Browse files Browse the repository at this point in the history
… missing custom songs causing index errors
  • Loading branch information
bookdude13 committed Jan 9, 2025
1 parent 6b1b56e commit a2b030d
Show file tree
Hide file tree
Showing 13 changed files with 378 additions and 105 deletions.
2 changes: 1 addition & 1 deletion SRModCore
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,62 @@
using Il2CppTMPro;
using Il2CppUtil.Controller;
using Il2Cpp;
using SRModCore;
using UnityEngine;
using static MelonLoader.MelonLogger;

namespace SRPlaylistManager.Harmony
{
[HarmonyPatch(typeof(PlaylistManagementController), nameof(PlaylistManagementController.TryDisplayCorrectRemoveFavoriteButton))]
public class Patch_PlaylistManagementController_TryDisplayCorrectRemoveFavoriteButton
{
public static void Postfix(PlaylistManagementController __instance)
public static void Prefix(PlaylistManagementController __instance)
{
// Override the remove button text
__instance.pf_RemoveFromPlaylistButton?.GetComponentInChildren<TMP_Text>(true)?.SetText("Playlist", true);
SetupToggleButton(__instance.pf_RemoveFromPlaylistButton);
SetupToggleButton(__instance.pf_SongAddFavoriteButton);

// Also add in our own behavior
var button = __instance.pf_RemoveFromPlaylistButton?.GetComponentInChildren<SynthUIButton>();
button.WhenClicked = new UnityEngine.Events.UnityEvent();
button.WhenClicked.AddListener(new Action(() => { SRPlaylistManager.Instance.OnToggleMainMenuPlaylistButton(); }));
// TODO figure out how to do the heart visible or not based on if in _any_ playlist

//// Override the remove button text
//var btnText = __instance.pf_RemoveFromPlaylistButton?.GetComponentInChildren<TMP_Text>(true);
//SRPlaylistManager.Instance.Log("Remove favorite btn text: " + btnText);
//btnText?.SetText("Playlist", true);

//// Also add in our own behavior
//var button = __instance.pf_RemoveFromPlaylistButton?.GetComponentInChildren<SynthUIButton>();
//SRPlaylistManager.Instance.Log("Remove favorite btn: " + button);
//button.WhenClicked = new UnityEngine.Events.UnityEvent();
//button.WhenClicked.AddListener(new Action(() => { SRPlaylistManager.Instance.OnToggleMainMenuPlaylistButton(); }));

// Hide icon. Still off-center, but not as obviously a different button :)
__instance.pf_SongAddFavoriteButton?.transform.Find("Icon")?.gameObject.SetActive(false);
//__instance.pf_SongAddFavoriteButton?.transform.Find("Icon")?.gameObject.SetActive(false);
}

private static void SetupToggleButton(GameObject buttonGO)
{
if (buttonGO == null)
return;

// Override the remove button text
var btnTexts = buttonGO.GetComponentsInChildren<TMP_Text>(true);
foreach (var btnText in btnTexts)
{
btnText?.SetText("Select Playlists", true);
}

// Make sure the tooltip doesn't linger when we open up the playlist selection
var button = buttonGO.GetComponentInChildren<SynthUIButton>();
button.hideTooltipOnClick = true;

// Also add in our own behavior
if (button != null)
{
button.WhenClicked = new UnityEngine.Events.UnityEvent();
button.WhenClicked.AddListener(new Action(() => {
// Toggle playlist selection
SRPlaylistManager.Instance.OnToggleMainMenuPlaylistButton();
}));
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using HarmonyLib;
using Il2CppSynth.SongSelection;
using Il2CppUtil.Controller;

namespace SRPlaylistManager.Harmony
{
[HarmonyPatch(typeof(SongSelectionManager), nameof(SongSelectionManager.PlayPreviewAudio))]
public class Patch_SongSelectionManager_PlayPreviewAudio
{
public static void Prefix()
{
// Force some UI refreshing on first load. This was the first hook I could make work.
PlaylistManagementController.GetInstance.TryDisplayCorrectRemoveFavoriteButton();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using HarmonyLib;
using Il2CppSynth.SongSelection;
using SRModCore;

namespace SRPlaylistManager.Harmony
{
Expand All @@ -10,9 +11,14 @@ public static bool Prefix(SongSelectionManager __instance)
{
// Don't follow the normal text changes
// TODO better text and do translation
__instance.favoriteBtnLabel.SetText("Playlist", true);
__instance.favoriteBtn.toolTipLabelNormal = "Select Playlists";
__instance.favoriteBtn.toolTipLabelSelected = "Select Playlists";

return false;
__instance.favoriteBtn.synthUIButton.SetText("Select Playlists");

// TODO set state based on if the current song is in _any_ playlist, not just favorites?

return true;
}
}
}
Loading

0 comments on commit a2b030d

Please sign in to comment.