继续重构调整(UI)
- 引入 UniTask 和异步版本的 UIModule - 调整 Runtime/UIBase 和 Presentation 下的脚本命名空间到 SepCore.UI - 将原来的 5 层 UI 迁移到异步实现 - 规范各层的 UI 脚本命名
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
namespace SepCore.UI
|
||||
{
|
||||
public class MenuContext : UIContext
|
||||
{
|
||||
}
|
||||
}
|
||||
+20
-29
@@ -1,15 +1,16 @@
|
||||
using Cysharp.Threading.Tasks;
|
||||
using SepCore.Event;
|
||||
using SepCore.Definition;
|
||||
using GameFramework.Event;
|
||||
using UnityGameFramework.Runtime;
|
||||
|
||||
namespace UI
|
||||
namespace SepCore.UI
|
||||
{
|
||||
public class StartMenuFormController : UIFormControllerCommonBase<StartMenuFormContext, StartMenuForm>
|
||||
public class MenuController : UIControllerBase<MenuContext, MenuForm>
|
||||
{
|
||||
protected override UIFormType UIFormTypeId => UIFormType.StartMenuForm;
|
||||
protected override UIFormType UIFormType => UIFormType.MenuForm;
|
||||
|
||||
protected override void RefreshUI(StartMenuForm form, StartMenuFormContext context)
|
||||
protected override void RefreshUI(MenuForm form, MenuContext context)
|
||||
{
|
||||
form.RefreshUI(context);
|
||||
}
|
||||
@@ -34,30 +35,20 @@ namespace UI
|
||||
GameEntry.Event.Unsubscribe(MenuAboutButtonClickEventArgs.EventId, OnMenuAboutButtonClick);
|
||||
}
|
||||
|
||||
private static StartMenuFormContext BuildStartMenuFormContext()
|
||||
private static MenuContext BuildMenuContext()
|
||||
{
|
||||
return new StartMenuFormContext();
|
||||
return new MenuContext();
|
||||
}
|
||||
|
||||
public override int? OpenUI(object userData = null)
|
||||
public override async UniTask<int?> OpenUIAsync(object userData = null, float timeout = 30f)
|
||||
{
|
||||
if (userData is StartMenuFormContext context)
|
||||
{
|
||||
return OpenUIInternal(context);
|
||||
}
|
||||
|
||||
if (userData != null)
|
||||
{
|
||||
Log.Warning("StartMenuFormController.OpenUI() userData type is invalid.");
|
||||
Log.Warning("MenuController.OpenUIAsync() userData type is invalid.");
|
||||
return null;
|
||||
}
|
||||
|
||||
return OpenUIInternal(BuildStartMenuFormContext());
|
||||
}
|
||||
|
||||
public int? OpenUI(StartMenuFormContext context)
|
||||
{
|
||||
return OpenUIInternal(context);
|
||||
return await OpenFormAsync(BuildMenuContext(), timeout);
|
||||
}
|
||||
|
||||
public override void BindUseCase(IUIUseCase useCase)
|
||||
@@ -67,17 +58,17 @@ namespace UI
|
||||
|
||||
private void OnMenuStartGameButtonClick(object sender, GameEventArgs e)
|
||||
{
|
||||
if (!(sender is StartMenuForm) || !(e is MenuStartGameEventArgs))
|
||||
if (sender is not MenuForm || e is not MenuStartGameEventArgs)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
GameEntry.UIRouter.OpenUI(UIFormType.SelectRoleForm);
|
||||
GameEntry.UIRouter.OpenUIAsync(UIFormType.SelectRoleForm).Forget();
|
||||
}
|
||||
|
||||
private void OnMenuFileButtonClick(object sender, GameEventArgs e)
|
||||
{
|
||||
if (!(sender is StartMenuForm) || !(e is MenuFileButtonClickEventArgs))
|
||||
if (sender is not MenuForm || e is not MenuFileButtonClickEventArgs)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -87,7 +78,7 @@ namespace UI
|
||||
|
||||
private void OnMenuGuideButtonClick(object sender, GameEventArgs e)
|
||||
{
|
||||
if (!(sender is StartMenuForm) || !(e is MenuGuideButtonClickEventArgs))
|
||||
if (sender is not MenuForm || e is not MenuGuideButtonClickEventArgs)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -97,22 +88,22 @@ namespace UI
|
||||
|
||||
private void OnMenuSettingButtonClick(object sender, GameEventArgs e)
|
||||
{
|
||||
if (!(sender is StartMenuForm) || !(e is MenuSettingButtonClickEventArgs))
|
||||
if (sender is not MenuForm || e is not MenuSettingButtonClickEventArgs)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
GameEntry.UIRouter.OpenUI(UIFormType.SettingForm);
|
||||
GameEntry.UIRouter.OpenUIAsync(UIFormType.SettingForm).Forget();
|
||||
}
|
||||
|
||||
private void OnMenuQuitButtonClick(object sender, GameEventArgs e)
|
||||
{
|
||||
if (!(sender is StartMenuForm) || !(e is MenuQuitButtonClickEventArgs))
|
||||
if (sender is not MenuForm || e is not MenuQuitButtonClickEventArgs)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
GameEntry.UIRouter.OpenUI(UIFormType.DialogForm, new DialogFormRawData
|
||||
GameEntry.UIRouter.OpenUIAsync(UIFormType.DialogForm, new DialogRawData
|
||||
{
|
||||
Mode = 2,
|
||||
Title = GameEntry.Localization.GetString("AskQuitGame.Title"),
|
||||
@@ -121,12 +112,12 @@ namespace UI
|
||||
{
|
||||
UnityGameFramework.Runtime.GameEntry.Shutdown(ShutdownType.Quit);
|
||||
}
|
||||
});
|
||||
}).Forget();
|
||||
}
|
||||
|
||||
private void OnMenuAboutButtonClick(object sender, GameEventArgs e)
|
||||
{
|
||||
if (!(sender is StartMenuForm) || !(e is MenuAboutButtonClickEventArgs))
|
||||
if (sender is not MenuForm || e is not MenuAboutButtonClickEventArgs)
|
||||
{
|
||||
return;
|
||||
}
|
||||
+4
-4
@@ -1,11 +1,11 @@
|
||||
using SepCore.Event;
|
||||
using UnityGameFramework.Runtime;
|
||||
|
||||
namespace UI
|
||||
namespace SepCore.UI
|
||||
{
|
||||
public class StartMenuForm : UGuiForm
|
||||
public class MenuForm : UGuiForm
|
||||
{
|
||||
public void RefreshUI(StartMenuFormContext context)
|
||||
public void RefreshUI(MenuContext context)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace UI
|
||||
{
|
||||
base.OnOpen(userData);
|
||||
|
||||
if (userData is StartMenuFormContext context)
|
||||
if (userData is MenuContext context)
|
||||
{
|
||||
RefreshUI(context);
|
||||
return;
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
namespace UI
|
||||
namespace SepCore.UI
|
||||
{
|
||||
public class SelectRoleFormContext : UIContext
|
||||
public class SelectRoleContext : UIContext
|
||||
{
|
||||
public RoleItemContext[] RoleItemContexts;
|
||||
public RolePropertyAreaContext RolePropertyAreaContext;
|
||||
+47
-39
@@ -1,37 +1,38 @@
|
||||
using Cysharp.Threading.Tasks;
|
||||
using SepCore.Event;
|
||||
using SepCore.Definition;
|
||||
using GameFramework.Event;
|
||||
using UnityEngine;
|
||||
using UnityGameFramework.Runtime;
|
||||
|
||||
namespace UI
|
||||
namespace SepCore.UI
|
||||
{
|
||||
public class SelectRoleFormController : UIFormControllerCommonBase<SelectRoleFormContext, SelectRoleForm>
|
||||
public class SelectRoleController : UIControllerBase<SelectRoleContext, SelectRoleForm>
|
||||
{
|
||||
private SelectRoleFormUseCase _useCase;
|
||||
private SelectRoleUseCase _useCase;
|
||||
|
||||
protected override UIFormType UIFormTypeId => UIFormType.SelectRoleForm;
|
||||
protected override UIFormType UIFormType => UIFormType.SelectRoleForm;
|
||||
|
||||
protected override void RefreshUI(SelectRoleForm form, SelectRoleFormContext context)
|
||||
protected override void RefreshUI(SelectRoleForm form, SelectRoleContext context)
|
||||
{
|
||||
form.RefreshUI(context);
|
||||
}
|
||||
|
||||
protected override void SubscribeCustomEvents()
|
||||
{
|
||||
GameEntry.Event.Subscribe(MenuSelectRoleReturnEventArgs.EventId, OnMenuSelectRoleReturn);
|
||||
GameEntry.Event.Subscribe(MenuSelectRoleSelectedEventArgs.EventId, OnMenuSelectRoleSelected);
|
||||
GameEntry.Event.Subscribe(MenuSelectRoleConfirmEventArgs.EventId, OnMenuSelectRoleConfirm);
|
||||
GameEntry.Event.Subscribe(MenuSelectRoleReturnEventArgs.EventId, OnSelectRoleReturn);
|
||||
GameEntry.Event.Subscribe(SelectRoleHoverEventArgs.EventId, OnSelectRoleHover);
|
||||
GameEntry.Event.Subscribe(SelectRoleConfirmEventArgs.EventId, OnMenuSelectRoleConfirm);
|
||||
}
|
||||
|
||||
protected override void UnsubscribeCustomEvents()
|
||||
{
|
||||
GameEntry.Event.Unsubscribe(MenuSelectRoleReturnEventArgs.EventId, OnMenuSelectRoleReturn);
|
||||
GameEntry.Event.Unsubscribe(MenuSelectRoleSelectedEventArgs.EventId, OnMenuSelectRoleSelected);
|
||||
GameEntry.Event.Unsubscribe(MenuSelectRoleConfirmEventArgs.EventId, OnMenuSelectRoleConfirm);
|
||||
GameEntry.Event.Unsubscribe(MenuSelectRoleReturnEventArgs.EventId, OnSelectRoleReturn);
|
||||
GameEntry.Event.Unsubscribe(SelectRoleHoverEventArgs.EventId, OnSelectRoleHover);
|
||||
GameEntry.Event.Unsubscribe(SelectRoleConfirmEventArgs.EventId, OnMenuSelectRoleConfirm);
|
||||
}
|
||||
|
||||
private static SelectRoleFormContext BuildContext(SelectRoleFormRawData rawData)
|
||||
private static SelectRoleContext BuildContext(SelectRoleRawData rawData)
|
||||
{
|
||||
if (rawData == null)
|
||||
{
|
||||
@@ -64,7 +65,7 @@ namespace UI
|
||||
};
|
||||
}
|
||||
|
||||
return new SelectRoleFormContext
|
||||
return new SelectRoleContext
|
||||
{
|
||||
RoleItemContexts = roleItems,
|
||||
RolePropertyAreaContext = propertyContext,
|
||||
@@ -72,33 +73,38 @@ namespace UI
|
||||
};
|
||||
}
|
||||
|
||||
public override int? OpenUI(object userData = null)
|
||||
public override async UniTask<int?> OpenUIAsync(object userData = null, float timeout = 30f)
|
||||
{
|
||||
if (userData is SelectRoleFormContext selectRoleFormContext)
|
||||
if (userData is SelectRoleRawData rawData)
|
||||
{
|
||||
return OpenUIInternal(selectRoleFormContext);
|
||||
return await OpenUIAsync(rawData, timeout);
|
||||
}
|
||||
|
||||
if (userData != null)
|
||||
{
|
||||
Log.Warning("SelectRoleFormController.OpenUI() userData type is invalid.");
|
||||
Log.Warning("SelectRoleController.OpenUIAsync() userData type is invalid.");
|
||||
return null;
|
||||
}
|
||||
|
||||
if (_useCase == null)
|
||||
{
|
||||
Log.Error("SelectRoleFormController.OpenUI() useCase is null.");
|
||||
Log.Error("SelectRoleController.OpenUIAsync() useCase is null.");
|
||||
return null;
|
||||
}
|
||||
|
||||
SelectRoleFormRawData rawData = _useCase.CreateModel();
|
||||
SelectRoleFormContext context = BuildContext(rawData);
|
||||
return OpenUIInternal(context);
|
||||
SelectRoleRawData initialRawData = _useCase.CreateModel();
|
||||
return await OpenUIAsync(initialRawData, timeout);
|
||||
}
|
||||
|
||||
public async UniTask<int?> OpenUIAsync(SelectRoleRawData rawData, float timeout = 30f)
|
||||
{
|
||||
SelectRoleContext context = BuildContext(rawData);
|
||||
return await OpenFormAsync(context, timeout);
|
||||
}
|
||||
|
||||
public override void BindUseCase(IUIUseCase useCase)
|
||||
{
|
||||
if (!(useCase is SelectRoleFormUseCase selectRoleUseCase))
|
||||
if (useCase is not SelectRoleUseCase selectRoleUseCase)
|
||||
{
|
||||
Log.Error("SelectRoleUseCase.BindUseCase() useCase is invalid.");
|
||||
return;
|
||||
@@ -135,19 +141,24 @@ namespace UI
|
||||
return false;
|
||||
}
|
||||
|
||||
private void OnMenuSelectRoleReturn(object sender, GameEventArgs e)
|
||||
private void OnSelectRoleReturn(object sender, GameEventArgs e)
|
||||
{
|
||||
if ((SelectRoleForm)sender != Form || !(e is MenuSelectRoleReturnEventArgs))
|
||||
if (sender is not SelectRoleForm selectRoleForm || selectRoleForm != Form)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
CloseUI();
|
||||
if (e is not MenuSelectRoleReturnEventArgs)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
CloseUIAsync().Forget();
|
||||
}
|
||||
|
||||
private void OnMenuSelectRoleSelected(object sender, GameEventArgs e)
|
||||
private void OnSelectRoleHover(object sender, GameEventArgs e)
|
||||
{
|
||||
if (!(e is MenuSelectRoleSelectedEventArgs args))
|
||||
if (e is not SelectRoleHoverEventArgs args)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -157,27 +168,24 @@ namespace UI
|
||||
return;
|
||||
}
|
||||
|
||||
OnSelectRoleHoverAsync(args).Forget();
|
||||
}
|
||||
|
||||
private async UniTaskVoid OnSelectRoleHoverAsync(SelectRoleHoverEventArgs args)
|
||||
{
|
||||
if (_useCase == null)
|
||||
{
|
||||
Log.Error("SelectRoleFormController.OnMenuSelectRoleSelected() useCase is null.");
|
||||
return;
|
||||
}
|
||||
|
||||
SelectRoleFormRawData rawData = _useCase.SelectRole(args.RoleId);
|
||||
SelectRoleFormContext context = BuildContext(rawData);
|
||||
if (context == null)
|
||||
{
|
||||
Log.Error("SelectRoleFormController.OnMenuSelectRoleSelected() context build failed.");
|
||||
return;
|
||||
}
|
||||
|
||||
SetContext(context);
|
||||
UpdateShowRole(context.RolePropertyAreaContext);
|
||||
SelectRoleRawData rawData = _useCase.SelectRole(args.RoleId);
|
||||
await OpenUIAsync(rawData);
|
||||
}
|
||||
|
||||
private void OnMenuSelectRoleConfirm(object sender, GameEventArgs e)
|
||||
{
|
||||
if (!(e is MenuSelectRoleConfirmEventArgs))
|
||||
if (e is not SelectRoleConfirmEventArgs)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -196,4 +204,4 @@ namespace UI
|
||||
_useCase.ConfirmSelectedRole();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+4
-4
@@ -3,7 +3,7 @@ using SepCore.Event;
|
||||
using UnityEngine;
|
||||
using UnityGameFramework.Runtime;
|
||||
|
||||
namespace UI
|
||||
namespace SepCore.UI
|
||||
{
|
||||
public class SelectRoleForm : UGuiForm
|
||||
{
|
||||
@@ -13,11 +13,11 @@ namespace UI
|
||||
|
||||
[SerializeField] private RolePropertyArea _propertyArea = null;
|
||||
|
||||
private SelectRoleFormContext _context = null;
|
||||
private SelectRoleContext _context = null;
|
||||
|
||||
private RoleItem[] _roleItems = null;
|
||||
|
||||
public void RefreshUI(SelectRoleFormContext context)
|
||||
public void RefreshUI(SelectRoleContext context)
|
||||
{
|
||||
_context = context;
|
||||
|
||||
@@ -54,7 +54,7 @@ namespace UI
|
||||
{
|
||||
base.OnOpen(userData);
|
||||
|
||||
if (userData is SelectRoleFormContext context)
|
||||
if (userData is SelectRoleContext context)
|
||||
{
|
||||
RefreshUI(context);
|
||||
return;
|
||||
+1
-1
@@ -12,7 +12,7 @@ using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityGameFramework.Runtime;
|
||||
|
||||
namespace UI
|
||||
namespace SepCore.UI
|
||||
{
|
||||
public class SettingForm : UGuiForm
|
||||
{
|
||||
@@ -1,6 +0,0 @@
|
||||
namespace UI
|
||||
{
|
||||
public class StartMenuFormContext : UIContext
|
||||
{
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user