2025-07-30 18:03:37 +08:00

105 lines
4.4 KiB
C#

using UnityEngine;
using TMPro;
using Animancer;
using Logic;
using RuntimeData;
using UnityEngine.UI;
using System.Collections.Generic;
using Logic.Multilingual;
using ParadoxNotion.Design;
using TH1Resource;
using UI;
public class WinUI
{
private Main _main;
private MapData _mapData;
private GameObject _ROWinUI;
private Button _returnButton;
private Image _frontBG;
private bool _curGameDone;
public WinUI(Main main, MapData mapData)
{
_main = main;
_mapData = mapData;
_ROWinUI = UIManager.Instance.ROUIManager.transform.Find("WinPanel").gameObject;
_ROWinUI.gameObject.SetActive(false);
_returnButton = _ROWinUI.transform.Find("MsgList/Row4/Button").GetComponent<Button>(); // ← 新增按钮
_returnButton.onClick.AddListener(OnReturnClicked); // ← 新增点击监听
_frontBG = _ROWinUI.transform.Find("BGFront")?.GetComponent<Image>();
_curGameDone = false;
}
public void Show()
{
_ROWinUI.gameObject.SetActive(true);
var anim = _ROWinUI.GetComponent<AnimancerComponent>();
if (anim != null)
anim.Play(ResourceCache.Instance.AnimCache.UICommonPanelFadeIn);
}
public void Update()
{
if (_ROWinUI.activeSelf || _curGameDone)
return;
if (_mapData == null)
return;
if (_mapData.PlayerMap.CheckSelfWin())
{
_curGameDone = true;
var tt = _ROWinUI.transform.Find("Title")?.GetComponent<TextMeshProUGUI>();
if (tt != null)
tt.text = "胜利!!!";
/*
MultilingualManager.Instance.SetUIText(_ROWinUI.transform.Find("Title")?.GetComponent<TextMeshProUGUI>(),
Table.Instance.TextDataAssets.WinUIWinText);*/
_ROWinUI.transform.Find("flowerDeco").gameObject.SetActive(true);
if(_frontBG != null)
_frontBG.color = Color.white;
_ROWinUI.transform.Find("MsgList/Row1/Value").GetComponent<TextMeshProUGUI>().text = _mapData.GetCityCount(_mapData.PlayerMap.SelfPlayerData.Id).ToString();
_ROWinUI.transform.Find("MsgList/Row2/Value").GetComponent<TextMeshProUGUI>().text = _mapData.PlayerMap.SelfPlayerData.Turn.ToString();
_ROWinUI.transform.Find("MsgList/Row3/Value").GetComponent<TextMeshProUGUI>().text = _mapData.PlayerMap.SelfPlayerData.PlayerScore.ToString();
Show();
_main.GameLogic.ChangeState(GameState.Finished);
}
else
if (_mapData.PlayerMap.CheckSelfLose())
{
_curGameDone = true;
var tt = _ROWinUI.transform.Find("Title")?.GetComponent<TextMeshProUGUI>();
if (tt != null)
tt.text = "失败...";
//TODO 有bug 暂时先用替代方案
/*MultilingualManager.Instance.SetUIText(_ROWinUI.transform.Find("Title")?.GetComponent<TextMeshProUGUI>(),
Table.Instance.TextDataAssets.WinUILoseText);
Debug.Log(Table.Instance.TextDataAssets.WinUILoseText);*/
if(_frontBG != null)
_frontBG.color = new Color(1f,0.5f,0.5f);
_ROWinUI.transform.Find("flowerDeco").gameObject.SetActive(false);
_ROWinUI.transform.Find("MsgList/Row1/Value").GetComponent<TextMeshProUGUI>().text = _mapData.GetCityCount(_mapData.PlayerMap.SelfPlayerData.Id).ToString();
_ROWinUI.transform.Find("MsgList/Row2/Value").GetComponent<TextMeshProUGUI>().text = (_mapData.PlayerMap.SelfPlayerData.Turn).ToString();
_ROWinUI.transform.Find("MsgList/Row3/Value").GetComponent<TextMeshProUGUI>().text = _mapData.PlayerMap.SelfPlayerData.PlayerScore.ToString();
Show();
_main.GameLogic.ChangeState(GameState.Finished);
}
// 如果没有正在显示,并且有排队的消息,就开始显示
}
public void OnReturnClicked()
{
_main.GameLogic.ChangeState(GameState.Menu);
var anim = _ROWinUI.GetComponent<AnimancerComponent>();
if (anim != null)
{
anim.Play(ResourceCache.Instance.AnimCache.UICommonPanelFadeOut);
Timer.Instance.TimerRegister(this, () =>
{
_ROWinUI.gameObject.SetActive(false);
},ResourceCache.Instance.AnimCache.UICommonPanelFadeOut.length);
}
else
_ROWinUI.gameObject.SetActive(false);
UIManager.Instance.GameUI.ShowMainUIManager();
}
}