49 lines
1.3 KiB
C#
49 lines
1.3 KiB
C#
using GeometryTD.UI;
|
|
using UnityGameFramework.Runtime;
|
|
using GeometryTD.CustomEvent;
|
|
using GeometryTD.Definition;
|
|
|
|
namespace GeometryTD.CustomComponent
|
|
{
|
|
public class ShopNodeComponent : GameFrameworkComponent
|
|
{
|
|
private ShopFormUseCase _shopFormUseCase;
|
|
private bool _initialized;
|
|
|
|
public void OnInit()
|
|
{
|
|
if (_initialized)
|
|
{
|
|
return;
|
|
}
|
|
|
|
_shopFormUseCase ??= new ShopFormUseCase();
|
|
GameEntry.UIRouter.BindUIUseCase(UIFormType.ShopForm, _shopFormUseCase);
|
|
_initialized = true;
|
|
}
|
|
|
|
public void StartShop()
|
|
{
|
|
if (!_initialized)
|
|
{
|
|
OnInit();
|
|
}
|
|
|
|
if (_shopFormUseCase == null || !_shopFormUseCase.PrepareForOpen())
|
|
{
|
|
Log.Warning("ShopNodeComponent.StartShop() failed. Shop use case is unavailable or goods generation failed.");
|
|
return;
|
|
}
|
|
|
|
GameEntry.UIRouter.OpenUI(UIFormType.ShopForm);
|
|
GameEntry.Event.Fire(this, NodeEnterEventArgs.Create());
|
|
}
|
|
|
|
public void EndShop()
|
|
{
|
|
GameEntry.UIRouter.CloseUI(UIFormType.ShopForm);
|
|
GameEntry.Event.Fire(this, NodeCompleteEventArgs.Create());
|
|
}
|
|
}
|
|
}
|