108 lines
2.6 KiB
C#
108 lines
2.6 KiB
C#
using GeometryTD.CustomEvent;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityGameFramework.Runtime;
|
|
|
|
namespace GeometryTD.UI
|
|
{
|
|
public class CombatInfoForm : UGuiForm
|
|
{
|
|
[SerializeField] private TMP_Text _levelMetaText;
|
|
|
|
[SerializeField] private TMP_Text _levelPhaseText;
|
|
|
|
[SerializeField] private TMP_Text _coinText;
|
|
|
|
[SerializeField] private CommonButton _pauseButton;
|
|
|
|
[SerializeField] private CommonButton _endButton;
|
|
|
|
private CombatInfoFormContext _context;
|
|
|
|
public void RefreshUI(CombatInfoFormContext context)
|
|
{
|
|
_context = context;
|
|
|
|
if (_levelMetaText != null)
|
|
{
|
|
_levelMetaText.text = context?.LevelMetaText ?? string.Empty;
|
|
}
|
|
|
|
if (_levelPhaseText != null)
|
|
{
|
|
_levelPhaseText.text = context?.LevelPhaseText ?? string.Empty;
|
|
}
|
|
|
|
if (_coinText != null)
|
|
{
|
|
_coinText.text = context?.CoinText ?? "0";
|
|
}
|
|
|
|
if (_pauseButton != null)
|
|
{
|
|
_pauseButton.Interactive = context?.CanPause ?? false;
|
|
}
|
|
|
|
if (_endButton != null)
|
|
{
|
|
_endButton.gameObject.SetActive(context?.CanEnd ?? false);
|
|
}
|
|
}
|
|
|
|
public void OnPauseButtonClick()
|
|
{
|
|
if (_context != null && !_context.CanPause)
|
|
{
|
|
return;
|
|
}
|
|
|
|
GameEntry.Event.Fire(this, CombatPauseEventArgs.Create());
|
|
}
|
|
|
|
public void OnEndButtonClick()
|
|
{
|
|
if (_context != null && !_context.CanEnd)
|
|
{
|
|
return;
|
|
}
|
|
|
|
GameEntry.Event.Fire(this, CombatEndEventArgs.Create());
|
|
}
|
|
|
|
protected override void OnOpen(object userData)
|
|
{
|
|
base.OnOpen(userData);
|
|
|
|
if (userData is CombatInfoFormContext context)
|
|
{
|
|
RefreshUI(context);
|
|
return;
|
|
}
|
|
|
|
Log.Warning("CombatInfoForm requires CombatInfoFormContext as userData.");
|
|
}
|
|
|
|
protected override void OnClose(bool isShutdown, object userData)
|
|
{
|
|
_context = null;
|
|
|
|
if (_levelMetaText != null)
|
|
{
|
|
_levelMetaText.text = string.Empty;
|
|
}
|
|
|
|
if (_levelPhaseText != null)
|
|
{
|
|
_levelPhaseText.text = string.Empty;
|
|
}
|
|
|
|
if (_coinText != null)
|
|
{
|
|
_coinText.text = string.Empty;
|
|
}
|
|
|
|
base.OnClose(isShutdown, userData);
|
|
}
|
|
}
|
|
}
|