5 层 UI 规范收敛 SelectRoleForm 的 RawData / Context
围绕规范 §3.2 / §3.4 / §8 整理 SelectRoleForm 的数据传输与展示模型,让两层各自只承担规范允许的职责,并把子组件归位到模块目录内。 RawData层: - RolePropertyAreaRawData 移除展示串 InitialPropertyText,改为业务字段 StatModifier[] InitialProperties,并补回 RoleId,避免 RawData 携带已格式化的展示文本(违反 §3.2)。 - SelectRoleRawData 拆掉平铺的 RoleIds / RoleIconNames 平行数组与 SelectedRoleId / SelectedRoleName / SelectedRoleInitialProperties 哨兵字段,聚合为 RoleItemRawData[] RoleItems 与 RolePropertyAreaRawData SelectedRole(null 表示未选中),跟 Context 端的子结构形态对称。 - SelectRoleUseCase.BuildModel 同步改造为构造子 RawData,不再处理 -1 哨兵 ID。 Context 层: - 删除 SelectRoleContext.RoleIds 冗余字段(信息已由 RoleItemContexts[i].RoleId 承载)。 - 新增 bool ShowRoleProperty,把"显示属性卡 vs 显示随机卡"从 RolePropertyAreaContext == null 的隐式哨兵改成显式信号;Form 端 UpdateShowRole 改为读 ShowRoleProperty 切换卡片,不再用 null 当三态信号。 - Controller.BuildContext 用 rawData.SelectedRole != null 取代 >= 0 判定,InitialPropertyText 仍由 Controller 通过 ItemDescUtility.CreatePropDescription 拼装后注入 Context。 目录归属 事件命名
This commit is contained in:
parent
d2ce741a37
commit
aca311dd60
|
|
@ -3,15 +3,15 @@ using GameFramework.Event;
|
|||
|
||||
namespace SepCore.Event
|
||||
{
|
||||
public class MenuSelectRoleReturnEventArgs : GameEventArgs
|
||||
public class SelectRoleReturnEventArgs : GameEventArgs
|
||||
{
|
||||
public static readonly int EventId = typeof(MenuSelectRoleReturnEventArgs).GetHashCode();
|
||||
public static readonly int EventId = typeof(SelectRoleReturnEventArgs).GetHashCode();
|
||||
|
||||
public override int Id => EventId;
|
||||
|
||||
public static MenuSelectRoleReturnEventArgs Create()
|
||||
public static SelectRoleReturnEventArgs Create()
|
||||
{
|
||||
return ReferencePool.Acquire<MenuSelectRoleReturnEventArgs>();
|
||||
return ReferencePool.Acquire<SelectRoleReturnEventArgs>();
|
||||
}
|
||||
|
||||
public override void Clear()
|
||||
|
|
|
|||
|
|
@ -1,8 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 2b9ea0ac3213e6b4da166ad0aebc8ad4
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -4,6 +4,6 @@ namespace SepCore.UI
|
|||
{
|
||||
public RoleItemContext[] RoleItemContexts;
|
||||
public RolePropertyAreaContext RolePropertyAreaContext;
|
||||
public int[] RoleIds;
|
||||
public bool ShowRoleProperty;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,14 +21,14 @@ namespace SepCore.UI
|
|||
|
||||
protected override void SubscribeCustomEvents()
|
||||
{
|
||||
GameEntry.Event.Subscribe(MenuSelectRoleReturnEventArgs.EventId, OnSelectRoleReturn);
|
||||
GameEntry.Event.Subscribe(SelectRoleReturnEventArgs.EventId, OnSelectRoleReturn);
|
||||
GameEntry.Event.Subscribe(SelectRoleHoverEventArgs.EventId, OnSelectRoleHover);
|
||||
GameEntry.Event.Subscribe(SelectRoleConfirmEventArgs.EventId, OnMenuSelectRoleConfirm);
|
||||
}
|
||||
|
||||
protected override void UnsubscribeCustomEvents()
|
||||
{
|
||||
GameEntry.Event.Unsubscribe(MenuSelectRoleReturnEventArgs.EventId, OnSelectRoleReturn);
|
||||
GameEntry.Event.Unsubscribe(SelectRoleReturnEventArgs.EventId, OnSelectRoleReturn);
|
||||
GameEntry.Event.Unsubscribe(SelectRoleHoverEventArgs.EventId, OnSelectRoleHover);
|
||||
GameEntry.Event.Unsubscribe(SelectRoleConfirmEventArgs.EventId, OnMenuSelectRoleConfirm);
|
||||
}
|
||||
|
|
@ -37,32 +37,29 @@ namespace SepCore.UI
|
|||
{
|
||||
if (rawData == null)
|
||||
{
|
||||
Log.Error("SelectRoleFormController.BuildContext() rawData is null.");
|
||||
Log.Error("SelectRoleController.BuildContext() rawData is null.");
|
||||
return null;
|
||||
}
|
||||
|
||||
int count = rawData.RoleIds?.Length ?? 0;
|
||||
int count = rawData.RoleItems?.Length ?? 0;
|
||||
RoleItemContext[] roleItems = new RoleItemContext[count];
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
string iconName = rawData.RoleIconNames != null && i < rawData.RoleIconNames.Length
|
||||
? rawData.RoleIconNames[i]
|
||||
: null;
|
||||
|
||||
RoleItemRawData itemRawData = rawData.RoleItems[i];
|
||||
roleItems[i] = new RoleItemContext
|
||||
{
|
||||
RoleId = rawData.RoleIds[i],
|
||||
IconName = iconName
|
||||
RoleId = itemRawData.RoleId,
|
||||
IconName = itemRawData.IconName
|
||||
};
|
||||
}
|
||||
|
||||
RolePropertyAreaContext propertyContext = null;
|
||||
if (rawData.SelectedRoleId >= 0)
|
||||
if (rawData.SelectedRole != null)
|
||||
{
|
||||
propertyContext = new RolePropertyAreaContext
|
||||
{
|
||||
RoleName = rawData.SelectedRoleName,
|
||||
InitialPropertyText = ItemDescUtility.CreatePropDescription(rawData.SelectedRoleInitialProperties)
|
||||
RoleName = rawData.SelectedRole.RoleName,
|
||||
InitialPropertyText = ItemDescUtility.CreatePropDescription(rawData.SelectedRole.InitialProperties)
|
||||
?? string.Empty
|
||||
};
|
||||
}
|
||||
|
|
@ -71,7 +68,7 @@ namespace SepCore.UI
|
|||
{
|
||||
RoleItemContexts = roleItems,
|
||||
RolePropertyAreaContext = propertyContext,
|
||||
RoleIds = rawData.RoleIds
|
||||
ShowRoleProperty = propertyContext != null
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -120,13 +117,14 @@ namespace SepCore.UI
|
|||
{
|
||||
if (Context == null)
|
||||
{
|
||||
Log.Error("SelectRoleFormController.UpdateShowRole() Context is null.");
|
||||
Log.Error("SelectRoleController.UpdateShowRole() Context is null.");
|
||||
return;
|
||||
}
|
||||
|
||||
Context.RolePropertyAreaContext = rolePropertyAreaContext;
|
||||
Context.ShowRoleProperty = rolePropertyAreaContext != null;
|
||||
|
||||
Form?.UpdateShowRole(rolePropertyAreaContext);
|
||||
Form?.UpdateShowRole(Context.ShowRoleProperty, rolePropertyAreaContext);
|
||||
}
|
||||
|
||||
private bool IsCurrentFormEventSender(object sender)
|
||||
|
|
@ -151,7 +149,7 @@ namespace SepCore.UI
|
|||
return;
|
||||
}
|
||||
|
||||
if (e is not MenuSelectRoleReturnEventArgs)
|
||||
if (e is not SelectRoleReturnEventArgs)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
@ -178,7 +176,7 @@ namespace SepCore.UI
|
|||
{
|
||||
if (_useCase == null)
|
||||
{
|
||||
Log.Error("SelectRoleFormController.OnMenuSelectRoleSelected() useCase is null.");
|
||||
Log.Error("SelectRoleController.OnMenuSelectRoleSelected() useCase is null.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -200,7 +198,7 @@ namespace SepCore.UI
|
|||
|
||||
if (_useCase == null)
|
||||
{
|
||||
Log.Error("SelectRoleFormController.OnMenuSelectRoleConfirm() useCase is null.");
|
||||
Log.Error("SelectRoleController.OnMenuSelectRoleConfirm() useCase is null.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ namespace SepCore.UI
|
|||
roleIndex++;
|
||||
}
|
||||
|
||||
UpdateShowRole(_context.RolePropertyAreaContext);
|
||||
UpdateShowRole(_context.ShowRoleProperty, _context.RolePropertyAreaContext);
|
||||
}
|
||||
|
||||
#region FSM
|
||||
|
|
@ -76,9 +76,9 @@ namespace SepCore.UI
|
|||
|
||||
#endregion
|
||||
|
||||
public void UpdateShowRole(RolePropertyAreaContext propertyAreaContext)
|
||||
public void UpdateShowRole(bool showRoleProperty, RolePropertyAreaContext propertyAreaContext)
|
||||
{
|
||||
if (propertyAreaContext == null)
|
||||
if (!showRoleProperty)
|
||||
{
|
||||
_randomRoleCard.SetActive(true);
|
||||
_roleCard.SetActive(false);
|
||||
|
|
@ -94,7 +94,7 @@ namespace SepCore.UI
|
|||
|
||||
public void OnReturnButtonClick()
|
||||
{
|
||||
GameEntry.Event.Fire(this, MenuSelectRoleReturnEventArgs.Create());
|
||||
GameEntry.Event.Fire(this, SelectRoleReturnEventArgs.Create());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: de04e3a2f42efa84798cde2397f505db
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 476e0babdb10df1499873cc46eaaa41e
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,8 +1,11 @@
|
|||
using SepCore.Definition;
|
||||
|
||||
namespace SepCore.UI
|
||||
{
|
||||
public class RolePropertyAreaRawData
|
||||
{
|
||||
public int RoleId;
|
||||
public string RoleName;
|
||||
public string InitialPropertyText;
|
||||
public StatModifier[] InitialProperties;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,13 +1,8 @@
|
|||
using SepCore.Definition;
|
||||
|
||||
namespace SepCore.UI
|
||||
{
|
||||
public class SelectRoleRawData
|
||||
{
|
||||
public int[] RoleIds;
|
||||
public string[] RoleIconNames;
|
||||
public int SelectedRoleId;
|
||||
public string SelectedRoleName;
|
||||
public StatModifier[] SelectedRoleInitialProperties;
|
||||
public RoleItemRawData[] RoleItems;
|
||||
public RolePropertyAreaRawData SelectedRole;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,22 +57,30 @@ namespace SepCore.UI
|
|||
{
|
||||
DRRole[] roles = _roleDataTable.GetAllDataRows();
|
||||
int count = _roleDataTable.Count;
|
||||
int[] roleIds = new int[count];
|
||||
string[] iconNames = new string[count];
|
||||
RoleItemRawData[] roleItems = new RoleItemRawData[count];
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
roleIds[i] = roles[i].Id;
|
||||
iconNames[i] = roles[i].IconName;
|
||||
roleItems[i] = new RoleItemRawData
|
||||
{
|
||||
RoleId = roles[i].Id,
|
||||
IconName = roles[i].IconName
|
||||
};
|
||||
}
|
||||
|
||||
DRRole selectedRole = selectedRoleId > 0 ? _roleDataTable.GetDataRow(selectedRoleId) : null;
|
||||
RolePropertyAreaRawData selectedRoleData = selectedRole == null
|
||||
? null
|
||||
: new RolePropertyAreaRawData
|
||||
{
|
||||
RoleId = selectedRole.Id,
|
||||
RoleName = selectedRole.RoleName,
|
||||
InitialProperties = selectedRole.InitialProperties
|
||||
};
|
||||
|
||||
return new SelectRoleRawData
|
||||
{
|
||||
RoleIds = roleIds,
|
||||
RoleIconNames = iconNames,
|
||||
SelectedRoleId = selectedRole?.Id ?? -1,
|
||||
SelectedRoleName = selectedRole?.RoleName,
|
||||
SelectedRoleInitialProperties = selectedRole?.InitialProperties
|
||||
RoleItems = roleItems,
|
||||
SelectedRole = selectedRoleData
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue