Files
RobustToolbox/Robust.Client/ViewVariables/Editors/VVPropEditorReference.cs
T
83c2a1be11 [Dependency] source generator part 2 (#6550)
* [Dependency] source generator

No more reflection, no more codegen at runtime

Also various changes to Roslyn helpers to make this easier to write.

Requires all types with dependencies to be partial and not have readonly dependency fields. An analyzer enforces this at warning level, the previous injection strategies have remained in the code *for now* as a fallback.

No fallback is available for [field: Dependency] properties, due to a Roslyn bug.

Code Fixes exist. We love Roslyn

* Apply dependencies generator changes to all code

* Release notes

* Preprocessor got hands

* Handle nullable dependencies

These are bad but gotta deal with it.

* Apply suggestions from code review

Co-authored-by: Moony <moony@hellomouse.net>

* Fine, let's not use collection expressions

---------

Co-authored-by: Moony <moony@hellomouse.net>
2026-05-08 12:38:33 +02:00

62 lines
1.9 KiB
C#

using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.IoC;
using Robust.Shared.Utility;
using Robust.Shared.ViewVariables;
namespace Robust.Client.ViewVariables.Editors
{
internal sealed partial class VVPropEditorReference : VVPropEditor
{
[Dependency] private IClientViewVariablesManager _vvMan = default!;
private object? _localValue;
private ViewVariablesObjectSelector? _selector;
public VVPropEditorReference()
{
IoCManager.InjectDependencies(this);
}
protected override Control MakeUI(object? value)
{
if (value == null)
{
return new Label { Text = "null", Align = Label.AlignMode.Right };
}
_localValue = value;
// NOTE: value is NOT always the actual object.
// Only thing we can really rely on is that ToString works out correctly.
// This is because of reference tokens, but due to simplicity the object ref is still passed.
var toString = PrettyPrint.PrintUserFacing(value);
var button = new Button
{
Text = $"Ref: {toString}",
ClipText = true,
HorizontalExpand = true,
};
button.OnPressed += ButtonOnOnPressed;
return button;
}
private void ButtonOnOnPressed(BaseButton.ButtonEventArgs obj)
{
if (_selector != null)
{
_vvMan.OpenVV(_selector);
}
else if (_localValue != null)
{
_vvMan.OpenVV(_localValue);
}
}
public override void WireNetworkSelector(uint sessionId, object[] selectorChain)
{
_selector = new ViewVariablesSessionRelativeSelector(sessionId, selectorChain);
}
}
}