171 lines
5.5 KiB
C#
171 lines
5.5 KiB
C#
using Animancer;
|
|
using UnityEngine;
|
|
using Logic;
|
|
using RuntimeData;
|
|
using TH1Resource;
|
|
using UnityEngine.UI;
|
|
using Unity.VisualScripting;
|
|
using UnityEditor;
|
|
|
|
public class BottomBarUI
|
|
{
|
|
public GameObject ROBottomBarUI;
|
|
public Button SettingsButton;
|
|
public Button QuitButton;
|
|
public Button GameStatsButton;
|
|
public Button TechTreeButton;
|
|
public Button NextTurnButton;
|
|
public Button MessageButton; // ← 新增按钮字段
|
|
public Transform QuitHint;
|
|
|
|
private Main _main;
|
|
private MapData _mapData;
|
|
|
|
//-------- UI表现层RenderData --------//
|
|
public bool UIBottomBarStatus = true;
|
|
|
|
//------- 动画数据 ---------//
|
|
private bool _isAnimating = false;
|
|
private float _fadeTime = 0f;
|
|
private bool _isShow = false;
|
|
|
|
private float _fadeDuration = 0.2f;
|
|
|
|
public BottomBarUI(Main main, MapData mapData)
|
|
{
|
|
_main = main;
|
|
_mapData = mapData;
|
|
ROBottomBarUI = UIManager.Instance.ROUIManager.transform.Find("BottomBarPanel").gameObject;
|
|
|
|
SettingsButton = ROBottomBarUI.transform.Find("SettingsButton").GetComponent<Button>();
|
|
QuitButton = ROBottomBarUI.transform.Find("QuitButton").GetComponent<Button>();
|
|
QuitHint = ROBottomBarUI.transform.Find("QuitHint");
|
|
GameStatsButton = ROBottomBarUI.transform.Find("GameStatsButton").GetComponent<Button>();
|
|
TechTreeButton = ROBottomBarUI.transform.Find("TechTreeButton").GetComponent<Button>();
|
|
NextTurnButton = ROBottomBarUI.transform.Find("NextTurnButton").GetComponent<Button>();
|
|
MessageButton = ROBottomBarUI.transform.Find("MessageButton").GetComponent<Button>(); // ← 新增按钮获取
|
|
|
|
SettingsButton.onClick.AddListener(OnSettingsClicked);
|
|
QuitButton.onClick.AddListener(OnQuitClicked);
|
|
QuitHintInit();
|
|
GameStatsButton.onClick.AddListener(OnRankingClicked);
|
|
TechTreeButton.onClick.AddListener(OnTechTreeClicked);
|
|
NextTurnButton.onClick.AddListener(OnNextTurnClicked);
|
|
MessageButton.onClick.AddListener(OnMessageClicked); // ← 新增点击监听
|
|
|
|
_isAnimating = false;
|
|
_isShow = true;
|
|
ROBottomBarUI.transform.GetComponent<CanvasGroup>().alpha = 1;
|
|
}
|
|
|
|
public void Update()
|
|
{
|
|
if (_isAnimating)
|
|
{
|
|
_fadeTime += Time.deltaTime / _fadeDuration;
|
|
if(_isShow)
|
|
ROBottomBarUI.transform.GetComponent<CanvasGroup>().alpha = Mathf.Lerp(0f, 1f, _fadeTime);
|
|
else
|
|
ROBottomBarUI.transform.GetComponent<CanvasGroup>().alpha = Mathf.Lerp(1f, 0f, _fadeTime);
|
|
|
|
if (_fadeTime >= 1f)
|
|
{
|
|
_isAnimating = false;
|
|
_fadeTime = 0f;
|
|
if (!_isShow)
|
|
ROBottomBarUI.SetActive(false);
|
|
}
|
|
return;
|
|
}
|
|
|
|
if (UIBottomBarStatus)
|
|
{
|
|
if (!ROBottomBarUI.activeSelf)
|
|
{
|
|
ROBottomBarUI.SetActive(true);
|
|
_isAnimating = true;
|
|
_isShow = true;
|
|
_fadeTime = 0f;
|
|
UIBottomBarStatus = true;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (ROBottomBarUI.activeSelf)
|
|
{
|
|
_isAnimating = true;
|
|
_isShow = false;
|
|
_fadeTime = 0f;
|
|
UIBottomBarStatus = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
public void SetBottomBarShowHide(bool status)
|
|
{
|
|
UIBottomBarStatus = status;
|
|
}
|
|
|
|
//quithint的初始化
|
|
private void QuitHintInit()
|
|
{
|
|
QuitHint.gameObject.SetActive(false);
|
|
QuitHint.Find("YesButton").GetComponent<Button>()?.onClick.AddListener(() =>
|
|
{
|
|
UIManager.Instance.GameUI.MainUI.NeedShow = true;
|
|
_main.GameLogic.ChangeState(GameState.Menu);
|
|
});
|
|
QuitHint.Find("NoButton").GetComponent<Button>()?.onClick.AddListener(() =>
|
|
{
|
|
var anim = QuitHint.GetComponent<AnimancerComponent>();
|
|
if (anim != null)
|
|
anim.Play(ResourceCache.Instance.AnimCache.UICommonPanelFadeOut);
|
|
Timer.Instance.TimerRegister(this, () =>
|
|
{
|
|
QuitHint.gameObject.SetActive(false);
|
|
},ResourceCache.Instance.AnimCache.UICommonPanelFadeOut.length);
|
|
});
|
|
}
|
|
|
|
|
|
// 按钮点击事件
|
|
private void OnSettingsClicked()
|
|
{
|
|
UIManager.Instance.SettingUI.NeedShow = !UIManager.Instance.SettingUI.NeedShow;
|
|
}
|
|
|
|
private void OnQuitClicked()
|
|
{
|
|
var anim = QuitHint.GetComponent<AnimancerComponent>();
|
|
if (!anim) return;
|
|
QuitHint.gameObject.SetActive(true);
|
|
anim.Play(ResourceCache.Instance.AnimCache.UICommonPanelFadeIn);
|
|
}
|
|
|
|
private void OnRankingClicked()
|
|
{
|
|
UIManager.Instance.RankingUI.NeedShow = !UIManager.Instance.RankingUI.NeedShow;
|
|
}
|
|
|
|
public void OnTechTreeClicked()
|
|
{
|
|
SetBottomBarShowHide(false);
|
|
UIManager.Instance.TechTreeUI.SetTechTreeShowHide(true);
|
|
_main.MapInteractionLogic.CancelAllHighlight();
|
|
UIManager.Instance.BottomInfoUI.SetBottomInfoHide();
|
|
}
|
|
|
|
private void OnNextTurnClicked()
|
|
{
|
|
|
|
UIManager.Instance.BottomInfoUI.SetBottomInfoHide();
|
|
_main.MapInteractionLogic.CancelAllHighlight();
|
|
_main.GameLogic.ChangeState(GameState.AIRound);
|
|
}
|
|
|
|
private void OnMessageClicked()
|
|
{
|
|
UIManager.Instance.MessageUI.NeedShow = !UIManager.Instance.MessageUI.NeedShow;
|
|
}
|
|
}
|