mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-09-02 18:17:09 +02:00
88 lines
2.5 KiB
C#
88 lines
2.5 KiB
C#
using System.Globalization;
|
|
using System.Numerics;
|
|
using Robust.Client.UserInterface;
|
|
using Robust.Client.UserInterface.Controls;
|
|
using Robust.Shared.Maths;
|
|
using static Robust.Client.UserInterface.Controls.BoxContainer;
|
|
|
|
namespace Robust.Client.ViewVariables.Editors
|
|
{
|
|
internal sealed class VVPropEditorVector2 : VVPropEditor
|
|
{
|
|
private readonly bool _intVec;
|
|
|
|
public VVPropEditorVector2(bool intVec)
|
|
{
|
|
_intVec = intVec;
|
|
}
|
|
|
|
protected override Control MakeUI(object? value)
|
|
{
|
|
var hBoxContainer = new BoxContainer
|
|
{
|
|
Orientation = LayoutOrientation.Horizontal,
|
|
MinSize = new Vector2(240, 0),
|
|
};
|
|
|
|
var x = new LineEdit
|
|
{
|
|
Editable = !ReadOnly,
|
|
HorizontalExpand = true,
|
|
PlaceHolder = "X",
|
|
ToolTip = "X"
|
|
};
|
|
|
|
hBoxContainer.AddChild(x);
|
|
|
|
var y = new LineEdit
|
|
{
|
|
Editable = !ReadOnly,
|
|
HorizontalExpand = true,
|
|
PlaceHolder = "Y",
|
|
ToolTip = "Y"
|
|
};
|
|
|
|
hBoxContainer.AddChild(y);
|
|
|
|
if (_intVec)
|
|
{
|
|
var vec = (Vector2i) value!;
|
|
x.Text = vec.X.ToString(CultureInfo.InvariantCulture);
|
|
y.Text = vec.Y.ToString(CultureInfo.InvariantCulture);
|
|
}
|
|
else
|
|
{
|
|
var vec = (Vector2) value!;
|
|
x.Text = vec.X.ToString(CultureInfo.InvariantCulture);
|
|
y.Text = vec.Y.ToString(CultureInfo.InvariantCulture);
|
|
}
|
|
|
|
void OnEntered(LineEdit.LineEditEventArgs e)
|
|
{
|
|
if (_intVec)
|
|
{
|
|
var xVal = int.Parse(x.Text, CultureInfo.InvariantCulture);
|
|
var yVal = int.Parse(y.Text, CultureInfo.InvariantCulture);
|
|
|
|
ValueChanged(new Vector2i(xVal, yVal));
|
|
}
|
|
else
|
|
{
|
|
var xVal = float.Parse(x.Text, CultureInfo.InvariantCulture);
|
|
var yVal = float.Parse(y.Text, CultureInfo.InvariantCulture);
|
|
|
|
ValueChanged(new Vector2(xVal, yVal));
|
|
}
|
|
}
|
|
|
|
if (!ReadOnly)
|
|
{
|
|
x.OnTextEntered += OnEntered;
|
|
y.OnTextEntered += OnEntered;
|
|
}
|
|
|
|
return hBoxContainer;
|
|
}
|
|
}
|
|
}
|