Add EditorActorCheckbox plumbing.

This commit is contained in:
Paul Chote
2019-08-16 10:09:52 +01:00
committed by abcdefg30
parent 5eaa99827d
commit 966290a623
4 changed files with 59 additions and 1 deletions

View File

@@ -555,6 +555,21 @@ namespace OpenRA.Mods.Common.Traits
} }
} }
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 class EditorActorSlider : EditorActorOption
{ {
public readonly float MinValue; public readonly float MinValue;

View File

@@ -36,6 +36,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
readonly Widget initContainer; readonly Widget initContainer;
readonly Widget buttonContainer; readonly Widget buttonContainer;
readonly Widget checkboxOptionTemplate;
readonly Widget sliderOptionTemplate; readonly Widget sliderOptionTemplate;
readonly Widget dropdownOptionTemplate; readonly Widget dropdownOptionTemplate;
@@ -91,6 +92,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
initContainer = actorEditPanel.Get("ACTOR_INIT_CONTAINER"); initContainer = actorEditPanel.Get("ACTOR_INIT_CONTAINER");
buttonContainer = actorEditPanel.Get("BUTTON_CONTAINER"); buttonContainer = actorEditPanel.Get("BUTTON_CONTAINER");
checkboxOptionTemplate = initContainer.Get("CHECKBOX_OPTION_TEMPLATE");
sliderOptionTemplate = initContainer.Get("SLIDER_OPTION_TEMPLATE"); sliderOptionTemplate = initContainer.Get("SLIDER_OPTION_TEMPLATE");
dropdownOptionTemplate = initContainer.Get("DROPDOWN_OPTION_TEMPLATE"); dropdownOptionTemplate = initContainer.Get("DROPDOWN_OPTION_TEMPLATE");
initContainer.RemoveChildren(); initContainer.RemoveChildren();
@@ -264,7 +266,30 @@ namespace OpenRA.Mods.Common.Widgets.Logic
foreach (var o in options) 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 so = (EditorActorSlider)o;
var sliderContainer = sliderOptionTemplate.Clone(); var sliderContainer = sliderOptionTemplate.Clone();

View File

@@ -258,6 +258,15 @@ Container@EDITOR_WORLD_ROOT:
Y: 57 Y: 57
Width: PARENT_RIGHT Width: PARENT_RIGHT
Children: 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: Container@SLIDER_OPTION_TEMPLATE:
Width: PARENT_RIGHT Width: PARENT_RIGHT
Height: 22 Height: 22

View File

@@ -251,6 +251,15 @@ Container@EDITOR_WORLD_ROOT:
Y: 73 Y: 73
Width: PARENT_RIGHT Width: PARENT_RIGHT
Children: 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: Container@SLIDER_OPTION_TEMPLATE:
Width: PARENT_RIGHT Width: PARENT_RIGHT
Height: 22 Height: 22