为 RepoItem 添加背景耐久变色

This commit is contained in:
SepComet
2026-03-04 19:17:13 +08:00
parent 1e5803f4c5
commit 298345fa17
10 changed files with 424 additions and 232 deletions
@@ -109,6 +109,9 @@ namespace GeometryTD.UI
return System.Array.Empty<RepoItemContext>();
}
Dictionary<long, MuzzleCompItemData> muzzleMap = BuildComponentMap(inventory.MuzzleComponents);
Dictionary<long, BearingCompItemData> bearingMap = BuildComponentMap(inventory.BearingComponents);
Dictionary<long, BaseCompItemData> baseMap = BuildComponentMap(inventory.BaseComponents);
List<RepoItemContext> itemContexts = new List<RepoItemContext>();
if (inventory.Towers != null)
@@ -125,6 +128,7 @@ namespace GeometryTD.UI
{
InstanceId = tower.InstanceId,
CanDrag = false,
EnduranceRate01 = ItemDescUtility.ResolveTowerEnduranceRate(tower, muzzleMap, bearingMap, baseMap),
ComponentSlotType = TowerCompSlotType.None,
IconAreaContext = BuildIconAreaContext(tower)
});
@@ -133,7 +137,7 @@ namespace GeometryTD.UI
tower.InstanceId,
tower.Name,
"Tower",
ItemDescUtility.BuildTowerDesc(tower.Stats) ?? string.Empty,
ItemDescUtility.BuildTowerDesc(tower, muzzleMap, bearingMap, baseMap) ?? string.Empty,
tower.Stats != null ? tower.Stats.Tags : null);
}
}
@@ -152,6 +156,7 @@ namespace GeometryTD.UI
{
InstanceId = item.InstanceId,
CanDrag = false,
EnduranceRate01 = ItemDescUtility.ResolveComponentEnduranceRate(item),
ComponentSlotType = TowerCompSlotType.Muzzle,
IconAreaContext = BuildIconAreaContext(item)
});
@@ -178,6 +183,7 @@ namespace GeometryTD.UI
{
InstanceId = item.InstanceId,
CanDrag = false,
EnduranceRate01 = ItemDescUtility.ResolveComponentEnduranceRate(item),
ComponentSlotType = TowerCompSlotType.Bearing,
IconAreaContext = BuildIconAreaContext(item)
});
@@ -205,6 +211,7 @@ namespace GeometryTD.UI
{
InstanceId = item.InstanceId,
CanDrag = false,
EnduranceRate01 = ItemDescUtility.ResolveComponentEnduranceRate(item),
ComponentSlotType = TowerCompSlotType.Base,
IconAreaContext = BuildIconAreaContext(item)
});
@@ -254,6 +261,29 @@ namespace GeometryTD.UI
};
}
private static Dictionary<long, TComp> BuildComponentMap<TComp>(IReadOnlyList<TComp> items)
where TComp : TowerCompItemData
{
Dictionary<long, TComp> map = new Dictionary<long, TComp>();
if (items == null)
{
return map;
}
for (int i = 0; i < items.Count; i++)
{
TComp item = items[i];
if (item == null || item.InstanceId <= 0)
{
continue;
}
map[item.InstanceId] = item;
}
return map;
}
private static IconAreaContext BuildIconAreaContext(TowerItemData tower)
{
if (tower == null)