Add INotifyEditorPlacementInfo interface.
This allows TraitInfos to act when the actor preview is placed in the editor, returning arbitrary data which the editor stores and gives back if the preview is removed.
This commit is contained in:
@@ -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")
|
||||
|
||||
@@ -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<INotifyEditorPlacementInfo, object> editorData = new Dictionary<INotifyEditorPlacementInfo, object>();
|
||||
|
||||
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<INotifyEditorPlacementInfo>())
|
||||
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>(T init) where T : ActorInit
|
||||
{
|
||||
reference.Add(init);
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user