140 lines
4.7 KiB
C#
140 lines
4.7 KiB
C#
using Logic.AI;
|
||
using Logic.Audio;
|
||
using Logic.Multilingual;
|
||
using TH1_Logic.Core;
|
||
using TMPro;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
|
||
namespace TH1_UI.View.Top
|
||
{
|
||
public class UITopWinView : Base.View
|
||
{
|
||
//public Button closeButton;
|
||
public ViDelegateAssisstant.Dele OnBtnCloseClick;
|
||
|
||
public Button CloseButton;
|
||
|
||
public TextMeshProUGUI WinTitle1;
|
||
public TextMeshProUGUI WinTitle2;
|
||
public TextMeshProUGUI TurnCount;
|
||
public TextMeshProUGUI CityCount;
|
||
public TextMeshProUGUI Score;
|
||
public TextMeshProUGUI Difficult;
|
||
public Image TopbarBG;
|
||
public Image WinFlowerDeco;
|
||
public Image WinPic;
|
||
|
||
public Image AvatarImg;
|
||
public RectTransform ChatBubble;
|
||
public TextMeshProUGUI ChatText;
|
||
|
||
private Color _winTextColor = Color.white;
|
||
private Color _loseTextColor = new Color32(0xC7, 0xC7, 0xC7, 255);
|
||
private Color _winTopbarColor = Color.white;
|
||
private Color _loseTopbarColor = new Color(0f,0f,0f,0.2f);
|
||
|
||
|
||
private bool _thisMatchAlreadyShow = false;
|
||
protected override void OnInit()
|
||
{
|
||
base.OnInit();
|
||
CloseButton.onClick.RemoveAllListeners();
|
||
CloseButton.onClick.AddListener(() => { OnBtnCloseClick.Invoke(); });
|
||
//CheckPanel.InitStart(RefreshStatus);
|
||
|
||
_thisMatchAlreadyShow = false;
|
||
}
|
||
|
||
public void OnMatchStart()
|
||
{
|
||
_thisMatchAlreadyShow = false;
|
||
}
|
||
|
||
//通常一局只会set一次,每次都是完全清空,然后绑定新的一个对局的按钮
|
||
public void SetContent()
|
||
{
|
||
RefreshData();
|
||
}
|
||
|
||
public void RefreshData()
|
||
{
|
||
if (Main.MapData == null) return;
|
||
if (!Main.MapData.CheckIfGameEnd(out var isWin)) return;
|
||
if (_thisMatchAlreadyShow) return;
|
||
|
||
// 检查UI是否已激活,如果未激活则尝试显示
|
||
if (!gameObject.activeInHierarchy)
|
||
{
|
||
Debug.LogWarning("[UITopWinView] RefreshData called but gameObject is not active, calling Show()");
|
||
Show();
|
||
}
|
||
|
||
// 检查关键组件是否为null
|
||
if (WinTitle1 == null || WinTitle2 == null || CloseButton == null)
|
||
{
|
||
Debug.LogError("[UITopWinView] Critical UI components are null, cannot show win UI");
|
||
return;
|
||
}
|
||
|
||
//Main.MapData.MatchSettlement.
|
||
MultilingualManager.Instance.SetUIText(WinTitle1,isWin? Table.Instance.TextDataAssets.WinUIWinText: Table.Instance.TextDataAssets.WinUILoseText);
|
||
WinTitle1.color = isWin?_winTextColor:_loseTextColor;
|
||
MultilingualManager.Instance.SetUIText(WinTitle2,isWin? Table.Instance.TextDataAssets.WinUIWinText: Table.Instance.TextDataAssets.WinUILoseText);
|
||
WinTitle2.color = isWin?_winTextColor:_loseTextColor;
|
||
|
||
if (Table.Instance.PlayerDataAssets.GetPlayerInfo(Main.MapData.PlayerMap.SelfPlayerData, out var info))
|
||
{
|
||
var winLoseChat = isWin ? info.GetRandomWinChat() : info.GetRandomLoseChat();
|
||
if (winLoseChat == "0" || string.IsNullOrEmpty(winLoseChat))
|
||
{
|
||
ChatBubble.gameObject.SetActive(false);
|
||
}
|
||
else
|
||
{
|
||
ChatBubble.gameObject.SetActive(true);
|
||
MultilingualManager.Instance.SetUIText(ChatText, winLoseChat);
|
||
LayoutRebuilder.ForceRebuildLayoutImmediate(ChatBubble);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
ChatBubble.gameObject.SetActive(false);
|
||
}
|
||
|
||
TopbarBG.color = isWin ? _winTopbarColor : _loseTextColor;
|
||
|
||
AvatarImg.sprite = info.LeaderAvatar;
|
||
WinPic.sprite = isWin ? info.WinPic : info.LosePic;
|
||
|
||
WinFlowerDeco.gameObject.SetActive(isWin);
|
||
CityCount.text = Main.MapData.GetCityCount(Main.MapData.PlayerMap.SelfPlayerData.Id).ToString();
|
||
var displayTurn = (int)Main.MapData.PlayerMap.SelfPlayerData.Turn;
|
||
if (Main.MapData.MapConfig.GameMode == RuntimeData.GameMode.PERFECT &&
|
||
Main.MapData.Net != null &&
|
||
Main.MapData.Net.CurPlayerId == Main.MapData.PlayerMap.SelfPlayerData.Id)
|
||
{
|
||
displayTurn = Mathf.Max(0, displayTurn - 1);
|
||
}
|
||
|
||
TurnCount.text = displayTurn.ToString();
|
||
Score.text = Main.MapData.PlayerMap.SelfPlayerData.PlayerScore.ToString();
|
||
if (Difficult != null)
|
||
Difficult.text = Main.MapData.MapConfig.AIDiff.ToString();
|
||
AudioManager.Instance.PlayAudio(isWin ? "SFX/MATCH_win": "SFX/MATCH_lose");
|
||
|
||
// 只有在数据完全设置成功后才设置标志
|
||
_thisMatchAlreadyShow = true;
|
||
Debug.Log($"[UITopWinView] Win UI shown successfully, isWin={isWin}");
|
||
}
|
||
|
||
public void CloseView()
|
||
{
|
||
AudioManager.Instance.StopMusic();
|
||
}
|
||
|
||
|
||
}
|
||
|
||
}
|