Files
ichni_Official/Assets/Scripts/UI/ChapterSelection/ChapterSelectionUI.cs

166 lines
5.7 KiB
C#
Raw Normal View History

2025-06-09 04:52:14 -04:00
using System;
2025-06-06 10:14:55 -04:00
using System.Collections;
using System.Collections.Generic;
2025-06-09 04:52:14 -04:00
using DG.Tweening;
2025-06-06 10:14:55 -04:00
using Ichni.Menu;
using Ichni.Story;
2025-06-09 04:52:14 -04:00
using Sirenix.OdinInspector;
2025-06-06 10:14:55 -04:00
using TMPro;
using UnityEngine;
2025-06-14 14:42:49 -04:00
using UnityEngine.Serialization;
2025-06-06 10:14:55 -04:00
using UnityEngine.UI;
namespace Ichni.UI
{
public class ChapterSelectionUI : MonoBehaviour
{
public RectTransform content;
2025-06-09 04:52:14 -04:00
public LayoutElement layoutElement;
2025-06-14 14:42:49 -04:00
[FormerlySerializedAs("button")] public Button expandButton;
public Button enterStorylineButton;
public Button enterSongSelectionButton;
public string chapterName;
2025-06-09 04:52:14 -04:00
public bool isExpanded;
public bool isDuringAnimation;
[Title("闭合内容")]
public Image bottomTip;
public Image upperTip;
public Image leftProgressBarBase;
public Image leftProgressBarFill;
2025-06-06 10:14:55 -04:00
public Image avatar;
2025-06-09 04:52:14 -04:00
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()
{
2025-06-14 14:42:49 -04:00
}
public void Initialize(ChapterSelectionUnit chapter)
{
expandButton.onClick.AddListener(() =>
2025-06-09 04:52:14 -04:00
{
if (isDuringAnimation)
{
return;
}
if (isExpanded)
{
2025-06-14 14:42:49 -04:00
Shrink();
2025-06-09 04:52:14 -04:00
}
else
{
Expand();
}
});
2025-06-14 14:42:49 -04:00
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();
});
2025-06-09 04:52:14 -04:00
}
2025-06-14 14:42:49 -04:00
private void Expand()
2025-06-09 04:52:14 -04:00
{
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<CanvasGroup>().DOFade(1, 0.4f)
.OnStart(()=>
{
expansionInfos.gameObject.SetActive(true);
}));
expandSequence.Join(expansionFunctions.GetComponent<CanvasGroup>().DOFade(1, 0.4f)
.OnStart(() =>
{
expansionFunctions.gameObject.SetActive(true);
}));
2025-06-06 10:14:55 -04:00
2025-06-09 04:52:14 -04:00
expandSequence.Append(bottomTip.DOFade(1f, 0.4f));
expandSequence.Join(upperTip.DOFade(1f, 0.4f));
2025-06-06 10:14:55 -04:00
2025-06-09 04:52:14 -04:00
expandSequence.OnStart(() => isDuringAnimation = true);
expandSequence.OnComplete(() => isDuringAnimation = false);
expandSequence.Play();
}
2025-06-14 14:42:49 -04:00
private void Shrink()
2025-06-09 04:52:14 -04:00
{
isExpanded = false;
2025-06-14 14:42:49 -04:00
Sequence shrinkSequence = DOTween.Sequence();
2025-06-09 04:52:14 -04:00
2025-06-14 14:42:49 -04:00
shrinkSequence.Append(bottomTip.DOFade(0f, 0.4f));
shrinkSequence.Join(upperTip.DOFade(0f, 0.4f));
2025-06-09 04:52:14 -04:00
2025-06-14 14:42:49 -04:00
shrinkSequence.Append(expansionInfos.GetComponent<CanvasGroup>().DOFade(0, 0.4f)
2025-06-09 04:52:14 -04:00
.OnComplete(()=>
{
expansionInfos.gameObject.SetActive(false);
}));
2025-06-14 14:42:49 -04:00
shrinkSequence.Join(expansionFunctions.GetComponent<CanvasGroup>().DOFade(0, 0.4f)
2025-06-09 04:52:14 -04:00
.OnComplete(() =>
{
expansionFunctions.gameObject.SetActive(false);
}));
2025-06-14 14:42:49 -04:00
shrinkSequence.Append(titleRect.DOSizeDelta(new Vector2(322, 100), 0.4f).SetEase(Ease.InQuad));
2025-06-09 04:52:14 -04:00
2025-06-14 14:42:49 -04:00
shrinkSequence.Append(expansionBackground.DOSizeDelta(new Vector2(322, 826), 0.4f)
.SetEase(Ease.InQuad)
2025-06-09 04:52:14 -04:00
.OnComplete(() =>
{
expansionBackground.gameObject.SetActive(false);
}));
2025-06-14 14:42:49 -04:00
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));
2025-06-09 04:52:14 -04:00
2025-06-14 14:42:49 -04:00
shrinkSequence.OnStart(() => isDuringAnimation = true);
shrinkSequence.OnComplete(() => isDuringAnimation = false);
2025-06-09 04:52:14 -04:00
2025-06-14 14:42:49 -04:00
shrinkSequence.Play();
2025-06-06 10:14:55 -04:00
}
}
}