合并 MenuForm 的 6 个按钮事件为 MenuButtonClickEventArgs
新增 MenuButtonId 枚举区分按钮来源,MenuController 改为单订阅 + switch 分派,删除 Menu{StartGame,File,Guide,Setting,Quit,About}EventArgs 及其 meta。MenuForm 的 OnXxxButtonClick 方法名按 prefab 反射绑定保留,仅薄薄转发到统一事件。
This commit is contained in:
@@ -17,22 +17,12 @@ namespace SepCore.UI
|
||||
|
||||
protected override void SubscribeCustomEvents()
|
||||
{
|
||||
GameEntry.Event.Subscribe(MenuStartGameEventArgs.EventId, OnMenuStartGameButtonClick);
|
||||
GameEntry.Event.Subscribe(MenuFileButtonClickEventArgs.EventId, OnMenuFileButtonClick);
|
||||
GameEntry.Event.Subscribe(MenuGuideButtonClickEventArgs.EventId, OnMenuGuideButtonClick);
|
||||
GameEntry.Event.Subscribe(MenuSettingButtonClickEventArgs.EventId, OnMenuSettingButtonClick);
|
||||
GameEntry.Event.Subscribe(MenuQuitButtonClickEventArgs.EventId, OnMenuQuitButtonClick);
|
||||
GameEntry.Event.Subscribe(MenuAboutButtonClickEventArgs.EventId, OnMenuAboutButtonClick);
|
||||
GameEntry.Event.Subscribe(MenuButtonClickEventArgs.EventId, OnMenuButtonClick);
|
||||
}
|
||||
|
||||
protected override void UnsubscribeCustomEvents()
|
||||
{
|
||||
GameEntry.Event.Unsubscribe(MenuStartGameEventArgs.EventId, OnMenuStartGameButtonClick);
|
||||
GameEntry.Event.Unsubscribe(MenuFileButtonClickEventArgs.EventId, OnMenuFileButtonClick);
|
||||
GameEntry.Event.Unsubscribe(MenuGuideButtonClickEventArgs.EventId, OnMenuGuideButtonClick);
|
||||
GameEntry.Event.Unsubscribe(MenuSettingButtonClickEventArgs.EventId, OnMenuSettingButtonClick);
|
||||
GameEntry.Event.Unsubscribe(MenuQuitButtonClickEventArgs.EventId, OnMenuQuitButtonClick);
|
||||
GameEntry.Event.Unsubscribe(MenuAboutButtonClickEventArgs.EventId, OnMenuAboutButtonClick);
|
||||
GameEntry.Event.Unsubscribe(MenuButtonClickEventArgs.EventId, OnMenuButtonClick);
|
||||
}
|
||||
|
||||
private static MenuContext BuildMenuContext()
|
||||
@@ -56,73 +46,46 @@ namespace SepCore.UI
|
||||
Log.Info("MenuForm doesn't need UseCase");
|
||||
}
|
||||
|
||||
private void OnMenuStartGameButtonClick(object sender, GameEventArgs e)
|
||||
private void OnMenuButtonClick(object sender, GameEventArgs e)
|
||||
{
|
||||
if (sender is not MenuForm || e is not MenuStartGameEventArgs)
|
||||
if (sender is not MenuForm || e is not MenuButtonClickEventArgs args)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
GameEntry.UIRouter.OpenUIAsync(UIFormType.SelectRoleForm).Forget();
|
||||
}
|
||||
|
||||
private void OnMenuFileButtonClick(object sender, GameEventArgs e)
|
||||
{
|
||||
if (sender is not MenuForm || e is not MenuFileButtonClickEventArgs)
|
||||
switch (args.Button)
|
||||
{
|
||||
return;
|
||||
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;
|
||||
}
|
||||
|
||||
Log.Warning("Menu file button click is not implemented.");
|
||||
}
|
||||
|
||||
private void OnMenuGuideButtonClick(object sender, GameEventArgs e)
|
||||
{
|
||||
if (sender is not MenuForm || e is not MenuGuideButtonClickEventArgs)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Log.Warning("Menu guide button click is not implemented.");
|
||||
}
|
||||
|
||||
private void OnMenuSettingButtonClick(object sender, GameEventArgs e)
|
||||
{
|
||||
if (sender is not MenuForm || e is not MenuSettingButtonClickEventArgs)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
GameEntry.UIRouter.OpenUIAsync(UIFormType.SettingForm).Forget();
|
||||
}
|
||||
|
||||
private void OnMenuQuitButtonClick(object sender, GameEventArgs e)
|
||||
{
|
||||
if (sender is not MenuForm || e is not MenuQuitButtonClickEventArgs)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
private void OnMenuAboutButtonClick(object sender, GameEventArgs e)
|
||||
{
|
||||
if (sender is not MenuForm || e is not MenuAboutButtonClickEventArgs)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Log.Warning("Menu about button click is not implemented.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using SepCore.Definition;
|
||||
using SepCore.Event;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
@@ -39,34 +40,41 @@ namespace SepCore.UI
|
||||
|
||||
#endregion
|
||||
|
||||
// 以下方法被 MenuForm.prefab 中的 Button.onClick 通过名称反射绑定。
|
||||
// 重命名前需同步修改 prefab 中的 m_MethodName 引用。
|
||||
public void OnStartButtonClick()
|
||||
{
|
||||
GameEntry.Event.Fire(this, MenuStartGameEventArgs.Create());
|
||||
FireButtonClick(MenuButtonId.StartGame);
|
||||
}
|
||||
|
||||
public void OnFileButtonClick()
|
||||
{
|
||||
GameEntry.Event.Fire(this, MenuFileButtonClickEventArgs.Create());
|
||||
FireButtonClick(MenuButtonId.File);
|
||||
}
|
||||
|
||||
public void OnGuideButtonClick()
|
||||
{
|
||||
GameEntry.Event.Fire(this, MenuGuideButtonClickEventArgs.Create());
|
||||
FireButtonClick(MenuButtonId.Guide);
|
||||
}
|
||||
|
||||
public void OnSettingButtonClick()
|
||||
{
|
||||
GameEntry.Event.Fire(this, MenuSettingButtonClickEventArgs.Create());
|
||||
FireButtonClick(MenuButtonId.Setting);
|
||||
}
|
||||
|
||||
public void OnQuitButtonClick()
|
||||
{
|
||||
GameEntry.Event.Fire(this, MenuQuitButtonClickEventArgs.Create());
|
||||
FireButtonClick(MenuButtonId.Quit);
|
||||
}
|
||||
|
||||
public void OnAboutButtonClick()
|
||||
{
|
||||
GameEntry.Event.Fire(this, MenuAboutButtonClickEventArgs.Create());
|
||||
FireButtonClick(MenuButtonId.About);
|
||||
}
|
||||
|
||||
private void FireButtonClick(MenuButtonId button)
|
||||
{
|
||||
GameEntry.Event.Fire(this, MenuButtonClickEventArgs.Create(button));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user