- 统一 ItemDescForm/RewardItem/GoodsItem 的描述格式
- 减少组件属性的 Clone 数量,目前只在合并仓库、组装防御塔时才进行复制
- 删除先前留下的冗余 fallback 代码
This commit is contained in:
SepComet
2026-03-12 15:58:14 +08:00
parent 9e59865368
commit 4962b98714
20 changed files with 263 additions and 435 deletions
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 4e2db7f572fa423f8eb29a8c796b952d
timeCreated: 1773300865
@@ -28,7 +28,7 @@ namespace GeometryTD.UI
if (rawData.Inventory.Towers != null)
{
foreach (TowerItemData tower in rawData.Inventory.Towers)
foreach (var tower in rawData.Inventory.Towers)
{
if (tower == null)
{
@@ -50,7 +50,7 @@ namespace GeometryTD.UI
if (rawData.Inventory.MuzzleComponents != null)
{
foreach (MuzzleCompItemData item in rawData.Inventory.MuzzleComponents)
foreach (var item in rawData.Inventory.MuzzleComponents)
{
if (item == null || item.IsAssembledIntoTower)
{
@@ -191,8 +191,8 @@ namespace GeometryTD.UI
Title = string.IsNullOrWhiteSpace(title) ? $"Item {itemId}" : title,
TypeText = typeText ?? string.Empty,
Description = description ?? string.Empty,
Tags = CloneTags(tags),
TagRuntimes = CloneTagRuntimes(tagRuntimes)
Tags = tags,
TagRuntimes = tagRuntimes
};
}
@@ -217,9 +217,8 @@ namespace GeometryTD.UI
return map;
}
for (int i = 0; i < items.Count; i++)
foreach (var item in items)
{
TComp item = items[i];
if (item == null || item.InstanceId <= 0)
{
continue;
@@ -239,9 +238,8 @@ namespace GeometryTD.UI
return map;
}
for (int i = 0; i < towers.Count; i++)
foreach (var tower in towers)
{
TowerItemData tower = towers[i];
if (tower == null || tower.InstanceId <= 0)
{
continue;
@@ -264,9 +262,8 @@ namespace GeometryTD.UI
List<TowerRepoItemContext> participantItems = new List<TowerRepoItemContext>();
if (inventory?.ParticipantTowerInstanceIds != null && towerMap != null)
{
for (int i = 0; i < inventory.ParticipantTowerInstanceIds.Count; i++)
foreach (var towerId in inventory.ParticipantTowerInstanceIds)
{
long towerId = inventory.ParticipantTowerInstanceIds[i];
if (towerId <= 0)
{
continue;
@@ -0,0 +1,142 @@
using System;
using GeometryTD.CustomUtility;
using GeometryTD.Definition;
using UnityEngine;
namespace GeometryTD.UI
{
public partial class RewardSelectFormController
{
private static RewardSelectFormContext BuildContext(RewardSelectFormRawData rawData)
{
if (rawData == null)
{
return null;
}
return new RewardSelectFormContext
{
TipText = string.IsNullOrWhiteSpace(rawData.TipText) ? "Select one reward" : rawData.TipText,
RefreshButtonText = BuildRefreshButtonText(rawData.RefreshCost, rawData.CanRefresh),
CanRefresh = rawData.CanRefresh,
CanGiveUp = rawData.CanGiveUp,
RewardItems = BuildRewardItemContexts(rawData.RewardItems)
};
}
private static string BuildRefreshButtonText(int refreshCost, bool canRefresh)
{
if (!canRefresh)
{
return "Refreshed";
}
if (refreshCost <= 0)
{
return "Refresh";
}
return $"Refresh -{refreshCost}";
}
private static RewardItemContext[] BuildRewardItemContexts(RewardSelectItemRawData[] rawItems)
{
if (rawItems == null || rawItems.Length <= 0)
{
return Array.Empty<RewardItemContext>();
}
RewardItemContext[] contexts = new RewardItemContext[rawItems.Length];
for (int i = 0; i < rawItems.Length; i++)
{
RewardSelectItemRawData rawItem = rawItems[i];
if (rawItem == null)
{
continue;
}
contexts[i] = new RewardItemContext
{
Index = i,
IconArea = new IconAreaContext
{
ComponentSlotType = rawItem.SlotType,
Icon = rawItem.Icon,
Rarity = rawItem.Rarity,
Color = ResolveIconColor(rawItem.SourceItem)
},
Title = rawItem.Title ?? string.Empty,
TypeText = ResolveTypeText(rawItem.TypeText, rawItem.SlotType),
Description = BuildDescription(rawItem),
Tags = BuildTagContexts(rawItem),
};
}
return contexts;
}
private static string BuildDescription(RewardSelectItemRawData rawItem)
{
string baseDescription = rawItem.Description;
string tagDescription = TagDisplayUtility.BuildTagDescriptionText(rawItem.Tags);
if (string.IsNullOrWhiteSpace(tagDescription))
{
return baseDescription;
}
if (string.IsNullOrWhiteSpace(baseDescription))
{
return tagDescription;
}
return $"{baseDescription}\n{tagDescription}";
}
private static Color ResolveIconColor(TowerCompItemData sourceItem)
{
if (sourceItem == null)
{
return Color.white;
}
return IconColorGenerator.GenerateForComponent(sourceItem);
}
private static string ResolveTypeText(string typeText, TowerCompSlotType slotType)
{
if (!string.IsNullOrWhiteSpace(typeText))
{
return typeText;
}
return slotType switch
{
TowerCompSlotType.Muzzle => "Muzzle Component",
TowerCompSlotType.Bearing => "Bearing Component",
TowerCompSlotType.Base => "Base Component",
TowerCompSlotType.Accessory => "Accessory",
_ => "Component"
};
}
private static TagItemContext[] BuildTagContexts(RewardSelectItemRawData rawItem)
{
string[] tagTexts = TagDisplayUtility.BuildTagTexts(rawItem?.Tags);
if (tagTexts == null || tagTexts.Length <= 0)
{
return 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;
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 869dc47fc2a44b53bf56890fdd65af81
timeCreated: 1773300896
@@ -153,21 +153,11 @@ namespace GeometryTD.UI
Description = seed.Description ?? string.Empty,
Price = 0,
ScreenPosition = args.ScreenPosition,
Tags = CloneTags(seed.Tags),
TagRuntimes = CloneTagRuntimes(seed.TagRuntimes)
Tags = seed.Tags,
TagRuntimes = seed.TagRuntimes
});
}
private static TagType[] CloneTags(TagType[] tags)
{
return tags != null ? (TagType[])tags.Clone() : System.Array.Empty<TagType>();
}
private static TagRuntimeData[] CloneTagRuntimes(TagRuntimeData[] tagRuntimes)
{
return InventoryCloneUtility.CloneTagRuntimes(tagRuntimes);
}
private void OnRepoItemDragEnded(object sender, GameEventArgs e)
{
if (!IsEventFromCurrentForm(sender))
@@ -320,9 +310,5 @@ namespace GeometryTD.UI
}
#endregion
private static string[] CloneTagTexts(string[] tagTexts)
{
return tagTexts != null ? (string[])tagTexts.Clone() : System.Array.Empty<string>();
}
}
}