153 lines
4.6 KiB
C#
153 lines
4.6 KiB
C#
using UnityEngine;
|
|
using Logic;
|
|
using RuntimeData;
|
|
using Animancer;
|
|
using TMPro;
|
|
using UnityEngine.UI;
|
|
|
|
public class MainUI
|
|
{
|
|
private Main _main;
|
|
private MapData _mapData;
|
|
public GameObject ROMainUI;
|
|
|
|
public Button NewGameButton;
|
|
public Button ResumeGameButton;
|
|
public Button StoryModeButton;
|
|
public Button LibraryButton;
|
|
public Button SettingButton;
|
|
public Button HistoryButton;
|
|
public Button AboutButton;
|
|
|
|
public bool NeedShow = false;
|
|
|
|
private bool _isShowing = false;
|
|
private bool _isAnimating = false;
|
|
private float _fadeDuration = 0.2f;
|
|
|
|
public MainUI(Main main, MapData mapData)
|
|
{
|
|
_main = main;
|
|
_mapData = mapData;
|
|
ROMainUI = _main.UIManager.ROUIManager.transform.Find("GameUI/MainUI").gameObject;
|
|
ROMainUI.gameObject.SetActive(false);
|
|
|
|
// 绑定所有按钮
|
|
NewGameButton = ROMainUI.transform.Find("ButtonRow/NewGameButton/MainUIButton").GetComponent<Button>();
|
|
ResumeGameButton = ROMainUI.transform.Find("ButtonRow/ResumeGameButton/MainUIButton").GetComponent<Button>();
|
|
StoryModeButton = ROMainUI.transform.Find("ButtonRow/StoryModeButton/MainUIButton").GetComponent<Button>();
|
|
LibraryButton = ROMainUI.transform.Find("ButtonRow/LibraryButton/MainUIButton").GetComponent<Button>();
|
|
HistoryButton = ROMainUI.transform.Find("ButtonRow/HistoryButton/MainUIButton").GetComponent<Button>();
|
|
|
|
SettingButton = ROMainUI.transform.Find("ButtonRow2/SettingButton").GetComponent<Button>();
|
|
AboutButton = ROMainUI.transform.Find("ButtonRow2/AboutButton").GetComponent<Button>();
|
|
|
|
NewGameButton.onClick.AddListener(OnNewGameClicked);
|
|
ResumeGameButton.onClick.AddListener(OnResumeGameClicked);
|
|
StoryModeButton.onClick.AddListener(OnStoryModeClicked);
|
|
LibraryButton.onClick.AddListener(OnLibraryClicked);
|
|
SettingButton.onClick.AddListener(OnSettingClicked);
|
|
HistoryButton.onClick.AddListener(OnHistoryClicked);
|
|
AboutButton.onClick.AddListener(OnAboutClicked);
|
|
|
|
//处理继续游戏的按钮
|
|
if (!_main.HasArchive())
|
|
{
|
|
ROMainUI.transform.Find("ButtonRow").Find("ResumeGameButton/MainUIButton/Text")
|
|
.GetComponent<TextMeshProUGUI>().text = "无存档";
|
|
}
|
|
else
|
|
ROMainUI.transform.Find("ButtonRow").Find("ResumeGameButton/MainUIButton/Text")
|
|
.GetComponent<TextMeshProUGUI>().text = "继 续";
|
|
}
|
|
|
|
public void Update()
|
|
{
|
|
if (_isAnimating) return;
|
|
|
|
if (NeedShow && !ROMainUI.activeSelf)
|
|
{
|
|
Show();
|
|
}
|
|
else if (!NeedShow && ROMainUI.activeSelf)
|
|
{
|
|
Hide();
|
|
}
|
|
}
|
|
|
|
public void Show()
|
|
{
|
|
if (_isShowing || _isAnimating) return;
|
|
|
|
_isShowing = true;
|
|
_isAnimating = true;
|
|
ROMainUI.SetActive(true);
|
|
|
|
AnimancerComponent animancer = ROMainUI.GetComponent<AnimancerComponent>();
|
|
AnimationClip fadeInClip = Resources.Load<AnimationClip>("Animations/UI/SettingPanelFadeIn");
|
|
if (fadeInClip != null)
|
|
animancer.Play(fadeInClip);
|
|
|
|
Timer.Instance.TimerRegister(ROMainUI, () => { _isAnimating = false; }, _fadeDuration);
|
|
}
|
|
|
|
public void Hide()
|
|
{
|
|
if (!_isShowing || _isAnimating) return;
|
|
|
|
_isShowing = false;
|
|
_isAnimating = true;
|
|
|
|
AnimancerComponent animancer = ROMainUI.GetComponent<AnimancerComponent>();
|
|
AnimationClip fadeOutClip = Resources.Load<AnimationClip>("Animations/UI/SettingPanelFadeOut");
|
|
if (fadeOutClip != null)
|
|
animancer.Play(fadeOutClip);
|
|
|
|
Timer.Instance.TimerRegister(ROMainUI, () =>
|
|
{
|
|
ROMainUI.SetActive(false);
|
|
_isAnimating = false;
|
|
}, _fadeDuration);
|
|
}
|
|
|
|
private void OnNewGameClicked()
|
|
{
|
|
NeedShow = false;
|
|
_main.UIManager.GameUI.ChooseUI.NeedShow = true;
|
|
}
|
|
|
|
private void OnResumeGameClicked()
|
|
{
|
|
//Debug.Log("Resume Game Clicked");
|
|
if(_main.HasArchive())
|
|
_main.ContinueGame();
|
|
NeedShow = false;
|
|
}
|
|
|
|
private void OnStoryModeClicked()
|
|
{
|
|
Debug.Log("Story Mode Clicked");
|
|
}
|
|
|
|
private void OnLibraryClicked()
|
|
{
|
|
NeedShow = false;
|
|
_main.UIManager.GameUI.LibraryUI.NeedShow = true;
|
|
}
|
|
|
|
private void OnSettingClicked()
|
|
{
|
|
_main.UIManager.SettingUI.NeedShow = true;
|
|
}
|
|
|
|
private void OnHistoryClicked()
|
|
{
|
|
_main.UIManager.GameUI.HistoryUI.NeedShow = true;
|
|
}
|
|
|
|
private void OnAboutClicked()
|
|
{
|
|
_main.UIManager.GameUI.AboutUI.NeedShow = true;
|
|
}
|
|
}
|