239 lines
8.3 KiB
C#
239 lines
8.3 KiB
C#
using UnityEngine;
|
||
using Logic;
|
||
using RuntimeData;
|
||
using Animancer;
|
||
using ET;
|
||
using TMPro;
|
||
using UnityEngine.UI;
|
||
using Logic.Audio;
|
||
using Logic.Config;
|
||
using TH1_Core.Managers;
|
||
using TH1_Logic.Core;
|
||
using TH1Resource;
|
||
using UI;
|
||
using Unity.VisualScripting;
|
||
|
||
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 Button BoardingButton;
|
||
public TextMeshProUGUI QQHintVersion;
|
||
public TextMeshProUGUI QQHintVersion2;
|
||
|
||
public bool NeedShow = false;
|
||
private bool _quickAnim;
|
||
|
||
private bool _isShowing = false;
|
||
private bool _isAnimating = false;
|
||
private float _fadeDuration = 0.2f;
|
||
|
||
private bool _languageHint;
|
||
public MainUI(Main main, MapData mapData)
|
||
{
|
||
_main = main;
|
||
_mapData = mapData;
|
||
ROMainUI = UIManager.Instance.ROUIManager.transform.Find("GameUI/MainUI").gameObject;
|
||
ROMainUI.gameObject.SetActive(false);
|
||
|
||
_languageHint = Application.systemLanguage != SystemLanguage.ChineseSimplified;
|
||
if(_languageHint)
|
||
ROMainUI.transform.Find("LanguageHint").gameObject.SetActive(true);
|
||
// step #1 绑定所有按钮
|
||
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>();
|
||
BoardingButton = ROMainUI.transform.Find("ButtonRow2/BoardingButton").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);
|
||
BoardingButton?.onClick.AddListener(OnBoardingClicked);
|
||
|
||
// step #2 设置主界面的版本号
|
||
QQHintVersion = ROMainUI.transform.Find("QQHint/Version")?.GetComponent<TextMeshProUGUI>();
|
||
//QQHintVersion.text = ConfigManager.Instance.VersionCfg.CurVersionId.ToString();
|
||
QQHintVersion2 = ROMainUI.transform.Find("QQHint/Version2")?.GetComponent<TextMeshProUGUI>();
|
||
//QQHintVersion2.text = ConfigManager.Instance.VersionCfg.CurVersionId.ToString();
|
||
if (QQHintVersion != null)
|
||
{
|
||
var version = ConfigManager.Instance.VersionCfg;
|
||
QQHintVersion.text = "[Demo V" + version.CurVersionMajorId + "." + version.CurVersionMinorId + "." + version.CurVersionPatchId + "]";
|
||
}
|
||
|
||
if (QQHintVersion2 != null)
|
||
{
|
||
var version = ConfigManager.Instance.VersionCfg;
|
||
QQHintVersion2.text = "[V" + version.CurVersionMajorId + "." + version.CurVersionMinorId + "." + version.CurVersionPatchId + "]";
|
||
}
|
||
|
||
// step #3 如果有存当,显示"继续"这个按钮
|
||
ROMainUI.transform.Find("ButtonRow").Find("ResumeGameButton").gameObject.SetActive(_main.HasArchive());
|
||
}
|
||
|
||
public void Update()
|
||
{
|
||
|
||
if (_isAnimating) return;
|
||
|
||
if (NeedShow && !ROMainUI.activeSelf)
|
||
Show();
|
||
else if (!NeedShow && ROMainUI.activeSelf)
|
||
Hide();
|
||
|
||
}
|
||
|
||
public void UpdateMainUI()
|
||
{
|
||
|
||
UIManager.Instance.ROHintWindow.SetActive(false);
|
||
ROMainUI.transform.Find("ButtonRow").Find("ResumeGameButton").gameObject.SetActive(_main.HasArchive());
|
||
}
|
||
public void Show()
|
||
{
|
||
UpdateMainUI();
|
||
|
||
if (_isShowing || _isAnimating) return;
|
||
|
||
AudioManager.Instance.PlayMusic("Main",0.3f,0.3f,true);
|
||
_isShowing = true;
|
||
|
||
ROMainUI.SetActive(true);
|
||
if (_quickAnim)
|
||
{
|
||
var canvas = ROMainUI.GetComponent<CanvasGroup>();
|
||
if(canvas != null)
|
||
canvas.alpha = 1f;
|
||
_quickAnim = false;
|
||
}
|
||
else
|
||
{
|
||
_isAnimating = true;
|
||
AnimancerComponent animancer = ROMainUI.GetComponent<AnimancerComponent>();
|
||
animancer.Play(ResourceCache.Instance.AnimCache.UICommonPanelFadeIn);
|
||
Timer.Instance.TimerRegister(ROMainUI, () => { _isAnimating = false; }, _fadeDuration,"MainUI_Show");
|
||
}
|
||
|
||
}
|
||
|
||
public void Hide()
|
||
{
|
||
if (!_isShowing || _isAnimating) return;
|
||
|
||
_isShowing = false;
|
||
|
||
if (_quickAnim)
|
||
{
|
||
ROMainUI.SetActive(false);
|
||
_isAnimating = false;
|
||
_quickAnim = false;
|
||
}
|
||
else
|
||
{
|
||
_isAnimating = true;
|
||
AnimancerComponent animancer = ROMainUI.GetComponent<AnimancerComponent>();
|
||
animancer.Play(ResourceCache.Instance.AnimCache.UICommonPanelFadeOut);
|
||
|
||
Timer.Instance.TimerRegister(ROMainUI, () =>
|
||
{
|
||
ROMainUI.SetActive(false);
|
||
_isAnimating = false;
|
||
}, _fadeDuration,"MainUI_Hide");
|
||
}
|
||
|
||
}
|
||
|
||
private void OnNewGameClicked()
|
||
{
|
||
NeedShow = false;
|
||
UIManager.Instance.GameUI.ChooseUI.NeedShow = true;
|
||
}
|
||
|
||
private void OnResumeGameClicked()
|
||
{
|
||
//Debug.Log("Resume Game Clicked");
|
||
if (_main.HasArchive())
|
||
{
|
||
ShowLoadingAndResumeGame(true);
|
||
}
|
||
//NeedShow = false;
|
||
}
|
||
|
||
//很脏的传入bool TODO要迭代
|
||
public void ShowLoadingAndResumeGame(bool QuickAnim = false)
|
||
{
|
||
float startTime = ResourceCache.Instance.AnimCache.UICommonPanelFadeIn.length;
|
||
float prepareTime = 0.2f + (QuickAnim ? 0.1f : ResourceCache.Instance.AnimCache.UICommonPanelFadeOut.length);
|
||
var loading = UIManager.Instance.ROUIManager.transform.Find("LoadingUI");
|
||
var loadingAnim = loading.GetComponent<AnimancerComponent>();
|
||
if (loadingAnim == null)
|
||
{
|
||
_main.ContinueGame();
|
||
return;
|
||
}
|
||
//先播放loading界面,然后加载游戏,再关掉loading界面
|
||
loading.gameObject.SetActive(true);
|
||
loadingAnim.Play(ResourceCache.Instance.AnimCache.UICommonPanelFadeIn);
|
||
Timer.Instance.TimerRegister(this,() => {
|
||
_main.ContinueGame();
|
||
NeedShow = false;
|
||
_quickAnim = QuickAnim;
|
||
//ROMainUI.SetActive(false);
|
||
},startTime,"MainUI_ShowLoadingAndRusume");
|
||
|
||
//播放loading消失的动画
|
||
Timer.Instance.TimerRegister(loading,()=> { loadingAnim.Play(ResourceCache.Instance.AnimCache.UICommonPanelFadeOut); },prepareTime + startTime,"MainUI_ShowLoadingAndRusume2");
|
||
//将loading设置为false
|
||
Timer.Instance.TimerRegister(loading,()=> { loading.gameObject.SetActive(false); },startTime + prepareTime + ResourceCache.Instance.AnimCache.UICommonPanelFadeOut.length,"MainUI_ShowLoadingAndRusume3");
|
||
}
|
||
|
||
private void OnStoryModeClicked()
|
||
{
|
||
Debug.Log("Story Mode Clicked");
|
||
}
|
||
|
||
private void OnLibraryClicked()
|
||
{
|
||
NeedShow = false;
|
||
UIManager.Instance.GameUI.LibraryUI.NeedShow = true;
|
||
}
|
||
|
||
private void OnSettingClicked()
|
||
{
|
||
UIManager.Instance.SettingUI.NeedShow = true;
|
||
}
|
||
|
||
private void OnBoardingClicked()
|
||
{
|
||
UIManager.Instance.BoardingUI.SetShow();
|
||
}
|
||
|
||
private void OnHistoryClicked()
|
||
{
|
||
UIManager.Instance.GameUI.HistoryUI.NeedShow = true;
|
||
}
|
||
|
||
private void OnAboutClicked()
|
||
{
|
||
UIManager.Instance.GameUI.AboutUI.NeedShow = true;
|
||
}
|
||
}
|