82 lines
2.1 KiB
C#
82 lines
2.1 KiB
C#
using TMPro;
|
|
using UnityEngine;
|
|
using UnityGameFramework.Runtime;
|
|
|
|
namespace GeometryTD.UI
|
|
{
|
|
public class EventForm : UGuiForm
|
|
{
|
|
[SerializeField] private TMP_Text _titleText;
|
|
[SerializeField] private TMP_Text _descriptionText;
|
|
[SerializeField] private EventOptionItem[] _optionItems;
|
|
|
|
private EventFormContext _context;
|
|
|
|
public void RefreshUI(EventFormContext context)
|
|
{
|
|
_context = context;
|
|
|
|
if (_titleText != null)
|
|
{
|
|
_titleText.text = context?.Title ?? string.Empty;
|
|
}
|
|
|
|
if (_descriptionText != null)
|
|
{
|
|
_descriptionText.text = context?.Description ?? string.Empty;
|
|
}
|
|
|
|
for (int i = 0; i < _optionItems.Length; i++)
|
|
{
|
|
EventOptionItemContext optionContext = null;
|
|
if (context?.OptionItems != null && i < context.OptionItems.Length)
|
|
{
|
|
optionContext = context.OptionItems[i];
|
|
}
|
|
|
|
if (_optionItems[i] != null)
|
|
{
|
|
_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)
|
|
{
|
|
_context = null;
|
|
|
|
if (_titleText != null)
|
|
{
|
|
_titleText.text = string.Empty;
|
|
}
|
|
|
|
if (_descriptionText != null)
|
|
{
|
|
_descriptionText.text = string.Empty;
|
|
}
|
|
|
|
foreach (var item in _optionItems)
|
|
{
|
|
if (item != null)
|
|
{
|
|
item.OnReset();
|
|
}
|
|
}
|
|
|
|
base.OnClose(isShutdown, userData);
|
|
}
|
|
}
|
|
} |