Files
RobustToolbox/Robust.Client/ViewVariables/Editors/VVPropEditorProtoId.cs
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

86 lines
2.3 KiB
C#

using System.Linq;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Prototypes;
namespace Robust.Client.ViewVariables.Editors;
internal sealed partial class VVPropEditorProtoId<T> : VVPropEditor where T : class, IPrototype
{
[Dependency] private ILocalizationManager _loc = default!;
[Dependency] private IPrototypeManager _protoManager = default!;
private ViewVariablesAddWindow? _addWindow;
private LineEdit? _lineEdit;
protected override Control MakeUI(object? value)
{
// ID LineEdit
_lineEdit = new LineEdit
{
Text = (ProtoId<T>)(value ?? ""),
PlaceHolder = _loc.GetString("vv-protoid-id-placeholder"),
Editable = !ReadOnly,
HorizontalExpand = true,
};
if (!ReadOnly)
{
_lineEdit.OnTextEntered += e =>
{
SetValue(e.Text);
};
}
// Select button
var selectButton = new Button
{
Text = _loc.GetString("vv-protoid-select-button-label"),
Disabled = ReadOnly,
};
selectButton.OnPressed += OnListButtonPressed;
// Container
var hBox = new BoxContainer
{
Orientation = BoxContainer.LayoutOrientation.Horizontal,
HorizontalExpand = true,
Children =
{
_lineEdit,
selectButton,
}
};
return hBox;
}
private void OnListButtonPressed(BaseButton.ButtonEventArgs args)
{
_addWindow?.Close();
var list = _protoManager.EnumeratePrototypes<T>().Select(p => p.ID);
_addWindow = new ViewVariablesAddWindow(list, _loc.GetString("vv-protoid-addwindow-title"));
_addWindow.AddButtonPressed += OnAddButtonPressed;
_addWindow.OpenCentered();
}
private void OnAddButtonPressed(ViewVariablesAddWindow.AddButtonPressedEventArgs args)
{
_lineEdit?.SetText(args.Entry);
_addWindow?.Close();
SetValue(args.Entry);
}
private void SetValue(string value)
{
var proto = (ProtoId<T>)value;
if (_protoManager.HasIndex(proto))
ValueChanged(proto, false);
}
}