132 lines
4.1 KiB
C#
132 lines
4.1 KiB
C#
using UnityEngine;
|
|
using Logic;
|
|
using RuntimeData;
|
|
using UnityEngine.UI;
|
|
using Unity.VisualScripting;
|
|
|
|
public class BottomBarUI
|
|
{
|
|
public GameObject ROBottomBarUI;
|
|
public Button SettingsButton;
|
|
public Button GameStatsButton;
|
|
public Button TechTreeButton;
|
|
public Button NextTurnButton;
|
|
public Button MessageButton; // ← 新增按钮字段
|
|
|
|
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>();
|
|
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);
|
|
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;
|
|
}
|
|
|
|
// 按钮点击事件
|
|
private void OnSettingsClicked()
|
|
{
|
|
UIManager.Instance.SettingUI.NeedShow = !UIManager.Instance.SettingUI.NeedShow;
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|