TH1/My project/Assets/Scripts/UI/TimeEndUI.cs
2025-06-13 03:56:58 +08:00

53 lines
2.0 KiB
C#

using UnityEngine;
using TMPro;
using Animancer;
using Logic;
using RuntimeData;
using UnityEngine.UI;
using System.Collections.Generic;
public class TimeEndUI
{
private Main _main;
private MapData _mapData;
public GameObject ROTimeEndUI;
public Button ReturnButton;
public TimeEndUI(Main main, MapData mapData)
{
_main = main;
_mapData = mapData;
ROTimeEndUI = _main.UIManager.ROUIManager.transform.Find("TimeEndPanel").gameObject;
ROTimeEndUI.gameObject.SetActive(false);
ReturnButton = ROTimeEndUI.transform.Find("MsgList/Row4/Button").GetComponent<Button>(); // ← 新增按钮
ReturnButton.onClick.AddListener(OnReturnClicked); // ← 新增点击监听
}
public void Update()
{
if (ROTimeEndUI.activeSelf)
return;
if (_mapData == null)
return;
if (_mapData.PlayerMap.CheckTimeEnd())
{
ROTimeEndUI.gameObject.SetActive(true);
int ans = 1;
foreach(var player in _mapData.PlayerMap.PlayerDataList)
if (player.Id != _mapData.PlayerMap.SelfPlayerId
&& player.PlayerScore > _mapData.PlayerMap.SelfPlayerData.PlayerScore)
ans++;
ROTimeEndUI.transform.Find("MsgList/Row0/Text").GetComponent<TextMeshProUGUI>().text = $"恭喜您取得信仰分第{ans}名!";
ROTimeEndUI.transform.Find("MsgList/Row1/Head1/Text").GetComponent<TextMeshProUGUI>().text = _mapData.GetCityCount(_mapData.PlayerMap.SelfPlayerData.Id).ToString();
ROTimeEndUI.transform.Find("MsgList/Row2/Head1/Text").GetComponent<TextMeshProUGUI>().text = "0";
ROTimeEndUI.transform.Find("MsgList/Row3/Head1/Text").GetComponent<TextMeshProUGUI>().text = _mapData.PlayerMap.SelfPlayerData.PlayerScore.ToString();
}
}
public void OnReturnClicked()
{
_main.GameLogic.ChangeState(GameState.Finished);
ROTimeEndUI.gameObject.SetActive(false);
_main.UIManager.GameUI.ShowMainUIManager();
}
}