TH1/Unity/Assets/Scripts/TH1_UI/View/Announce/UIAnnounceMajorEventView.cs
2025-10-31 13:39:10 +08:00

172 lines
6.6 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 System.Collections.Generic;
using Logic;
using Logic.Audio;
using Logic.CrashSight;
using Logic.Multilingual;
using RuntimeData;
using TH1_Core.Events;
using TH1_Logic.Core;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
namespace TH1_UI.View.Announce
{
public class UIAnnounceMajorEventView : Base.View
{
public Button closeButton;
public TextMeshProUGUI Title;
public TextMeshProUGUI Content;
public Transform ChatBubble;
public Transform CharImage;
public Transform WonderImage;
public ViDelegateAssisstant.Dele OnBtnCloseClick;
private Material _grayScaleMat;
protected override void InitStart()
{
base.InitStart();
closeButton.onClick.RemoveAllListeners();
closeButton.onClick.AddListener(() => { OnBtnCloseClick.Invoke(); });
_grayScaleMat = Resources.Load<Material>("Materials/GrayScale");
}
public void SetContent(UIAnnounceMajorEventType eventType, int param1, int param2)
{
if (Title == null || Content == null || CharImage == null || WonderImage == null)
{
LogSystem.LogError("UIAnnounceMajorEventView.SetContent(): Title or Content or Image or Image is null");
return;
}
UICenterMessageInfo info;
PlayerData player;
PlayerInfo playerInfo;
switch (eventType)
{
case UIAnnounceMajorEventType.StartGame:
//step #1 获取界面的文本info以及真人玩家data和playerInfo
if (!Table.Instance.UICenterMessageDataAssets.GetUICenterMessageInfo(UICenterMessageID.StartGame, out info)) break;
player = Main.MapData.PlayerMap.SelfPlayerData;
Table.Instance.PlayerDataAssets.GetPlayerInfo(player, out playerInfo);
string leaderName = MultilingualManager.Instance.GetMultilingualText(uint.Parse(playerInfo.LeaderName));
string civName = MultilingualManager.Instance.GetMultilingualText(uint.Parse(playerInfo.CivName));
string forceName = MultilingualManager.Instance.GetMultilingualText(uint.Parse(playerInfo.ForceName));
//step #2 设置文字和图片
MultilingualManager.Instance.SetUIText(Content,info.Message,new List<string>(){leaderName,forceName,civName});
Title.text = MultilingualManager.Instance.GetMultilingualText(uint.Parse(info.Title));
SetImage(CharImage,playerInfo.LeaderIllustration);
//step #3 设置领袖的对话气泡内容
if (ChatBubble != null)
{
ChatBubble.gameObject.SetActive(true);
var txt = ChatBubble.Find("Text")?.GetComponent<TextMeshProUGUI>();
MultilingualManager.Instance.SetUIText(txt,playerInfo.GetRandomStartChat());
}
//step #4 播放音乐
AudioManager.Instance.PlayMusic(playerInfo.MusicName,1f,2f,true);
break;
case UIAnnounceMajorEventType.FirstMeet:
//param1 = pid param2 = coin
//step #1 获取界面的文本info以及真人玩家data和playerInfo
if (!Table.Instance.UICenterMessageDataAssets.GetUICenterMessageInfo(UICenterMessageID.MeetNewPlayer, out info)) break;
if (!Main.MapData.PlayerMap.GetPlayerDataByPlayerID((uint)param1, out player)) break;
Table.Instance.PlayerDataAssets.GetPlayerInfo(player, out playerInfo);
//step #2 设置文字和图片
SetImage(CharImage,playerInfo.LeaderIllustration);
string forceNameFinal = MultilingualManager.Instance.GetMultilingualText(uint.Parse(playerInfo.ForceName));
string leaderNameFinal = MultilingualManager.Instance.GetMultilingualText(uint.Parse(playerInfo.LeaderName));
string civNameFinal = MultilingualManager.Instance.GetMultilingualText(uint.Parse(playerInfo.CivName));
Title.text = MultilingualManager.Instance.GetMultilingualText(uint.Parse(info.Title));
MultilingualManager.Instance.SetUIText(Content,info.Message,new List<string>{civNameFinal,forceNameFinal,leaderNameFinal,param2.ToString()});
//step #3 设置领袖的对话气泡内容
if (ChatBubble != null)
{
ChatBubble.gameObject.SetActive(true);
var txt = ChatBubble.Find("Text")?.GetComponent<TextMeshProUGUI>();
MultilingualManager.Instance.SetUIText(txt,playerInfo.GetRandomMeetChat());
}
//step #4 播放音乐
AudioManager.Instance.PlayMusic(playerInfo.MusicName,1f,2f,true);
break;
case UIAnnounceMajorEventType.CivLose:
//step #1 获取各种info信息
if (!Table.Instance.UICenterMessageDataAssets.GetUICenterMessageInfo(UICenterMessageID.ForcesFallen,out info))break;
if (!Main.MapData.PlayerMap.GetPlayerDataByPlayerID((uint)param1, out player)) break;
if (!Table.Instance.PlayerDataAssets.GetPlayerInfo(player, out playerInfo)) break;
//step #2 设置界面信息
SetImage(CharImage,playerInfo.LeaderIllustration,isGray:true);
string forceNameParam = MultilingualManager.Instance.GetMultilingualText(uint.Parse(playerInfo.ForceName));
MultilingualManager.Instance.SetUIText(Content,info.Message,new List<string>{forceNameParam});
MultilingualManager.Instance.SetUIText(Title ,info.Title);
//step #3 设置领袖的对话气泡内容
if (ChatBubble != null)
{
ChatBubble.gameObject.SetActive(true);
var txt = ChatBubble.Find("Text")?.GetComponent<TextMeshProUGUI>();
MultilingualManager.Instance.SetUIText(txt,playerInfo.GetRandomLoseChat());
}
break;
case UIAnnounceMajorEventType.WonderStart:
case UIAnnounceMajorEventType.WonderEnd:
//step #1 获取各种info信息
if (!Table.Instance.UICenterMessageDataAssets.GetUICenterMessageInfo(eventType,(uint)param1,out info))break;
player = Main.MapData.PlayerMap.SelfPlayerData;
if (!Table.Instance.GridAndResourceDataAssets.GetWonderInfoByType(info.WonderType, player, out var wonderInfo)) break;
//step #2 设置界面信息
SetImage(WonderImage,wonderInfo.Sprite);
string nameParam = MultilingualManager.Instance.GetMultilingualText(uint.Parse(wonderInfo.Name));
MultilingualManager.Instance.SetUIText(Content,info.Message,new List<string>{nameParam});
MultilingualManager.Instance.SetUIText(Title ,info.Title);
//step #3 关闭bubble
if (ChatBubble != null) ChatBubble.gameObject.SetActive(false);
break;
default:
break;
}
}
private bool SetImage(Transform target,Sprite sprite,bool isGray = false)
{
if (target.GetComponent<Image>() == null) return false;
CharImage.gameObject.SetActive(false);
WonderImage.gameObject.SetActive(false);
target.gameObject.SetActive(true);
target.GetComponent<Image>().sprite = sprite;
target.GetComponent<Image>().material = isGray ? _grayScaleMat : null;
return true;
}
public void CloseView()
{
AudioManager.Instance.StopMusic();
}
}
}