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
@@ -13,102 +13,30 @@ public class UI_SelectSong_AutoPlayToggle : MonoBehaviour
[Header("Tween")]
[SerializeField] private float tweenDuration = 0.25f;
[SerializeField] private Ease tweenEase = Ease.OutCubic;
private static readonly Color32 OnBg = new Color32(0x3A, 0x3A, 0x3A, 0xFF);
private static readonly Color32 OffBg = new Color32(0xFF, 0xFF, 0xFF, 0xFF);
private static readonly Color32 OnText = new Color32(0xFF, 0xFF, 0xFF, 0xFF);
private static readonly Color32 OffText = new Color32(0x3A, 0x3A, 0x3A, 0xFF);
private Color initialButtonColor = Color.white;
private Color initialTextColor = Color.white;
private bool hasInitialButtonColor;
private bool hasInitialTextColor;
private void Awake()
{
TryAutoWire();
}
private void OnEnable()
{
TryAutoWire();
if (button != null)
{
button.onClick.RemoveListener(OnClick);
button.onClick.AddListener(OnClick);
}
if (toggle != null)
{
toggle.onValueChanged.RemoveListener(OnToggleChanged);
toggle.onValueChanged.AddListener(OnToggleChanged);
// Keep UI state consistent with global setting.
toggle.SetIsOnWithoutNotify(GameConfig.autoPlayEnabled);
}
ApplyVisual(GameConfig.autoPlayEnabled, instant: true);
}
private void OnDisable()
{
if (button != null)
{
button.onClick.RemoveListener(OnClick);
}
if (toggle != null)
{
toggle.onValueChanged.RemoveListener(OnToggleChanged);
}
KillTweens();
}
public void TryAutoWire()
{
button = button != null ? button : GetComponent<Button>();
toggle = toggle != null ? toggle : GetComponent<Toggle>();
buttonImage = buttonImage != null ? buttonImage : GetComponent<Image>();
if (buttonImage == null && toggle != null && toggle.targetGraphic is Image tgImage)
{
buttonImage = tgImage;
}
labelText = labelText != null ? labelText : GetComponentInChildren<Text>(true);
}
private void OnClick()
{
bool next = !GameConfig.autoPlayEnabled;
GameConfig.SetAutoPlayEnabled(next);
if (toggle != null)
{
toggle.SetIsOnWithoutNotify(next);
}
ApplyVisual(next, instant: false);
}
private void OnToggleChanged(bool isOn)
{
GameConfig.SetAutoPlayEnabled(isOn);
ApplyVisual(isOn, instant: false);
}
private void ApplyVisual(bool enabled, bool instant)
{
Color targetBg = enabled ? OnBg : OffBg;
Color targetText = enabled ? OnText : OffText;
if (instant || !Application.isPlaying || tweenDuration <= 0f)
{
if (buttonImage != null) buttonImage.color = targetBg;
if (labelText != null) labelText.color = targetText;
return;
}
KillTweens();
if (buttonImage != null)
buttonImage.DOColor(targetBg, tweenDuration).SetEase(tweenEase);
if (labelText != null)
labelText.DOColor(targetText, tweenDuration).SetEase(tweenEase);
// Legacy component retained only for scene compatibility.
// Autoplay UI is now driven exclusively by selected_songInfo.autoplayButton.
}
private void KillTweens()
{
if (buttonImage != null) buttonImage.DOKill();
if (labelText != null) labelText.DOKill();
}
}