CombatNode 相关逻辑补充
- CombatFinishForm:战斗节点的结算页面(杀死的敌人、获得的金币、获得的道具) - CombatSelectForm:战斗节点建造防御塔的选择 UI 以及对防御塔进行操作的 UI(只实现了建造逻辑,在 MapEntity 里做射线检测) - 构建了基本的防御塔三组件(ShooterMuzzleComp/BasicBearingComp/BasicBaseComp)和防御塔主控(DefenseTowerController)以及相应的实体类(DefenseTowerEntity)
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
namespace GeometryTD.UI
|
||||
{
|
||||
public class CombatFinishFormContext : UIContext
|
||||
{
|
||||
public string EnemyKilledText;
|
||||
public string GoldGainedText;
|
||||
public RepoItemContext[] RewardItems;
|
||||
public bool CanReturn;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e8fd0de74a04422488e2e78615713bca
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace GeometryTD.UI
|
||||
{
|
||||
public enum CombatSelectActionType : byte
|
||||
{
|
||||
None = 0,
|
||||
BuildTower = 1,
|
||||
UpgradeTower = 2,
|
||||
DestroyTower = 3
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2813faca2af4a574ea60171b6221c69c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,15 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace GeometryTD.UI
|
||||
{
|
||||
public class CombatSelectFormContext : UIContext
|
||||
{
|
||||
public bool IsVisible;
|
||||
public Vector2 ContentPosition;
|
||||
public bool ShowBuildArea;
|
||||
public bool ShowFuncArea;
|
||||
public TowerSelectItemContext[] BuildItems;
|
||||
public TowerSelectItemContext UpgradeItem;
|
||||
public TowerSelectItemContext DestroyItem;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 10d666a1cb0d16a44a6fa5e92d6e8f3f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,14 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace GeometryTD.UI
|
||||
{
|
||||
public class TowerSelectItemContext : UIContext
|
||||
{
|
||||
public Sprite Icon;
|
||||
public string PriceText;
|
||||
public bool IsVisible;
|
||||
public bool IsInteractable;
|
||||
public CombatSelectActionType ActionType;
|
||||
public int ActionIndex;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1a54121a8acc89c43b45617601960c33
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,189 @@
|
||||
using System.Collections.Generic;
|
||||
using GameFramework.Event;
|
||||
using GeometryTD.CustomEvent;
|
||||
using GeometryTD.Definition;
|
||||
using UnityGameFramework.Runtime;
|
||||
|
||||
namespace GeometryTD.UI
|
||||
{
|
||||
public class CombatFinishFormController : UIFormControllerCommonBase<CombatFinishFormContext, CombatFinishForm>
|
||||
{
|
||||
private CombatFinishFormUseCase _useCase;
|
||||
|
||||
protected override UIFormType UIFormTypeId => UIFormType.CombatFinishForm;
|
||||
|
||||
protected override void RefreshUI(CombatFinishForm form, CombatFinishFormContext context)
|
||||
{
|
||||
form.RefreshUI(context);
|
||||
}
|
||||
|
||||
protected override void SubscribeCustomEvents()
|
||||
{
|
||||
GameEntry.Event.Subscribe(CombatFinishReturnEventArgs.EventId, OnCombatFinishReturnButtonClicked);
|
||||
}
|
||||
|
||||
protected override void UnsubscribeCustomEvents()
|
||||
{
|
||||
GameEntry.Event.Unsubscribe(CombatFinishReturnEventArgs.EventId, OnCombatFinishReturnButtonClicked);
|
||||
}
|
||||
|
||||
public override int? OpenUI(object userData = null)
|
||||
{
|
||||
if (userData is CombatFinishFormContext context)
|
||||
{
|
||||
return OpenUIInternal(context);
|
||||
}
|
||||
|
||||
if (userData is CombatFinishFormRawData rawDataFromUserData)
|
||||
{
|
||||
return OpenUI(rawDataFromUserData);
|
||||
}
|
||||
|
||||
if (userData != null)
|
||||
{
|
||||
Log.Warning("CombatFinishFormController.OpenUI() userData type is invalid.");
|
||||
return null;
|
||||
}
|
||||
|
||||
if (_useCase == null)
|
||||
{
|
||||
Log.Error("CombatFinishFormController.OpenUI() useCase is null.");
|
||||
return null;
|
||||
}
|
||||
|
||||
CombatFinishFormRawData rawData = _useCase.CreateInitialModel();
|
||||
return OpenUI(rawData);
|
||||
}
|
||||
|
||||
public int? OpenUI(CombatFinishFormRawData rawData)
|
||||
{
|
||||
CombatFinishFormContext context = BuildContext(rawData);
|
||||
return OpenUIInternal(context);
|
||||
}
|
||||
|
||||
public override void BindUseCase(IUIUseCase useCase)
|
||||
{
|
||||
if (!(useCase is CombatFinishFormUseCase combatFinishFormUseCase))
|
||||
{
|
||||
Log.Error("CombatFinishFormController.BindUseCase() useCase is invalid.");
|
||||
return;
|
||||
}
|
||||
|
||||
_useCase = combatFinishFormUseCase;
|
||||
}
|
||||
|
||||
private static CombatFinishFormContext BuildContext(CombatFinishFormRawData rawData)
|
||||
{
|
||||
if (rawData == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new CombatFinishFormContext
|
||||
{
|
||||
EnemyKilledText = rawData.DefeatedEnemyCount.ToString(),
|
||||
GoldGainedText = rawData.GainedGold.ToString(),
|
||||
RewardItems = BuildRewardItems(rawData.RewardInventory),
|
||||
CanReturn = rawData.CanReturn
|
||||
};
|
||||
}
|
||||
|
||||
private static RepoItemContext[] BuildRewardItems(BackpackInventoryData inventory)
|
||||
{
|
||||
if (inventory == null)
|
||||
{
|
||||
return System.Array.Empty<RepoItemContext>();
|
||||
}
|
||||
|
||||
List<RepoItemContext> itemContexts = new List<RepoItemContext>();
|
||||
|
||||
if (inventory.Towers != null)
|
||||
{
|
||||
for (int i = 0; i < inventory.Towers.Count; i++)
|
||||
{
|
||||
var tower = inventory.Towers[i];
|
||||
if (tower == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
itemContexts.Add(new RepoItemContext
|
||||
{
|
||||
Title = $"[Tower] {tower.Name} ({tower.Rarity})",
|
||||
InstanceId = tower.InstanceId,
|
||||
ComponentSlotType = TowerCompSlotType.None
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (inventory.MuzzleComponents != null)
|
||||
{
|
||||
for (int i = 0; i < inventory.MuzzleComponents.Count; i++)
|
||||
{
|
||||
var item = inventory.MuzzleComponents[i];
|
||||
if (item == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
itemContexts.Add(new RepoItemContext
|
||||
{
|
||||
Title = $"[Muzzle] {item.Name} ({item.Rarity})",
|
||||
InstanceId = item.InstanceId,
|
||||
ComponentSlotType = TowerCompSlotType.Muzzle
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (inventory.BearingComponents != null)
|
||||
{
|
||||
for (int i = 0; i < inventory.BearingComponents.Count; i++)
|
||||
{
|
||||
var item = inventory.BearingComponents[i];
|
||||
if (item == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
itemContexts.Add(new RepoItemContext
|
||||
{
|
||||
Title = $"[Bearing] {item.Name} ({item.Rarity})",
|
||||
InstanceId = item.InstanceId,
|
||||
ComponentSlotType = TowerCompSlotType.Bearing
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (inventory.BaseComponents != null)
|
||||
{
|
||||
for (int i = 0; i < inventory.BaseComponents.Count; i++)
|
||||
{
|
||||
var item = inventory.BaseComponents[i];
|
||||
if (item == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
itemContexts.Add(new RepoItemContext
|
||||
{
|
||||
Title = $"[Base] {item.Name} ({item.Rarity})",
|
||||
InstanceId = item.InstanceId,
|
||||
ComponentSlotType = TowerCompSlotType.Base
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return itemContexts.ToArray();
|
||||
}
|
||||
|
||||
private void OnCombatFinishReturnButtonClicked(object sender, GameEventArgs e)
|
||||
{
|
||||
if (!(sender is CombatFinishForm) || !(e is CombatFinishReturnEventArgs))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_useCase?.TryReturnToMenu();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6f9701c56f0541208d99c47b7e64e58c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,266 @@
|
||||
using GameFramework.Event;
|
||||
using GeometryTD.CustomEvent;
|
||||
using GeometryTD.Definition;
|
||||
using UnityEngine;
|
||||
using UnityGameFramework.Runtime;
|
||||
|
||||
namespace GeometryTD.UI
|
||||
{
|
||||
public class CombatSelectFormController : UIFormControllerCommonBase<CombatSelectFormContext, CombatSelectForm>
|
||||
{
|
||||
private CombatSelectFormUseCase _useCase;
|
||||
|
||||
protected override UIFormType UIFormTypeId => UIFormType.CombatSelectForm;
|
||||
|
||||
protected override void RefreshUI(CombatSelectForm form, CombatSelectFormContext context)
|
||||
{
|
||||
form.RefreshUI(context);
|
||||
}
|
||||
|
||||
protected override void SubscribeCustomEvents()
|
||||
{
|
||||
GameEntry.Event.Subscribe(CombatSelectItemClickEventArgs.EventId, OnSelectItemClicked);
|
||||
}
|
||||
|
||||
protected override void UnsubscribeCustomEvents()
|
||||
{
|
||||
GameEntry.Event.Unsubscribe(CombatSelectItemClickEventArgs.EventId, OnSelectItemClicked);
|
||||
}
|
||||
|
||||
public int? OpenUI(CombatSelectFormRawData rawData)
|
||||
{
|
||||
CombatSelectFormContext context = BuildContext(rawData);
|
||||
if (context == null || !context.IsVisible)
|
||||
{
|
||||
CloseUI();
|
||||
return null;
|
||||
}
|
||||
|
||||
return OpenUIInternal(context);
|
||||
}
|
||||
|
||||
public override int? OpenUI(object userData = null)
|
||||
{
|
||||
if (userData is CombatSelectFormUserData clickUserData)
|
||||
{
|
||||
return OpenUI(clickUserData);
|
||||
}
|
||||
|
||||
if (userData is CombatSelectFormContext context)
|
||||
{
|
||||
if (context == null || !context.IsVisible)
|
||||
{
|
||||
CloseUI();
|
||||
return null;
|
||||
}
|
||||
|
||||
return OpenUIInternal(context);
|
||||
}
|
||||
|
||||
if (userData is CombatSelectFormRawData rawDataFromUserData)
|
||||
{
|
||||
return OpenUI(rawDataFromUserData);
|
||||
}
|
||||
|
||||
if (userData != null)
|
||||
{
|
||||
Log.Warning("CombatSelectFormController.OpenUI() userData type is invalid.");
|
||||
return null;
|
||||
}
|
||||
|
||||
if (_useCase == null)
|
||||
{
|
||||
Log.Error("CombatSelectFormController.OpenUI() useCase is null.");
|
||||
return null;
|
||||
}
|
||||
|
||||
CombatSelectFormRawData rawData = _useCase.CreateInitialModel();
|
||||
return OpenUI(rawData);
|
||||
}
|
||||
|
||||
public int? OpenUI(CombatSelectFormUserData userData)
|
||||
{
|
||||
if (_useCase == null)
|
||||
{
|
||||
Log.Error("CombatSelectFormController.OpenUI() useCase is null.");
|
||||
return null;
|
||||
}
|
||||
|
||||
if (userData == null)
|
||||
{
|
||||
_useCase.Hide();
|
||||
CloseUI();
|
||||
return null;
|
||||
}
|
||||
|
||||
switch (userData.ClickObjectType)
|
||||
{
|
||||
case CombatSelectClickObjectType.Foundation:
|
||||
_useCase.ShowForFoundation(userData.ContentPosition);
|
||||
break;
|
||||
case CombatSelectClickObjectType.Tower:
|
||||
_useCase.SetUpgradePrice(userData.UpgradeCost);
|
||||
_useCase.SetDestroyGain(userData.DestroyGain);
|
||||
_useCase.ShowForTower(userData.ContentPosition);
|
||||
break;
|
||||
default:
|
||||
_useCase.Hide();
|
||||
CloseUI();
|
||||
return null;
|
||||
}
|
||||
|
||||
return OpenUI(_useCase.TryRefresh());
|
||||
}
|
||||
|
||||
public override void BindUseCase(IUIUseCase useCase)
|
||||
{
|
||||
if (!(useCase is CombatSelectFormUseCase combatSelectFormUseCase))
|
||||
{
|
||||
Log.Error("CombatSelectFormController.BindUseCase() useCase is invalid.");
|
||||
return;
|
||||
}
|
||||
|
||||
_useCase = combatSelectFormUseCase;
|
||||
}
|
||||
|
||||
public int? ShowForFoundation(Vector2 contentPosition)
|
||||
{
|
||||
if (_useCase == null)
|
||||
{
|
||||
Log.Error("CombatSelectFormController.ShowForFoundation() useCase is null.");
|
||||
return null;
|
||||
}
|
||||
|
||||
_useCase.ShowForFoundation(contentPosition);
|
||||
return OpenUI(_useCase.TryRefresh());
|
||||
}
|
||||
|
||||
public int? ShowForTower(Vector2 contentPosition, int upgradeCost, int destroyGain)
|
||||
{
|
||||
if (_useCase == null)
|
||||
{
|
||||
Log.Error("CombatSelectFormController.ShowForTower() useCase is null.");
|
||||
return null;
|
||||
}
|
||||
|
||||
_useCase.SetUpgradePrice(upgradeCost);
|
||||
_useCase.SetDestroyGain(destroyGain);
|
||||
_useCase.ShowForTower(contentPosition);
|
||||
return OpenUI(_useCase.TryRefresh());
|
||||
}
|
||||
|
||||
public void HideSelection()
|
||||
{
|
||||
_useCase?.Hide();
|
||||
CloseUI();
|
||||
}
|
||||
|
||||
public void RefreshFromUseCase()
|
||||
{
|
||||
if (_useCase == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
CombatSelectFormRawData rawData = _useCase.TryRefresh();
|
||||
CombatSelectFormContext context = BuildContext(rawData);
|
||||
if (context == null || !context.IsVisible)
|
||||
{
|
||||
CloseUI();
|
||||
return;
|
||||
}
|
||||
|
||||
SetContext(context);
|
||||
RefreshCurrentUI();
|
||||
}
|
||||
|
||||
private static CombatSelectFormContext BuildContext(CombatSelectFormRawData rawData)
|
||||
{
|
||||
if (rawData == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new CombatSelectFormContext
|
||||
{
|
||||
IsVisible = rawData.IsVisible,
|
||||
ContentPosition = rawData.ContentPosition,
|
||||
ShowBuildArea = rawData.IsVisible && rawData.DisplayMode == CombatSelectDisplayMode.Build,
|
||||
ShowFuncArea = rawData.IsVisible && rawData.DisplayMode == CombatSelectDisplayMode.Func,
|
||||
BuildItems = BuildItemContexts(rawData.BuildItems),
|
||||
UpgradeItem = BuildItemContext(rawData.UpgradeItem),
|
||||
DestroyItem = BuildItemContext(rawData.DestroyItem)
|
||||
};
|
||||
}
|
||||
|
||||
private static TowerSelectItemContext[] BuildItemContexts(TowerSelectItemRawData[] itemRawData)
|
||||
{
|
||||
if (itemRawData == null || itemRawData.Length <= 0)
|
||||
{
|
||||
return System.Array.Empty<TowerSelectItemContext>();
|
||||
}
|
||||
|
||||
TowerSelectItemContext[] contexts = new TowerSelectItemContext[itemRawData.Length];
|
||||
for (int i = 0; i < itemRawData.Length; i++)
|
||||
{
|
||||
contexts[i] = BuildItemContext(itemRawData[i]);
|
||||
}
|
||||
|
||||
return contexts;
|
||||
}
|
||||
|
||||
private static TowerSelectItemContext BuildItemContext(TowerSelectItemRawData rawData)
|
||||
{
|
||||
if (rawData == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new TowerSelectItemContext
|
||||
{
|
||||
Icon = rawData.Icon,
|
||||
PriceText = BuildPriceText(rawData.Price, rawData.IsGain),
|
||||
IsVisible = rawData.IsVisible,
|
||||
IsInteractable = rawData.IsInteractable,
|
||||
ActionType = rawData.ActionType,
|
||||
ActionIndex = rawData.ActionIndex
|
||||
};
|
||||
}
|
||||
|
||||
private static string BuildPriceText(int price, bool isGain)
|
||||
{
|
||||
int positivePrice = Mathf.Max(0, price);
|
||||
if (isGain)
|
||||
{
|
||||
return $"+{positivePrice}";
|
||||
}
|
||||
|
||||
return positivePrice.ToString();
|
||||
}
|
||||
|
||||
private void OnSelectItemClicked(object sender, GameEventArgs e)
|
||||
{
|
||||
if (!(e is CombatSelectItemClickEventArgs args))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (_useCase == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (Form != null && sender is Component component)
|
||||
{
|
||||
CombatSelectForm ownerForm = component.GetComponentInParent<CombatSelectForm>();
|
||||
if (ownerForm != Form)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
_useCase.TryExecuteAction(args.ActionType, args.ActionIndex);
|
||||
RefreshFromUseCase();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 03cc7fd540e32b34bad5b8786717725f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,12 @@
|
||||
using GeometryTD.Definition;
|
||||
|
||||
namespace GeometryTD.UI
|
||||
{
|
||||
public class CombatFinishFormRawData
|
||||
{
|
||||
public int DefeatedEnemyCount;
|
||||
public int GainedGold;
|
||||
public BackpackInventoryData RewardInventory;
|
||||
public bool CanReturn;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6ee396100a8f4c7f99e3978c7154c00b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace GeometryTD.UI
|
||||
{
|
||||
public enum CombatSelectClickObjectType : byte
|
||||
{
|
||||
None = 0,
|
||||
Foundation = 1,
|
||||
Tower = 2
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d7dfced55a9048eea7df3b269e55e81e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace GeometryTD.UI
|
||||
{
|
||||
public enum CombatSelectDisplayMode : byte
|
||||
{
|
||||
Hidden = 0,
|
||||
Build = 1,
|
||||
Func = 2
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cc38eaebc2c34d9428b1233aa57c653e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,14 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace GeometryTD.UI
|
||||
{
|
||||
public class CombatSelectFormRawData
|
||||
{
|
||||
public bool IsVisible;
|
||||
public Vector2 ContentPosition;
|
||||
public CombatSelectDisplayMode DisplayMode;
|
||||
public TowerSelectItemRawData[] BuildItems;
|
||||
public TowerSelectItemRawData UpgradeItem;
|
||||
public TowerSelectItemRawData DestroyItem;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0958de13e46a34742acfa4352c7b6d4e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,15 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace GeometryTD.UI
|
||||
{
|
||||
public class CombatSelectFormUserData
|
||||
{
|
||||
public CombatSelectClickObjectType ClickObjectType;
|
||||
public Vector2 ContentPosition;
|
||||
public Vector3 WorldPosition;
|
||||
public Vector3Int CellPosition;
|
||||
public int TowerEntityId;
|
||||
public int UpgradeCost;
|
||||
public int DestroyGain;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 53ae7da2d92244c893cea60fa4c05951
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,15 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace GeometryTD.UI
|
||||
{
|
||||
public class TowerSelectItemRawData
|
||||
{
|
||||
public Sprite Icon;
|
||||
public int Price;
|
||||
public bool IsGain;
|
||||
public bool IsVisible;
|
||||
public bool IsInteractable;
|
||||
public CombatSelectActionType ActionType;
|
||||
public int ActionIndex;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 583bd0c79840d6649a4f340af2a8bf5b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,73 @@
|
||||
using GeometryTD.CustomComponent;
|
||||
using GeometryTD.Definition;
|
||||
using UnityEngine;
|
||||
|
||||
namespace GeometryTD.UI
|
||||
{
|
||||
public class CombatFinishFormUseCase : IUIUseCase
|
||||
{
|
||||
private readonly RepoFormUseCase _repoFormUseCase = new RepoFormUseCase();
|
||||
private CombatScheduler _combatScheduler;
|
||||
private int _defeatedEnemyCount;
|
||||
private int _gainedGold;
|
||||
private BackpackInventoryData _rewardInventory;
|
||||
private bool _isSummaryPrepared;
|
||||
|
||||
public CombatFinishFormRawData CreateInitialModel()
|
||||
{
|
||||
return BuildModel();
|
||||
}
|
||||
|
||||
public CombatFinishFormRawData TryRefresh()
|
||||
{
|
||||
return BuildModel();
|
||||
}
|
||||
|
||||
public void SetSummary(int defeatedEnemyCount, int gainedGold, BackpackInventoryData rewardInventory = null)
|
||||
{
|
||||
_defeatedEnemyCount = Mathf.Max(0, defeatedEnemyCount);
|
||||
_gainedGold = Mathf.Max(0, gainedGold);
|
||||
_rewardInventory = rewardInventory;
|
||||
_isSummaryPrepared = true;
|
||||
}
|
||||
|
||||
public CombatFinishFormUseCase(CombatScheduler combatScheduler)
|
||||
{
|
||||
this._combatScheduler = combatScheduler;
|
||||
}
|
||||
|
||||
public bool TryReturnToMenu()
|
||||
{
|
||||
return _combatScheduler.OnCombatFinishReturnRequested();
|
||||
}
|
||||
|
||||
private CombatFinishFormRawData BuildModel()
|
||||
{
|
||||
if (!_isSummaryPrepared)
|
||||
{
|
||||
_defeatedEnemyCount = GameEntry.CombatNode != null
|
||||
? Mathf.Max(0, GameEntry.CombatNode.LastDefeatedEnemyCount)
|
||||
: 0;
|
||||
_gainedGold = GameEntry.CombatNode != null
|
||||
? Mathf.Max(0, GameEntry.CombatNode.LastGainedGold)
|
||||
: 0;
|
||||
_rewardInventory = null;
|
||||
}
|
||||
|
||||
BackpackInventoryData rewardInventory = _rewardInventory;
|
||||
if (rewardInventory == null)
|
||||
{
|
||||
RepoFormRawData repoRawData = _repoFormUseCase.CreateInitialModel();
|
||||
rewardInventory = repoRawData != null ? repoRawData.Inventory : null;
|
||||
}
|
||||
|
||||
return new CombatFinishFormRawData
|
||||
{
|
||||
DefeatedEnemyCount = _defeatedEnemyCount,
|
||||
GainedGold = _gainedGold,
|
||||
RewardInventory = rewardInventory,
|
||||
CanReturn = true
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9e5ee9e49e70480c9f98e6c77eb86f5f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,300 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace GeometryTD.UI
|
||||
{
|
||||
public class CombatSelectFormUseCase : IUIUseCase
|
||||
{
|
||||
private const int BuildOptionCount = 4;
|
||||
|
||||
private readonly Option[] _buildOptions = new Option[BuildOptionCount];
|
||||
private readonly Option _upgradeOption = new Option(CombatSelectActionType.UpgradeTower, 0, true);
|
||||
private readonly Option _destroyOption = new Option(CombatSelectActionType.DestroyTower, 0, false);
|
||||
|
||||
private Func<int> _coinProvider;
|
||||
private bool _isVisible;
|
||||
private CombatSelectDisplayMode _displayMode = CombatSelectDisplayMode.Hidden;
|
||||
private Vector2 _contentPosition;
|
||||
|
||||
public CombatSelectFormUseCase()
|
||||
{
|
||||
_coinProvider = DefaultCoinProvider;
|
||||
|
||||
for (int i = 0; i < BuildOptionCount; i++)
|
||||
{
|
||||
_buildOptions[i] = new Option(CombatSelectActionType.BuildTower, i, true);
|
||||
}
|
||||
}
|
||||
|
||||
public CombatSelectFormRawData CreateInitialModel()
|
||||
{
|
||||
return BuildModel();
|
||||
}
|
||||
|
||||
public CombatSelectFormRawData TryRefresh()
|
||||
{
|
||||
return BuildModel();
|
||||
}
|
||||
|
||||
public void SetCoinProvider(Func<int> coinProvider)
|
||||
{
|
||||
_coinProvider = coinProvider ?? DefaultCoinProvider;
|
||||
}
|
||||
|
||||
public void SetBuildAction(int buildIndex, Func<bool> buildAction, int cost, Sprite icon = null)
|
||||
{
|
||||
if (buildIndex < 0 || buildIndex >= _buildOptions.Length)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Option option = _buildOptions[buildIndex];
|
||||
option.Action = buildAction;
|
||||
option.Price = Mathf.Max(0, cost);
|
||||
option.Icon = icon;
|
||||
option.IsGain = false;
|
||||
option.IsVisible = true;
|
||||
}
|
||||
|
||||
public void SetBuildAction(int buildIndex, Action buildAction, int cost, Sprite icon = null)
|
||||
{
|
||||
if (buildAction == null)
|
||||
{
|
||||
SetBuildAction(buildIndex, (Func<bool>)null, cost, icon);
|
||||
return;
|
||||
}
|
||||
|
||||
SetBuildAction(
|
||||
buildIndex,
|
||||
() =>
|
||||
{
|
||||
buildAction.Invoke();
|
||||
return true;
|
||||
},
|
||||
cost,
|
||||
icon);
|
||||
}
|
||||
|
||||
public void SetUpgradeAction(Func<bool> upgradeAction, int cost, Sprite icon = null)
|
||||
{
|
||||
_upgradeOption.Action = upgradeAction;
|
||||
_upgradeOption.Price = Mathf.Max(0, cost);
|
||||
_upgradeOption.Icon = icon;
|
||||
_upgradeOption.IsGain = false;
|
||||
_upgradeOption.IsVisible = true;
|
||||
}
|
||||
|
||||
public void SetUpgradeAction(Action upgradeAction, int cost, Sprite icon = null)
|
||||
{
|
||||
if (upgradeAction == null)
|
||||
{
|
||||
SetUpgradeAction((Func<bool>)null, cost, icon);
|
||||
return;
|
||||
}
|
||||
|
||||
SetUpgradeAction(
|
||||
() =>
|
||||
{
|
||||
upgradeAction.Invoke();
|
||||
return true;
|
||||
},
|
||||
cost,
|
||||
icon);
|
||||
}
|
||||
|
||||
public void SetDestroyAction(Func<bool> destroyAction, int gain, Sprite icon = null)
|
||||
{
|
||||
_destroyOption.Action = destroyAction;
|
||||
_destroyOption.Price = Mathf.Max(0, gain);
|
||||
_destroyOption.Icon = icon;
|
||||
_destroyOption.IsGain = true;
|
||||
_destroyOption.IsVisible = true;
|
||||
}
|
||||
|
||||
public void SetDestroyAction(Action destroyAction, int gain, Sprite icon = null)
|
||||
{
|
||||
if (destroyAction == null)
|
||||
{
|
||||
SetDestroyAction((Func<bool>)null, gain, icon);
|
||||
return;
|
||||
}
|
||||
|
||||
SetDestroyAction(
|
||||
() =>
|
||||
{
|
||||
destroyAction.Invoke();
|
||||
return true;
|
||||
},
|
||||
gain,
|
||||
icon);
|
||||
}
|
||||
|
||||
public void SetUpgradePrice(int cost)
|
||||
{
|
||||
_upgradeOption.Price = Mathf.Max(0, cost);
|
||||
}
|
||||
|
||||
public void SetDestroyGain(int gain)
|
||||
{
|
||||
_destroyOption.Price = Mathf.Max(0, gain);
|
||||
_destroyOption.IsGain = true;
|
||||
}
|
||||
|
||||
public void ShowForFoundation(Vector2 contentPosition)
|
||||
{
|
||||
_contentPosition = contentPosition;
|
||||
_displayMode = CombatSelectDisplayMode.Build;
|
||||
_isVisible = true;
|
||||
}
|
||||
|
||||
public void ShowForTower(Vector2 contentPosition)
|
||||
{
|
||||
_contentPosition = contentPosition;
|
||||
_displayMode = CombatSelectDisplayMode.Func;
|
||||
_isVisible = true;
|
||||
}
|
||||
|
||||
public void Hide()
|
||||
{
|
||||
_isVisible = false;
|
||||
_displayMode = CombatSelectDisplayMode.Hidden;
|
||||
}
|
||||
|
||||
public bool TryExecuteAction(CombatSelectActionType actionType, int actionIndex)
|
||||
{
|
||||
if (!_isVisible)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Option option = GetOption(actionType, actionIndex);
|
||||
if (option == null || !option.IsVisible)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int currentCoin = Mathf.Max(0, _coinProvider != null ? _coinProvider.Invoke() : 0);
|
||||
if (!CanExecute(option, currentCoin))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (option.Action == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool result = option.Action.Invoke();
|
||||
if (result)
|
||||
{
|
||||
Hide();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private CombatSelectFormRawData BuildModel()
|
||||
{
|
||||
int currentCoin = Mathf.Max(0, _coinProvider != null ? _coinProvider.Invoke() : 0);
|
||||
TowerSelectItemRawData[] buildItems = new TowerSelectItemRawData[_buildOptions.Length];
|
||||
for (int i = 0; i < _buildOptions.Length; i++)
|
||||
{
|
||||
buildItems[i] = BuildOptionRawData(_buildOptions[i], currentCoin);
|
||||
}
|
||||
|
||||
return new CombatSelectFormRawData
|
||||
{
|
||||
IsVisible = _isVisible,
|
||||
ContentPosition = _contentPosition,
|
||||
DisplayMode = _displayMode,
|
||||
BuildItems = buildItems,
|
||||
UpgradeItem = BuildOptionRawData(_upgradeOption, currentCoin),
|
||||
DestroyItem = BuildOptionRawData(_destroyOption, currentCoin)
|
||||
};
|
||||
}
|
||||
|
||||
private Option GetOption(CombatSelectActionType actionType, int actionIndex)
|
||||
{
|
||||
switch (actionType)
|
||||
{
|
||||
case CombatSelectActionType.BuildTower:
|
||||
if (actionIndex < 0 || actionIndex >= _buildOptions.Length)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return _buildOptions[actionIndex];
|
||||
case CombatSelectActionType.UpgradeTower:
|
||||
return _upgradeOption;
|
||||
case CombatSelectActionType.DestroyTower:
|
||||
return _destroyOption;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static int DefaultCoinProvider()
|
||||
{
|
||||
if (GameEntry.CombatNode == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return Mathf.Max(0, GameEntry.CombatNode.CurrentCoin);
|
||||
}
|
||||
|
||||
private static bool CanExecute(Option option, int currentCoin)
|
||||
{
|
||||
if (option == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (option.RequiresAffordable && currentCoin < option.Price)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static TowerSelectItemRawData BuildOptionRawData(Option option, int currentCoin)
|
||||
{
|
||||
if (option == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new TowerSelectItemRawData
|
||||
{
|
||||
Icon = option.Icon,
|
||||
Price = option.Price,
|
||||
IsGain = option.IsGain,
|
||||
IsVisible = option.IsVisible,
|
||||
IsInteractable = option.Action != null && CanExecute(option, currentCoin),
|
||||
ActionType = option.ActionType,
|
||||
ActionIndex = option.ActionIndex
|
||||
};
|
||||
}
|
||||
|
||||
private sealed class Option
|
||||
{
|
||||
public readonly CombatSelectActionType ActionType;
|
||||
public readonly int ActionIndex;
|
||||
public readonly bool RequiresAffordable;
|
||||
|
||||
public int Price;
|
||||
public bool IsGain;
|
||||
public bool IsVisible = true;
|
||||
public Sprite Icon;
|
||||
public Func<bool> Action;
|
||||
|
||||
public Option(CombatSelectActionType actionType, int actionIndex, bool requiresAffordable)
|
||||
{
|
||||
ActionType = actionType;
|
||||
ActionIndex = actionIndex;
|
||||
RequiresAffordable = requiresAffordable;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 040ca52500c562c4d9737d44a8940050
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,173 @@
|
||||
using System.Collections.Generic;
|
||||
using GameFramework.ObjectPool;
|
||||
using GeometryTD.CustomEvent;
|
||||
using GeometryTD.PoolObjectBase;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityGameFramework.Runtime;
|
||||
|
||||
namespace GeometryTD.UI
|
||||
{
|
||||
public class CombatFinishForm : UGuiForm
|
||||
{
|
||||
[SerializeField] private TMP_Text _enemyKilledText;
|
||||
[SerializeField] private TMP_Text _goldGainedText;
|
||||
[SerializeField] private Transform _itemGainedParent;
|
||||
[SerializeField] private RepoItem _itemTemplate;
|
||||
[SerializeField] private int _instancePoolCapacity = 16;
|
||||
|
||||
private readonly List<RepoItem> _activeItems = new List<RepoItem>();
|
||||
private IObjectPool<RepoItemObject> _itemPool;
|
||||
private string _poolName;
|
||||
private CombatFinishFormContext _context;
|
||||
|
||||
public void RefreshUI(CombatFinishFormContext context)
|
||||
{
|
||||
_context = context;
|
||||
|
||||
if (_enemyKilledText != null)
|
||||
{
|
||||
_enemyKilledText.text = context?.EnemyKilledText ?? "0";
|
||||
}
|
||||
|
||||
if (_goldGainedText != null)
|
||||
{
|
||||
_goldGainedText.text = context?.GoldGainedText ?? "0";
|
||||
}
|
||||
|
||||
RefreshRewardItems(context?.RewardItems);
|
||||
}
|
||||
|
||||
public void OnReturnButtonClick()
|
||||
{
|
||||
if (_context != null && !_context.CanReturn)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
GameEntry.Event.Fire(this, CombatFinishReturnEventArgs.Create());
|
||||
}
|
||||
|
||||
protected override void OnOpen(object userData)
|
||||
{
|
||||
base.OnOpen(userData);
|
||||
|
||||
if (userData is CombatFinishFormContext context)
|
||||
{
|
||||
RefreshUI(context);
|
||||
return;
|
||||
}
|
||||
|
||||
Log.Warning("CombatFinishForm requires CombatFinishFormContext as userData.");
|
||||
}
|
||||
|
||||
protected override void OnClose(bool isShutdown, object userData)
|
||||
{
|
||||
_context = null;
|
||||
|
||||
if (_enemyKilledText != null)
|
||||
{
|
||||
_enemyKilledText.text = string.Empty;
|
||||
}
|
||||
|
||||
if (_goldGainedText != null)
|
||||
{
|
||||
_goldGainedText.text = string.Empty;
|
||||
}
|
||||
|
||||
ClearRewardItems();
|
||||
base.OnClose(isShutdown, userData);
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
ClearRewardItems();
|
||||
_itemPool?.ReleaseAllUnused();
|
||||
}
|
||||
|
||||
private void EnsurePool()
|
||||
{
|
||||
if (_itemPool != null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_poolName = $"CombatFinishRepoItemPool_{GetInstanceID()}";
|
||||
_itemPool = GameEntry.ObjectPool.CreateSingleSpawnObjectPool<RepoItemObject>(_poolName, _instancePoolCapacity);
|
||||
}
|
||||
|
||||
private void RefreshRewardItems(RepoItemContext[] rewardItems)
|
||||
{
|
||||
ClearRewardItems();
|
||||
|
||||
if (rewardItems == null || rewardItems.Length <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
EnsurePool();
|
||||
|
||||
for (int i = 0; i < rewardItems.Length; i++)
|
||||
{
|
||||
RepoItem item = CreateOrSpawnItem();
|
||||
if (item == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
item.gameObject.SetActive(true);
|
||||
item.OnInit(rewardItems[i]);
|
||||
_activeItems.Add(item);
|
||||
}
|
||||
}
|
||||
|
||||
private void ClearRewardItems()
|
||||
{
|
||||
for (int i = _activeItems.Count - 1; i >= 0; i--)
|
||||
{
|
||||
RepoItem item = _activeItems[i];
|
||||
if (item == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
item.OnReset();
|
||||
item.gameObject.SetActive(false);
|
||||
_itemPool?.Unspawn(item);
|
||||
}
|
||||
|
||||
_activeItems.Clear();
|
||||
}
|
||||
|
||||
private RepoItem CreateOrSpawnItem()
|
||||
{
|
||||
if (_itemGainedParent == null)
|
||||
{
|
||||
Log.Warning("CombatFinishForm requires an item gained parent.");
|
||||
return null;
|
||||
}
|
||||
|
||||
if (_itemPool == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
RepoItemObject itemObject = _itemPool.Spawn();
|
||||
RepoItem item = itemObject != null ? (RepoItem)itemObject.Target : null;
|
||||
if (item == null)
|
||||
{
|
||||
if (_itemTemplate == null)
|
||||
{
|
||||
Log.Warning("CombatFinishForm requires an item template.");
|
||||
return null;
|
||||
}
|
||||
|
||||
item = Instantiate(_itemTemplate);
|
||||
_itemPool.Register(RepoItemObject.Create(item), true);
|
||||
}
|
||||
|
||||
item.transform.SetParent(_itemGainedParent, false);
|
||||
return item;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9679d912cb0ce9e4d95db41021d94463
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,60 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace GeometryTD.UI
|
||||
{
|
||||
public class CombatSelectBuildArea : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private TowerSelectItem[] _towerBuildItems;
|
||||
|
||||
public void OnInit(TowerSelectItemContext[] itemContexts)
|
||||
{
|
||||
if (_towerBuildItems == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < _towerBuildItems.Length; i++)
|
||||
{
|
||||
TowerSelectItem item = _towerBuildItems[i];
|
||||
if (item == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
TowerSelectItemContext itemContext =
|
||||
itemContexts != null && i < itemContexts.Length ? itemContexts[i] : null;
|
||||
bool isVisible = itemContext != null && itemContext.IsVisible;
|
||||
|
||||
item.gameObject.SetActive(isVisible);
|
||||
if (isVisible)
|
||||
{
|
||||
item.OnInit(itemContext);
|
||||
}
|
||||
else
|
||||
{
|
||||
item.OnReset();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void OnReset()
|
||||
{
|
||||
if (_towerBuildItems == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < _towerBuildItems.Length; i++)
|
||||
{
|
||||
TowerSelectItem item = _towerBuildItems[i];
|
||||
if (item == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
item.OnReset();
|
||||
item.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 73470d4b91d03924b9233b58311e917c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,111 @@
|
||||
using UnityEngine;
|
||||
using UnityGameFramework.Runtime;
|
||||
|
||||
namespace GeometryTD.UI
|
||||
{
|
||||
public class CombatSelectForm : UGuiForm
|
||||
{
|
||||
[SerializeField] private RectTransform _content;
|
||||
|
||||
[SerializeField] private CombatSelectBuildArea _buildArea;
|
||||
|
||||
[SerializeField] private CombatSelectFuncArea _funcArea;
|
||||
|
||||
private CombatSelectFormContext _context;
|
||||
|
||||
public void RefreshUI(CombatSelectFormContext context)
|
||||
{
|
||||
_context = context;
|
||||
EnsureContentReference();
|
||||
|
||||
if (_content == null)
|
||||
{
|
||||
Log.Warning("CombatSelectForm content is missing.");
|
||||
return;
|
||||
}
|
||||
|
||||
bool isVisible = context != null && context.IsVisible;
|
||||
_content.gameObject.SetActive(isVisible);
|
||||
if (!isVisible)
|
||||
{
|
||||
_buildArea?.OnReset();
|
||||
_funcArea?.OnReset();
|
||||
return;
|
||||
}
|
||||
|
||||
_content.anchoredPosition = context.ContentPosition;
|
||||
|
||||
if (_buildArea != null)
|
||||
{
|
||||
bool showBuildArea = context.ShowBuildArea;
|
||||
_buildArea.gameObject.SetActive(showBuildArea);
|
||||
if (showBuildArea)
|
||||
{
|
||||
_buildArea.OnInit(context.BuildItems);
|
||||
}
|
||||
else
|
||||
{
|
||||
_buildArea.OnReset();
|
||||
}
|
||||
}
|
||||
|
||||
if (_funcArea != null)
|
||||
{
|
||||
bool showFuncArea = context.ShowFuncArea;
|
||||
_funcArea.gameObject.SetActive(showFuncArea);
|
||||
if (showFuncArea)
|
||||
{
|
||||
_funcArea.OnInit(context.UpgradeItem, context.DestroyItem);
|
||||
}
|
||||
else
|
||||
{
|
||||
_funcArea.OnReset();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnOpen(object userData)
|
||||
{
|
||||
base.OnOpen(userData);
|
||||
|
||||
if (userData is CombatSelectFormContext context)
|
||||
{
|
||||
RefreshUI(context);
|
||||
return;
|
||||
}
|
||||
|
||||
Log.Warning("CombatSelectForm requires CombatSelectFormContext as userData.");
|
||||
RefreshUI(null);
|
||||
}
|
||||
|
||||
protected override void OnClose(bool isShutdown, object userData)
|
||||
{
|
||||
_context = null;
|
||||
_buildArea?.OnReset();
|
||||
_funcArea?.OnReset();
|
||||
|
||||
if (_content != null)
|
||||
{
|
||||
_content.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
base.OnClose(isShutdown, userData);
|
||||
}
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
EnsureContentReference();
|
||||
}
|
||||
|
||||
private void EnsureContentReference()
|
||||
{
|
||||
if (_content != null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Transform contentTransform = transform.Find("Content");
|
||||
_content = contentTransform as RectTransform;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e62b0f7fcf3ccfd4e88da34d80cc14ab
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,53 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace GeometryTD.UI
|
||||
{
|
||||
public class CombatSelectFuncArea : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private TowerSelectItem _upgradeItem;
|
||||
|
||||
[SerializeField] private TowerSelectItem _destroyItem;
|
||||
|
||||
public void OnInit(TowerSelectItemContext upgradeItemContext, TowerSelectItemContext destroyItemContext)
|
||||
{
|
||||
RefreshItem(_upgradeItem, upgradeItemContext);
|
||||
RefreshItem(_destroyItem, destroyItemContext);
|
||||
}
|
||||
|
||||
public void OnReset()
|
||||
{
|
||||
ResetItem(_upgradeItem);
|
||||
ResetItem(_destroyItem);
|
||||
}
|
||||
|
||||
private static void RefreshItem(TowerSelectItem item, TowerSelectItemContext context)
|
||||
{
|
||||
if (item == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
bool isVisible = context != null && context.IsVisible;
|
||||
item.gameObject.SetActive(isVisible);
|
||||
if (isVisible)
|
||||
{
|
||||
item.OnInit(context);
|
||||
}
|
||||
else
|
||||
{
|
||||
item.OnReset();
|
||||
}
|
||||
}
|
||||
|
||||
private static void ResetItem(TowerSelectItem item)
|
||||
{
|
||||
if (item == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
item.OnReset();
|
||||
item.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 891304d1e879da34c9b989ca2fcd14a7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,96 @@
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using GeometryTD.CustomEvent;
|
||||
using UnityGameFramework.Runtime;
|
||||
|
||||
namespace GeometryTD.UI
|
||||
{
|
||||
public class TowerSelectItem : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Image _icon;
|
||||
|
||||
[SerializeField] private TMP_Text _price;
|
||||
|
||||
[SerializeField] private CommonButton _button;
|
||||
|
||||
private TowerSelectItemContext _context;
|
||||
private Sprite _defaultIcon;
|
||||
private bool _hasCachedDefaultIcon;
|
||||
|
||||
public void OnInit(TowerSelectItemContext context)
|
||||
{
|
||||
CacheDefaultIcon();
|
||||
_context = context;
|
||||
|
||||
if (_icon != null)
|
||||
{
|
||||
if (context != null && context.Icon != null)
|
||||
{
|
||||
_icon.sprite = context.Icon;
|
||||
}
|
||||
else if (_defaultIcon != null)
|
||||
{
|
||||
_icon.sprite = _defaultIcon;
|
||||
}
|
||||
|
||||
_icon.enabled = _icon.sprite != null;
|
||||
}
|
||||
|
||||
if (_price != null)
|
||||
{
|
||||
_price.text = context?.PriceText ?? string.Empty;
|
||||
}
|
||||
|
||||
if (_button != null)
|
||||
{
|
||||
_button.Interactive = context != null && context.IsInteractable;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnReset()
|
||||
{
|
||||
_context = null;
|
||||
CacheDefaultIcon();
|
||||
|
||||
if (_icon != null)
|
||||
{
|
||||
_icon.sprite = _defaultIcon;
|
||||
_icon.enabled = _icon.sprite != null;
|
||||
}
|
||||
|
||||
if (_price != null)
|
||||
{
|
||||
_price.text = string.Empty;
|
||||
}
|
||||
|
||||
if (_button != null)
|
||||
{
|
||||
_button.Interactive = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnClick()
|
||||
{
|
||||
if (_context == null || !_context.IsInteractable)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
GameEntry.Event.Fire(
|
||||
this,
|
||||
CombatSelectItemClickEventArgs.Create(_context.ActionType, _context.ActionIndex));
|
||||
}
|
||||
|
||||
private void CacheDefaultIcon()
|
||||
{
|
||||
if (_hasCachedDefaultIcon || _icon == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_defaultIcon = _icon.sprite;
|
||||
_hasCachedDefaultIcon = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4da5ef45ee18db44ebe3c015dddb61d6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user