using System; using System.Collections; using System.Collections.Generic; using DG.Tweening; using Ichni.Menu; using Ichni.Story; using Sirenix.OdinInspector; using TMPro; using UnityEngine; using UnityEngine.Serialization; using UnityEngine.UI; namespace Ichni.UI { public class ChapterSelectionUI : MonoBehaviour { public RectTransform content; public LayoutElement layoutElement; [FormerlySerializedAs("button")] public Button expandButton; public Button enterStorylineButton; public Button enterSongSelectionButton; public string chapterName; public bool isExpanded; public bool isDuringAnimation; [Title("闭合内容")] public Image bottomTip; public Image upperTip; public Image leftProgressBarBase; public Image leftProgressBarFill; public Image avatar; public Image avatarMask; public TMP_Text decorationChapterText0; public TMP_Text decorationChapterText1; public TMP_Text progressText; public RectTransform titleRect; public TMP_Text titleText; [Title("展开内容")] public RectTransform expansionBackground; public RectTransform expansionFunctions; public RectTransform expansionInfos; private void Awake() { } public void Initialize(ChapterSelectionUnit chapter) { expandButton.onClick.AddListener(() => { if (isDuringAnimation) { return; } if (isExpanded) { Shrink(); } else { Expand(); } }); enterStorylineButton.onClick.AddListener(() => { if (isDuringAnimation) { return; } ChapterSelectionManager.instance.chapterSelectionUIPage.FadeOut(); StoryManager.instance.storyUIPage.FadeIn(); }); enterSongSelectionButton.onClick.AddListener(() => { if (isDuringAnimation) { return; } ChapterSelectionManager.instance.chapterSelectionUIPage.FadeOut(); SongSelectionManager.instance.songSelectionUIPage.FadeIn(); }); } private void Expand() { isExpanded = true; Sequence expandSequence = DOTween.Sequence(); expandSequence.Append(expansionBackground.DOSizeDelta(new Vector2(1147, 826), 0.4f) .OnStart(() => { expansionBackground.gameObject.SetActive(true); })); expandSequence.Join(DOTween.To(() => layoutElement.preferredWidth, x => layoutElement.preferredWidth = x, 1147, 0.4f)); expandSequence.Join(avatarMask.rectTransform.DOSizeDelta(new Vector2(1147, 826), 0.4f)); expandSequence.Append(titleRect.DOSizeDelta(new Vector2(0, 100), 0.4f)); expandSequence.Append(expansionInfos.GetComponent().DOFade(1, 0.4f) .OnStart(()=> { expansionInfos.gameObject.SetActive(true); })); expandSequence.Join(expansionFunctions.GetComponent().DOFade(1, 0.4f) .OnStart(() => { expansionFunctions.gameObject.SetActive(true); })); expandSequence.Append(bottomTip.DOFade(1f, 0.4f)); expandSequence.Join(upperTip.DOFade(1f, 0.4f)); expandSequence.OnStart(() => isDuringAnimation = true); expandSequence.OnComplete(() => isDuringAnimation = false); expandSequence.Play(); } private void Shrink() { isExpanded = false; Sequence shrinkSequence = DOTween.Sequence(); shrinkSequence.Append(bottomTip.DOFade(0f, 0.4f)); shrinkSequence.Join(upperTip.DOFade(0f, 0.4f)); shrinkSequence.Append(expansionInfos.GetComponent().DOFade(0, 0.4f) .OnComplete(()=> { expansionInfos.gameObject.SetActive(false); })); shrinkSequence.Join(expansionFunctions.GetComponent().DOFade(0, 0.4f) .OnComplete(() => { expansionFunctions.gameObject.SetActive(false); })); shrinkSequence.Append(titleRect.DOSizeDelta(new Vector2(322, 100), 0.4f).SetEase(Ease.InQuad)); shrinkSequence.Append(expansionBackground.DOSizeDelta(new Vector2(322, 826), 0.4f) .SetEase(Ease.InQuad) .OnComplete(() => { expansionBackground.gameObject.SetActive(false); })); shrinkSequence.Join(DOTween.To(() => layoutElement.preferredWidth, x => layoutElement.preferredWidth = x, 322, 0.4f).SetEase(Ease.InQuad)); shrinkSequence.Join(avatarMask.rectTransform.DOSizeDelta(new Vector2(322, 826), 0.4f).SetEase(Ease.InQuad)); shrinkSequence.OnStart(() => isDuringAnimation = true); shrinkSequence.OnComplete(() => isDuringAnimation = false); shrinkSequence.Play(); } } }