76 lines
2.4 KiB
C#
76 lines
2.4 KiB
C#
using GeometryTD.UI;
|
|
using UnityGameFramework.Runtime;
|
|
using GeometryTD.CustomEvent;
|
|
using GeometryTD.Definition;
|
|
using GeometryTD.Procedure;
|
|
|
|
namespace GeometryTD.CustomComponent
|
|
{
|
|
public class ShopNodeComponent : GameFrameworkComponent
|
|
{
|
|
private string _activeRunId;
|
|
private int _activeNodeId;
|
|
private RunNodeType _activeNodeType = RunNodeType.None;
|
|
private int _activeSequenceIndex = -1;
|
|
|
|
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(string runId = null, int nodeId = 0, RunNodeType nodeType = RunNodeType.None, int sequenceIndex = -1)
|
|
{
|
|
if (!_initialized)
|
|
{
|
|
OnInit();
|
|
}
|
|
|
|
if (_shopFormUseCase == null || !_shopFormUseCase.PrepareForOpen())
|
|
{
|
|
Log.Warning("ShopNodeComponent.StartShop() failed. Shop use case is unavailable or goods generation failed.");
|
|
return;
|
|
}
|
|
|
|
_activeRunId = runId;
|
|
_activeNodeId = nodeId;
|
|
_activeNodeType = nodeType;
|
|
_activeSequenceIndex = sequenceIndex;
|
|
GameEntry.UIRouter.OpenUI(UIFormType.ShopForm);
|
|
GameEntry.Event.Fire(this, NodeEnterEventArgs.Create(runId, nodeId, nodeType, sequenceIndex));
|
|
}
|
|
|
|
public void EndShop()
|
|
{
|
|
GameEntry.UIRouter.CloseUI(UIFormType.ShopForm);
|
|
GameEntry.Event.Fire(
|
|
this,
|
|
NodeCompleteEventArgs.Create(
|
|
_activeRunId,
|
|
_activeNodeId,
|
|
_activeNodeType,
|
|
_activeSequenceIndex,
|
|
true,
|
|
GameEntry.PlayerInventory != null ? GameEntry.PlayerInventory.GetInventorySnapshot() : null));
|
|
ClearActiveNodeContext();
|
|
}
|
|
|
|
private void ClearActiveNodeContext()
|
|
{
|
|
_activeRunId = null;
|
|
_activeNodeId = 0;
|
|
_activeNodeType = RunNodeType.None;
|
|
_activeSequenceIndex = -1;
|
|
}
|
|
}
|
|
}
|