为 RepoItem 添加背景耐久变色
This commit is contained in:
@@ -8,6 +8,7 @@ namespace GeometryTD.UI
|
||||
{
|
||||
public long InstanceId;
|
||||
public bool CanDrag;
|
||||
public float EnduranceRate01;
|
||||
public TowerCompSlotType ComponentSlotType;
|
||||
public IconAreaContext IconAreaContext;
|
||||
}
|
||||
|
||||
@@ -102,6 +102,9 @@ namespace GeometryTD.UI
|
||||
return null;
|
||||
}
|
||||
|
||||
Dictionary<long, MuzzleCompItemData> muzzleMap = BuildComponentMap(rawData.Inventory.MuzzleComponents);
|
||||
Dictionary<long, BearingCompItemData> bearingMap = BuildComponentMap(rawData.Inventory.BearingComponents);
|
||||
Dictionary<long, BaseCompItemData> baseMap = BuildComponentMap(rawData.Inventory.BaseComponents);
|
||||
List<RepoItemContext> items = new List<RepoItemContext>();
|
||||
|
||||
if (rawData.Inventory.Towers != null)
|
||||
@@ -117,6 +120,7 @@ namespace GeometryTD.UI
|
||||
{
|
||||
InstanceId = tower.InstanceId,
|
||||
CanDrag = true,
|
||||
EnduranceRate01 = ItemDescUtility.ResolveTowerEnduranceRate(tower, muzzleMap, bearingMap, baseMap),
|
||||
ComponentSlotType = TowerCompSlotType.None,
|
||||
IconAreaContext = BuildIconAreaContext(tower)
|
||||
});
|
||||
@@ -124,7 +128,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);
|
||||
}
|
||||
}
|
||||
@@ -142,6 +146,7 @@ namespace GeometryTD.UI
|
||||
{
|
||||
InstanceId = item.InstanceId,
|
||||
CanDrag = true,
|
||||
EnduranceRate01 = ItemDescUtility.ResolveComponentEnduranceRate(item),
|
||||
ComponentSlotType = TowerCompSlotType.Muzzle,
|
||||
IconAreaContext = BuildIconAreaContext(item)
|
||||
});
|
||||
@@ -167,6 +172,7 @@ namespace GeometryTD.UI
|
||||
{
|
||||
InstanceId = item.InstanceId,
|
||||
CanDrag = true,
|
||||
EnduranceRate01 = ItemDescUtility.ResolveComponentEnduranceRate(item),
|
||||
ComponentSlotType = TowerCompSlotType.Bearing,
|
||||
IconAreaContext = BuildIconAreaContext(item)
|
||||
});
|
||||
@@ -192,6 +198,7 @@ namespace GeometryTD.UI
|
||||
{
|
||||
InstanceId = item.InstanceId,
|
||||
CanDrag = true,
|
||||
EnduranceRate01 = ItemDescUtility.ResolveComponentEnduranceRate(item),
|
||||
ComponentSlotType = TowerCompSlotType.Base,
|
||||
IconAreaContext = BuildIconAreaContext(item)
|
||||
});
|
||||
@@ -258,6 +265,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)
|
||||
|
||||
@@ -57,7 +57,7 @@ namespace GeometryTD.UI
|
||||
ConfigId = 2,
|
||||
Name = "控制枪口",
|
||||
Rarity = RarityType.Blue,
|
||||
Endurance = 100f,
|
||||
Endurance = 80,
|
||||
IsAssembledIntoTower = false,
|
||||
AttackDamage = new[] { 30, 50, 70, 90, 100 },
|
||||
DamageRandomRate = 0.01f,
|
||||
@@ -86,7 +86,7 @@ namespace GeometryTD.UI
|
||||
ConfigId = 1,
|
||||
Name = "元素轴承",
|
||||
Rarity = RarityType.Green,
|
||||
Endurance = 95f,
|
||||
Endurance = 1f,
|
||||
IsAssembledIntoTower = true,
|
||||
RotateSpeed = new[] { 10f, 12f, 13f, 14f, 15f },
|
||||
AttackRange = new[] { 2f, 2f, 2f, 2f, 2f },
|
||||
@@ -100,7 +100,7 @@ namespace GeometryTD.UI
|
||||
ConfigId = 2,
|
||||
Name = "控制轴承",
|
||||
Rarity = RarityType.Blue,
|
||||
Endurance = 100f,
|
||||
Endurance = 20,
|
||||
IsAssembledIntoTower = false,
|
||||
RotateSpeed = new[] { 20f, 25f, 30f, 32f, 35f },
|
||||
AttackRange = new[] { 6f, 6.5f, 7f, 8f, 8f },
|
||||
@@ -141,7 +141,7 @@ namespace GeometryTD.UI
|
||||
ConfigId = 2,
|
||||
Name = "控制底座",
|
||||
Rarity = RarityType.Blue,
|
||||
Endurance = 100f,
|
||||
Endurance = 50f,
|
||||
IsAssembledIntoTower = false,
|
||||
AttackSpeed = new[] { 4f, 4.2f, 4.4f, 4.6f, 4.8f },
|
||||
AttackPropertyType = AttackPropertyType.Ice,
|
||||
@@ -154,7 +154,7 @@ namespace GeometryTD.UI
|
||||
ConfigId = 3,
|
||||
Name = "穿透底座",
|
||||
Rarity = RarityType.Purple,
|
||||
Endurance = 95f,
|
||||
Endurance = 30f,
|
||||
IsAssembledIntoTower = false,
|
||||
AttackSpeed = new[] { 1f, 1f, 1f, 1f, 1f },
|
||||
AttackPropertyType = AttackPropertyType.Physics,
|
||||
|
||||
@@ -9,11 +9,13 @@ namespace GeometryTD.UI
|
||||
{
|
||||
public class RepoItem : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler
|
||||
{
|
||||
[SerializeField] private Image _highlightImage;
|
||||
[SerializeField] private Image _bgImage;
|
||||
|
||||
[SerializeField] private IconArea _iconArea;
|
||||
|
||||
private static readonly Color NormalColor = new Color32(40, 40, 40, 180);
|
||||
private static readonly Color SelectedColor = new Color32(255, 216, 102, 255);
|
||||
private static readonly Color EmptyEnduranceColor = new Color(0.8f, 0f, 0f, 1f);
|
||||
private static readonly Color FullEnduranceColor = new Color(0f, 0.8f, 0f, 1f);
|
||||
private static readonly Vector2 DefaultDragGhostSize = new Vector2(64f, 64f);
|
||||
|
||||
[SerializeField] private RepoItemContext _context;
|
||||
@@ -74,12 +76,24 @@ namespace GeometryTD.UI
|
||||
public void SetSelected(bool isSelected)
|
||||
{
|
||||
_isSelected = isSelected;
|
||||
if (_highlightImage == null)
|
||||
RefreshBackgroundColor();
|
||||
}
|
||||
|
||||
private void RefreshBackgroundColor()
|
||||
{
|
||||
if (_bgImage == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_highlightImage.color = isSelected ? SelectedColor : NormalColor;
|
||||
if (_isSelected)
|
||||
{
|
||||
_bgImage.color = SelectedColor;
|
||||
return;
|
||||
}
|
||||
|
||||
float enduranceRate = _context != null ? Mathf.Clamp01(_context.EnduranceRate01) : 1f;
|
||||
_bgImage.color = Color.Lerp(EmptyEnduranceColor, FullEnduranceColor, enduranceRate);
|
||||
}
|
||||
|
||||
public void OnClick()
|
||||
|
||||
Reference in New Issue
Block a user