对 DisplayItemInfoForm 按 5 层 UI 规范做结构整理

- 删除无用的 DisplayItemInfoUseCase,转为轻量 UI(Controller + Context + View)
- RawData 类型安全:object Data 拆分为 WeaponData + PropItem
- View 事件规范:回收按钮改用 UI 专用事件,由 Controller 通过回调转发
- 简化 _locked 状态管理,统一在 CloseUIAsync 中清理
This commit is contained in:
SepComet
2026-06-16 17:09:21 +08:00
committed by basil
parent 68b9f98e0e
commit 1fe2f31ede
11 changed files with 107 additions and 173 deletions
@@ -18,6 +18,7 @@ namespace SepCore.UI
public string Description;
public int Price;
public Vector3 TargetPos;
public bool ShowRecycleButton;
public DisplayItemInfoContext()
{
@@ -29,6 +30,7 @@ namespace SepCore.UI
Description = string.Empty;
Price = 0;
TargetPos = Vector3.zero;
ShowRecycleButton = false;
}
public DisplayItemInfoContext(DisplayItemInfoRawData rawData)
@@ -38,6 +40,7 @@ namespace SepCore.UI
Rarity = rawData.Rarity;
Price = rawData.Price;
TargetPos = rawData.TargetPos;
ShowRecycleButton = rawData.OnRecycle != null;
if (ItemType == ItemType.None)
{
IconAssetName = string.Empty;
@@ -45,14 +48,14 @@ namespace SepCore.UI
}
else if (ItemType == ItemType.Weapon)
{
var data = (WeaponData)rawData.Data;
var data = rawData.WeaponData;
IconAssetName = data.IconAssetName;
Title = data.Title;
Description = ItemDescUtility.CreateWeaponDescription(data);
}
else
{
var data = (PropItem)rawData.Data;
var data = rawData.PropData;
IconAssetName = data.IconAssetName;
Title = data.Title;
Description = ItemDescUtility.CreatePropDescription(data);
@@ -1,3 +1,4 @@
using System;
using Cysharp.Threading.Tasks;
using SepCore.Event;
using SepCore.Definition;
@@ -12,17 +13,20 @@ namespace SepCore.UI
protected override UIFormType UIFormType => UIFormType.DisplayItemInfoForm;
private bool _locked = false;
private Action<int, int> _onRecycle;
protected override void SubscribeCustomEvents()
{
GameEntry.Event.Subscribe(DisplayItemInfoLockEventArgs.EventId, DisplayItemInfoLock);
GameEntry.Event.Subscribe(DisplayItemInfoHideEventArgs.EventId, DisplayItemInfoHide);
GameEntry.Event.Subscribe(DisplayItemInfoRecycleEventArgs.EventId, DisplayItemInfoRecycle);
}
protected override void UnsubscribeCustomEvents()
{
GameEntry.Event.Unsubscribe(DisplayItemInfoLockEventArgs.EventId, DisplayItemInfoLock);
GameEntry.Event.Unsubscribe(DisplayItemInfoHideEventArgs.EventId, DisplayItemInfoHide);
GameEntry.Event.Unsubscribe(DisplayItemInfoRecycleEventArgs.EventId, DisplayItemInfoRecycle);
}
protected override void RefreshUI(DisplayItemInfoForm form, DisplayItemInfoContext context)
@@ -69,21 +73,22 @@ namespace SepCore.UI
return;
}
_locked = false;
_onRecycle = rawData.OnRecycle;
await OpenFormAsync(context, timeout);
}
public override async UniTask CloseUIAsync(object userData = null, float timeout = 30f)
{
_locked = false;
_onRecycle = null;
await base.CloseUIAsync(userData, timeout);
}
public override void BindUseCase(IUIUseCase useCase)
{
if (useCase is not DisplayItemInfoUseCase)
if (useCase != null)
{
Log.Error("DisplayItemInfoForm.BindUseCase() useCase is invalid.");
Log.Warning("DisplayItemInfoController does not use a use case.");
}
}
@@ -121,17 +126,24 @@ namespace SepCore.UI
return;
}
if (args.Force)
{
GameEntry.UIRouter.CloseUIAsync(UIFormType.DisplayItemInfoForm).Forget();
_locked = false;
return;
}
if (_locked && !args.Force) return;
GameEntry.UIRouter.CloseUIAsync(UIFormType.DisplayItemInfoForm).Forget();
_locked = false;
}
private void DisplayItemInfoRecycle(object sender, GameEventArgs e)
{
if (e is not DisplayItemInfoRecycleEventArgs args)
{
return;
}
if (!IsCurrentFormSender(sender))
{
return;
}
_onRecycle?.Invoke(args.Index, args.Price);
}
#endregion
@@ -62,7 +62,7 @@ namespace SepCore.UI
if (_recycleButton != null)
{
_recycleButton.gameObject.SetActive(_context.ItemType == ItemType.Weapon);
_recycleButton.gameObject.SetActive(_context.ShowRecycleButton);
}
if (_iconArea != null && !string.IsNullOrEmpty(_context.IconAssetName))
@@ -191,8 +191,8 @@ namespace SepCore.UI
public void OnRecycleButtonClick()
{
if (_context == null || _context.ItemType != ItemType.Weapon) return;
GameEntry.Event.Fire(this, ShopWeaponRecycleEventArgs.Create(_context.Index, _context.Price));
if (_context == null) return;
GameEntry.Event.Fire(this, DisplayItemInfoRecycleEventArgs.Create(_context.Index, _context.Price));
}
public void OnCancelButtonClick()