- S4-03 | 先固化 Tag 系统设计与首发范围

- S4-04 | 实现组件实例 Tag 的统一生成入口
- S4-05 | 实现组塔后的 Tag 汇总与展示入口
This commit is contained in:
SepComet
2026-03-09 21:06:43 +08:00
parent 73b7adedb8
commit 34ef001ef3
31 changed files with 1280 additions and 178 deletions
@@ -18,7 +18,7 @@ namespace GeometryTD.UI
public string Title;
public string TypeText;
public string Description;
public TagType[] Tags;
public string[] TagTexts;
}
protected override UIFormType UIFormTypeId => UIFormType.CombatFinishForm;
@@ -138,7 +138,7 @@ namespace GeometryTD.UI
tower.Name,
"Tower",
ItemDescUtility.BuildTowerDesc(tower, muzzleMap, bearingMap, baseMap) ?? string.Empty,
tower.Stats != null ? tower.Stats.Tags : null);
TagDisplayUtility.BuildTowerTagTexts(tower.Stats));
}
}
@@ -166,7 +166,7 @@ namespace GeometryTD.UI
item.Name,
BuildComponentTypeText(item.SlotType),
ItemDescUtility.BuildMuzzleDesc(item) ?? string.Empty,
item.Tags);
TagDisplayUtility.BuildTagTexts(item.Tags));
}
}
@@ -194,7 +194,7 @@ namespace GeometryTD.UI
item.Name,
BuildComponentTypeText(item.SlotType),
ItemDescUtility.BuildBearingDesc(item) ?? string.Empty,
item.Tags);
TagDisplayUtility.BuildTagTexts(item.Tags));
}
}
@@ -222,7 +222,7 @@ namespace GeometryTD.UI
item.Name,
BuildComponentTypeText(item.SlotType),
ItemDescUtility.BuildBaseDesc(item) ?? string.Empty,
item.Tags);
TagDisplayUtility.BuildTagTexts(item.Tags));
}
}
@@ -261,7 +261,7 @@ namespace GeometryTD.UI
return Color.white;
}
private void AddItemDescSeed(long itemId, string title, string typeText, string description, TagType[] tags)
private void AddItemDescSeed(long itemId, string title, string typeText, string description, string[] tagTexts)
{
if (itemId <= 0)
{
@@ -273,13 +273,13 @@ namespace GeometryTD.UI
Title = string.IsNullOrWhiteSpace(title) ? $"Item {itemId}" : title,
TypeText = typeText ?? string.Empty,
Description = description ?? string.Empty,
Tags = CloneTags(tags)
TagTexts = CloneTagTexts(tagTexts)
};
}
private static TagType[] CloneTags(TagType[] tags)
private static string[] CloneTagTexts(string[] tagTexts)
{
return tags != null ? (TagType[])tags.Clone() : System.Array.Empty<TagType>();
return tagTexts != null ? (string[])tagTexts.Clone() : System.Array.Empty<string>();
}
private static string BuildComponentTypeText(TowerCompSlotType slotType)
@@ -374,7 +374,7 @@ namespace GeometryTD.UI
Description = seed.Description ?? string.Empty,
Price = 0,
TargetPos = args.TargetPos,
Tags = CloneTags(seed.Tags)
TagTexts = CloneTagTexts(seed.TagTexts)
});
}
@@ -405,4 +405,3 @@ namespace GeometryTD.UI
@@ -43,7 +43,7 @@ namespace GeometryTD.UI
tower.Name,
"Tower",
ItemDescUtility.BuildTowerDesc(tower, muzzleMap, bearingMap, baseMap) ?? string.Empty,
tower.Stats != null ? tower.Stats.Tags : null);
TagDisplayUtility.BuildTowerTagTexts(tower.Stats));
}
}
@@ -71,7 +71,7 @@ namespace GeometryTD.UI
item.Name,
BuildComponentTypeText(item.SlotType),
ItemDescUtility.BuildMuzzleDesc(item) ?? string.Empty,
item.Tags);
TagDisplayUtility.BuildTagTexts(item.Tags));
}
}
@@ -99,7 +99,7 @@ namespace GeometryTD.UI
item.Name,
BuildComponentTypeText(item.SlotType),
ItemDescUtility.BuildBearingDesc(item) ?? string.Empty,
item.Tags);
TagDisplayUtility.BuildTagTexts(item.Tags));
}
}
@@ -127,7 +127,7 @@ namespace GeometryTD.UI
item.Name,
BuildComponentTypeText(item.SlotType),
ItemDescUtility.BuildBaseDesc(item) ?? string.Empty,
item.Tags);
TagDisplayUtility.BuildTagTexts(item.Tags));
}
}
@@ -169,7 +169,7 @@ namespace GeometryTD.UI
_compAreaTowerIds.Add(itemContext.InstanceId);
}
private void AddItemDescSeed(long itemId, string title, string typeText, string description, TagType[] tags)
private void AddItemDescSeed(long itemId, string title, string typeText, string description, string[] tagTexts)
{
if (itemId <= 0)
{
@@ -181,15 +181,10 @@ namespace GeometryTD.UI
Title = string.IsNullOrWhiteSpace(title) ? $"Item {itemId}" : title,
TypeText = typeText ?? string.Empty,
Description = description ?? string.Empty,
Tags = CloneTags(tags)
TagTexts = tagTexts != null ? (string[])tagTexts.Clone() : Array.Empty<string>()
};
}
private static TagType[] CloneTags(TagType[] tags)
{
return tags != null ? (TagType[])tags.Clone() : Array.Empty<TagType>();
}
private static string BuildComponentTypeText(TowerCompSlotType slotType)
{
return slotType switch
@@ -391,4 +386,3 @@ namespace GeometryTD.UI
}
}
}
@@ -22,7 +22,7 @@ namespace GeometryTD.UI
public string Title;
public string TypeText;
public string Description;
public TagType[] Tags;
public string[] TagTexts;
}
protected override UIFormType UIFormTypeId => UIFormType.RepoForm;
@@ -151,7 +151,7 @@ namespace GeometryTD.UI
Description = seed.Description ?? string.Empty,
Price = 0,
TargetPos = args.TargetPos,
Tags = CloneTags(seed.Tags)
TagTexts = CloneTagTexts(seed.TagTexts)
});
}
@@ -301,5 +301,9 @@ namespace GeometryTD.UI
}
#endregion
private static string[] CloneTagTexts(string[] tagTexts)
{
return tagTexts != null ? (string[])tagTexts.Clone() : System.Array.Empty<string>();
}
}
}
@@ -1,5 +1,3 @@
using System.Collections.Generic;
using GeometryTD.Definition;
using UnityEngine;
namespace GeometryTD.UI
@@ -11,6 +9,6 @@ namespace GeometryTD.UI
public string Description;
public int Price;
public Vector3 TargetPos;
public List<TagType> Tags;
public TagItemContext[] Tags;
}
}
}
@@ -1,5 +1,5 @@
using System.Collections.Generic;
using GameFramework.Event;
using GeometryTD.CustomUtility;
using GeometryTD.Definition;
using UnityGameFramework.Runtime;
@@ -35,18 +35,33 @@ namespace GeometryTD.UI
Description = rawData.Description,
Price = rawData.Price,
TargetPos = rawData.TargetPos,
Tags = BuildTags(rawData.Tags)
Tags = BuildTags(rawData)
};
}
private static List<TagType> BuildTags(TagType[] tags)
private static TagItemContext[] BuildTags(ItemDescFormRawData rawData)
{
if (tags == null || tags.Length <= 0)
string[] tagTexts = rawData?.TagTexts;
if ((tagTexts == null || tagTexts.Length <= 0) && rawData?.Tags != null)
{
return new List<TagType>();
tagTexts = TagDisplayUtility.BuildTagTexts(rawData.Tags);
}
return new List<TagType>(tags);
if (tagTexts == null || tagTexts.Length <= 0)
{
return System.Array.Empty<TagItemContext>();
}
TagItemContext[] contexts = new TagItemContext[tagTexts.Length];
for (int i = 0; i < tagTexts.Length; i++)
{
contexts[i] = new TagItemContext
{
TagName = tagTexts[i] ?? string.Empty
};
}
return contexts;
}
public int? OpenUI(ItemDescFormRawData rawData)
@@ -179,44 +179,24 @@ namespace GeometryTD.UI
private static TagItemContext[] BuildTagContexts(TagType[] tags)
{
if (tags == null || tags.Length <= 0)
string[] tagTexts = TagDisplayUtility.BuildTagTexts(tags);
if (tagTexts == null || tagTexts.Length <= 0)
{
return System.Array.Empty<TagItemContext>();
}
TagItemContext[] contexts = new TagItemContext[tags.Length];
for (int i = 0; i < tags.Length; i++)
TagItemContext[] contexts = new TagItemContext[tagTexts.Length];
for (int i = 0; i < tagTexts.Length; i++)
{
TagType tagType = tags[i];
contexts[i] = new TagItemContext
{
TagName = ResolveTagName(tagType)
TagName = tagTexts[i]
};
}
return contexts;
}
private static string ResolveTagName(TagType tagType)
{
if (tagType == TagType.None)
{
return string.Empty;
}
var tagTable = GameEntry.DataTable.GetDataTable<DRTag>();
if (tagTable != null)
{
DRTag tagRow = tagTable.GetDataRow((int)tagType);
if (tagRow != null && !string.IsNullOrWhiteSpace(tagRow.Name))
{
return tagRow.Name;
}
}
return tagType.ToString();
}
private void OnRewardSelected(object sender, GameEventArgs e)
{
if (!IsEventFromCurrentForm(sender) || !(e is RewardSelectItemSelectedEventArgs args))
@@ -11,5 +11,6 @@ namespace GeometryTD.UI
public int Price;
public Vector3 TargetPos;
public TagType[] Tags;
public string[] TagTexts;
}
}
@@ -1,6 +1,4 @@
using System.Collections.Generic;
using GeometryTD.DataTable;
using GeometryTD.Definition;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
@@ -249,11 +247,11 @@ namespace GeometryTD.UI
return value >= min && value <= max;
}
private void RefreshTags(List<TagType> tags)
private void RefreshTags(TagItemContext[] tags)
{
ClearTags();
if (_tagAreaParent == null || _tagItemPrefab == null || tags == null || tags.Count <= 0)
if (_tagAreaParent == null || _tagItemPrefab == null || tags == null || tags.Length <= 0)
{
return;
}
@@ -263,10 +261,10 @@ namespace GeometryTD.UI
_tagItemPrefab.SetActive(false);
}
for (int i = 0; i < tags.Count; i++)
for (int i = 0; i < tags.Length; i++)
{
string tagName = ResolveTagName(tags[i]);
if (string.IsNullOrWhiteSpace(tagName))
TagItemContext tagContext = tags[i];
if (tagContext == null || string.IsNullOrWhiteSpace(tagContext.TagName))
{
continue;
}
@@ -276,17 +274,14 @@ namespace GeometryTD.UI
if (tagGo.TryGetComponent(out TagItem tagItem))
{
tagItem.OnInit(new TagItemContext
{
TagName = tagName
});
tagItem.OnInit(tagContext);
}
else
{
TMP_Text tagText = tagGo.GetComponentInChildren<TMP_Text>(true);
if (tagText != null)
{
tagText.text = tagName;
tagText.text = tagContext.TagName;
}
}
@@ -308,26 +303,6 @@ namespace GeometryTD.UI
_runtimeTagItems.Clear();
}
private static string ResolveTagName(TagType tagType)
{
if (tagType == TagType.None)
{
return string.Empty;
}
var tagTable = GameEntry.DataTable.GetDataTable<DRTag>();
if (tagTable != null)
{
DRTag tagRow = tagTable.GetDataRow((int)tagType);
if (tagRow != null && !string.IsNullOrWhiteSpace(tagRow.Name))
{
return tagRow.Name;
}
}
return tagType.ToString();
}
private void CloseSelf()
{
GameEntry.UI.CloseUIForm(this);
@@ -1,6 +1,7 @@
using GeometryTD.CustomEvent;
using GeometryTD.Definition;
using GameFramework.Event;
using GeometryTD.CustomUtility;
using UnityEngine;
using UnityGameFramework.Runtime;
@@ -165,18 +166,7 @@ namespace GeometryTD.UI
private static string[] BuildTagTexts(TagType[] tags)
{
if (tags == null || tags.Length <= 0)
{
return System.Array.Empty<string>();
}
string[] results = new string[tags.Length];
for (int i = 0; i < tags.Length; i++)
{
results[i] = tags[i].ToString();
}
return results;
return TagDisplayUtility.BuildTagTexts(tags);
}
}
}
@@ -16,11 +16,13 @@ namespace GeometryTD.UI
private readonly List<GoodsItemRawData> _currentGoods = new List<GoodsItemRawData>(GoodsCount);
private readonly List<DRShopPrice> _shopPriceRows = new List<DRShopPrice>();
private readonly Dictionary<TagType, RarityType> _tagMinRarityByTag = new Dictionary<TagType, RarityType>();
private IDataTable<DRShopPrice> _shopPriceTable;
private IDataTable<DRMuzzleComp> _muzzleCompTable;
private IDataTable<DRBearingComp> _bearingCompTable;
private IDataTable<DRBaseComp> _baseCompTable;
private IDataTable<DRTag> _tagTable;
public bool PrepareForOpen()
{
@@ -99,8 +101,9 @@ namespace GeometryTD.UI
_muzzleCompTable ??= GameEntry.DataTable.GetDataTable<DRMuzzleComp>();
_bearingCompTable ??= GameEntry.DataTable.GetDataTable<DRBearingComp>();
_baseCompTable ??= GameEntry.DataTable.GetDataTable<DRBaseComp>();
_tagTable ??= GameEntry.DataTable.GetDataTable<DRTag>();
if (_shopPriceTable == null || _muzzleCompTable == null || _bearingCompTable == null || _baseCompTable == null)
if (_shopPriceTable == null || _muzzleCompTable == null || _bearingCompTable == null || _baseCompTable == null || _tagTable == null)
{
Log.Warning("ShopFormUseCase.EnsureTables() failed. Missing required data tables.");
return false;
@@ -124,10 +127,13 @@ namespace GeometryTD.UI
}
}
EnsureTagMinRarityLookup();
return _shopPriceRows.Count > 0 &&
_muzzleCompTable.Count > 0 &&
_bearingCompTable.Count > 0 &&
_baseCompTable.Count > 0;
_baseCompTable.Count > 0 &&
_tagMinRarityByTag.Count > 0;
}
private bool TryBuildRandomGoodsItem(int goodsIndex, out GoodsItemRawData goodsItem)
@@ -176,15 +182,23 @@ namespace GeometryTD.UI
{
DRMuzzleComp[] rows = _muzzleCompTable.GetAllDataRows();
DRMuzzleComp config = rows[UnityEngine.Random.Range(0, rows.Length)];
long instanceId = _nextTempInstanceId++;
RarityType normalizedRarity = InventoryRarityRuleService.NormalizeComponentRarity(rarity);
return new MuzzleCompItemData
{
InstanceId = _nextTempInstanceId++,
InstanceId = instanceId,
ConfigId = config.Id,
Name = config.Name,
Rarity = InventoryRarityRuleService.NormalizeComponentRarity(rarity),
Rarity = normalizedRarity,
Endurance = 100f,
Constraint = config.Constraint,
Tags = config.PossibleTag != null ? (TagType[])config.PossibleTag.Clone() : Array.Empty<TagType>(),
Tags = InventoryTagRuleService.ResolveComponentTags(
config.PossibleTag,
normalizedRarity,
InventoryTagSourceType.Shop,
instanceId,
config.Id,
_tagMinRarityByTag),
AttackDamage = config.AttackDamage != null ? (int[])config.AttackDamage.Clone() : Array.Empty<int>(),
DamageRandomRate = config.DamageRandomRate,
AttackMethodType = config.AttackMethodType
@@ -195,15 +209,23 @@ namespace GeometryTD.UI
{
DRBearingComp[] rows = _bearingCompTable.GetAllDataRows();
DRBearingComp config = rows[UnityEngine.Random.Range(0, rows.Length)];
long instanceId = _nextTempInstanceId++;
RarityType normalizedRarity = InventoryRarityRuleService.NormalizeComponentRarity(rarity);
return new BearingCompItemData
{
InstanceId = _nextTempInstanceId++,
InstanceId = instanceId,
ConfigId = config.Id,
Name = config.Name,
Rarity = InventoryRarityRuleService.NormalizeComponentRarity(rarity),
Rarity = normalizedRarity,
Endurance = 100f,
Constraint = config.Constraint,
Tags = config.PossibleTag != null ? (TagType[])config.PossibleTag.Clone() : Array.Empty<TagType>(),
Tags = InventoryTagRuleService.ResolveComponentTags(
config.PossibleTag,
normalizedRarity,
InventoryTagSourceType.Shop,
instanceId,
config.Id,
_tagMinRarityByTag),
RotateSpeed = config.RotateSpeed != null ? (float[])config.RotateSpeed.Clone() : Array.Empty<float>(),
AttackRange = config.AttackRange != null ? (float[])config.AttackRange.Clone() : Array.Empty<float>()
};
@@ -213,20 +235,49 @@ namespace GeometryTD.UI
{
DRBaseComp[] rows = _baseCompTable.GetAllDataRows();
DRBaseComp config = rows[UnityEngine.Random.Range(0, rows.Length)];
long instanceId = _nextTempInstanceId++;
RarityType normalizedRarity = InventoryRarityRuleService.NormalizeComponentRarity(rarity);
return new BaseCompItemData
{
InstanceId = _nextTempInstanceId++,
InstanceId = instanceId,
ConfigId = config.Id,
Name = config.Name,
Rarity = InventoryRarityRuleService.NormalizeComponentRarity(rarity),
Rarity = normalizedRarity,
Endurance = 100f,
Constraint = config.Constraint,
Tags = config.PossibleTag != null ? (TagType[])config.PossibleTag.Clone() : Array.Empty<TagType>(),
Tags = InventoryTagRuleService.ResolveComponentTags(
config.PossibleTag,
normalizedRarity,
InventoryTagSourceType.Shop,
instanceId,
config.Id,
_tagMinRarityByTag),
AttackSpeed = config.AttackSpeed != null ? (float[])config.AttackSpeed.Clone() : Array.Empty<float>(),
AttackPropertyType = config.AttackPropertyType
};
}
private void EnsureTagMinRarityLookup()
{
if (_tagMinRarityByTag.Count > 0 || _tagTable == null)
{
return;
}
DRTag[] rows = _tagTable.GetAllDataRows();
for (int i = 0; i < rows.Length; i++)
{
DRTag row = rows[i];
if (row == null || row.Id <= 0)
{
continue;
}
TagType tagType = (TagType)row.Id;
_tagMinRarityByTag[tagType] = row.MinRarity;
}
}
private int ResolveRandomPrice(RarityType rarity)
{
for (int i = 0; i < _shopPriceRows.Count; i++)