2025-11-04 11:44:44 +08:00

107 lines
4.7 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using UnityEngine;
using TMPro;
using Animancer;
using Logic;
using RuntimeData;
using UnityEngine.UI;
using System.Collections.Generic;
using Logic.Multilingual;
using ParadoxNotion.Design;
using TH1_Core.Managers;
using TH1_Logic.Core;
using TH1Renderer;
using TH1Resource;
using UI;
public class WinUI
{
private GameObject _ROWinUI;
private Button _returnButton;
private Image _frontBG;
private bool _curGameDone;
public WinUI()
{
_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>();
var player = Main.MapData.PlayerMap.SelfPlayerData;
Table.Instance.PlayerDataAssets.GetPlayerInfo(player, out var info);
_ROWinUI.transform.Find("CharMask/Char").GetComponent<Image>().sprite = info.LeaderIllustration;
_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 (Main.MapData == null) return;
if (!Main.MapData.CheckIfGameEnd(out var isWin)) return;
if (isWin)
{
_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 = Main.MapData.GetCityCount(Main.MapData.PlayerMap.SelfPlayerData.Id).ToString();
_ROWinUI.transform.Find("MsgList/Row2/Value").GetComponent<TextMeshProUGUI>().text = Main.MapData.PlayerMap.SelfPlayerData.Turn.ToString();
_ROWinUI.transform.Find("MsgList/Row3/Value").GetComponent<TextMeshProUGUI>().text = Main.MapData.PlayerMap.SelfPlayerData.PlayerScore.ToString();
Show();
}
else
{
_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 = Main.MapData.GetCityCount(Main.MapData.PlayerMap.SelfPlayerData.Id).ToString();
_ROWinUI.transform.Find("MsgList/Row2/Value").GetComponent<TextMeshProUGUI>().text = (Main.MapData.PlayerMap.SelfPlayerData.Turn).ToString();
_ROWinUI.transform.Find("MsgList/Row3/Value").GetComponent<TextMeshProUGUI>().text = Main.MapData.PlayerMap.SelfPlayerData.PlayerScore.ToString();
Show();
}
// 如果没有正在显示,并且有排队的消息,就开始显示
}
public void OnReturnClicked()
{
Main.Instance.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,"WinUI_OnReturnClicked");
}
else
_ROWinUI.gameObject.SetActive(false);
UIManager.Instance.GameUI.ShowMainUIManager();
//处理MapRenderer和UIManager的生命周期OnGameClosed
MapRenderer.Instance.OnGameClosed();
}
}