266 lines
9.0 KiB
C#
266 lines
9.0 KiB
C#
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.Serialization;
|
||
using UnityEngine.UI;
|
||
|
||
namespace TH1_UI.View.Announce
|
||
{
|
||
public class UIAnnounceMajorEventView : Base.View
|
||
{
|
||
public Button closeButton;
|
||
public TextMeshProUGUI Title;
|
||
public TextMeshProUGUI Content;
|
||
public Transform CivAvatar;
|
||
public Transform WonderAvatar;
|
||
public RectTransform ChatBubble;
|
||
public TextMeshProUGUI ChatBubbleText;
|
||
[FormerlySerializedAs("CharImage")] public Image LeaderImage;
|
||
public Image WonderImage;
|
||
public Image WonderGroundImage;
|
||
public Image WindowTopBarStripeBG1;
|
||
public Image WindowTopBarStripeBG2;
|
||
public ViDelegateAssisstant.Dele OnBtnCloseClick;
|
||
private Material _grayScaleMat;
|
||
private UIAnnounceMajorEventType _eventType;
|
||
private int _param1;
|
||
private int _param2;
|
||
|
||
protected override void OnInit()
|
||
{
|
||
base.OnInit();
|
||
closeButton.onClick.RemoveAllListeners();
|
||
closeButton.onClick.AddListener(() =>
|
||
{
|
||
if (_eventType == UIAnnounceMajorEventType.FirstMeet)
|
||
{
|
||
var pos = closeButton.transform.position;
|
||
pos.y += 4;
|
||
//如果是firstmeet,关闭时播放金币动画
|
||
Main.MapData.PlayerMap.SelfPlayerData.AddCoin_ViewOnly(_param2,pos);
|
||
}
|
||
OnBtnCloseClick.Invoke();
|
||
AudioManager.Instance.ResumeBgmRotationIfEnabled();
|
||
});
|
||
|
||
_grayScaleMat = TH1Resource.ResourceLoader.Load<Material>("Materials/GrayScale");
|
||
}
|
||
|
||
public bool SetContent(UIAnnounceMajorEventType eventType, int param1, int param2)
|
||
{
|
||
_eventType = eventType;
|
||
_param1 = param1;
|
||
_param2 = param2;
|
||
if (Title == null || Content == null || LeaderImage == null || WonderImage == null)
|
||
{
|
||
LogSystem.LogError("UIAnnounceMajorEventView.SetContent(): Title or Content or Image or Image is null");
|
||
return false;
|
||
}
|
||
|
||
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)) return false;
|
||
var map = Main.MapData;
|
||
player = map?.PlayerMap?.SelfPlayerData;
|
||
if (player == null) return false;
|
||
if (!Table.Instance.PlayerDataAssets.GetPlayerInfo(player, out playerInfo)) return false;
|
||
string leaderName = MultilingualManager.Instance.GetMultilingualTextSafe(playerInfo.LeaderName);
|
||
string civName = MultilingualManager.Instance.GetMultilingualTextSafe(playerInfo.CivName);
|
||
string forceName = Logic.PlayerLogic.GetDisplayForceName(map, player);
|
||
|
||
//step #2 设置文字和图片
|
||
MultilingualManager.Instance.SetUIText(Content,info.Message,new List<string>(){leaderName,civName,forceName});
|
||
Title.text = MultilingualManager.Instance.GetMultilingualTextSafe(info.Title);
|
||
SetLeaderImage(playerInfo.LeaderAvatar);
|
||
|
||
//step #3 设置领袖的对话气泡内容
|
||
if (ChatBubble != null)
|
||
{
|
||
var startChat = playerInfo.GetRandomStartChat();
|
||
if (startChat != "0")
|
||
{
|
||
ChatBubble.gameObject.SetActive(true);
|
||
MultilingualManager.Instance.SetUIText(ChatBubbleText, startChat);
|
||
LayoutRebuilder.ForceRebuildLayoutImmediate(ChatBubble);
|
||
}
|
||
else
|
||
{
|
||
ChatBubble.gameObject.SetActive(false);
|
||
}
|
||
}
|
||
//step #4 播放音乐
|
||
|
||
AudioManager.Instance.PlayMusic(playerInfo.MusicName,1f,2f,true);
|
||
|
||
//step #5 设置底板颜色
|
||
SetColor(player);
|
||
|
||
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 设置文字和图片
|
||
SetLeaderImage(playerInfo.LeaderAvatar);
|
||
|
||
string forceNameFinal = Logic.PlayerLogic.GetDisplayForceName(Main.MapData, player);
|
||
string leaderNameFinal = MultilingualManager.Instance.GetMultilingualTextSafe(playerInfo.LeaderName);
|
||
string civNameFinal = MultilingualManager.Instance.GetMultilingualTextSafe(playerInfo.CivName);
|
||
|
||
Title.text = MultilingualManager.Instance.GetMultilingualTextSafe(info.Title);
|
||
MultilingualManager.Instance.SetUIText(Content,info.Message,new List<string>{civNameFinal,forceNameFinal,leaderNameFinal,param2.ToString()});
|
||
|
||
//step #3 设置领袖的对话气泡内容
|
||
if (ChatBubble != null)
|
||
{
|
||
var meetChat = playerInfo.GetRandomMeetChat();
|
||
if (meetChat != "0")
|
||
{
|
||
ChatBubble.gameObject.SetActive(true);
|
||
MultilingualManager.Instance.SetUIText(ChatBubbleText, meetChat);
|
||
LayoutRebuilder.ForceRebuildLayoutImmediate(ChatBubble);
|
||
}
|
||
else
|
||
{
|
||
ChatBubble.gameObject.SetActive(false);
|
||
}
|
||
}
|
||
|
||
//step #4 播放音乐
|
||
|
||
AudioManager.Instance.PlayMusic(playerInfo.MusicName,1f,2f,true);
|
||
|
||
//step #5 设置底板颜色
|
||
SetColor(player);
|
||
|
||
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 设置界面信息
|
||
SetLeaderImage(playerInfo.LeaderAvatar,isGray:true);
|
||
|
||
string forceNameParam = Logic.PlayerLogic.GetDisplayForceName(Main.MapData, player);
|
||
MultilingualManager.Instance.SetUIText(Content,info.Message,new List<string>{forceNameParam});
|
||
MultilingualManager.Instance.SetUIText(Title ,info.Title);
|
||
|
||
|
||
//step #3 设置领袖的对话气泡内容
|
||
if (ChatBubble != null)
|
||
{
|
||
var loseChat = playerInfo.GetRandomLoseChat();
|
||
if (loseChat != "0")
|
||
{
|
||
ChatBubble.gameObject.SetActive(true);
|
||
var txt = ChatBubble.Find("Text")?.GetComponent<TextMeshProUGUI>();
|
||
MultilingualManager.Instance.SetUIText(txt, loseChat);
|
||
LayoutRebuilder.ForceRebuildLayoutImmediate(ChatBubble);
|
||
}
|
||
else
|
||
{
|
||
ChatBubble.gameObject.SetActive(false);
|
||
}
|
||
}
|
||
|
||
SetColor(player,isLose:true);
|
||
|
||
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 设置界面信息
|
||
SetWonderImage(player,info.WonderType,eventType == UIAnnounceMajorEventType.WonderStart);
|
||
|
||
string nameParam = MultilingualManager.Instance.GetMultilingualTextSafe(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);
|
||
|
||
//step #4 设置底板颜色
|
||
SetColor(player);
|
||
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
|
||
return true;
|
||
}
|
||
|
||
|
||
private void SetColor(PlayerData player,bool isLose = false)
|
||
{
|
||
if (isLose)
|
||
{
|
||
WindowTopBarStripeBG2.color = Color.gray;
|
||
var color = Color.gray;
|
||
color.a = 0.4f;
|
||
WindowTopBarStripeBG1.color = color;
|
||
return;
|
||
}
|
||
if (!Table.Instance.PlayerDataAssets.GetPlayerInfo(player, out var info)) return;
|
||
WindowTopBarStripeBG2.color = info.Color;
|
||
var color2 = info.Color;
|
||
color2.a = 0.4f;
|
||
WindowTopBarStripeBG1.color = color2;
|
||
}
|
||
private bool SetLeaderImage(Sprite sprite,bool isGray = false)
|
||
{
|
||
CivAvatar.gameObject.SetActive(true);
|
||
WonderAvatar.gameObject.SetActive(false);
|
||
|
||
LeaderImage.sprite = sprite;
|
||
LeaderImage.material = isGray ? _grayScaleMat : null;
|
||
return true;
|
||
}
|
||
|
||
private bool SetWonderImage(PlayerData player,WonderTypeEnum wonderType,bool isGray)
|
||
{
|
||
CivAvatar.gameObject.SetActive(false);
|
||
WonderAvatar.gameObject.SetActive(true);
|
||
if (!Table.Instance.GridAndResourceDataAssets.GetWonderInfoByType(wonderType, player, out var info))
|
||
return false;
|
||
var groundSprite = Table.Instance.GridAndResourceDataAssets.GetGroundSprite(player.CivEnum, GridSpType.None);
|
||
WonderGroundImage.sprite = groundSprite;
|
||
WonderImage.sprite = info.Sprite;
|
||
WonderGroundImage.material = isGray ? _grayScaleMat : null;
|
||
WonderImage.material = isGray ? _grayScaleMat : null;
|
||
return true;
|
||
}
|
||
|
||
public void CloseView()
|
||
{
|
||
AudioManager.Instance.StopMusic();
|
||
}
|
||
}
|
||
|
||
}
|