修复已知的 bug,规划后期的开发方向
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user