UI update 02

This commit is contained in:
2026-06-30 21:21:30 +08:00
parent b2a1e307a4
commit f62f643cfc
1666 changed files with 211081 additions and 22799 deletions
+151 -54
View File
@@ -10,6 +10,7 @@ using Bansonic;
public class selected_songInfo : MonoBehaviour
{
private static readonly bool VerboseLogs = false;
private const string LastEnteredSongIdPrefsKey = "last_entered_song_id";
[Header("ranking")]
public Button rankingButton;
public rankingList s_rl;
@@ -17,6 +18,7 @@ public class selected_songInfo : MonoBehaviour
[Header("Music Controls")]
public Button playpausebutton;
public Button stopbutton;
public Image playPauseStateImage;
public Text currentTime;
public Text maxtime;
public Slider playbarSlider;
@@ -44,10 +46,18 @@ public class selected_songInfo : MonoBehaviour
public Color _16d5to22;
public Color _equal22;
[Header("autoplay button")]
public Button autoplayButton;
public Sprite ap_enabled;
public Sprite ap_disabled;
[Header("Inspector")]
public List<Button> difficultyButtons = new List<Button>();
[Header("Inspector")]
public List<Text> difficultyTexts = new List<Text>();
[Header("Difficulty Text Colors")]
[SerializeField] private Color difficultySelectedTextColor = Color.white;
[SerializeField] private Color difficultyUnselectedTextColor = Color.black;
[Header("enter detail page")]
public Button enterDetailPageButton;
[Header("quick enter game play")]
@@ -77,6 +87,9 @@ public class selected_songInfo : MonoBehaviour
private bool _promptAwaitingChoice = false;
private bool _doNotShowAgainPrompt = false;
private bool _doNotShowPrefLoaded = false;
private Image autoplayButtonImage;
private SpriteState cachedAutoplaySpriteState;
private bool hasCachedAutoplaySpriteState;
private const string QuickEnterPromptSkipPrefKey = "quickenter_team_warning_skip";
@@ -244,6 +257,7 @@ public class selected_songInfo : MonoBehaviour
void OnEnable()
{
LogVerbose("selected_songInfo.OnEnable called");
GameConfig.LoadPrefs();
EnsurePromptReferences();
LoadDoNotShowAgainPreference();
SetPromptRootVisible(false);
@@ -251,6 +265,8 @@ public class selected_songInfo : MonoBehaviour
ResolveDifficultyIdDisplayTexts();
InitializeMusicControls();
BindAutoplayButton();
RefreshAutoplayButtonVisual();
// register listeners here to ensure binding even if Start wasn't called yet
if (enterDetailPageButton != null)
@@ -294,6 +310,7 @@ public class selected_songInfo : MonoBehaviour
LogVerbose("selected_songInfo.OnDisable called");
UnbindMusicControls();
UnbindAutoplayButton();
if (enterDetailPageButton != null)
{
@@ -385,6 +402,9 @@ public class selected_songInfo : MonoBehaviour
SetPromptRootVisible(false);
ApplyDoNotShowAgainVisual();
ResolveDifficultyIdDisplayTexts();
GameConfig.LoadPrefs();
CacheAutoplayButtonImage();
RefreshAutoplayButtonVisual();
// ensure black mask is transparent and inactive at start
if (blackMaskImage != null)
@@ -431,6 +451,94 @@ public class selected_songInfo : MonoBehaviour
LogVerbose($"selected_songInfo.Start: SongDataHolder.SelectedSongData is {(SongDataHolder.SelectedSongData == null ? "NULL" : SongDataHolder.SelectedSongData.songName)}");
}
private void BindAutoplayButton()
{
if (autoplayButton == null)
{
return;
}
CacheAutoplayButtonImage();
autoplayButton.onClick.RemoveListener(OnAutoplayButtonClicked);
autoplayButton.onClick.AddListener(OnAutoplayButtonClicked);
}
private void UnbindAutoplayButton()
{
if (autoplayButton == null)
{
return;
}
autoplayButton.onClick.RemoveListener(OnAutoplayButtonClicked);
}
private void CacheAutoplayButtonImage()
{
if (autoplayButton == null)
{
autoplayButtonImage = null;
return;
}
if (autoplayButtonImage == null)
{
autoplayButtonImage = autoplayButton.GetComponent<Image>();
if (autoplayButtonImage == null)
{
autoplayButtonImage = autoplayButton.targetGraphic as Image;
}
}
if (!hasCachedAutoplaySpriteState)
{
cachedAutoplaySpriteState = autoplayButton.spriteState;
hasCachedAutoplaySpriteState = true;
}
}
private void OnAutoplayButtonClicked()
{
bool next = !GameConfig.autoPlayEnabled;
GameConfig.SetAutoPlayEnabled(next);
RefreshAutoplayButtonVisual();
}
private void RefreshAutoplayButtonVisual()
{
CacheAutoplayButtonImage();
if (autoplayButtonImage == null)
{
return;
}
Sprite targetSprite = GameConfig.autoPlayEnabled ? ap_enabled : ap_disabled;
if (targetSprite == null)
{
return;
}
autoplayButtonImage.sprite = targetSprite;
autoplayButtonImage.overrideSprite = targetSprite;
autoplayButtonImage.SetAllDirty();
if (autoplayButton != null)
{
SpriteState state = hasCachedAutoplaySpriteState ? cachedAutoplaySpriteState : autoplayButton.spriteState;
state.highlightedSprite = targetSprite;
state.pressedSprite = targetSprite;
state.selectedSprite = targetSprite;
autoplayButton.spriteState = state;
if (autoplayButton.targetGraphic is Image targetGraphicImage && targetGraphicImage != autoplayButtonImage)
{
targetGraphicImage.sprite = targetSprite;
targetGraphicImage.overrideSprite = targetSprite;
targetGraphicImage.SetAllDirty();
}
}
}
private SongData GetCurrentSelectedSong()
{
if (SongDataHolder.SelectedSongData != null)
@@ -620,17 +728,15 @@ public class selected_songInfo : MonoBehaviour
private void UpdatePlayPauseButtonSprite(bool isPlaying)
{
if (playpausebutton == null) return;
Image btnImg = playpausebutton.GetComponent<Image>();
if (btnImg == null) return;
if (playPauseStateImage == null) return;
if (isPlaying)
{
if (pauseSprite != null) btnImg.sprite = pauseSprite;
if (pauseSprite != null) playPauseStateImage.sprite = pauseSprite;
}
else
{
if (playSprite != null) btnImg.sprite = playSprite;
if (playSprite != null) playPauseStateImage.sprite = playSprite;
}
}
@@ -699,47 +805,6 @@ public class selected_songInfo : MonoBehaviour
// fill amount is ratio of difficultyLevel / maxDifficulty
float fill = Mathf.Clamp01(difficultyLevel / (float)maxDifficulty);
c_DifficultyImage.fillAmount = fill;
// choose color by ranges: left-closed, right-open, intervals of 5.5
// [0,5.5), [5.5,11), [11,16.5), [16.5,22), exactly 22 -> equal color
Color chosen = _0to5d5;
if (Mathf.Approximately(difficultyLevel, maxDifficulty))
{
chosen = _equal22;
}
else if (difficultyLevel >= 16.5f)
{
chosen = _16d5to22;
}
else if (difficultyLevel >= 11f)
{
chosen = _11to16d5;
}
else if (difficultyLevel >= 5.5f)
{
chosen = _5d5to11;
}
else if (difficultyLevel >= 0)
{
chosen = _0to5d5;
}
else
{
chosen = Color.white;
}
// ensure color is opaque
chosen.a = 1f;
// apply color to the mask image if available, otherwise fall back to the difficulty image
if (c_imageMask != null)
{
c_imageMask.color = chosen;
}
else
{
c_DifficultyImage.color = chosen;
}
}
// Update sumScore_thisDifficulty based on currently selected difficulty
@@ -855,7 +920,7 @@ public class selected_songInfo : MonoBehaviour
// set corresponding text (if exists) to white
if (difficultyTexts != null && i < difficultyTexts.Count && difficultyTexts[i] != null)
{
difficultyTexts[i].color = Color.white;
difficultyTexts[i].color = difficultySelectedTextColor;
}
}
else
@@ -868,7 +933,7 @@ public class selected_songInfo : MonoBehaviour
// set corresponding text (if exists) to black
if (difficultyTexts != null && i < difficultyTexts.Count && difficultyTexts[i] != null)
{
difficultyTexts[i].color = Color.black;
difficultyTexts[i].color = difficultyUnselectedTextColor;
}
}
}
@@ -880,6 +945,7 @@ public class selected_songInfo : MonoBehaviour
if (SongDataHolder.SelectedSongData != null)
{
SongDataHolder.SelectedSongData.thisLevel_selectedDifficultyID = Mathf.Clamp(index, 0, 3);
PersistSelectedSongDifficulty(SongDataHolder.SelectedSongData);
// immediately update UI to reflect new selection
SetDifficultyButtonBackground(SongDataHolder.SelectedSongData.thisLevel_selectedDifficultyID);
@@ -893,6 +959,18 @@ public class selected_songInfo : MonoBehaviour
}
}
private void PersistSelectedSongDifficulty(SongData song)
{
if (song == null)
{
return;
}
int difficulty = Mathf.Clamp(song.thisLevel_selectedDifficultyID, 0, 3);
PlayerPrefs.SetInt(SongButton.BuildSongSelectedDifficultyPrefsKey(song.songID), difficulty);
PlayerPrefs.Save();
}
private void EnsureSongInfoRoot()
{
if (songInfo_Root == null)
@@ -991,8 +1069,17 @@ public class selected_songInfo : MonoBehaviour
private IEnumerator LoadSceneAsync(string sceneName)
{
if (gTransition.LoadScene(sceneName, LoadSceneMode.Single))
{
while (gTransition.IsBusy)
{
yield return null;
}
yield break;
}
AsyncOperation asyncLoad = SceneManager.LoadSceneAsync(sceneName);
while (!asyncLoad.isDone)
while (asyncLoad != null && !asyncLoad.isDone)
{
yield return null;
}
@@ -1275,6 +1362,8 @@ public class selected_songInfo : MonoBehaviour
// keep selected in holder to make it accessible in new scene
SongDataHolder.SelectedSongData = sd;
PlayerPrefs.SetInt(LastEnteredSongIdPrefsKey, sd.songID);
PlayerPrefs.Save();
// start fade and load sequence
StartCoroutine(QuickEnterSequence());
@@ -1386,10 +1475,18 @@ public class selected_songInfo : MonoBehaviour
LogVerbose("Fade complete, loading gameplay scene...");
// selected_songInfo is scene UI and must not survive scene switching.
// Gameplay startup is already handled by BeatmapManager/GameManager via pendingSongData.
if (gTransition.LoadScene("gamePlay_gamePlay", LoadSceneMode.Single))
{
while (gTransition.IsBusy)
{
yield return null;
}
yield break;
}
var asyncOp = SceneManager.LoadSceneAsync("gamePlay_gamePlay");
if (asyncOp != null)
{
// wait until load completes
while (!asyncOp.isDone)
{
yield return null;
@@ -1397,11 +1494,11 @@ public class selected_songInfo : MonoBehaviour
}
else
{
// fallback to synchronous load
SceneManager.LoadScene("gamePlay_gamePlay");
if (!gTransition.LoadScene("gamePlay_gamePlay", LoadSceneMode.Single))
{
SceneManager.LoadScene("gamePlay_gamePlay");
}
}
yield break;
}
private SongData FindSongDataFromSelectedButton()