322 lines
12 KiB
C#
322 lines
12 KiB
C#
using System.Runtime.InteropServices.WindowsRuntime;
|
|
using Animancer;
|
|
using UnityEngine;
|
|
using Logic;
|
|
using MongoDB.Driver;
|
|
using RuntimeData;
|
|
using TH1_Core.Managers;
|
|
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 ChooseFirstHeroButton;
|
|
public Transform QuitHint;
|
|
public Transform ChooseFirstHeroPanel;
|
|
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>(); // ← 新增按钮获取
|
|
ChooseFirstHeroButton = ROBottomBarUI.transform.Find("ChooseFirstHeroButton").GetComponent<Button>();
|
|
ChooseFirstHeroPanel = ROBottomBarUI.transform.Find("ChooseFirstHeroPanel");
|
|
|
|
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.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); // ← 新增点击监听
|
|
|
|
ChooseFirstHeroButton.onClick.RemoveAllListeners();
|
|
ChooseFirstHeroButton.onClick.AddListener(OnChooseFirstHeroClicked);
|
|
ChooseFirstHeroPanelInit();
|
|
|
|
_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.RemoveAllListeners();
|
|
QuitHint.Find("YesButton").GetComponent<Button>()?.onClick.AddListener(() =>
|
|
{
|
|
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 ChooseFirstHeroPanelInit()
|
|
{
|
|
|
|
ChooseFirstHeroButton.gameObject.SetActive(false);
|
|
ChooseFirstHeroPanel.gameObject.SetActive(false);
|
|
if (Main.MapData == null) return;
|
|
if (!Main.MapData.PlayerMap.SelfPlayerData.HasFirstHero)
|
|
ChooseFirstHeroButton.gameObject.SetActive(true);
|
|
else
|
|
return;
|
|
//ChooseFirstHeroButton.gameObject.SetActive(true);
|
|
|
|
//step #2 设定每个单位的点击操作
|
|
var heroGroup = ChooseFirstHeroPanel.Find("HeroGroup");
|
|
var choosedGroup = ChooseFirstHeroPanel.Find("ChoosedGroup");
|
|
|
|
foreach (Transform child in heroGroup)
|
|
{
|
|
//GameObject child = childTransform.gameObject;
|
|
|
|
var btn = child.Find("BG")?.GetComponent<Button>();
|
|
if (btn == null) continue;
|
|
var giantType = child.Find("BG")?.GetComponent<UnitTypeMono>()?.GiantType;
|
|
|
|
if(giantType == null)continue;
|
|
|
|
btn.onClick.RemoveAllListeners();
|
|
btn.onClick.AddListener(() =>
|
|
{
|
|
|
|
_chooseFirstHeroType = giantType.Value;
|
|
foreach (Transform chd in choosedGroup)
|
|
{
|
|
chd.gameObject.SetActive(false);
|
|
var chdgiant = chd.GetComponent<UnitTypeMono>()?.GiantType;
|
|
if(chdgiant == giantType) chd.gameObject.SetActive(true);
|
|
}
|
|
});
|
|
}
|
|
|
|
//step #3 默认选中蕾米莉亚
|
|
_chooseFirstHeroType = GiantType.EgyptianRemilia;
|
|
foreach (Transform chd in choosedGroup)
|
|
{
|
|
chd.gameObject.SetActive(false);
|
|
var chdgiant2 = chd.GetComponent<UnitTypeMono>().GiantType;
|
|
if(chdgiant2 == _chooseFirstHeroType) chd.gameObject.SetActive(true);
|
|
}
|
|
|
|
//step #4 绑定选中和取消按钮
|
|
ChooseFirstHeroPanel.Find("YesButton").GetComponent<Button>()?.onClick.RemoveAllListeners();
|
|
ChooseFirstHeroPanel.Find("YesButton").GetComponent<Button>()?.onClick.AddListener(() =>
|
|
{
|
|
Main.MapData.PlayerMap.SelfPlayerData.HasFirstHero = true;
|
|
Main.MapData.PlayerMap.SelfPlayerData.FirstHero = _chooseFirstHeroType;
|
|
//Main.PlayerLogic.ResearchTech(Main.MapData,Main.MapData.PlayerMap.SelfPlayerData,_chooseFirstHeroType,0);
|
|
|
|
ChooseFirstHeroButton.gameObject.SetActive(false);
|
|
var anim = ChooseFirstHeroPanel.GetComponent<AnimancerComponent>();
|
|
if (anim != null)
|
|
anim.Play(ResourceCache.Instance.AnimCache.UICommonPanelFadeOut);
|
|
Timer.Instance.TimerRegister(this, () =>
|
|
{
|
|
ChooseFirstHeroPanel.gameObject.SetActive(false);
|
|
},ResourceCache.Instance.AnimCache.UICommonPanelFadeOut.length,"BottomBarUI_ChooseFirstHeroPanel");
|
|
});
|
|
ChooseFirstHeroPanel.Find("NoButton").GetComponent<Button>()?.onClick.RemoveAllListeners();
|
|
ChooseFirstHeroPanel.Find("NoButton").GetComponent<Button>()?.onClick.AddListener(() =>
|
|
{
|
|
var anim = ChooseFirstHeroPanel.GetComponent<AnimancerComponent>();
|
|
if (anim != null)
|
|
anim.Play(ResourceCache.Instance.AnimCache.UICommonPanelFadeOut);
|
|
Timer.Instance.TimerRegister(this, () =>
|
|
{
|
|
ChooseFirstHeroPanel.gameObject.SetActive(false);
|
|
},ResourceCache.Instance.AnimCache.UICommonPanelFadeOut.length,"BottomBarUI_ChooseFirstHeroPanel");
|
|
});
|
|
}
|
|
|
|
private void OnChooseFirstHeroClicked()
|
|
{
|
|
if (Main.MapData.PlayerMap.SelfPlayerData.HasFirstHero) return;
|
|
var anim = ChooseFirstHeroPanel.GetComponent<AnimancerComponent>();
|
|
if (!anim) return;
|
|
ChooseFirstHeroPanel.gameObject.SetActive(true);
|
|
anim.Play(ResourceCache.Instance.AnimCache.UICommonPanelFadeIn);
|
|
}
|
|
|
|
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()
|
|
{
|
|
_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();
|
|
_main.GameLogic.ChangeState(GameState.AIRound);
|
|
}
|
|
|
|
private void OnMessageClicked()
|
|
{
|
|
UIManager.Instance.MessageUI.NeedShow = !UIManager.Instance.MessageUI.NeedShow;
|
|
}
|
|
|
|
|
|
}
|