修复已知的 bug,规划后期的开发方向

This commit is contained in:
SepComet
2026-02-17 22:46:28 +08:00
parent 85b0205c73
commit e151619c69
24 changed files with 482 additions and 1313 deletions
@@ -93,6 +93,7 @@ namespace Entity
set
{
if (value == _enable) return;
_enable = value;
_movementComponent.SetMove(value);
_backpackComponent.SetWeaponState(value);
_inputComponent.SetListening(value);
@@ -6,12 +6,10 @@
//------------------------------------------------------------
using Components;
using Definition;
using Definition.DataStruct;
using Entity.EntityData;
using StarForce;
using Game.Utility;
using UnityEngine;
using UnityGameFramework.Runtime;
namespace Entity
{
@@ -6,7 +6,7 @@ using Definition.DataStruct;
using Definition.Enum;
using DG.Tweening;
using Entity.EntityData;
using StarForce;
using Game.Utility;
using UnityEngine;
using UnityGameFramework.Runtime;
@@ -94,8 +94,6 @@ namespace Procedure
GameEntry.Entity.ShowPlayer(_currentPlayerData);
GameEntry.UIRouter.OpenUI(UIFormType.HudForm);
InitGameState();
}
protected override void OnUpdate(IFsm<IProcedureManager> procedureOwner, float elapseSeconds,
@@ -0,0 +1,183 @@
using Definition.Enum;
using GameFramework.Event;
using UnityGameFramework.Runtime;
namespace UI
{
public abstract class UIFormControllerCommonBase<TContext, TForm> : UIFormControllerBase<TContext>
where TContext : UIContext
where TForm : UGuiForm
{
private TContext _context;
private TForm _form;
private int? _formSerialId;
private bool _pendingRefresh;
private bool _isBindEvent;
protected TContext Context => _context;
protected TForm Form => _form;
protected int? FormSerialId => _formSerialId;
protected abstract UIFormType UIFormTypeId { get; }
protected abstract void RefreshUI(TForm form, TContext context);
protected virtual void SubscribeCustomEvents()
{
}
protected virtual void UnsubscribeCustomEvents()
{
}
protected virtual void CloseLoadedFormDirect(TForm form)
{
form.Close();
}
protected void SetContext(TContext context)
{
_context = context;
}
protected void RefreshCurrentUI()
{
if (_context == null)
{
return;
}
if (_form == null)
{
_pendingRefresh = true;
return;
}
RefreshUI(_form, _context);
_pendingRefresh = false;
}
protected override int? OpenUIInternal(TContext context)
{
if (context == null)
{
Log.Warning("{0}.OpenUI() context is null.", GetType().Name);
return null;
}
_context = context;
if (_form != null && _formSerialId.HasValue && GameEntry.UI.HasUIForm(_formSerialId.Value))
{
RefreshUI(_form, _context);
return _formSerialId;
}
CloseUI();
_pendingRefresh = true;
SubscribeEvents();
_formSerialId = GameEntry.UI.OpenUIForm(UIFormTypeId, _context);
return _formSerialId;
}
public override void CloseUI()
{
_pendingRefresh = false;
UnsubscribeEvents();
if (_formSerialId.HasValue)
{
if (GameEntry.UI.HasUIForm(_formSerialId.Value))
{
GameEntry.UI.CloseUIForm(_formSerialId.Value);
}
_form = null;
_formSerialId = null;
return;
}
if (_form != null)
{
CloseLoadedFormDirect(_form);
_form = null;
}
}
private void SubscribeEvents()
{
if (_isBindEvent)
{
return;
}
GameEntry.Event.Subscribe(OpenUIFormSuccessEventArgs.EventId, OpenUIFormSuccess);
GameEntry.Event.Subscribe(CloseUIFormCompleteEventArgs.EventId, CloseUIFormComplete);
SubscribeCustomEvents();
_isBindEvent = true;
}
private void UnsubscribeEvents()
{
if (!_isBindEvent)
{
return;
}
GameEntry.Event.Unsubscribe(OpenUIFormSuccessEventArgs.EventId, OpenUIFormSuccess);
GameEntry.Event.Unsubscribe(CloseUIFormCompleteEventArgs.EventId, CloseUIFormComplete);
UnsubscribeCustomEvents();
_isBindEvent = false;
}
private void OpenUIFormSuccess(object sender, GameEventArgs e)
{
if (!(e is OpenUIFormSuccessEventArgs args))
{
return;
}
if (!_formSerialId.HasValue)
{
return;
}
if (args.UIForm == null || args.UIForm.SerialId != _formSerialId.Value || args.UserData != _context)
{
return;
}
_form = args.UIForm.Logic as TForm;
if (_form == null)
{
Log.Warning("{0} open success but form logic is invalid.", GetType().Name);
return;
}
if (_pendingRefresh)
{
RefreshCurrentUI();
}
}
private void CloseUIFormComplete(object sender, GameEventArgs e)
{
if (!(e is CloseUIFormCompleteEventArgs args))
{
return;
}
if (args.SerialId != _formSerialId)
{
return;
}
_form = null;
_formSerialId = null;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 696c0314286f89c4082c2aa2eddaec2d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -1,60 +1,17 @@
using Definition.Enum;
using GameFramework.Event;
using UnityGameFramework.Runtime;
namespace UI
{
public class TUIFormController : UIFormControllerBase<UIContext>
public class TUIFormController : UIFormControllerCommonBase<UIContext, TUIForm>
{
private IUIUseCase _useCase;
private UIContext _context;
private TUIForm _tForm;
private int? _tFormSerialId;
private bool _pendingRefresh;
private bool _isBindEvent;
private void SubscribeEvents()
protected override UIFormType UIFormTypeId => UIFormType.TUIForm;
protected override void RefreshUI(TUIForm form, UIContext context)
{
if (_isBindEvent) return;
GameEntry.Event.Subscribe(OpenUIFormSuccessEventArgs.EventId, OpenUIFormSuccess);
GameEntry.Event.Subscribe(CloseUIFormCompleteEventArgs.EventId, CloseUIFormComplete);
_isBindEvent = true;
}
private void UnsubscribeEvents()
{
if (!_isBindEvent) return;
GameEntry.Event.Unsubscribe(OpenUIFormSuccessEventArgs.EventId, OpenUIFormSuccess);
GameEntry.Event.Unsubscribe(CloseUIFormCompleteEventArgs.EventId, CloseUIFormComplete);
_isBindEvent = false;
}
protected override int? OpenUIInternal(UIContext context)
{
if (context == null)
{
Log.Warning("TUIFormController open failed. context is null.");
return null;
}
_context = context;
if (_tForm != null && _tFormSerialId.HasValue &&
GameEntry.UI.HasUIForm(_tFormSerialId.Value))
{
_tForm.RefreshUI(_context);
return _tFormSerialId;
}
CloseUI();
_pendingRefresh = true;
SubscribeEvents();
_tFormSerialId = GameEntry.UI.OpenUIForm(UIFormType.TUIForm, context);
return _tFormSerialId;
form.RefreshUI(context);
}
public override int? OpenUI(object userData = null)
@@ -70,110 +27,18 @@ namespace UI
return null;
}
return OpenUIInternal(_context);
}
public override void CloseUI()
{
_pendingRefresh = false;
UnsubscribeEvents();
if (_tFormSerialId.HasValue)
{
if (GameEntry.UI.HasUIForm(_tFormSerialId.Value))
{
GameEntry.UI.CloseUIForm(_tFormSerialId.Value);
}
_tForm = null;
_tFormSerialId = null;
return;
}
if (_tForm != null)
{
_tForm.Close();
_tForm = null;
}
return OpenUIInternal(Context);
}
public override void BindUseCase(IUIUseCase useCase)
{
if (!(useCase is IUIUseCase UIFormUseCase))
if (!(useCase is IUIUseCase uiFormUseCase))
{
Log.Error("LevelUpForm.BindUseCase() useCase is invalid.");
return;
}
_useCase = UIFormUseCase;
_useCase = uiFormUseCase;
}
private void TryRefreshUI()
{
if (_context == null)
{
return;
}
if (_tForm == null)
{
_pendingRefresh = true;
return;
}
_tForm.RefreshUI(_context);
_pendingRefresh = false;
}
#region EventHanlders
private void OpenUIFormSuccess(object sender, GameEventArgs e)
{
if (!(e is OpenUIFormSuccessEventArgs args))
{
return;
}
if (!_tFormSerialId.HasValue)
{
return;
}
if (args.UIForm == null || args.UIForm.SerialId != _tFormSerialId.Value || args.UserData != _context)
{
return;
}
_tForm = args.UIForm.Logic as TUIForm;
if (_tForm == null)
{
Log.Warning("DialogFormController open success but form logic is invalid.");
return;
}
if (_pendingRefresh)
{
TryRefreshUI();
}
}
private void CloseUIFormComplete(object sender, GameEventArgs e)
{
if (!(e is CloseUIFormCompleteEventArgs args))
{
return;
}
if (args.SerialId != _tFormSerialId)
{
return;
}
_tForm = null;
_tFormSerialId = null;
}
#endregion
}
}
+3 -3
View File
@@ -18,11 +18,11 @@ namespace UI
private const float OnHoverAlpha = 0.7f;
private const float OnClickAlpha = 0.6f;
[SerializeField] private UnityEvent _onPointerEnterAction = null;
[SerializeField] private UnityEvent _onPointerEnterAction = new();
[SerializeField] private UnityEvent _onClickAction = null;
[SerializeField] private UnityEvent _onClickAction = new();
[SerializeField] private UnityEvent _onPointerExitAction = null;
[SerializeField] private UnityEvent _onPointerExitAction = new();
[SerializeField] private bool _enableFade = true;
@@ -1,39 +1,20 @@
using Definition.Enum;
using GameFramework.Event;
using UnityGameFramework.Runtime;
namespace UI
{
public class DisplayItemInfoFormController : UIFormControllerBase<DisplayItemInfoFormContext>
public class DisplayItemInfoFormController : UIFormControllerCommonBase<DisplayItemInfoFormContext, DisplayItemInfoForm>
{
private DisplayItemInfoFormContext _context;
protected override UIFormType UIFormTypeId => UIFormType.DisplayItemInfoForm;
private DisplayItemInfoForm _itemInfoForm;
private int? _itemInfoFormSerialId;
private bool _pendingRefresh;
private bool _isBindEvent = false;
private void SubscribeEvents()
protected override void RefreshUI(DisplayItemInfoForm form, DisplayItemInfoFormContext context)
{
if (_isBindEvent) return;
GameEntry.Event.Subscribe(OpenUIFormSuccessEventArgs.EventId, OpenUIFormSuccess);
GameEntry.Event.Subscribe(CloseUIFormCompleteEventArgs.EventId, CloseUIFormComplete);
_isBindEvent = true;
form.RefreshUI(context);
}
private void UnsubscribeEvents()
protected override void CloseLoadedFormDirect(DisplayItemInfoForm form)
{
if (!_isBindEvent) return;
GameEntry.Event.Unsubscribe(OpenUIFormSuccessEventArgs.EventId, OpenUIFormSuccess);
GameEntry.Event.Unsubscribe(CloseUIFormCompleteEventArgs.EventId, CloseUIFormComplete);
_isBindEvent = false;
GameEntry.UI.CloseUIForm(form);
}
private static DisplayItemInfoFormContext BuildContext(DisplayItemInfoFormRawData rawData)
@@ -56,32 +37,6 @@ namespace UI
};
}
#region UI Methods
protected override int? OpenUIInternal(DisplayItemInfoFormContext context)
{
if (context == null)
{
Log.Warning("ItemInfoFormController open failed. context is null.");
return null;
}
_context = context;
if (_itemInfoForm != null && _itemInfoFormSerialId.HasValue &&
GameEntry.UI.HasUIForm(_itemInfoFormSerialId.Value))
{
_itemInfoForm.RefreshUI(_context);
return _itemInfoFormSerialId;
}
CloseUI();
_pendingRefresh = true;
SubscribeEvents();
_itemInfoFormSerialId = GameEntry.UI.OpenUIForm(UIFormType.DisplayItemInfoForm, context);
return _itemInfoFormSerialId;
}
public int? OpenUI(DisplayItemInfoFormRawData rawData)
{
DisplayItemInfoFormContext context = BuildContext(rawData);
@@ -105,33 +60,8 @@ namespace UI
Log.Warning("DisplayItemInfoFormController.OpenUI() userData type is invalid.");
return null;
}
return OpenUIInternal(_context);
}
public override void CloseUI()
{
_pendingRefresh = false;
UnsubscribeEvents();
if (_itemInfoFormSerialId.HasValue)
{
if (GameEntry.UI.HasUIForm(_itemInfoFormSerialId.Value))
{
GameEntry.UI.CloseUIForm(_itemInfoFormSerialId.Value);
}
_itemInfoForm = null;
_itemInfoFormSerialId = null;
return;
}
if (_itemInfoForm != null)
{
GameEntry.UI.CloseUIForm(_itemInfoForm);
_itemInfoForm = null;
}
return OpenUIInternal(Context);
}
public override void BindUseCase(IUIUseCase useCase)
@@ -139,78 +69,7 @@ namespace UI
if (!(useCase is DisplayItemInfoFormUseCase))
{
Log.Error("DisplayItemInfoForm.BindUseCase() useCase is invalid.");
return;
}
}
private void TryRefreshUI()
{
if (_context == null)
{
return;
}
if (_itemInfoForm == null)
{
_pendingRefresh = true;
return;
}
_itemInfoForm.RefreshUI(_context);
_pendingRefresh = false;
}
#endregion
#region EventHanlders
private void OpenUIFormSuccess(object sender, GameEventArgs e)
{
if (!(e is OpenUIFormSuccessEventArgs args))
{
return;
}
if (!_itemInfoFormSerialId.HasValue)
{
return;
}
if (args.UIForm == null || args.UIForm.SerialId != _itemInfoFormSerialId.Value || args.UserData != _context)
{
return;
}
_itemInfoForm = args.UIForm.Logic as DisplayItemInfoForm;
if (_itemInfoForm == null)
{
Log.Warning("DisplayItemInfoFormController open success but form logic is invalid.");
return;
}
if (_pendingRefresh)
{
TryRefreshUI();
}
}
private void CloseUIFormComplete(object sender, GameEventArgs e)
{
if (!(e is CloseUIFormCompleteEventArgs args))
{
return;
}
if (args.SerialId != _itemInfoFormSerialId)
{
return;
}
_itemInfoForm = null;
_itemInfoFormSerialId = null;
}
#endregion
}
}
@@ -1,39 +1,15 @@
using Definition.Enum;
using GameFramework.Event;
using UnityGameFramework.Runtime;
namespace UI
{
public class HudFormController : UIFormControllerBase<HudFormContext>
public class HudFormController : UIFormControllerCommonBase<HudFormContext, HudForm>
{
private HudFormContext _context;
protected override UIFormType UIFormTypeId => UIFormType.HudForm;
private HudForm _hudForm;
private int? _hudFormSerialId;
private bool _pendingRefresh;
private bool _isBindEvent;
private void SubscribeEvents()
protected override void RefreshUI(HudForm form, HudFormContext context)
{
if (_isBindEvent) return;
GameEntry.Event.Subscribe(OpenUIFormSuccessEventArgs.EventId, OpenUIFormSuccess);
GameEntry.Event.Subscribe(CloseUIFormCompleteEventArgs.EventId, CloseUIFormComplete);
_isBindEvent = true;
}
private void UnsubscribeEvents()
{
if (!_isBindEvent) return;
GameEntry.Event.Unsubscribe(OpenUIFormSuccessEventArgs.EventId, OpenUIFormSuccess);
GameEntry.Event.Unsubscribe(CloseUIFormCompleteEventArgs.EventId, CloseUIFormComplete);
_isBindEvent = false;
form.RefreshUI(context);
}
private static HudFormContext BuildHudFormContext()
@@ -41,32 +17,6 @@ namespace UI
return new HudFormContext();
}
#region UI Methods
protected override int? OpenUIInternal(HudFormContext context)
{
if (context == null)
{
Log.Warning("HudFormController.OpenUI() context is null.");
return null;
}
_context = context;
if (_hudForm != null && _hudFormSerialId.HasValue &&
GameEntry.UI.HasUIForm(_hudFormSerialId.Value))
{
_hudForm.RefreshUI(_context);
return _hudFormSerialId;
}
CloseUI();
_pendingRefresh = true;
SubscribeEvents();
_hudFormSerialId = GameEntry.UI.OpenUIForm(UIFormType.HudForm, context);
return _hudFormSerialId;
}
public override int? OpenUI(object userData = null)
{
if (userData is HudFormContext context)
@@ -88,105 +38,9 @@ namespace UI
return OpenUIInternal(context);
}
public override void CloseUI()
{
_pendingRefresh = false;
UnsubscribeEvents();
if (_hudFormSerialId.HasValue)
{
if (GameEntry.UI.HasUIForm(_hudFormSerialId.Value))
{
GameEntry.UI.CloseUIForm(_hudFormSerialId.Value);
}
_hudForm = null;
_hudFormSerialId = null;
return;
}
if (_hudForm != null)
{
_hudForm.Close();
_hudForm = null;
}
}
public override void BindUseCase(IUIUseCase useCase)
{
Log.Info("HudFormController doesn't need UseCase");
}
private void TryRefreshUI()
{
if (_context == null)
{
return;
}
if (_hudForm == null)
{
_pendingRefresh = true;
return;
}
_hudForm.RefreshUI(_context);
_pendingRefresh = false;
}
#endregion
#region Event Handlers
private void OpenUIFormSuccess(object sender, GameEventArgs e)
{
if (!(e is OpenUIFormSuccessEventArgs args))
{
return;
}
if (!_hudFormSerialId.HasValue)
{
return;
}
if (args.UIForm == null || args.UIForm.SerialId != _hudFormSerialId.Value ||
args.UserData != _context)
{
return;
}
_hudForm = args.UIForm.Logic as HudForm;
if (_hudForm == null)
{
Log.Warning("HudFormController open success but form logic is invalid.");
return;
}
if (_pendingRefresh)
{
TryRefreshUI();
}
}
private void CloseUIFormComplete(object sender, GameEventArgs e)
{
if (!(e is CloseUIFormCompleteEventArgs args))
{
return;
}
if (args.SerialId != _hudFormSerialId)
{
return;
}
_hudForm = null;
_hudFormSerialId = null;
}
#endregion
}
}
@@ -3,51 +3,40 @@ using CustomEvent;
using Definition.Enum;
using Game.Utility;
using GameFramework.Event;
using Procedure;
using UnityGameFramework.Runtime;
namespace UI
{
public class LevelUpFormController : UIFormControllerBase<LevelUpFormContext>
public class LevelUpFormController : UIFormControllerCommonBase<LevelUpFormContext, LevelUpForm>
{
private LevelUpFormUseCase _useCase;
private bool _pendingRefresh;
protected override UIFormType UIFormTypeId => UIFormType.LevelUpForm;
private int? _levelUpFormSerialId;
private LevelUpForm _levelUpForm;
private LevelUpFormContext _context;
private bool _isBindEvent;
private void SubscribeEvents()
protected override void RefreshUI(LevelUpForm form, LevelUpFormContext context)
{
if (_isBindEvent) return;
GameEntry.Event.Subscribe(OpenUIFormSuccessEventArgs.EventId, OpenUIFormSuccess);
GameEntry.Event.Subscribe(CloseUIFormCompleteEventArgs.EventId, CloseUIFormComplete);
GameEntry.Event.Subscribe(RefreshEventArgs.EventId, OnRefresh);
GameEntry.Event.Subscribe(LevelUpPropSelectedEventArgs.EventId, OnLevelUpPropSelected);
_isBindEvent = true;
form.RefreshUI(context);
}
private void UnsubscribeEvents()
protected override void SubscribeCustomEvents()
{
if (!_isBindEvent) return;
GameEntry.Event.Subscribe(RefreshEventArgs.EventId, OnRefresh);
GameEntry.Event.Subscribe(LevelUpPropSelectedEventArgs.EventId, OnLevelUpPropSelected);
}
GameEntry.Event.Unsubscribe(OpenUIFormSuccessEventArgs.EventId, OpenUIFormSuccess);
GameEntry.Event.Unsubscribe(CloseUIFormCompleteEventArgs.EventId, CloseUIFormComplete);
protected override void UnsubscribeCustomEvents()
{
GameEntry.Event.Unsubscribe(RefreshEventArgs.EventId, OnRefresh);
GameEntry.Event.Unsubscribe(LevelUpPropSelectedEventArgs.EventId, OnLevelUpPropSelected);
_isBindEvent = false;
}
private static LevelUpFormContext BuildContext(LevelUpFormRawData rawData)
{
if (rawData == null || rawData.Rewards == null)
{
return null;
}
List<LevelUpRewardItemContext> props = new List<LevelUpRewardItemContext>(rawData.Rewards.Count);
foreach (var reward in rawData.Rewards)
{
@@ -72,33 +61,6 @@ namespace UI
};
}
#region UI Methods
protected override int? OpenUIInternal(LevelUpFormContext context)
{
if (context == null)
{
Log.Warning("LevelUpFormController.OpenUI() context is null.");
return null;
}
_context = context;
if (_levelUpForm != null && _levelUpFormSerialId.HasValue &&
GameEntry.UI.HasUIForm(_levelUpFormSerialId.Value))
{
_levelUpForm.RefreshUI(_context);
return _levelUpFormSerialId;
}
CloseUI();
_pendingRefresh = true;
SubscribeEvents();
_levelUpFormSerialId = GameEntry.UI.OpenUIForm(UIFormType.LevelUpForm, context);
return _levelUpFormSerialId;
}
public override int? OpenUI(object userData = null)
{
if (userData is LevelUpFormContext context)
@@ -133,47 +95,6 @@ namespace UI
return OpenUIInternal(context);
}
private void TryRefreshUI()
{
if (_context == null)
{
return;
}
if (_levelUpForm == null)
{
_pendingRefresh = true;
return;
}
_levelUpForm.RefreshUI(_context);
_pendingRefresh = false;
}
public override void CloseUI()
{
_pendingRefresh = false;
UnsubscribeEvents();
if (_levelUpFormSerialId.HasValue)
{
if (GameEntry.UI.HasUIForm(_levelUpFormSerialId.Value))
{
GameEntry.UI.CloseUIForm(_levelUpFormSerialId.Value);
}
_levelUpForm = null;
_levelUpFormSerialId = null;
return;
}
if (_levelUpForm != null)
{
_levelUpForm.Close();
_levelUpForm = null;
}
}
public override void BindUseCase(IUIUseCase useCase)
{
if (!(useCase is LevelUpFormUseCase levelUpFormUseCase))
@@ -185,10 +106,6 @@ namespace UI
_useCase = levelUpFormUseCase;
}
#endregion
#region Service
private void SelectReward(int selectedIndex)
{
if (_useCase == null)
@@ -198,7 +115,6 @@ namespace UI
}
LevelUpFormRawData rawData = _useCase.SelectReward(selectedIndex);
if (rawData == null)
{
return;
@@ -224,51 +140,6 @@ namespace UI
OpenUI(rawData);
}
#endregion
#region Event Handlers
private void OpenUIFormSuccess(object sender, GameEventArgs e)
{
if (!(e is OpenUIFormSuccessEventArgs args)) return;
if (!_levelUpFormSerialId.HasValue) return;
if (args.UIForm == null || args.UIForm.SerialId != _levelUpFormSerialId.Value || args.UserData != _context)
{
return;
}
_levelUpForm = args.UIForm.Logic as LevelUpForm;
if (_levelUpForm == null)
{
Log.Warning("LevelUpFormController open success but form logic is invalid.");
return;
}
if (_pendingRefresh)
{
TryRefreshUI();
}
}
private void CloseUIFormComplete(object sender, GameEventArgs e)
{
if (!(e is CloseUIFormCompleteEventArgs args))
{
return;
}
if (args.SerialId != _levelUpFormSerialId)
{
return;
}
_levelUpForm = null;
_levelUpFormSerialId = null;
}
private void OnRefresh(object sender, GameEventArgs e)
{
if (!(sender is LevelUpForm))
@@ -293,7 +164,5 @@ namespace UI
SelectReward(args.SelectedId);
}
#endregion
}
}
@@ -9,50 +9,34 @@ using UnityGameFramework.Runtime;
namespace UI
{
public class ShopFormController : UIFormControllerBase<ShopFormContext>
public class ShopFormController : UIFormControllerCommonBase<ShopFormContext, ShopForm>
{
private ShopFormUseCase _useCase;
private bool _pendingRefresh;
private int? _shopFormSerialId;
private ShopForm _shopForm;
private ShopFormRawData _rawData;
private ShopFormContext _context;
protected override UIFormType UIFormTypeId => UIFormType.ShopForm;
private bool _isBindEvent;
private void SubscribeEvents()
protected override void RefreshUI(ShopForm form, ShopFormContext context)
{
if (_isBindEvent) return;
form.RefreshUI(context);
}
GameEntry.Event.Subscribe(OpenUIFormSuccessEventArgs.EventId, OpenUIFormSuccess);
GameEntry.Event.Subscribe(CloseUIFormCompleteEventArgs.EventId, CloseUIFormComplete);
protected override void SubscribeCustomEvents()
{
GameEntry.Event.Subscribe(RefreshEventArgs.EventId, Refresh);
GameEntry.Event.Subscribe(ShopPurchaseEventArgs.EventId, ShopPurchase);
GameEntry.Event.Subscribe(ShopContinueEventArgs.EventId, ShopContinue);
GameEntry.Event.Subscribe(DisplayItemShowEventArgs.EventId, DisplayItemShow);
GameEntry.Event.Subscribe(DisplayItemHideEventArgs.EventId, DisplayItemHide);
_isBindEvent = true;
}
private void UnsubscribeEvents()
protected override void UnsubscribeCustomEvents()
{
if (!_isBindEvent) return;
GameEntry.Event.Unsubscribe(OpenUIFormSuccessEventArgs.EventId, OpenUIFormSuccess);
GameEntry.Event.Unsubscribe(CloseUIFormCompleteEventArgs.EventId, CloseUIFormComplete);
GameEntry.Event.Unsubscribe(RefreshEventArgs.EventId, Refresh);
GameEntry.Event.Unsubscribe(ShopPurchaseEventArgs.EventId, ShopPurchase);
GameEntry.Event.Unsubscribe(ShopContinueEventArgs.EventId, ShopContinue);
GameEntry.Event.Unsubscribe(DisplayItemShowEventArgs.EventId, DisplayItemShow);
GameEntry.Event.Unsubscribe(DisplayItemHideEventArgs.EventId, DisplayItemHide);
_isBindEvent = false;
}
#region BuildContext
@@ -72,38 +56,52 @@ namespace UI
RefreshPrice = rawData.RefreshPrice,
PlayerCoin = rawData.PlayerCoin,
GoodsItems = rawData.GoodsItems,
PropListContext = BuildDisplayListAreaContext("道具", rawData.PropItems, rawData.PropMaxCount),
WeaponListContext = BuildDisplayListAreaContext("武器", rawData.WeaponItems, rawData.WeaponMaxCount)
PropListContext = BuildDisplayListAreaContext(DisplayListAreaType.Prop, rawData.PropItems, rawData.PropMaxCount),
WeaponListContext = BuildDisplayListAreaContext(DisplayListAreaType.Weapon, rawData.WeaponItems, rawData.WeaponMaxCount)
};
}
private static DisplayListAreaContext BuildDisplayListAreaContext(string title, IReadOnlyList<object> items,
private static DisplayListAreaContext BuildDisplayListAreaContext(DisplayListAreaType listType, IReadOnlyList<object> items,
int maxCount)
{
DisplayItemContext[] itemContexts = new DisplayItemContext[items.Count];
if (title == "武器")
string title = GetDisplayListTitle(listType);
if (items == null)
{
if (items is IReadOnlyList<WeaponBase> weapons)
return new DisplayListAreaContext
{
for (int i = 0; i < weapons.Count; i++)
{
WeaponBase weapon = weapons[i];
if (weapon == null) break;
itemContexts[i] = BuildWeaponItem(weapon);
}
}
Title = title,
CurrentCount = 0,
MaxCount = maxCount,
ItemContexts = System.Array.Empty<DisplayItemContext>()
};
}
else if (title == "道具")
DisplayItemContext[] itemContexts = new DisplayItemContext[items.Count];
switch (listType)
{
if (items is IReadOnlyList<PropItem> propItems)
{
for (int i = 0; i < propItems.Count; i++)
case DisplayListAreaType.Weapon:
if (items is IReadOnlyList<WeaponBase> weapons)
{
PropItem propItem = propItems[i];
if (propItem == null) break;
itemContexts[i] = BuildPropItem(propItem);
for (int i = 0; i < weapons.Count; i++)
{
WeaponBase weapon = weapons[i];
if (weapon == null) break;
itemContexts[i] = BuildWeaponItem(weapon);
}
}
}
break;
case DisplayListAreaType.Prop:
if (items is IReadOnlyList<PropItem> propItems)
{
for (int i = 0; i < propItems.Count; i++)
{
PropItem propItem = propItems[i];
if (propItem == null) break;
itemContexts[i] = BuildPropItem(propItem);
}
}
break;
}
int currentCount = itemContexts.Length;
@@ -116,6 +114,16 @@ namespace UI
};
}
private static string GetDisplayListTitle(DisplayListAreaType listType)
{
return listType switch
{
DisplayListAreaType.Weapon => "武器",
DisplayListAreaType.Prop => "道具",
_ => string.Empty
};
}
private static DisplayItemContext BuildPropItem(PropItem propItem)
{
string iconAssetName = null;
@@ -135,7 +143,6 @@ namespace UI
};
}
private static DisplayItemContext BuildWeaponItem(WeaponBase weaponBase)
{
string iconAssetName = null;
@@ -176,33 +183,8 @@ namespace UI
#endregion
#region UI Methods
protected override int? OpenUIInternal(ShopFormContext context)
{
if (context == null)
{
Log.Warning("ShopFormController.OpenUI() context is null.");
return null;
}
_context = context;
if (_shopForm != null && _shopFormSerialId.HasValue &&
GameEntry.UI.HasUIForm(_shopFormSerialId.Value))
{
_shopForm.RefreshUI(_context);
return _shopFormSerialId;
}
CloseUI();
_pendingRefresh = true;
SubscribeEvents();
_shopFormSerialId = GameEntry.UI.OpenUIForm(UIFormType.ShopForm, context);
return _shopFormSerialId;
}
public int? OpenUI(ShopFormRawData rawData)
{
ShopFormContext context = BuildContext(rawData);
@@ -237,29 +219,6 @@ namespace UI
return OpenUI(rawData);
}
public override void CloseUI()
{
_pendingRefresh = false;
UnsubscribeEvents();
if (_shopFormSerialId.HasValue)
{
if (GameEntry.UI.HasUIForm(_shopFormSerialId.Value))
{
GameEntry.UI.CloseUIForm(_shopFormSerialId.Value);
}
_shopForm = null;
_shopFormSerialId = null;
return;
}
if (_shopForm != null)
{
_shopForm.Close();
_shopForm = null;
}
}
public override void BindUseCase(IUIUseCase useCase)
{
if (!(useCase is ShopFormUseCase shopFormUseCase))
@@ -271,118 +230,60 @@ namespace UI
_useCase = shopFormUseCase;
}
private void TryRefreshUI()
{
if (_context == null)
{
return;
}
if (_shopForm == null)
{
_pendingRefresh = true;
return;
}
_shopForm.RefreshUI(_context);
_pendingRefresh = false;
}
#endregion
#region Service
private void RefreshGoodsItems(ShopRefreshResult result)
{
if (_context == null || result == null)
if (Context == null || result == null)
{
return;
}
_context.GoodsItems = result.GoodsItems;
_context.RefreshPrice = result.RefreshPrice;
Context.GoodsItems = result.GoodsItems;
Context.RefreshPrice = result.RefreshPrice;
if (_shopForm == null)
if (Form == null)
{
return;
}
_shopForm.RefreshGoodsItems(result.GoodsItems);
_shopForm.RefreshRefreshPrice(result.RefreshPrice);
Form.RefreshGoodsItems(result.GoodsItems);
Form.RefreshRefreshPrice(result.RefreshPrice);
}
private void ApplyGoodsPurchased(ShopPurchaseResult result)
{
if (_context == null || result == null)
if (Context == null || result == null)
{
return;
}
if (_context.GoodsItems != null && result.GoodsIndex >= 0 && result.GoodsIndex < _context.GoodsItems.Count)
if (Context.GoodsItems != null && result.GoodsIndex >= 0 && result.GoodsIndex < Context.GoodsItems.Count)
{
_context.GoodsItems[result.GoodsIndex] = null;
Context.GoodsItems[result.GoodsIndex] = null;
}
if (result.DisplayItem != null)
{
if (result.DisplayItem.IsWeapon)
{
AppendDisplayItemContext(_context.WeaponListContext, result.DisplayItem);
AppendDisplayItemContext(Context.WeaponListContext, result.DisplayItem);
}
else
{
AppendDisplayItemContext(_context.PropListContext, result.DisplayItem);
AppendDisplayItemContext(Context.PropListContext, result.DisplayItem);
}
}
_shopForm?.ApplyGoodsPurchased(result.GoodsIndex, result.DisplayItem);
Form?.ApplyGoodsPurchased(result.GoodsIndex, result.DisplayItem);
}
#endregion
#region Event Handlers
private void OpenUIFormSuccess(object sender, GameEventArgs e)
{
if (!(e is OpenUIFormSuccessEventArgs args)) return;
if (!_shopFormSerialId.HasValue) return;
if (args.UIForm == null || args.UIForm.SerialId != _shopFormSerialId.Value || args.UserData != _context)
{
return;
}
_shopForm = args.UIForm.Logic as ShopForm;
if (_shopForm == null)
{
Log.Warning("ShopFormController open success but form logic is invalid.");
return;
}
if (_pendingRefresh)
{
TryRefreshUI();
}
}
private void CloseUIFormComplete(object sender, GameEventArgs e)
{
if (!(e is CloseUIFormCompleteEventArgs args))
{
return;
}
if (args.SerialId != _shopFormSerialId)
{
return;
}
_shopForm = null;
_shopFormSerialId = null;
}
private void Refresh(object sender, GameEventArgs e)
{
if (!(sender is ShopForm))
@@ -442,7 +343,7 @@ namespace UI
private void DisplayItemShow(object sender, GameEventArgs e)
{
if (!(e is DisplayItemShowEventArgs args)) return;
if (!(e is DisplayItemShowEventArgs args) || _rawData == null) return;
DisplayItemInfoFormRawData rawData = new();
rawData.TargetPos = args.TargetPos;
@@ -472,7 +373,6 @@ namespace UI
GameEntry.UIRouter.OpenUI(UIFormType.DisplayItemInfoForm, rawData);
}
private void DisplayItemHide(object sender, GameEventArgs e)
{
if (!(e is DisplayItemHideEventArgs)) return;
@@ -242,6 +242,14 @@ namespace UI
};
}
if (goods.GoodsType == GoodsType.Weapon)
{
// TODO: Weapon purchase apply flow depends on the upcoming weapon system integration.
// Implement weapon creation/equip/add-to-inventory here when weapon runtime model is ready.
Log.Warning("ShopFormUseCase::ApplyGoodsPurchase: Weapon purchase flow is not implemented yet.");
return null;
}
return null;
}
}
@@ -8,6 +8,13 @@ using UnityGameFramework.Runtime;
namespace UI
{
public enum DisplayListAreaType : byte
{
None = 0,
Prop = 1,
Weapon = 2
}
public class DisplayListArea : MonoBehaviour
{
[SerializeField] private TMP_Text _titleText;
@@ -72,7 +79,7 @@ namespace UI
public void OnDestroy()
{
_displayItemObjectPool.ReleaseAllUnused();
_displayItemObjectPool?.ReleaseAllUnused();
}
public DisplayItem AddItem(DisplayItemContext itemContext)
@@ -275,4 +282,4 @@ namespace UI
_countText.text = maxCount == -1 ? $"({currentCount})" : $"({currentCount}/{maxCount})";
}
}
}
}
@@ -23,7 +23,8 @@ namespace UI
}
if (_context.Props == null) return;
for (int i = 0; i < _propItems.Length; i++)
int count = Mathf.Min(_propItems.Length, _context.Props.Count);
for (int i = 0; i < count; i++)
{
_propItems[i].gameObject.SetActive(true);
_propItems[i].Init(_context.Props[i]);
@@ -66,4 +67,4 @@ namespace UI
GameEntry.Event.Fire(this, RefreshEventArgs.Create(_context.RefreshPrice));
}
}
}
}
@@ -1,39 +1,20 @@
using Definition.Enum;
using GameFramework.Event;
using UnityGameFramework.Runtime;
namespace UI
{
public class DialogFormController : UIFormControllerBase<DialogFormContext>
public class DialogFormController : UIFormControllerCommonBase<DialogFormContext, DialogForm>
{
private DialogFormContext _context;
private DialogForm _dialogForm;
private int? _dialogFormSerialId;
private bool _pendingRefresh;
private bool _isBindEvent;
protected override UIFormType UIFormTypeId => UIFormType.DialogForm;
private void SubscribeEvents()
protected override void RefreshUI(DialogForm form, DialogFormContext context)
{
if (_isBindEvent) return;
GameEntry.Event.Subscribe(OpenUIFormSuccessEventArgs.EventId, OpenUIFormSuccess);
GameEntry.Event.Subscribe(CloseUIFormCompleteEventArgs.EventId, CloseUIFormComplete);
_isBindEvent = true;
form.RefreshUI(context);
}
private void UnsubscribeEvents()
protected override void CloseLoadedFormDirect(DialogForm form)
{
if (!_isBindEvent) return;
GameEntry.Event.Unsubscribe(OpenUIFormSuccessEventArgs.EventId, OpenUIFormSuccess);
GameEntry.Event.Unsubscribe(CloseUIFormCompleteEventArgs.EventId, CloseUIFormComplete);
_isBindEvent = false;
GameEntry.UI.CloseUIForm(form);
}
private static DialogFormContext BuildContext(DialogFormRawData rawData)
@@ -59,30 +40,6 @@ namespace UI
};
}
protected override int? OpenUIInternal(DialogFormContext context)
{
if (context == null)
{
Log.Warning("DialogFormController.OpenUI() context is null.");
return null;
}
_context = context;
if (_dialogForm != null && _dialogFormSerialId.HasValue &&
GameEntry.UI.HasUIForm(_dialogFormSerialId.Value))
{
_dialogForm.RefreshUI(_context);
return _dialogFormSerialId;
}
CloseUI();
_pendingRefresh = true;
SubscribeEvents();
_dialogFormSerialId = GameEntry.UI.OpenUIForm(UIFormType.DialogForm, context);
return _dialogFormSerialId;
}
public int? OpenUI(DialogFormRawData rawData)
{
DialogFormContext context = BuildContext(rawData);
@@ -101,42 +58,13 @@ namespace UI
return OpenUI(rawData);
}
if (userData is DialogFormRawData dialogParams)
{
return OpenUIInternal(BuildContext(dialogParams));
}
if (userData != null)
{
Log.Warning("DialogFormController.OpenUI() userData type is invalid.");
return null;
}
return OpenUIInternal(_context);
}
public override void CloseUI()
{
_pendingRefresh = false;
UnsubscribeEvents();
if (_dialogFormSerialId.HasValue)
{
if (GameEntry.UI.HasUIForm(_dialogFormSerialId.Value))
{
GameEntry.UI.CloseUIForm(_dialogFormSerialId.Value);
}
_dialogForm = null;
_dialogFormSerialId = null;
return;
}
if (_dialogForm != null)
{
GameEntry.UI.CloseUIForm(_dialogForm);
_dialogForm = null;
}
return OpenUIInternal(Context);
}
public override void BindUseCase(IUIUseCase useCase)
@@ -146,70 +74,5 @@ namespace UI
Log.Warning("DialogFormController does not use a use case.");
}
}
private void TryRefreshUI()
{
if (_context == null)
{
return;
}
if (_dialogForm == null)
{
_pendingRefresh = true;
return;
}
_dialogForm.RefreshUI(_context);
_pendingRefresh = false;
}
private void OpenUIFormSuccess(object sender, GameEventArgs e)
{
if (!(e is OpenUIFormSuccessEventArgs args))
{
return;
}
if (!_dialogFormSerialId.HasValue)
{
return;
}
if (args.UIForm == null || args.UIForm.SerialId != _dialogFormSerialId.Value ||
args.UserData != _context)
{
return;
}
_dialogForm = args.UIForm.Logic as DialogForm;
if (_dialogForm == null)
{
Log.Warning("DialogFormController open success but form logic is invalid.");
return;
}
if (_pendingRefresh)
{
TryRefreshUI();
}
}
private void CloseUIFormComplete(object sender, GameEventArgs e)
{
if (!(e is CloseUIFormCompleteEventArgs args))
{
return;
}
if (args.SerialId != _dialogFormSerialId)
{
return;
}
_dialogForm = null;
_dialogFormSerialId = null;
}
}
}
@@ -100,7 +100,7 @@ namespace UI
/// <summary>
/// 用户自定义数据。
/// </summary>
public string UserData
public object UserData
{
get;
set;
@@ -5,44 +5,29 @@ using UnityGameFramework.Runtime;
namespace UI
{
public class SelectRoleFormController : UIFormControllerBase<SelectRoleFormContext>
public class SelectRoleFormController : UIFormControllerCommonBase<SelectRoleFormContext, SelectRoleForm>
{
private SelectRoleFormUseCase _useCase;
private SelectRoleFormContext _context;
protected override UIFormType UIFormTypeId => UIFormType.SelectRoleForm;
private SelectRoleForm _selectRoleForm;
private int? _selectRoleFormSerialId;
private bool _pendingRefresh;
private bool _isBindEvent;
private void SubscribeEvents()
protected override void RefreshUI(SelectRoleForm form, SelectRoleFormContext context)
{
if (_isBindEvent) return;
form.RefreshUI(context);
}
GameEntry.Event.Subscribe(OpenUIFormSuccessEventArgs.EventId, OpenUIFormSuccess);
GameEntry.Event.Subscribe(CloseUIFormCompleteEventArgs.EventId, CloseUIFormComplete);
protected override void SubscribeCustomEvents()
{
GameEntry.Event.Subscribe(MenuSelectRoleReturnEventArgs.EventId, OnMenuSelectRoleReturn);
GameEntry.Event.Subscribe(MenuSelectRoleSelectedEventArgs.EventId, OnMenuSelectRoleSelected);
GameEntry.Event.Subscribe(MenuSelectRoleConfirmEventArgs.EventId, OnMenuSelectRoleConfirm);
_isBindEvent = true;
}
private void UnsubscribeEvents()
protected override void UnsubscribeCustomEvents()
{
if (!_isBindEvent) return;
GameEntry.Event.Unsubscribe(OpenUIFormSuccessEventArgs.EventId, OpenUIFormSuccess);
GameEntry.Event.Unsubscribe(CloseUIFormCompleteEventArgs.EventId, CloseUIFormComplete);
GameEntry.Event.Unsubscribe(MenuSelectRoleReturnEventArgs.EventId, OnMenuSelectRoleReturn);
GameEntry.Event.Unsubscribe(MenuSelectRoleSelectedEventArgs.EventId, OnMenuSelectRoleSelected);
GameEntry.Event.Unsubscribe(MenuSelectRoleConfirmEventArgs.EventId, OnMenuSelectRoleConfirm);
_isBindEvent = false;
}
private static SelectRoleFormContext BuildContext(SelectRoleFormRawData rawData)
@@ -85,32 +70,6 @@ namespace UI
};
}
#region UI Methods
protected override int? OpenUIInternal(SelectRoleFormContext context)
{
if (context == null)
{
Log.Warning("SelectRoleFormController.OpenUI() context is null.");
return null;
}
_context = context;
if (_selectRoleForm != null && _selectRoleFormSerialId.HasValue &&
GameEntry.UI.HasUIForm(_selectRoleFormSerialId.Value))
{
_selectRoleForm.RefreshUI(_context);
return _selectRoleFormSerialId;
}
CloseUI();
_pendingRefresh = true;
SubscribeEvents();
_selectRoleFormSerialId = GameEntry.UI.OpenUIForm(UIFormType.SelectRoleForm, context);
return _selectRoleFormSerialId;
}
public override int? OpenUI(object userData = null)
{
if (userData is SelectRoleFormContext selectRoleFormContext)
@@ -124,35 +83,17 @@ namespace UI
return null;
}
if (_useCase == null)
{
Log.Error("SelectRoleFormController.OpenUI() useCase is null.");
return null;
}
SelectRoleFormRawData rawData = _useCase.CreateModel();
SelectRoleFormContext context = BuildContext(rawData);
return OpenUIInternal(context);
}
public override void CloseUI()
{
_pendingRefresh = false;
UnsubscribeEvents();
if (_selectRoleFormSerialId.HasValue)
{
if (GameEntry.UI.HasUIForm(_selectRoleFormSerialId.Value))
{
GameEntry.UI.CloseUIForm(_selectRoleFormSerialId.Value);
}
_selectRoleForm = null;
_selectRoleFormSerialId = null;
return;
}
if (_selectRoleForm != null)
{
_selectRoleForm.Close();
_selectRoleForm = null;
}
}
public override void BindUseCase(IUIUseCase useCase)
{
if (!(useCase is SelectRoleFormUseCase selectRoleUseCase))
@@ -164,90 +105,14 @@ namespace UI
_useCase = selectRoleUseCase;
}
private void TryRefreshUI()
{
if (_context == null)
{
return;
}
if (_selectRoleForm == null)
{
_pendingRefresh = true;
return;
}
_selectRoleForm.RefreshUI(_context);
_pendingRefresh = false;
}
#endregion
#region Service
public void UpdateShowRole(RolePropertyAreaContext rolePropertyAreaContext)
{
if (_context != null)
if (Context != null)
{
_context.RolePropertyAreaContext = rolePropertyAreaContext;
Context.RolePropertyAreaContext = rolePropertyAreaContext;
}
if (_selectRoleForm != null)
{
_selectRoleForm.UpdateShowRole(rolePropertyAreaContext);
}
}
#endregion
#region Event Handlers
private void OpenUIFormSuccess(object sender, GameEventArgs e)
{
if (!(e is OpenUIFormSuccessEventArgs args))
{
return;
}
if (!_selectRoleFormSerialId.HasValue)
{
return;
}
if (args.UIForm == null || args.UIForm.SerialId != _selectRoleFormSerialId.Value ||
args.UserData != _context)
{
return;
}
_selectRoleForm = args.UIForm.Logic as SelectRoleForm;
if (_selectRoleForm == null)
{
Log.Warning("SelectRoleFormController open success but form logic is invalid.");
return;
}
if (_pendingRefresh)
{
TryRefreshUI();
}
}
private void CloseUIFormComplete(object sender, GameEventArgs e)
{
if (!(e is CloseUIFormCompleteEventArgs args))
{
return;
}
if (args.SerialId != _selectRoleFormSerialId)
{
return;
}
_selectRoleForm = null;
_selectRoleFormSerialId = null;
Form?.UpdateShowRole(rolePropertyAreaContext);
}
private void OnMenuSelectRoleReturn(object sender, GameEventArgs e)
@@ -274,8 +139,8 @@ namespace UI
return;
}
_context = context;
UpdateShowRole(_context.RolePropertyAreaContext);
SetContext(context);
UpdateShowRole(context.RolePropertyAreaContext);
}
private void OnMenuSelectRoleConfirm(object sender, GameEventArgs e)
@@ -285,9 +150,7 @@ namespace UI
return;
}
_useCase.ConfirmSelectedRole();
_useCase?.ConfirmSelectedRole();
}
#endregion
}
}
@@ -5,82 +5,39 @@ using UnityGameFramework.Runtime;
namespace UI
{
public class StartMenuFormController : UIFormControllerBase<StartMenuFormContext>
public class StartMenuFormController : UIFormControllerCommonBase<StartMenuFormContext, StartMenuForm>
{
private StartMenuFormContext _context;
protected override UIFormType UIFormTypeId => UIFormType.StartMenuForm;
private StartMenuForm _startMenuForm;
private int? _startMenuFormSerialId;
private bool _pendingRefresh;
private bool _isBindEvent;
private void SubscribeEvents()
protected override void RefreshUI(StartMenuForm form, StartMenuFormContext context)
{
if (_isBindEvent) return;
GameEntry.Event.Subscribe(OpenUIFormSuccessEventArgs.EventId, OpenUIFormSuccess);
GameEntry.Event.Subscribe(CloseUIFormCompleteEventArgs.EventId, CloseUIFormComplete);
form.RefreshUI(context);
}
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);
_isBindEvent = true;
}
private void UnsubscribeEvents()
protected override void UnsubscribeCustomEvents()
{
if (!_isBindEvent) return;
GameEntry.Event.Unsubscribe(OpenUIFormSuccessEventArgs.EventId, OpenUIFormSuccess);
GameEntry.Event.Unsubscribe(CloseUIFormCompleteEventArgs.EventId, CloseUIFormComplete);
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);
_isBindEvent = false;
}
private static StartMenuFormContext BuildStartMenuFormContext()
{
return new StartMenuFormContext();
}
#region UI Methods
protected override int? OpenUIInternal(StartMenuFormContext context)
{
if (context == null)
{
Log.Warning("StartMenuFormController.OpenUI() context is null.");
return null;
}
_context = context;
if (_startMenuForm != null && _startMenuFormSerialId.HasValue &&
GameEntry.UI.HasUIForm(_startMenuFormSerialId.Value))
{
_startMenuForm.RefreshUI(_context);
return _startMenuFormSerialId;
}
CloseUI();
_pendingRefresh = true;
SubscribeEvents();
_startMenuFormSerialId = GameEntry.UI.OpenUIForm(UIFormType.StartMenuForm, context);
return _startMenuFormSerialId;
}
public override int? OpenUI(object userData = null)
{
@@ -103,105 +60,11 @@ namespace UI
return OpenUIInternal(context);
}
public override void CloseUI()
{
_pendingRefresh = false;
UnsubscribeEvents();
if (_startMenuFormSerialId.HasValue)
{
if (GameEntry.UI.HasUIForm(_startMenuFormSerialId.Value))
{
GameEntry.UI.CloseUIForm(_startMenuFormSerialId.Value);
}
_startMenuForm = null;
_startMenuFormSerialId = null;
return;
}
if (_startMenuForm != null)
{
_startMenuForm.Close();
_startMenuForm = null;
}
}
public override void BindUseCase(IUIUseCase useCase)
{
Log.Info("StartMenuForm doesn't need UseCase");
}
private void TryRefreshUI()
{
if (_context == null)
{
return;
}
if (_startMenuForm == null)
{
_pendingRefresh = true;
return;
}
_startMenuForm.RefreshUI(_context);
_pendingRefresh = false;
}
#endregion
#region Event Handlers
private void OpenUIFormSuccess(object sender, GameEventArgs e)
{
if (!(e is OpenUIFormSuccessEventArgs args))
{
return;
}
if (!_startMenuFormSerialId.HasValue)
{
return;
}
if (args.UIForm == null || args.UIForm.SerialId != _startMenuFormSerialId.Value ||
args.UserData != _context)
{
return;
}
_startMenuForm = args.UIForm.Logic as StartMenuForm;
if (_startMenuForm == null)
{
Log.Warning("StartMenuFormController open success but form logic is invalid.");
return;
}
if (_pendingRefresh)
{
TryRefreshUI();
}
}
private void CloseUIFormComplete(object sender, GameEventArgs e)
{
if (!(e is CloseUIFormCompleteEventArgs args))
{
return;
}
if (args.SerialId != _startMenuFormSerialId)
{
return;
}
_startMenuForm = null;
_startMenuFormSerialId = null;
}
private void OnMenuStartGameButtonClick(object sender, GameEventArgs e)
{
if (!(sender is StartMenuForm) || !(e is MenuStartGameEventArgs))
@@ -270,7 +133,5 @@ namespace UI
Log.Warning("Menu about button click is not implemented.");
}
#endregion
}
}
+6 -11
View File
@@ -15,18 +15,16 @@ using UnityEngine;
using UnityGameFramework.Runtime;
using Random = UnityEngine.Random;
namespace StarForce
namespace Game.Utility
{
/// <summary>
/// AI 工具类。
/// </summary>
public static class AIUtility
{
private static Dictionary<CampPair, RelationType> s_CampPairToRelation =
new Dictionary<CampPair, RelationType>();
private static Dictionary<CampPair, RelationType> s_CampPairToRelation = new();
private static Dictionary<KeyValuePair<CampType, RelationType>, CampType[]> s_CampAndRelationToCamps =
new Dictionary<KeyValuePair<CampType, RelationType>, CampType[]>();
private static Dictionary<KeyValuePair<CampType, RelationType>, CampType[]> s_CampAndRelationToCamps = new();
static AIUtility()
{
@@ -68,9 +66,7 @@ namespace StarForce
{
if (first > second)
{
CampType temp = first;
first = second;
second = temp;
(first, second) = (second, first);
}
RelationType relationType;
@@ -92,8 +88,7 @@ namespace StarForce
public static CampType[] GetCamps(CampType camp, RelationType relation)
{
KeyValuePair<CampType, RelationType> key = new KeyValuePair<CampType, RelationType>(camp, relation);
CampType[] result = null;
if (s_CampAndRelationToCamps.TryGetValue(key, out result))
if (s_CampAndRelationToCamps.TryGetValue(key, out var result))
{
return result;
}
@@ -194,7 +189,7 @@ namespace StarForce
}
int entityDamageHP = CalcDamageHP(weaponImpactData.AttackBase, weaponImpactData.AttackStat,
entityImpactData.DefenseStat, entityImpactData.DefenseStat);
entityImpactData.DefenseStat, entityImpactData.DodgeStat);
entity.ApplyDamage(weapon, entityDamageHP);
return;