82 lines
2.2 KiB
C#
82 lines
2.2 KiB
C#
using TMPro;
|
|
using UnityEngine;
|
|
using UnityGameFramework.Runtime;
|
|
|
|
namespace GeometryTD.UI
|
|
{
|
|
public class EventForm : UGuiForm
|
|
{
|
|
[SerializeField] private TMP_Text m_TitleText;
|
|
[SerializeField] private TMP_Text m_DescriptionText;
|
|
[SerializeField] private EventOptionItem[] m_OptionItems;
|
|
|
|
private EventFormContext m_Context;
|
|
public void RefreshUI(EventFormContext context)
|
|
{
|
|
m_Context = context;
|
|
|
|
if (m_TitleText != null)
|
|
{
|
|
m_TitleText.text = context?.Title ?? string.Empty;
|
|
}
|
|
|
|
if (m_DescriptionText != null)
|
|
{
|
|
m_DescriptionText.text = context?.Description ?? string.Empty;
|
|
}
|
|
|
|
for (int i = 0; i < m_OptionItems.Length; i++)
|
|
{
|
|
EventOptionItemContext optionContext = null;
|
|
if (context?.OptionItems != null && i < context.OptionItems.Length)
|
|
{
|
|
optionContext = context.OptionItems[i];
|
|
}
|
|
|
|
if (m_OptionItems[i] != null)
|
|
{
|
|
m_OptionItems[i].OnInit(optionContext);
|
|
}
|
|
}
|
|
}
|
|
|
|
protected override void OnOpen(object userData)
|
|
{
|
|
base.OnOpen(userData);
|
|
|
|
if (userData is EventFormContext context)
|
|
{
|
|
RefreshUI(context);
|
|
return;
|
|
}
|
|
|
|
Log.Warning("EventForm requires EventFormContext as userData.");
|
|
}
|
|
|
|
protected override void OnClose(bool isShutdown, object userData)
|
|
{
|
|
m_Context = null;
|
|
|
|
if (m_TitleText != null)
|
|
{
|
|
m_TitleText.text = string.Empty;
|
|
}
|
|
|
|
if (m_DescriptionText != null)
|
|
{
|
|
m_DescriptionText.text = string.Empty;
|
|
}
|
|
|
|
for (int i = 0; i < m_OptionItems.Length; i++)
|
|
{
|
|
if (m_OptionItems[i] != null)
|
|
{
|
|
m_OptionItems[i].OnReset();
|
|
}
|
|
}
|
|
|
|
base.OnClose(isShutdown, userData);
|
|
}
|
|
}
|
|
}
|