From 4ce0e467833bc3badfcf5aa06bd668e6665d10f4 Mon Sep 17 00:00:00 2001 From: wrexbe Date: Fri, 22 Mar 2024 22:58:35 -0700 Subject: [PATCH] Treat EntProtoId? differently --- .../ClientViewVariablesManager.cs | 8 +++-- .../Editors/VVPropEditorNullableEntProtoId.cs | 35 +++++++++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 Robust.Client/ViewVariables/Editors/VVPropEditorNullableEntProtoId.cs 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; + } +}