81 lines
3.5 KiB
C#
81 lines
3.5 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using DG.Tweening;
|
|
using Sirenix.OdinInspector;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace Ichni.Menu.UI
|
|
{
|
|
public partial class SongSelectionTabUI : MonoBehaviour
|
|
{
|
|
public SongItemData connectedSong;
|
|
public TMP_Text songNameText;
|
|
public Button switchDifficultyButton;
|
|
public Button previewButton;
|
|
public Button startSongButton;
|
|
public string currentDifficultyName;
|
|
|
|
[Title("背景图&选中处理")]
|
|
public Image backgroundImage;
|
|
public Sprite unselectedSprite;
|
|
public Sprite selectedSprite;
|
|
|
|
public void SetUpTab(SongItemData song)
|
|
{
|
|
connectedSong = song;
|
|
songNameText.text = song.songName;
|
|
currentDifficultyName = song.difficultyDataList[0].difficultyName;
|
|
switchDifficultyButton.GetComponentInChildren<TMP_Text>().text = currentDifficultyName + " Lv." + song.difficultyDataList[0].difficultyValue;
|
|
switchDifficultyButton.GetComponentInChildren<TMP_Text>().color = song.difficultyDataList[0].color;
|
|
|
|
switchDifficultyButton.onClick.AddListener(() =>
|
|
{
|
|
int currentIndex = song.difficultyDataList.FindIndex(d => d.difficultyName == currentDifficultyName);
|
|
int nextIndex = (currentIndex + 1) % song.difficultyDataList.Count;
|
|
currentDifficultyName = song.difficultyDataList[nextIndex].difficultyName;
|
|
|
|
switchDifficultyButton.GetComponentInChildren<TMP_Text>().text = currentDifficultyName + " Lv." + song.difficultyDataList[nextIndex].difficultyValue;
|
|
switchDifficultyButton.GetComponentInChildren<TMP_Text>().color = song.difficultyDataList[nextIndex].color;
|
|
});
|
|
|
|
previewButton.onClick.AddListener(() =>
|
|
{
|
|
MenuAudioManager.instance.audioContainer.StopEvent("PlayPreview");
|
|
MenuAudioManager.instance.audioContainer.SetSwitch(connectedSong.songSwitch);
|
|
MenuAudioManager.instance.audioContainer.PostEvent("PlayPreview");
|
|
});
|
|
|
|
startSongButton.onClick.AddListener(() =>
|
|
{
|
|
if (MenuManager.instance.songSelectionUIPage.songListController.selectedTab == this)
|
|
{
|
|
MenuManager.instance.prepareUIPage.SetUpPrepareUIPage(song.songName);
|
|
MenuManager.instance.prepareUIPage.FadeIn();
|
|
}
|
|
else
|
|
{
|
|
StartCoroutine(MenuManager.instance.songSelectionUIPage.songListController.SnapToTab(this));
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
public partial class SongSelectionTabUI
|
|
{
|
|
public void SetSelection(bool isSelected)
|
|
{
|
|
backgroundImage.sprite = isSelected ? selectedSprite : unselectedSprite;
|
|
if (isSelected)
|
|
{
|
|
GetComponent<RectTransform>().DOScale(1.2f, 0.2f).SetEase(Ease.OutQuad).Play();
|
|
GetComponent<RectTransform>().GetChild(0).GetComponent<RectTransform>().DOAnchorPosX(-100, 0.2f).SetEase(Ease.OutQuad).Play();
|
|
}else
|
|
{
|
|
GetComponent<RectTransform>().DOScale(1f, 0.2f).SetEase(Ease.OutQuad).Play();
|
|
GetComponent<RectTransform>().GetChild(0).GetComponent<RectTransform>().DOAnchorPosX(0, 0.2f).SetEase(Ease.OutQuad).Play();
|
|
}
|
|
}
|
|
}
|
|
} |