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 => so.OnChange(actor, value);
slider.OnChange += value => editorActionHandle.OnChange(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); initContainer.AddChild(sliderContainer);
} }
else if (o is EditorActorDropdown) else if (o is EditorActorDropdown)

View File

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

View File

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

View File

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