diff --git a/Robust.Client/ViewVariables/ClientViewVariablesManager.cs b/Robust.Client/ViewVariables/ClientViewVariablesManager.cs index f8045ec94d0..4db12ced18f 100644 --- a/Robust.Client/ViewVariables/ClientViewVariablesManager.cs +++ b/Robust.Client/ViewVariables/ClientViewVariablesManager.cs @@ -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(); } diff --git a/Robust.Client/ViewVariables/Editors/VVPropEditorNullableEntProtoId.cs b/Robust.Client/ViewVariables/Editors/VVPropEditorNullableEntProtoId.cs new file mode 100644 index 00000000000..d0137f1f8c5 --- /dev/null +++ b/Robust.Client/ViewVariables/Editors/VVPropEditorNullableEntProtoId.cs @@ -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; + } +}