79 lines
2.4 KiB
C#
79 lines
2.4 KiB
C#
using GeometryTD.CustomEvent;
|
|
using GeometryTD.Definition;
|
|
using GameFramework.Event;
|
|
using UnityGameFramework.Runtime;
|
|
|
|
namespace GeometryTD.UI
|
|
{
|
|
public class MainFormController : UIFormControllerCommonBase<MainFormContext, MainForm>
|
|
{
|
|
protected override UIFormType UIFormTypeId => UIFormType.MainForm;
|
|
|
|
protected override void RefreshUI(MainForm form, MainFormContext context)
|
|
{
|
|
form.RefreshUI(context);
|
|
}
|
|
|
|
protected override void SubscribeCustomEvents()
|
|
{
|
|
GameEntry.Event.Subscribe(ReturnButtonClickedEventArgs.EventId, OnReturnButtonClicked);
|
|
GameEntry.Event.Subscribe(RepoButtonClickedEventArgs.EventId, OnRepoButtonClicked);
|
|
}
|
|
|
|
protected override void UnsubscribeCustomEvents()
|
|
{
|
|
GameEntry.Event.Unsubscribe(ReturnButtonClickedEventArgs.EventId, OnReturnButtonClicked);
|
|
GameEntry.Event.Unsubscribe(RepoButtonClickedEventArgs.EventId, OnRepoButtonClicked);
|
|
}
|
|
|
|
public override int? OpenUI(object userData = null)
|
|
{
|
|
if (userData is MainFormContext context)
|
|
{
|
|
return OpenUIInternal(context);
|
|
}
|
|
|
|
if (userData != null)
|
|
{
|
|
Log.Warning("MainFormController.OpenUI() userData type is invalid.");
|
|
return null;
|
|
}
|
|
|
|
return OpenUIInternal(BuildDefaultContext());
|
|
}
|
|
|
|
public override void BindUseCase(IUIUseCase useCase)
|
|
{
|
|
if (useCase != null)
|
|
{
|
|
Log.Warning("MainFormController does not use a use case.");
|
|
}
|
|
}
|
|
|
|
private static MainFormContext BuildDefaultContext()
|
|
{
|
|
return new MainFormContext();
|
|
}
|
|
|
|
private void OnReturnButtonClicked(object sender, GameEventArgs e)
|
|
{
|
|
if (!(sender is MainForm) || !(e is ReturnButtonClickedEventArgs))
|
|
{
|
|
return;
|
|
}
|
|
|
|
//TODO:游戏 UI 返回菜单 UI
|
|
//GameEntry.UIRouter.CloseUI(UIFormType.MainForm);
|
|
}
|
|
|
|
private void OnRepoButtonClicked(object sender, GameEventArgs e)
|
|
{
|
|
if (!(sender is MainForm) || !(e is RepoButtonClickedEventArgs))
|
|
{
|
|
return;
|
|
}
|
|
|
|
GameEntry.UIRouter.OpenUI(UIFormType.RepoForm);
|
|
}
|
|
}
|
|
} |