From c08e290f44c071d75dc3d1b2407f05ff7ddec74a Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Fri, 16 Aug 2019 10:10:13 +0100 Subject: [PATCH] Add "Spawn Child Actor" checkbox in the map editor actor properties. --- .../Traits/Buildings/FreeActor.cs | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/OpenRA.Mods.Common/Traits/Buildings/FreeActor.cs b/OpenRA.Mods.Common/Traits/Buildings/FreeActor.cs index 2f6ce6b045..541c98cb9d 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/FreeActor.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/FreeActor.cs @@ -9,6 +9,7 @@ */ #endregion +using System.Collections.Generic; using OpenRA.Primitives; using OpenRA.Traits; @@ -16,7 +17,7 @@ namespace OpenRA.Mods.Common.Traits { [Desc("Player receives a unit for free once the building is placed. This also works for structures.", "If you want more than one unit to appear copy this section and assign IDs like FreeActor@2, ...")] - public class FreeActorInfo : ConditionalTraitInfo + public class FreeActorInfo : ConditionalTraitInfo, IEditorActorOptions { [ActorReference] [FieldLoader.Require] @@ -32,6 +33,26 @@ namespace OpenRA.Mods.Common.Traits [Desc("Whether another actor should spawn upon re-enabling the trait.")] public readonly bool AllowRespawn = false; + [Desc("Display order for the free actor checkbox in the map editor")] + public readonly int EditorFreeActorDisplayOrder = 4; + + IEnumerable IEditorActorOptions.ActorOptions(ActorInfo ai, World world) + { + yield return new EditorActorCheckbox("Spawn Child Actor", EditorFreeActorDisplayOrder, + actor => + { + var init = actor.Init(); + if (init != null) + return init.Value(world); + + return true; + }, + (actor, value) => + { + actor.ReplaceInit(new FreeActorInit(value)); + }); + } + public override object Create(ActorInitializer init) { return new FreeActor(init, this); } }