Files
ichni_Official/Assets/Scripts/UI/SongSelection/SongSelectionUIPage.cs
2026-07-26 12:12:45 +08:00

112 lines
4.0 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using DG.Tweening;
using Ichni.RhythmGame;
using Ichni.Story;
using Ichni.UI;
using SLSUtilities.WwiseAssistance;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
using UnityEngine.UI.Extensions;
namespace Ichni.Menu
{
public partial class SongSelectionUIPage : UIPageBase
{
public Button backButton;
[Tooltip("从选曲页进入当前章节剧情树的按钮。会优先定位当前选中歌曲对应的 SongBlock未找到时显示剧情开头。")]
public Button enterStoryButton;
public Gradient2 backgroundFrames;
public float framePositionOffset = -1;
public SongListControllerUI songListController;
public PlaySongUI playSongUI;
public SongInfoUI songInfoUI;
public DifficultySelectionContainer difficultySelectionContainer;
//public int currentSelectedDifficultyIndex;
protected override void Awake()
{
base.Awake();
fadeOutAction = () =>
{
songListController.ClearSongTabs();
MenuInputManager.OnMoveUp -= songListController.GoToFormerTab;
MenuInputManager.OnMoveDown -= songListController.GoToNextTab;
};
fadeInStartAction = () =>
{
songListController.InitializeList();
};
fadeInFinishAction = () =>
{
MenuInputManager.OnMoveUp += songListController.GoToFormerTab;
MenuInputManager.OnMoveDown += songListController.GoToNextTab;
};
backButton.onClick.AddListener(ReturnToChapterSelection);
if (enterStoryButton != null)
enterStoryButton.onClick.AddListener(OpenStoryForSelectedSong);
songInfoUI.SetUp();
}
private void OnDestroy()
{
backButton.onClick.RemoveListener(ReturnToChapterSelection);
if (enterStoryButton != null)
enterStoryButton.onClick.RemoveListener(OpenStoryForSelectedSong);
}
/// <summary>
/// 选曲页的全局返回语义固定为回到章节选择页。
/// 即使本次页面最初由 Story SongBlock 打开,也不再把 Back 视为“返回剧情树”;
/// 玩家需要使用专门的 <see cref="enterStoryButton"/> 进入剧情。
/// </summary>
private void ReturnToChapterSelection()
{
FadeOut();
SongSelectionManager.instance.StopPreviewSong();
// Story SongBlock 入口上下文只服务于一次“进入游戏后返回剧情”的流程。
// 玩家主动离开选曲页时必须清除它,避免之后普通选曲误继承旧的目标歌曲与返回目的地。
InformationTransistor.instance?.storySongEntryContext?.Clear();
MenuManager.instance.chapterSelectionUIPage.FadeIn();
}
/// <summary>
/// 从选曲页打开当前章节的剧情树。若当前歌曲在 StoryData 中存在对应 SongBlock
/// StoryManager 会把视口定位到该 Block未选中歌曲或没有对应 Block 时则显示剧情开头。
/// </summary>
private void OpenStoryForSelectedSong()
{
ChapterSelectionUnit chapter = ChapterSelectionManager.instance?.currentChapter;
StoryManager.instance?.TryOpenStoryForSong(chapter, selectedSong);
}
private void Start()
{
Sequence framesSeq = DOTween.Sequence();
framesSeq.Append(DOTween.To(() => framePositionOffset, x => framePositionOffset = x, 1f, 3f)
.SetEase(Ease.Linear)
.OnUpdate(() => backgroundFrames.Offset = framePositionOffset));
framesSeq.AppendInterval(1f);
framesSeq.SetLoops(-1, LoopType.Restart);
framesSeq.Play();
}
}
public partial class SongSelectionUIPage
{
public SongItemData selectedSong;
public DifficultyData selectedDifficulty;
public SongStatusSave selectedSave;
}
}