Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "Spawn Child Actor" and "Deployed" checkboxes to the map editor. #16947

Merged
merged 3 commits into from Oct 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 22 additions & 1 deletion OpenRA.Mods.Common/Traits/Buildings/FreeActor.cs
Expand Up @@ -9,14 +9,15 @@
*/
#endregion

using System.Collections.Generic;
using OpenRA.Primitives;
using OpenRA.Traits;

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]
Expand All @@ -32,6 +33,26 @@ public class FreeActorInfo : ConditionalTraitInfo
[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); }
}

Expand Down
22 changes: 21 additions & 1 deletion OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnDeploy.cs
Expand Up @@ -20,7 +20,7 @@ namespace OpenRA.Mods.Common.Traits
{
[Desc("Grants a condition when a deploy order is issued." +
"Can be paused with the granted condition to disable undeploying.")]
public class GrantConditionOnDeployInfo : PausableConditionalTraitInfo
public class GrantConditionOnDeployInfo : PausableConditionalTraitInfo, IEditorActorOptions
{
[GrantedConditionReference]
[Desc("The condition to grant while the actor is undeployed.")]
Expand Down Expand Up @@ -61,6 +61,26 @@ public class GrantConditionOnDeployInfo : PausableConditionalTraitInfo
[VoiceReference]
public readonly string Voice = "Action";

[Desc("Display order for the deployed checkbox in the map editor")]
public readonly int EditorDeployedDisplayOrder = 4;

IEnumerable<EditorActorOption> IEditorActorOptions.ActorOptions(ActorInfo ai, World world)
{
yield return new EditorActorCheckbox("Deployed", EditorDeployedDisplayOrder,
actor =>
{
var init = actor.Init<DeployStateInit>();
if (init != null)
return init.Value(world) == DeployState.Deployed;

return false;
},
(actor, value) =>
{
actor.ReplaceInit(new DeployStateInit(value ? DeployState.Deployed : DeployState.Undeployed));
});
}

public override object Create(ActorInitializer init) { return new GrantConditionOnDeploy(init, this); }
}

Expand Down
15 changes: 15 additions & 0 deletions OpenRA.Mods.Common/TraitsInterfaces.cs
Expand Up @@ -555,6 +555,21 @@ public EditorActorOption(string name, int displayOrder)
}
}

public class EditorActorCheckbox : EditorActorOption
{
public readonly Func<EditorActorPreview, bool> GetValue;
public readonly Action<EditorActorPreview, bool> OnChange;

public EditorActorCheckbox(string name, int displayOrder,
Func<EditorActorPreview, bool> getValue,
Action<EditorActorPreview, bool> onChange)
: base(name, displayOrder)
{
GetValue = getValue;
OnChange = onChange;
}
}

public class EditorActorSlider : EditorActorOption
{
public readonly float MinValue;
Expand Down
27 changes: 26 additions & 1 deletion OpenRA.Mods.Common/Widgets/Logic/Editor/ActorEditLogic.cs
Expand Up @@ -36,6 +36,7 @@ enum ActorIDStatus { Normal = 0, Duplicate = 1, Empty = 3 }
readonly Widget initContainer;
readonly Widget buttonContainer;

readonly Widget checkboxOptionTemplate;
readonly Widget sliderOptionTemplate;
readonly Widget dropdownOptionTemplate;

Expand Down Expand Up @@ -91,6 +92,7 @@ public ActorEditLogic(Widget widget, World world, WorldRenderer worldRenderer, D
initContainer = actorEditPanel.Get("ACTOR_INIT_CONTAINER");
buttonContainer = actorEditPanel.Get("BUTTON_CONTAINER");

checkboxOptionTemplate = initContainer.Get("CHECKBOX_OPTION_TEMPLATE");
sliderOptionTemplate = initContainer.Get("SLIDER_OPTION_TEMPLATE");
dropdownOptionTemplate = initContainer.Get("DROPDOWN_OPTION_TEMPLATE");
initContainer.RemoveChildren();
Expand Down Expand Up @@ -264,7 +266,30 @@ public override void Tick()

foreach (var o in options)
{
if (o is EditorActorSlider)
if (o is EditorActorCheckbox)
{
var co = (EditorActorCheckbox)o;
var checkboxContainer = checkboxOptionTemplate.Clone();
checkboxContainer.Bounds.Y = initContainer.Bounds.Height;
initContainer.Bounds.Height += checkboxContainer.Bounds.Height;

var checkbox = checkboxContainer.Get<CheckboxWidget>("OPTION");
checkbox.GetText = () => co.Name;

var editorActionHandle = new EditorActorOptionActionHandle<bool>(co.OnChange, co.GetValue(actor));
editActorPreview.Add(editorActionHandle);

checkbox.IsChecked = () => co.GetValue(actor);
checkbox.OnClick = () =>
{
var newValue = co.GetValue(actor) ^ true;
co.OnChange(actor, newValue);
editorActionHandle.OnChange(newValue);
};

initContainer.AddChild(checkboxContainer);
}
else if (o is EditorActorSlider)
{
var so = (EditorActorSlider)o;
var sliderContainer = sliderOptionTemplate.Clone();
Expand Down
9 changes: 9 additions & 0 deletions mods/cnc/chrome/editor.yaml
Expand Up @@ -258,6 +258,15 @@ Container@EDITOR_WORLD_ROOT:
Y: 57
Width: PARENT_RIGHT
Children:
Container@CHECKBOX_OPTION_TEMPLATE:
Width: PARENT_RIGHT
Height: 22
Children:
Checkbox@OPTION:
X: 67
Y: 1
Width: PARENT_RIGHT - 67
Height: 20
Container@SLIDER_OPTION_TEMPLATE:
Width: PARENT_RIGHT
Height: 22
Expand Down
9 changes: 9 additions & 0 deletions mods/common/chrome/editor.yaml
Expand Up @@ -251,6 +251,15 @@ Container@EDITOR_WORLD_ROOT:
Y: 73
Width: PARENT_RIGHT
Children:
Container@CHECKBOX_OPTION_TEMPLATE:
Width: PARENT_RIGHT
Height: 22
Children:
Checkbox@OPTION:
X: 84
Y: 1
Width: PARENT_RIGHT - 84
Height: 20
Container@SLIDER_OPTION_TEMPLATE:
Width: PARENT_RIGHT
Height: 22
Expand Down