365 lines
14 KiB
C#
365 lines
14 KiB
C#
using System.Collections.Generic;
|
||
using System.Runtime.InteropServices.WindowsRuntime;
|
||
using Animancer;
|
||
using UnityEngine;
|
||
using Logic;
|
||
using Logic.Multilingual;
|
||
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 TMPro;
|
||
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;
|
||
|
||
// 在NetInfo临时使用
|
||
public Transform NetInfo;
|
||
public struct BottomBarNetInfoRow
|
||
{
|
||
//memberId
|
||
public ulong uid;
|
||
public TextMeshProUGUI Name;
|
||
public TextMeshProUGUI Prop;
|
||
public TextMeshProUGUI Status;
|
||
}
|
||
public List<BottomBarNetInfoRow> NetInfoRow;
|
||
|
||
|
||
|
||
|
||
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>();
|
||
NetInfo = ROBottomBarUI.transform.Find("NetInfo");
|
||
GameStartInit();
|
||
|
||
}
|
||
|
||
public void GameStartInit()
|
||
{
|
||
SettingsButton.onClick.RemoveAllListeners();
|
||
SettingsButton.onClick.AddListener(OnSettingsClicked);
|
||
QuitButton.onClick.RemoveAllListeners();
|
||
QuitButton.onClick.AddListener(OnQuitClicked);
|
||
QuitHintInit();
|
||
TutorButton.onClick.RemoveAllListeners();
|
||
|
||
|
||
SLButton.onClick.RemoveAllListeners();
|
||
SLButton.gameObject.SetActive(false);
|
||
TutorButton.gameObject.SetActive(false);
|
||
if (Main.MapData != null && Main.MapData.Net.Mode == NetMode.Single)
|
||
{
|
||
SLButton.gameObject.SetActive(true);
|
||
TutorButton.gameObject.SetActive(true);
|
||
NetInfo.gameObject.SetActive(true);
|
||
SLButton.onClick.AddListener(OnSLClicked);
|
||
TutorButton.onClick.AddListener(OnTutorClicked);
|
||
}
|
||
|
||
NetInfo.gameObject.SetActive(false);
|
||
if (Main.MapData != null && Main.MapData.Net.Mode == NetMode.Multi)
|
||
{
|
||
NetInfoRow = new List<BottomBarNetInfoRow>();
|
||
var lobbyInfo = LobbyManager.Instance.Lobby as SteamLobbyManager;
|
||
var mids = lobbyInfo.GetAllMemberInfo();
|
||
|
||
int ct = 0;
|
||
int maxRow = 2;
|
||
//关联每个有人的玩家的行的相关组件
|
||
foreach(var pair in mids)
|
||
{
|
||
var t = new BottomBarNetInfoRow();
|
||
t.uid = pair.Key;
|
||
t.Name = NetInfo.Find("Row" + ct + "/Name")?.GetComponent<TextMeshProUGUI>();
|
||
if (t.Name != null)
|
||
t.Name.text = pair.Value.Name;
|
||
|
||
//设置房主还是客人信息
|
||
t.Prop = NetInfo.Find("Row" + ct + "/Prop")?.GetComponent<TextMeshProUGUI>();
|
||
if (pair.Key == lobbyInfo.GetLobbyOwnerId())
|
||
MultilingualManager.Instance.SetUIText(t.Prop,Table.Instance.TextDataAssets.MultiplayRoomOwnerTitle);
|
||
else
|
||
MultilingualManager.Instance.SetUIText(t.Prop,Table.Instance.TextDataAssets.MultiplayRoomGuestTitle);
|
||
|
||
//设置联网状态信息
|
||
t.Status = NetInfo.Find("Row" + ct + "/Status")?.GetComponent<TextMeshProUGUI>();
|
||
MultilingualManager.Instance.SetUIText(t.Status,Table.Instance.TextDataAssets.MultiplayNetOkTitle);
|
||
NetInfoRow.Add(t);
|
||
ct++;
|
||
if (ct >= maxRow) break;
|
||
}
|
||
for(;ct < maxRow;ct ++)
|
||
NetInfo.Find("Row" + ct + "/Prop")?.gameObject.SetActive(false);
|
||
}
|
||
|
||
|
||
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 (Main.MapData == null) return;
|
||
HeroButton.gameObject.transform.Find("Hint").gameObject.SetActive(Main.MapData.PlayerMap.SelfPlayerData.PlayerHeroData.GetHeroButtonHint());
|
||
UpdateNetInfo();
|
||
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 UpdateNetInfo()
|
||
{
|
||
if(Main.MapData == null)return;
|
||
if (Main.MapData.Net.Mode != NetMode.Multi) return;
|
||
|
||
NetInfo.gameObject.SetActive(true);
|
||
if (Main.MapData != null && Main.MapData.Net.Mode == NetMode.Multi)
|
||
{
|
||
var lobbyInfo = LobbyManager.Instance.Lobby as SteamLobbyManager;
|
||
var mids = lobbyInfo.GetAllMemberInfo();
|
||
int maxRow = 2;
|
||
//遍历所有行
|
||
for (int i = 0; i < maxRow; i++)
|
||
{
|
||
if (i >= NetInfoRow.Count) continue;
|
||
//如果开局init的时候,就没有给他init上,那么跳过 ,否则不管玩家是不是掉线,都要显示计算的
|
||
if (NetInfo.Find("Row" + i)?.gameObject.activeSelf != true) continue;
|
||
|
||
//判断是不是已经掉线
|
||
var confirmData = Main.Instance.ConfirmMap.GetPlayerConfirm(NetInfoRow[i].uid);
|
||
if (confirmData.State != MemberNetState.OK)
|
||
{
|
||
MultilingualManager.Instance.SetUIText(NetInfoRow[i].Prop,Table.Instance.TextDataAssets.MultiplayRoomGuestTitle);
|
||
MultilingualManager.Instance.SetUIText(NetInfoRow[i].Status,Table.Instance.TextDataAssets.MultiplayNetAIPlayTitle);
|
||
}
|
||
else
|
||
{
|
||
if(NetInfoRow[i].uid == lobbyInfo.GetLobbyOwnerId())
|
||
MultilingualManager.Instance.SetUIText(NetInfoRow[i].Prop,Table.Instance.TextDataAssets.MultiplayRoomOwnerTitle);
|
||
else
|
||
MultilingualManager.Instance.SetUIText(NetInfoRow[i].Prop,Table.Instance.TextDataAssets.MultiplayRoomGuestTitle);
|
||
MultilingualManager.Instance.SetUIText(NetInfoRow[i].Status,Table.Instance.TextDataAssets.MultiplayNetOkTitle);
|
||
}
|
||
|
||
}
|
||
|
||
}
|
||
|
||
|
||
}
|
||
|
||
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);
|
||
EventManager.Publish(new ShowUIInfoTechTree(){non = 0});
|
||
_main.MapInteractionLogic.CancelAllHighlight();
|
||
}
|
||
|
||
private void OnNextTurnClicked()
|
||
{
|
||
_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});
|
||
}
|
||
|
||
|
||
}
|