Skip to content

Commit

Permalink
VV editor for EntProtoId? (#4986)
Browse files Browse the repository at this point in the history
Co-authored-by: wrexbe <[email protected]>
  • Loading branch information
wrexbe and wrexbe committed Mar 24, 2024
1 parent 8d47771 commit df0945f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
8 changes: 6 additions & 2 deletions Robust.Client/ViewVariables/ClientViewVariablesManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,12 @@ public VVPropEditor PropertyFor(Type? type)
return new VVPropEditorString();
}

if (type == typeof(EntProtoId) ||
type == typeof(EntProtoId?))
if (type == typeof(EntProtoId?))
{
return new VVPropEditorNullableEntProtoId();
}

if (type == typeof(EntProtoId))
{
return new VVPropEditorEntProtoId();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.Prototypes;

namespace Robust.Client.ViewVariables.Editors;

internal sealed class VVPropEditorNullableEntProtoId : VVPropEditor
{
protected override Control MakeUI(object? value)
{
var lineEdit = new LineEdit
{
Text = value is EntProtoId protoId ? protoId.Id : "",
Editable = !ReadOnly,
HorizontalExpand = true,
};

if (!ReadOnly)
{
lineEdit.OnTextEntered += e =>
{
if (string.IsNullOrWhiteSpace(e.Text))
{
ValueChanged(null);
}
else
{
ValueChanged((EntProtoId) e.Text);
}
};
}

return lineEdit;
}
}

0 comments on commit df0945f

Please sign in to comment.