Files
ichni_Official/Assets/Scripts/UI/SongSelection/PlaySongUI.cs

90 lines
3.1 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using DG.Tweening;
using SLSUtilities.WwiseAssistance;
using UniRx;
using UnityEngine;
using UnityEngine.UI;
namespace Ichni.Menu
{
public class PlaySongUI : MonoBehaviour
{
public Button enterGameButton;
public List<RectTransform> arrows;
private void Start()
{
enterGameButton.onClick.AddListener(EnterGame);
}
/// <summary>
/// 设置标准 Play 按钮是否允许进入游戏。
/// 当当前歌曲没有可用难度时由 DifficultySelectionContainer 关闭;歌曲锁定仍沿用原有的独立判断。
/// </summary>
public void SetEnterGameAvailable(bool isAvailable)
{
enterGameButton.interactable = isAvailable;
}
private void EnterGame()
{
SongSelectionUIPage songSelectionUIPage = MenuManager.instance.songSelectionUIPage;
SongSelectionTab selectedTab = songSelectionUIPage.songListController.selectedTab;
// 即使 Button 的 interactable 状态被错误地恢复,也不能把空难度传给 InformationTransistor。
if (songSelectionUIPage.selectedSong == null || songSelectionUIPage.selectedDifficulty == null || selectedTab == null)
{
return;
}
// 不能只读取 Tab 的旧显示状态。解锁 Key 可能刚被剧情授予,或 UI 状态被其它逻辑改写;
// 标准 Play 与快速点击都会回到 UnlockSaveModule 的同一最终授权判断。
UnlockSaveModule unlockSaveModule = GameSaveManager.instance?.UnlockSaveModule;
if (unlockSaveModule == null || !unlockSaveModule.CanEnterSong(
ChapterSelectionManager.instance?.currentChapter,
songSelectionUIPage.selectedSong))
{
return;
}
selectedTab.RefreshUnlockState();
if (MenuManager.instance.isEnteringGame)
{
return;
}
MenuManager.instance.isEnteringGame = true;
InformationTransistor.instance.SetInformation(
ChapterSelectionManager.instance.currentChapter,
songSelectionUIPage.selectedSong,
songSelectionUIPage.selectedDifficulty);
AudioManager.Post(AK.EVENTS.ENTERTOGAME);
SongSelectionManager.instance.StopPreviewSong();
DOTween.KillAll();
Sequence arrowSeq = DOTween.Sequence();
foreach (var arrow in arrows)
{
arrowSeq.Join(arrow.DOAnchorPosX(-584.5f, 0.2f));
}
arrowSeq.OnComplete(() =>
{
MenuManager.instance.transitionUIPage.FadeIn();
Observable.Timer(TimeSpan.FromSeconds(0.6f)).Subscribe(_ =>
{
MenuManager.instance.EnterGame();
});
});
arrowSeq.Play();
}
}
}