90 lines
2.4 KiB
C#
90 lines
2.4 KiB
C#
using TMPro;
|
|
using UnityEngine;
|
|
using UnityGameFramework.Runtime;
|
|
|
|
namespace GeometryTD.UI
|
|
{
|
|
public class NodeMapForm : UGuiForm
|
|
{
|
|
[SerializeField] private TMP_Text _titleText;
|
|
[SerializeField] private TMP_Text _progressText;
|
|
[SerializeField] private TMP_Text _currentNodeText;
|
|
[SerializeField] private NodeItem[] _nodeItems;
|
|
|
|
private NodeMapFormContext _context;
|
|
|
|
public void RefreshUI(NodeMapFormContext context)
|
|
{
|
|
_context = context;
|
|
if (_titleText != null)
|
|
{
|
|
_titleText.text = context?.Title ?? string.Empty;
|
|
}
|
|
|
|
if (_progressText != null)
|
|
{
|
|
_progressText.text = context?.ProgressText ?? string.Empty;
|
|
}
|
|
|
|
if (_currentNodeText != null)
|
|
{
|
|
_currentNodeText.text = context?.CurrentNodeText ?? string.Empty;
|
|
}
|
|
|
|
if (_nodeItems == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
for (int i = 0; i < _nodeItems.Length; i++)
|
|
{
|
|
NodeItemContext itemContext =
|
|
context?.NodeItems != null && i < context.NodeItems.Length ? context.NodeItems[i] : null;
|
|
_nodeItems[i]?.RefreshUI(itemContext);
|
|
}
|
|
}
|
|
|
|
protected override void OnOpen(object userData)
|
|
{
|
|
base.OnOpen(userData);
|
|
|
|
if (userData is NodeMapFormContext context)
|
|
{
|
|
RefreshUI(context);
|
|
return;
|
|
}
|
|
|
|
Log.Warning("NodeMapForm requires NodeMapFormContext as userData.");
|
|
}
|
|
|
|
protected override void OnClose(bool isShutdown, object userData)
|
|
{
|
|
_context = null;
|
|
if (_titleText != null)
|
|
{
|
|
_titleText.text = string.Empty;
|
|
}
|
|
|
|
if (_progressText != null)
|
|
{
|
|
_progressText.text = string.Empty;
|
|
}
|
|
|
|
if (_currentNodeText != null)
|
|
{
|
|
_currentNodeText.text = string.Empty;
|
|
}
|
|
|
|
if (_nodeItems != null)
|
|
{
|
|
for (int i = 0; i < _nodeItems.Length; i++)
|
|
{
|
|
_nodeItems[i]?.RefreshUI(null);
|
|
}
|
|
}
|
|
|
|
base.OnClose(isShutdown, userData);
|
|
}
|
|
}
|
|
}
|