Add "Spawn Child Actor" checkbox in the map editor actor properties.

This commit is contained in:
Paul Chote
2019-08-16 10:10:13 +01:00
committed by abcdefg30
parent 966290a623
commit c08e290f44

View File

@@ -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<EditorActorOption> IEditorActorOptions.ActorOptions(ActorInfo ai, World world)
{
yield return new EditorActorCheckbox("Spawn Child Actor", EditorFreeActorDisplayOrder,
actor =>
{
var init = actor.Init<FreeActorInit>();
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); }
}