diff --git a/OpenRA.Mods.Common/Traits/World/EditorActorLayer.cs b/OpenRA.Mods.Common/Traits/World/EditorActorLayer.cs index be9107ff52..f175ce72d0 100644 --- a/OpenRA.Mods.Common/Traits/World/EditorActorLayer.cs +++ b/OpenRA.Mods.Common/Traits/World/EditorActorLayer.cs @@ -140,6 +140,8 @@ namespace OpenRA.Mods.Common.Traits foreach (var cell in footprint) AddPreviewLocation(preview, cell); + preview.AddedToEditor(); + if (!initialSetup) { UpdateNeighbours(preview.Footprint); @@ -171,6 +173,7 @@ namespace OpenRA.Mods.Common.Traits cellMap.Remove(cell); } + preview.RemovedFromEditor(); UpdateNeighbours(preview.Footprint); if (preview.Info.Name == "mpspawn") diff --git a/OpenRA.Mods.Common/Traits/World/EditorActorPreview.cs b/OpenRA.Mods.Common/Traits/World/EditorActorPreview.cs index ce1265fa9a..2cad5cf300 100644 --- a/OpenRA.Mods.Common/Traits/World/EditorActorPreview.cs +++ b/OpenRA.Mods.Common/Traits/World/EditorActorPreview.cs @@ -45,12 +45,13 @@ 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; readonly WorldRenderer worldRenderer; readonly TooltipInfoBase tooltip; IActorPreview[] previews; readonly ActorReference reference; - public readonly Color RadarColor; + readonly Dictionary editorData = new Dictionary(); public EditorActorPreview(WorldRenderer worldRenderer, string id, ActorReference reference, PlayerReference owner) { @@ -131,6 +132,18 @@ namespace OpenRA.Mods.Common.Traits yield return SelectionBox; } + public void AddedToEditor() + { + foreach (var notify in Info.TraitInfos()) + editorData[notify] = notify.AddedToEditor(this, worldRenderer.World); + } + + public void RemovedFromEditor() + { + foreach (var kv in editorData) + kv.Key.RemovedFromEditor(this, worldRenderer.World, kv.Value); + } + public void AddInit(T init) where T : ActorInit { reference.Add(init); diff --git a/OpenRA.Mods.Common/TraitsInterfaces.cs b/OpenRA.Mods.Common/TraitsInterfaces.cs index 8ff9541cda..ab6793d3c0 100644 --- a/OpenRA.Mods.Common/TraitsInterfaces.cs +++ b/OpenRA.Mods.Common/TraitsInterfaces.cs @@ -590,6 +590,13 @@ namespace OpenRA.Mods.Common.Traits } } + [RequireExplicitImplementation] + public interface INotifyEditorPlacementInfo : ITraitInfoInterface + { + object AddedToEditor(EditorActorPreview preview, World editorWorld); + void RemovedFromEditor(EditorActorPreview preview, World editorWorld, object data); + } + [RequireExplicitImplementation] public interface IPreventMapSpawn {