diff --git a/OpenRA.Mods.Common/TraitsInterfaces.cs b/OpenRA.Mods.Common/TraitsInterfaces.cs index d3daccd3d4..929ec5410b 100644 --- a/OpenRA.Mods.Common/TraitsInterfaces.cs +++ b/OpenRA.Mods.Common/TraitsInterfaces.cs @@ -555,6 +555,21 @@ namespace OpenRA.Mods.Common.Traits } } + public class EditorActorCheckbox : EditorActorOption + { + public readonly Func GetValue; + public readonly Action OnChange; + + public EditorActorCheckbox(string name, int displayOrder, + Func getValue, + Action onChange) + : base(name, displayOrder) + { + GetValue = getValue; + OnChange = onChange; + } + } + public class EditorActorSlider : EditorActorOption { public readonly float MinValue; diff --git a/OpenRA.Mods.Common/Widgets/Logic/Editor/ActorEditLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Editor/ActorEditLogic.cs index 59e06977de..785f04760d 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Editor/ActorEditLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Editor/ActorEditLogic.cs @@ -36,6 +36,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic readonly Widget initContainer; readonly Widget buttonContainer; + readonly Widget checkboxOptionTemplate; readonly Widget sliderOptionTemplate; readonly Widget dropdownOptionTemplate; @@ -91,6 +92,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic 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(); @@ -264,7 +266,30 @@ namespace OpenRA.Mods.Common.Widgets.Logic 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("OPTION"); + checkbox.GetText = () => co.Name; + + var editorActionHandle = new EditorActorOptionActionHandle(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(); diff --git a/mods/cnc/chrome/editor.yaml b/mods/cnc/chrome/editor.yaml index f345fd774f..9c4cb2d1d6 100644 --- a/mods/cnc/chrome/editor.yaml +++ b/mods/cnc/chrome/editor.yaml @@ -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 diff --git a/mods/common/chrome/editor.yaml b/mods/common/chrome/editor.yaml index 6d12e859e9..0b706eb9b9 100644 --- a/mods/common/chrome/editor.yaml +++ b/mods/common/chrome/editor.yaml @@ -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