UI update 02

This commit is contained in:
FloatGaming
2026-06-30 21:21:30 +08:00
parent b2a1e307a4
commit f62f643cfc
1666 changed files with 211081 additions and 22799 deletions
@@ -32,6 +32,7 @@ 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;
// Track pending restore to avoid multiple overlapping restores
private Coroutine restoreCoroutine;
@@ -115,8 +116,17 @@ public class SongSelectUI : MonoBehaviour
private IEnumerator LoadSceneAsync(string sceneName)
{
if (Bansonic.gTransition.LoadScene(sceneName, LoadSceneMode.Single))
{
while (Bansonic.gTransition.IsBusy)
{
yield return null;
}
yield break;
}
AsyncOperation asyncLoad = SceneManager.LoadSceneAsync(sceneName, LoadSceneMode.Single);
while (!asyncLoad.isDone)
while (asyncLoad != null && !asyncLoad.isDone)
{
yield return null;
}
@@ -307,7 +317,8 @@ public class SongSelectUI : MonoBehaviour
{
// read saved index using CurrentDlcKey
string dlcKey = (string.IsNullOrEmpty(CurrentDlcKey) ? "default_0" : CurrentDlcKey);
string key = "song_selected_" + dlcKey;
string key = SongButton.BuildSongSelectedIndexPrefsKey(dlcKey);
string songIdKey = SongButton.BuildSongSelectedIdPrefsKey(dlcKey);
// collect song buttons under contentPanel
var allSongButtons = contentPanel.GetComponentsInChildren<SongButton>(true);
@@ -317,6 +328,19 @@ public class SongSelectUI : MonoBehaviour
return;
}
if (ForceFirstSongOnNextRestore)
{
SongDataHolder.SelectedSongData = null;
SongButton firstButton = allSongButtons[0];
ForceFirstSongOnNextRestore = false;
if (firstButton != null)
{
firstButton.OnSongButtonClick();
if (VerboseLogs) Debug.Log("SongSelectUI: forced fallback to the first song because no last-entered record was found.");
}
return;
}
// Ensure every DLC has a default persisted value (0)
int savedIndex;
if (!PlayerPrefs.HasKey(key))
@@ -333,20 +357,49 @@ public class SongSelectUI : MonoBehaviour
if (savedIndex < 0) savedIndex = 0;
if (savedIndex >= allSongButtons.Length) savedIndex = 0;
var btn = allSongButtons[savedIndex];
SongButton btn = null;
if (PlayerPrefs.HasKey(songIdKey))
{
int savedSongId = PlayerPrefs.GetInt(songIdKey, 0);
if (savedSongId > 0)
{
for (int i = 0; i < allSongButtons.Length; i++)
{
SongButton candidate = allSongButtons[i];
if (candidate == null)
{
continue;
}
if (candidate.GetSongSerialId() == savedSongId)
{
btn = candidate;
savedIndex = i;
break;
}
}
}
}
if (btn == null)
{
btn = allSongButtons[savedIndex];
}
if (btn == null)
{
// hard fallback to first
btn = allSongButtons[0];
savedIndex = 0;
}
if (btn != null)
{
// simulate click
btn.OnSongButtonClick();
if (VerboseLogs) Debug.Log($"SongSelectUI: restored and clicked song index={savedIndex} for key={key}, totalButtons={allSongButtons.Length}");
}
btn.OnSongButtonClick();
if (VerboseLogs) Debug.Log($"SongSelectUI: restored and clicked song index={savedIndex} for key={key}, totalButtons={allSongButtons.Length}");
}
}
private void ClearSongList()
{
@@ -391,16 +444,8 @@ public class SongSelectUI : MonoBehaviour
songButton.SetButtonData(song.songName, bestTotal, diffForDisplay, resolvedIllustration, song.songID);
}
Image songImage = songButtonObj.GetComponentInChildren<Image>();
TMP_Text[] texts = songButtonObj.GetComponentsInChildren<TMP_Text>();
Sprite displayIllustration = sd != null ? sd.GetResolvedIllustration() : song.GetResolvedIllustration();
if (songImage != null && displayIllustration != null)
{
songImage.sprite = displayIllustration;
songImage.enabled = true;
}
if (texts.Length >= 4)
{
texts[0].text = song.songName;