diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 5163e67a14..8a512af623 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -39,6 +39,7 @@ END TEMPLATE--> ### New features +* ViewVariables editors for `ProtoId` fields now have a Select button which opens a window listing all available prototypes of the appropriate type. * added **IConfigurationManager**.*SubscribeMultiple* ext. method to provide simpler way to unsubscribe from multiple cvar at once * Added `SharedMapSystem.QueueDeleteMap`, which deletes a map with the specified MapId in the next tick. * Added generic version of `ComponentRegistry.TryGetComponent`. diff --git a/Resources/Locale/en-US/view-variables.ftl b/Resources/Locale/en-US/view-variables.ftl index c16b1434fd..45f7ebacb9 100644 --- a/Resources/Locale/en-US/view-variables.ftl +++ b/Resources/Locale/en-US/view-variables.ftl @@ -25,3 +25,9 @@ vv-sound-reference-distance = Reference Distance vv-sound-loop = Loop vv-sound-play-offset = Play Offset (s) vv-sound-variation = Pitch variation + + +## ProtoId +vv-protoid-id-placeholder = Prototype ID +vv-protoid-select-button-label = Select +vv-protoid-addwindow-title = Set Prototype diff --git a/Robust.Client/ViewVariables/Editors/VVPropEditorProtoId.cs b/Robust.Client/ViewVariables/Editors/VVPropEditorProtoId.cs index bf288191e6..01f977bea4 100644 --- a/Robust.Client/ViewVariables/Editors/VVPropEditorProtoId.cs +++ b/Robust.Client/ViewVariables/Editors/VVPropEditorProtoId.cs @@ -1,38 +1,85 @@ +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 class VVPropEditorProtoId : VVPropEditor where T : class, IPrototype { + [Dependency] private readonly ILocalizationManager _loc = default!; [Dependency] private readonly IPrototypeManager _protoManager = default!; + private ViewVariablesAddWindow? _addWindow; + private LineEdit? _lineEdit; + protected override Control MakeUI(object? value) { - var lineEdit = new LineEdit + // ID LineEdit + _lineEdit = new LineEdit { - Text = (ProtoId) (value ?? ""), + Text = (ProtoId)(value ?? ""), + PlaceHolder = _loc.GetString("vv-protoid-id-placeholder"), Editable = !ReadOnly, HorizontalExpand = true, }; if (!ReadOnly) { - lineEdit.OnTextEntered += e => + _lineEdit.OnTextEntered += e => { - var id = (ProtoId)e.Text; - - if (!_protoManager.HasIndex(id)) - { - return; - } - - ValueChanged(id); + SetValue(e.Text); }; } - return lineEdit; + // 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().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)value; + if (_protoManager.HasIndex(proto)) + ValueChanged(proto, false); } }