92 lines
3.2 KiB
C#
92 lines
3.2 KiB
C#
using Cysharp.Threading.Tasks;
|
|
using SepCore.Event;
|
|
using SepCore.Definition;
|
|
using GameFramework.Event;
|
|
using UnityGameFramework.Runtime;
|
|
|
|
namespace SepCore.UI
|
|
{
|
|
public class MenuController : UIControllerBase<MenuContext, MenuForm>
|
|
{
|
|
protected override UIFormType UIFormType => UIFormType.MenuForm;
|
|
|
|
protected override void RefreshUI(MenuForm form, MenuContext context)
|
|
{
|
|
form.RefreshUI(context);
|
|
}
|
|
|
|
protected override void SubscribeCustomEvents()
|
|
{
|
|
GameEntry.Event.Subscribe(MenuButtonClickEventArgs.EventId, OnMenuButtonClick);
|
|
}
|
|
|
|
protected override void UnsubscribeCustomEvents()
|
|
{
|
|
GameEntry.Event.Unsubscribe(MenuButtonClickEventArgs.EventId, OnMenuButtonClick);
|
|
}
|
|
|
|
private static MenuContext BuildMenuContext()
|
|
{
|
|
return new MenuContext();
|
|
}
|
|
|
|
public override async UniTask OpenUIAsync(object userData = null, float timeout = 30f)
|
|
{
|
|
if (userData != null)
|
|
{
|
|
Log.Warning("MenuController.OpenUIAsync() userData type is invalid.");
|
|
return;
|
|
}
|
|
|
|
await OpenFormAsync(BuildMenuContext(), timeout);
|
|
}
|
|
|
|
public override void BindUseCase(IUIUseCase useCase)
|
|
{
|
|
Log.Info("MenuForm doesn't need UseCase");
|
|
}
|
|
|
|
private void OnMenuButtonClick(object sender, GameEventArgs e)
|
|
{
|
|
if (sender is not MenuForm || e is not MenuButtonClickEventArgs args)
|
|
{
|
|
return;
|
|
}
|
|
|
|
switch (args.Button)
|
|
{
|
|
case MenuButtonId.StartGame:
|
|
GameEntry.UIRouter.OpenUIAsync(UIFormType.SelectRoleForm).Forget();
|
|
break;
|
|
case MenuButtonId.Setting:
|
|
GameEntry.UIRouter.OpenUIAsync(UIFormType.SettingForm).Forget();
|
|
break;
|
|
case MenuButtonId.Quit:
|
|
GameEntry.UIRouter.OpenUIAsync(UIFormType.DialogForm, new DialogRawData
|
|
{
|
|
Mode = 2,
|
|
Title = GameEntry.Localization.GetString("AskQuitGame.Title"),
|
|
Message = GameEntry.Localization.GetString("AskQuitGame.Message"),
|
|
OnClickConfirm = delegate(object userData)
|
|
{
|
|
UnityGameFramework.Runtime.GameEntry.Shutdown(ShutdownType.Quit);
|
|
}
|
|
}).Forget();
|
|
break;
|
|
case MenuButtonId.File:
|
|
Log.Warning("Menu file button click is not implemented.");
|
|
break;
|
|
case MenuButtonId.Guide:
|
|
Log.Warning("Menu guide button click is not implemented.");
|
|
break;
|
|
case MenuButtonId.About:
|
|
Log.Warning("Menu about button click is not implemented.");
|
|
break;
|
|
default:
|
|
Log.Warning("MenuController received unknown MenuButtonId: {0}", args.Button);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|