Add a text field next to the map editor actor initializer sliders.

This commit is contained in:
Niklas Holma
2020-09-27 18:49:17 +01:00
committed by abcdefg30
parent b5613acad8
commit 8596ce00cc
4 changed files with 33 additions and 5 deletions

View File

@@ -308,6 +308,20 @@ namespace OpenRA.Mods.Common.Widgets.Logic
slider.OnChange += value => so.OnChange(actor, value);
slider.OnChange += value => editorActionHandle.OnChange(value);
var valueField = sliderContainer.GetOrNull<TextFieldWidget>("VALUE");
if (valueField != null)
{
Action<float> updateValueField = f => valueField.Text = ((int)f).ToString();
updateValueField(so.GetValue(actor));
slider.OnChange += updateValueField;
valueField.OnTextEdited = () =>
{
if (float.TryParse(valueField.Text, out var result))
slider.UpdateValue(result);
};
}
initContainer.AddChild(sliderContainer);
}
else if (o is EditorActorDropdown)

View File

@@ -48,9 +48,11 @@ namespace OpenRA.Mods.Common.Widgets
GetValue = other.GetValue;
}
void UpdateValue(float newValue)
public void UpdateValue(float newValue)
{
var oldValue = Value;
Value = newValue.Clamp(MinimumValue, MaximumValue);
if (oldValue != Value)
OnChange(Value);
}
@@ -114,7 +116,7 @@ namespace OpenRA.Mods.Common.Widgets
if (!IsVisible())
return;
Value = GetValue();
UpdateValue(GetValue());
var tr = ThumbRect;
var rb = RenderBounds;

View File

@@ -277,8 +277,14 @@ Container@EDITOR_WORLD_ROOT:
Slider@OPTION:
X: 58
Y: 1
Width: 207
Width: 146
Height: 20
TextField@VALUE:
X: 206
Y: 1
Width: 50
Height: 20
Type: Integer
Container@DROPDOWN_OPTION_TEMPLATE:
Width: PARENT_RIGHT
Height: 27

View File

@@ -271,8 +271,14 @@ Container@EDITOR_WORLD_ROOT:
Slider@OPTION:
X: 75
Y: 1
Width: 210
Width: 149
Height: 20
TextField@VALUE:
X: 226
Y: 1
Width: 50
Height: 20
Type: Integer
Container@DROPDOWN_OPTION_TEMPLATE:
Width: PARENT_RIGHT
Height: 27