Fix radar preview not updating when editing actor owner

This commit is contained in:
abc013
2021-10-21 16:02:07 +02:00
committed by Matthias Mailänder
parent 3bee524c6b
commit 0898655175

View File

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