some updates
This commit is contained in:
@@ -33,6 +33,8 @@ public class SongSelectUI : MonoBehaviour
|
||||
// Current DLC key used for per-DLC saved song selection
|
||||
public static string CurrentDlcKey = "dlc_default_0";
|
||||
public static bool ForceFirstSongOnNextRestore;
|
||||
private const string GlobalSelectedDifficultyPrefsKey = "song_select_global_difficulty";
|
||||
private static int cachedSelectedDifficulty = -1;
|
||||
|
||||
// Track pending restore to avoid multiple overlapping restores
|
||||
private Coroutine restoreCoroutine;
|
||||
@@ -72,6 +74,79 @@ public class SongSelectUI : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
public static int GetSelectedDifficulty()
|
||||
{
|
||||
if (cachedSelectedDifficulty < 0)
|
||||
{
|
||||
cachedSelectedDifficulty = Mathf.Clamp(PlayerPrefs.GetInt(GlobalSelectedDifficultyPrefsKey, 0), 0, 3);
|
||||
}
|
||||
|
||||
return cachedSelectedDifficulty;
|
||||
}
|
||||
|
||||
public static void SetSelectedDifficulty(int difficulty)
|
||||
{
|
||||
cachedSelectedDifficulty = Mathf.Clamp(difficulty, 0, 3);
|
||||
PlayerPrefs.SetInt(GlobalSelectedDifficultyPrefsKey, cachedSelectedDifficulty);
|
||||
PlayerPrefs.Save();
|
||||
}
|
||||
|
||||
public static void ApplySelectedDifficultyToLoadedSongButtons()
|
||||
{
|
||||
int difficulty = GetSelectedDifficulty();
|
||||
SongButton[] buttons = UnityEngine.Object.FindObjectsByType<SongButton>(FindObjectsInactive.Include, FindObjectsSortMode.None);
|
||||
for (int i = 0; i < buttons.Length; i++)
|
||||
{
|
||||
SongButton button = buttons[i];
|
||||
if (button == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
SongData song = button.GetAssignedSongData();
|
||||
ApplySelectedDifficultyToSong(song, difficulty, true);
|
||||
button.RefreshCurrentDifficultyDisplay();
|
||||
}
|
||||
|
||||
PlayerPrefs.Save();
|
||||
}
|
||||
|
||||
public static void ApplySelectedDifficultyToSongList(IEnumerable<SongData> songs)
|
||||
{
|
||||
int difficulty = GetSelectedDifficulty();
|
||||
if (songs == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (SongData song in songs)
|
||||
{
|
||||
ApplySelectedDifficultyToSong(song, difficulty, true);
|
||||
}
|
||||
|
||||
PlayerPrefs.Save();
|
||||
}
|
||||
|
||||
public static void ApplySelectedDifficultyToSong(SongData song)
|
||||
{
|
||||
ApplySelectedDifficultyToSong(song, GetSelectedDifficulty(), true);
|
||||
}
|
||||
|
||||
private static void ApplySelectedDifficultyToSong(SongData song, int difficulty, bool persist)
|
||||
{
|
||||
if (song == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
difficulty = Mathf.Clamp(difficulty, 0, 3);
|
||||
song.thisLevel_selectedDifficultyID = difficulty;
|
||||
if (persist)
|
||||
{
|
||||
PlayerPrefs.SetInt(SongButton.BuildSongSelectedDifficultyPrefsKey(song.songID), difficulty);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
KillActiveTweensAndCoroutines();
|
||||
@@ -180,6 +255,8 @@ public class SongSelectUI : MonoBehaviour
|
||||
// allow UI to render a frame before heavy instantiation
|
||||
yield return null;
|
||||
|
||||
ApplySelectedDifficultyToSongList(list);
|
||||
|
||||
int count = 0;
|
||||
foreach (var song in list)
|
||||
{
|
||||
@@ -449,7 +526,7 @@ public class SongSelectUI : MonoBehaviour
|
||||
|
||||
TMP_Text[] texts = songButtonObj.GetComponentsInChildren<TMP_Text>();
|
||||
|
||||
if (texts.Length >= 4)
|
||||
if (songButton == null && texts.Length >= 4)
|
||||
{
|
||||
texts[0].text = song.songName;
|
||||
texts[1].text = "Record : " + bestTotal;
|
||||
|
||||
Reference in New Issue
Block a user