From bc5107e2977db8fac931f0cc7b8269f1e818a079 Mon Sep 17 00:00:00 2001 From: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com> Date: Fri, 15 Sep 2023 12:11:28 +1200 Subject: [PATCH] Misc NetEntity fixes for VV (#4390) --- .../ClientViewVariablesManager.cs | 5 ++ .../Editors/VVPropEditorEntityUid.cs | 4 +- .../Editors/VVPropEditorNetEntity.cs | 48 +++++++++++++++++++ .../ViewVariables/ViewVariablesTrait.cs | 4 ++ Robust.Shared/GameObjects/EntityUid.cs | 4 +- Robust.Shared/GameObjects/NetEntity.cs | 4 +- 6 files changed, 65 insertions(+), 4 deletions(-) create mode 100644 Robust.Client/ViewVariables/Editors/VVPropEditorNetEntity.cs diff --git a/Robust.Client/ViewVariables/ClientViewVariablesManager.cs b/Robust.Client/ViewVariables/ClientViewVariablesManager.cs index ea7ee680b6..760e541fc6 100644 --- a/Robust.Client/ViewVariables/ClientViewVariablesManager.cs +++ b/Robust.Client/ViewVariables/ClientViewVariablesManager.cs @@ -190,6 +190,11 @@ namespace Robust.Client.ViewVariables return new VVPropEditorEntityUid(); } + if (type == typeof(NetEntity)) + { + return new VVPropEditorNetEntity(); + } + if (type == typeof(Color)) { return new VVPropEditorColor(); diff --git a/Robust.Client/ViewVariables/Editors/VVPropEditorEntityUid.cs b/Robust.Client/ViewVariables/Editors/VVPropEditorEntityUid.cs index 656fb68faa..265988d473 100644 --- a/Robust.Client/ViewVariables/Editors/VVPropEditorEntityUid.cs +++ b/Robust.Client/ViewVariables/Editors/VVPropEditorEntityUid.cs @@ -4,7 +4,6 @@ using Robust.Client.UserInterface.Controls; using Robust.Shared.Console; using Robust.Shared.GameObjects; using Robust.Shared.IoC; -using Robust.Shared.Maths; using static Robust.Client.UserInterface.Controls.BoxContainer; namespace Robust.Client.ViewVariables.Editors @@ -39,7 +38,8 @@ namespace Robust.Client.ViewVariables.Editors vvButton.OnPressed += e => { - IoCManager.Resolve().ExecuteCommand($"vv {uid}"); + var id = IoCManager.Resolve().GetNetEntity(uid); + IoCManager.Resolve().ExecuteCommand($"vv {id}"); }; hBox.AddChild(lineEdit); diff --git a/Robust.Client/ViewVariables/Editors/VVPropEditorNetEntity.cs b/Robust.Client/ViewVariables/Editors/VVPropEditorNetEntity.cs new file mode 100644 index 0000000000..422378985e --- /dev/null +++ b/Robust.Client/ViewVariables/Editors/VVPropEditorNetEntity.cs @@ -0,0 +1,48 @@ +using System.Numerics; +using Robust.Client.UserInterface; +using Robust.Client.UserInterface.Controls; +using Robust.Shared.Console; +using Robust.Shared.GameObjects; +using Robust.Shared.IoC; +using static Robust.Client.UserInterface.Controls.BoxContainer; + +namespace Robust.Client.ViewVariables.Editors; + +public sealed class VVPropEditorNetEntity : VVPropEditor +{ + protected override Control MakeUI(object? value) + { + var hBox = new BoxContainer + { + Orientation = LayoutOrientation.Horizontal, + MinSize = new Vector2(200, 0) + }; + + var nuid = (NetEntity)value!; + var lineEdit = new LineEdit + { + Text = nuid.ToString(), + Editable = !ReadOnly, + HorizontalExpand = true, + }; + if (!ReadOnly) + { + lineEdit.OnTextEntered += e => + ValueChanged(NetEntity.Parse(e.Text)); + } + + var vvButton = new Button() + { + Text = "View", + }; + + vvButton.OnPressed += e => + { + IoCManager.Resolve().ExecuteCommand($"vv {nuid}"); + }; + + hBox.AddChild(lineEdit); + hBox.AddChild(vvButton); + return hBox; + } +} \ No newline at end of file diff --git a/Robust.Server/ViewVariables/ViewVariablesTrait.cs b/Robust.Server/ViewVariables/ViewVariablesTrait.cs index 59eb5e3c50..2f44b08159 100644 --- a/Robust.Server/ViewVariables/ViewVariablesTrait.cs +++ b/Robust.Server/ViewVariables/ViewVariablesTrait.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using Robust.Server.ViewVariables.Traits; +using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Network.Messages; using Robust.Shared.Prototypes; @@ -92,6 +93,9 @@ namespace Robust.Server.ViewVariables return null; } + if (value is EntityUid uid) + return IoCManager.Resolve().GetNetEntity(uid); + var valType = value.GetType(); if (!valType.IsValueType) { diff --git a/Robust.Shared/GameObjects/EntityUid.cs b/Robust.Shared/GameObjects/EntityUid.cs index 88177a7f40..3695258c65 100644 --- a/Robust.Shared/GameObjects/EntityUid.cs +++ b/Robust.Shared/GameObjects/EntityUid.cs @@ -190,8 +190,10 @@ namespace Robust.Shared.GameObjects // This might seem useless, but it allows you to retrieve remote entities that don't exist on the client. [ViewVariables] - private EntityUid Uid => this; + private EntityUid _uid => this; + [ViewVariables] + private NetEntity _netId => IoCManager.Resolve().GetNetEntity(this); #endregion } } diff --git a/Robust.Shared/GameObjects/NetEntity.cs b/Robust.Shared/GameObjects/NetEntity.cs index e32fba9d65..b4603b5ebb 100644 --- a/Robust.Shared/GameObjects/NetEntity.cs +++ b/Robust.Shared/GameObjects/NetEntity.cs @@ -214,7 +214,7 @@ public readonly struct NetEntity : IEquatable, IComparable } [ViewVariables] - private EntityUid Uid + private EntityUid _uid { get { @@ -222,5 +222,7 @@ public readonly struct NetEntity : IEquatable, IComparable } } + [ViewVariables] private NetEntity _netId => this; + #endregion }