198 lines
7.4 KiB
C#
198 lines
7.4 KiB
C#
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;
|
|
public Button expandButton;
|
|
public Button enterStorylineButton;
|
|
public Button enterSongSelectionButton;
|
|
|
|
public ChapterSelectionUnit connectedChapter;
|
|
|
|
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 outerSongProgressText;
|
|
public RectTransform titleRect;
|
|
public TMP_Text titleText;
|
|
|
|
[Title("展开内容")]
|
|
public RectTransform expansionBackground;
|
|
public Image expansionRipple;
|
|
public Material rippleMaterial;
|
|
public Sequence rippleSequence;
|
|
|
|
public RectTransform expansionFunctions;
|
|
|
|
public RectTransform expansionInfos;
|
|
public TMP_Text innerSongProgressText;
|
|
public TMP_Text fullComboText;
|
|
public TMP_Text allPerfectText;
|
|
public TMP_Text beatmapProgressText;
|
|
|
|
|
|
public void Initialize(ChapterSelectionUnit chapter)
|
|
{
|
|
connectedChapter = chapter;
|
|
expansionRipple.material = new Material(rippleMaterial);
|
|
|
|
expandButton.onClick.AddListener(() =>
|
|
{
|
|
if (isDuringAnimation)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (isExpanded)
|
|
{
|
|
Shrink();
|
|
}
|
|
else
|
|
{
|
|
Expand();
|
|
}
|
|
});
|
|
|
|
enterStorylineButton.onClick.AddListener(() =>
|
|
{
|
|
if (isDuringAnimation)
|
|
{
|
|
return;
|
|
}
|
|
|
|
ChapterSelectionManager.instance.currentChapter = connectedChapter;
|
|
MenuAudioManager.instance.audioContainer.SetSwitch(connectedChapter.chapterSwitch);
|
|
ChapterSelectionManager.instance.chapterSelectionUIPage.FadeOut();
|
|
StoryManager.instance.storyUIPage.FadeIn();
|
|
});
|
|
|
|
enterSongSelectionButton.onClick.AddListener(() =>
|
|
{
|
|
if (isDuringAnimation)
|
|
{
|
|
return;
|
|
}
|
|
|
|
ChapterSelectionManager.instance.currentChapter = connectedChapter;
|
|
MenuAudioManager.instance.audioContainer.SetSwitch(connectedChapter.chapterSwitch);
|
|
ChapterSelectionManager.instance.chapterSelectionUIPage.FadeOut();
|
|
SongSelectionManager.instance.songSelectionUIPage.FadeIn();
|
|
});
|
|
|
|
(int beatmapCount, int finishedSongCount, int finishedBeatmapCount, int fullComboCount, int allPerfectCount) = chapter.GetChapterSaveInfo();
|
|
float songProgressPercent = (float)finishedSongCount / chapter.songs.Count * 100f;
|
|
outerSongProgressText.text = songProgressPercent.ToString("F2") + "%";
|
|
innerSongProgressText.text = songProgressPercent.ToString("F2") + "%";
|
|
fullComboText.text = fullComboCount.ToString();
|
|
allPerfectText.text = allPerfectCount.ToString();
|
|
beatmapProgressText.text = $"{finishedBeatmapCount}/{beatmapCount}";
|
|
}
|
|
|
|
private void Expand()
|
|
{
|
|
isExpanded = true;
|
|
|
|
Sequence expandSequence = DOTween.Sequence();
|
|
|
|
expandSequence.Append(expansionBackground.DOSizeDelta(new Vector2(1147, 826), 0.3f)
|
|
.OnStart(() =>
|
|
{
|
|
expansionBackground.gameObject.SetActive(true);
|
|
}));
|
|
expandSequence.Join(DOTween.To(() => layoutElement.preferredWidth,
|
|
x => layoutElement.preferredWidth = x, 1147, 0.3f));
|
|
expandSequence.Join(avatarMask.rectTransform.DOSizeDelta(new Vector2(1147, 826), 0.3f));
|
|
expandSequence.Join(titleRect.DOSizeDelta(new Vector2(0, 100), 0.3f));
|
|
expandSequence.Append(expansionInfos.GetComponent<CanvasGroup>().DOFade(1, 0.3f)
|
|
.OnStart(()=>
|
|
{
|
|
expansionInfos.gameObject.SetActive(true);
|
|
}));
|
|
expandSequence.Join(expansionFunctions.GetComponent<CanvasGroup>().DOFade(1, 0.3f)
|
|
.OnStart(() =>
|
|
{
|
|
expansionFunctions.gameObject.SetActive(true);
|
|
}));
|
|
|
|
expandSequence.Join(bottomTip.DOFade(1f, 0.3f));
|
|
expandSequence.Join(upperTip.DOFade(1f, 0.3f));
|
|
|
|
expandSequence.OnStart(() => isDuringAnimation = true);
|
|
expandSequence.OnComplete(() =>
|
|
{
|
|
isDuringAnimation = false;
|
|
expansionRipple.material.SetFloat("_RippleTime", 0f);
|
|
rippleSequence = DOTween.Sequence();
|
|
rippleSequence.AppendInterval(5f);
|
|
rippleSequence.Append(expansionRipple.material.DOFloat(1, "_RippleTime", 2f));
|
|
rippleSequence.SetLoops(-1);
|
|
rippleSequence.Play();
|
|
});
|
|
|
|
expandSequence.Play();
|
|
}
|
|
|
|
private void Shrink()
|
|
{
|
|
isExpanded = false;
|
|
|
|
rippleSequence?.Kill(true);
|
|
|
|
Sequence shrinkSequence = DOTween.Sequence();
|
|
|
|
shrinkSequence.Append(bottomTip.DOFade(0f, 0.3f));
|
|
shrinkSequence.Join(upperTip.DOFade(0f, 0.3f));
|
|
|
|
shrinkSequence.Join(expansionInfos.GetComponent<CanvasGroup>().DOFade(0, 0.3f)
|
|
.OnComplete(()=>
|
|
{
|
|
expansionInfos.gameObject.SetActive(false);
|
|
}));
|
|
shrinkSequence.Join(expansionFunctions.GetComponent<CanvasGroup>().DOFade(0, 0.3f)
|
|
.OnComplete(() =>
|
|
{
|
|
expansionFunctions.gameObject.SetActive(false);
|
|
}));
|
|
|
|
shrinkSequence.Join(titleRect.DOSizeDelta(new Vector2(322, 100), 0.3f));
|
|
|
|
shrinkSequence.Append(expansionBackground.DOSizeDelta(new Vector2(322, 826), 0.3f)
|
|
.OnComplete(() =>
|
|
{
|
|
expansionBackground.gameObject.SetActive(false);
|
|
}));
|
|
|
|
shrinkSequence.Join(DOTween.To(() => layoutElement.preferredWidth,
|
|
x => layoutElement.preferredWidth = x, 322, 0.3f));
|
|
shrinkSequence.Join(avatarMask.rectTransform.DOSizeDelta(new Vector2(322, 826), 0.3f));
|
|
|
|
shrinkSequence.OnStart(() => isDuringAnimation = true);
|
|
shrinkSequence.OnComplete(() => isDuringAnimation = false);
|
|
|
|
shrinkSequence.Play();
|
|
}
|
|
}
|
|
} |