265 lines
10 KiB
C#
265 lines
10 KiB
C#
using System.Runtime.InteropServices.WindowsRuntime;
|
|
using Animancer;
|
|
using UnityEngine;
|
|
using Logic;
|
|
using MongoDB.Driver;
|
|
using RuntimeData;
|
|
using TH1_Core.Events;
|
|
using TH1_Core.Managers;
|
|
using TH1_Logic.Core;
|
|
using TH1_Logic.Net;
|
|
using TH1_Logic.Steam;
|
|
using TH1Renderer;
|
|
using TH1Resource;
|
|
using UI;
|
|
using UI.HintUI;
|
|
using UnityEngine.UI;
|
|
using Unity.VisualScripting;
|
|
using UnityEditor;
|
|
|
|
public class BottomBarUI
|
|
{
|
|
public GameObject ROBottomBarUI;
|
|
public Button SettingsButton;
|
|
public Button QuitButton;
|
|
public Button TutorButton;
|
|
public Button SLButton;
|
|
public Button RankingButton;
|
|
public Button TechTreeButton;
|
|
public Button NextTurnButton;
|
|
public Button MessageButton; // ← 新增按钮字段
|
|
public Button HeroButton;
|
|
public Transform QuitHint;
|
|
public Transform TutorPanel;
|
|
|
|
private GiantType _chooseFirstHeroType;
|
|
|
|
private Main _main;
|
|
|
|
//-------- 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)
|
|
{
|
|
_main = main;
|
|
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");
|
|
TutorButton = ROBottomBarUI.transform.Find("TutorButton").GetComponent<Button>();
|
|
SLButton = ROBottomBarUI.transform.Find("SLButton").GetComponent<Button>();
|
|
TutorPanel = ROBottomBarUI.transform.Find("Tutor");
|
|
RankingButton = ROBottomBarUI.transform.Find("RankingButton").GetComponent<Button>();
|
|
TechTreeButton = ROBottomBarUI.transform.Find("TechTreeButton").GetComponent<Button>();
|
|
NextTurnButton = ROBottomBarUI.transform.Find("NextTurnButton").GetComponent<Button>();
|
|
MessageButton = ROBottomBarUI.transform.Find("MessageButton").GetComponent<Button>(); // ← 新增按钮获取
|
|
HeroButton = ROBottomBarUI.transform.Find("HeroButton").GetComponent<Button>();
|
|
GameStartInit();
|
|
|
|
}
|
|
|
|
public void GameStartInit()
|
|
{
|
|
SettingsButton.onClick.RemoveAllListeners();
|
|
SettingsButton.onClick.AddListener(OnSettingsClicked);
|
|
QuitButton.onClick.RemoveAllListeners();
|
|
QuitButton.onClick.AddListener(OnQuitClicked);
|
|
QuitHintInit();
|
|
TutorButton.onClick.RemoveAllListeners();
|
|
TutorButton.onClick.AddListener(OnTutorClicked);
|
|
|
|
SLButton.onClick.RemoveAllListeners();
|
|
SLButton.gameObject.SetActive(false);
|
|
if (Main.MapData != null && Main.MapData.Net.Mode == NetMode.Single)
|
|
{
|
|
SLButton.gameObject.SetActive(true);
|
|
SLButton.onClick.AddListener(OnSLClicked);
|
|
}
|
|
|
|
|
|
RankingButton.onClick.RemoveAllListeners();
|
|
RankingButton.onClick.AddListener(OnRankingClicked);
|
|
TechTreeButton.onClick.RemoveAllListeners();
|
|
TechTreeButton.onClick.AddListener(OnTechTreeClicked);
|
|
NextTurnButton.onClick.RemoveAllListeners();
|
|
NextTurnButton.onClick.AddListener(OnNextTurnClicked);
|
|
MessageButton.onClick.RemoveAllListeners();
|
|
MessageButton.onClick.AddListener(OnMessageClicked); // ← 新增点击监听
|
|
|
|
HeroButton.onClick.RemoveAllListeners();
|
|
HeroButton.onClick.AddListener(OnHeroButtonClicked);
|
|
UpdateHeroButtonSprite();
|
|
_isAnimating = false;
|
|
_isShow = true;
|
|
ROBottomBarUI.transform.GetComponent<CanvasGroup>().alpha = 1;
|
|
|
|
|
|
}
|
|
|
|
public void UpdateHeroButtonSprite()
|
|
{
|
|
HeroButton.gameObject.transform.Find("Icon/Avatar").GetComponent<Image>().sprite = Main.MapData.PlayerMap.SelfPlayerData.PlayerHeroData.GetHeroButtonSprite();
|
|
HeroButton.gameObject.transform.Find("Hint").gameObject.SetActive(Main.MapData.PlayerMap.SelfPlayerData.PlayerHeroData.GetHeroButtonHint());
|
|
}
|
|
|
|
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.RemoveAllListeners();
|
|
QuitHint.Find("YesButton").GetComponent<Button>()?.onClick.AddListener(() =>
|
|
{
|
|
if(Main.MapData?.Net.Mode == NetMode.Multi)
|
|
LobbyManager.Instance.Lobby?.LeaveLobby();
|
|
MapRenderer.Instance.OnGameClosed();
|
|
UIManager.Instance.GameUI.MainUI.NeedShow = true;
|
|
_main.GameLogic.ChangeState(GameState.Menu);
|
|
});
|
|
QuitHint.Find("NoButton").GetComponent<Button>()?.onClick.RemoveAllListeners();
|
|
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,"BottomBarUI_QuitHintInit");
|
|
});
|
|
}
|
|
|
|
|
|
// 按钮点击事件
|
|
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 OnTutorClicked()
|
|
{
|
|
var anim = TutorPanel.GetComponent<AnimancerComponent>();
|
|
if (!anim) return;
|
|
if (TutorPanel.gameObject.activeSelf)
|
|
{
|
|
|
|
TutorPanel.gameObject.SetActive(false);
|
|
}
|
|
else
|
|
{
|
|
TutorPanel.gameObject.SetActive(true);
|
|
anim.Play(ResourceCache.Instance.AnimCache.UICommonPanelFadeIn);
|
|
}
|
|
|
|
}
|
|
private void OnSLClicked()
|
|
{
|
|
if (Main.MapData == null) return;
|
|
if (!Main.MapData.CurPlayer.IsSelfPlayer()) return;
|
|
if (Main.MapData.Net.Mode != NetMode.Single) return;
|
|
_main.GameLogic.ChangeState(GameState.Menu);
|
|
UIManager.Instance.GameUI.MainUI.ShowLoadingAndResumeGame(false);
|
|
}
|
|
|
|
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();
|
|
if (Main.MapData.Net.Mode == NetMode.Multi && !LobbyManager.Instance.Lobby.IsLobbyOwner())
|
|
{
|
|
GameNetSender.Instance.TurnEndConfirm();
|
|
}
|
|
// 单机或者是房主直接切
|
|
else Main.PlayerLogic.EndPlayerTurn(Main.MapData, Main.MapData.PlayerMap.SelfPlayerId);
|
|
}
|
|
|
|
private void OnMessageClicked()
|
|
{
|
|
UIManager.Instance.MessageUI.NeedShow = !UIManager.Instance.MessageUI.NeedShow;
|
|
}
|
|
|
|
private void OnHeroButtonClicked()
|
|
{
|
|
EventManager.Publish(new ShowUIInfoHero(){non = 0});
|
|
UIManager.Instance.BottomInfoUI.SetBottomInfoHide();
|
|
}
|
|
|
|
|
|
}
|