106 lines
2.5 KiB
C#
106 lines
2.5 KiB
C#
// 文件位置: Assets/Scripts/TH1_UI/View/Notify/UINotifyMomentView.cs
|
||
|
||
using Logic.Multilingual;
|
||
using TH1_Core.Events;
|
||
using TH1_UI.View.Base;
|
||
using TMPro;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
|
||
namespace TH1_UI.View.Notify
|
||
{
|
||
public class UINotifyMomentView : Base.View
|
||
{
|
||
//public Button closeButton;
|
||
public Image momentImage;
|
||
public TextMeshProUGUI titleText;
|
||
public TextMeshProUGUI bigTitleText;
|
||
public TextMeshProUGUI descriptionText;
|
||
public Image bigTitleBG;
|
||
public Image bg;
|
||
public ViDelegateAssisstant.Dele OnAutoClose;
|
||
|
||
protected override void OnInit()
|
||
{
|
||
base.OnInit();
|
||
//if (closeButton != null)
|
||
//{
|
||
// closeButton.onClick.RemoveAllListeners();
|
||
//closeButton.onClick.AddListener(() => { OnAutoClose?.Invoke(); });
|
||
//}
|
||
}
|
||
|
||
public void SetContent(ShowUINotifyMoment eventData)
|
||
{
|
||
// 从MomentDataAssets获取数据
|
||
if (Table.Instance.MomentDataAssets.GetMomentSubData(eventData.MomentSubType, out var momentSubData))
|
||
{
|
||
// 设置标题
|
||
if (titleText != null)
|
||
{
|
||
MultilingualManager.Instance.SetUIText(titleText,momentSubData.Title);
|
||
}
|
||
|
||
// 设置描述
|
||
if (descriptionText != null)
|
||
{
|
||
MultilingualManager.Instance.SetUIText(descriptionText,momentSubData.Desc);
|
||
}
|
||
|
||
// 获取并设置图片
|
||
if (momentImage != null)
|
||
{
|
||
Sprite sprite = momentSubData.GetImage(eventData.Empire);
|
||
if (sprite != null)
|
||
{
|
||
momentImage.sprite = sprite;
|
||
}
|
||
}
|
||
|
||
// 从MomentMainData获取大标题和颜色设置
|
||
if (Table.Instance.MomentDataAssets.GetMomentMainData(momentSubData.MomentType, out var momentMainData))
|
||
{
|
||
// 设置大标题文字
|
||
if (bigTitleText != null)
|
||
{
|
||
MultilingualManager.Instance.SetUIText(bigTitleText,momentMainData.Title);
|
||
bigTitleText.color = momentMainData.BigTitleTextColor;
|
||
}
|
||
|
||
// 设置小标题文字颜色
|
||
if (titleText != null)
|
||
{
|
||
titleText.color = momentMainData.TitleTextBG;
|
||
}
|
||
|
||
// 设置描述文字颜色
|
||
if (descriptionText != null)
|
||
{
|
||
descriptionText.color = momentMainData.TitleTextBG;
|
||
}
|
||
|
||
// 设置BigTitleBG的颜色
|
||
if (bigTitleBG != null)
|
||
{
|
||
bigTitleBG.color = momentMainData.TitleBG;
|
||
}
|
||
|
||
// 设置BG的颜色
|
||
if (bg != null)
|
||
{
|
||
bg.color = momentMainData.DescBG;
|
||
}
|
||
}
|
||
}
|
||
|
||
// 自动关闭定时器(例如3秒后自动关闭)
|
||
Timer.Instance.TimerRegister(this, AutoClose, 2f, "UINotifyMomentView");
|
||
}
|
||
|
||
void AutoClose()
|
||
{
|
||
OnAutoClose?.Invoke();
|
||
}
|
||
}
|
||
}
|