diff --git a/OpenRA.Mods.Common/Traits/World/EditorActorPreview.cs b/OpenRA.Mods.Common/Traits/World/EditorActorPreview.cs index f59bb46381..51d934f29a 100644 --- a/OpenRA.Mods.Common/Traits/World/EditorActorPreview.cs +++ b/OpenRA.Mods.Common/Traits/World/EditorActorPreview.cs @@ -40,7 +40,8 @@ namespace OpenRA.Mods.Common.Traits public PlayerReference Owner { get; set; } public SubCell SubCell { get; private set; } public bool Selected { get; set; } - public readonly Color RadarColor; + public Color RadarColor { get; private set; } + readonly RadarColorFromTerrainInfo terrainRadarColorInfo; readonly WorldRenderer worldRenderer; readonly TooltipInfoBase tooltip; @@ -73,9 +74,6 @@ namespace OpenRA.Mods.Common.Traits var subCellInit = reference.GetOrDefault(); var subCell = subCellInit != null ? subCellInit.Value : SubCell.Any; - var radarColorInfo = Info.TraitInfoOrDefault(); - RadarColor = radarColorInfo == null ? owner.Color : radarColorInfo.GetColorFromTerrain(world); - Footprint = ios?.OccupiedCells(Info, location, subCell) ?? new Dictionary() { { location, SubCell.FullCell } }; tooltip = Info.TraitInfos().FirstOrDefault(info => info.EnabledByDefault) as TooltipInfoBase @@ -85,6 +83,9 @@ namespace OpenRA.Mods.Common.Traits GeneratePreviews(); + terrainRadarColorInfo = Info.TraitInfoOrDefault(); + UpdateRadarColor(); + // Bounds are fixed from the initial render. // If this is a problem, then we may need to fetch the area from somewhere else var r = previews.SelectMany(p => p.ScreenBounds(worldRenderer, CenterPosition)); @@ -191,6 +192,7 @@ namespace OpenRA.Mods.Common.Traits reference.Add(init); GeneratePreviews(); + UpdateRadarColor(); } public void RemoveInit() where T : ActorInit, ISingleInstanceInit @@ -251,6 +253,11 @@ namespace OpenRA.Mods.Common.Traits .ToArray(); } + void UpdateRadarColor() + { + RadarColor = terrainRadarColorInfo == null ? Owner.Color : terrainRadarColorInfo.GetColorFromTerrain(worldRenderer.World); + } + public ActorReference Export() { return reference.Clone();