mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-09-15 06:42:25 +02:00
Add a Select button to ProtoId VV editor (#6097)
* Add a Select button to ProtoId VV editor * Changelog * Fix ftl string name --------- Co-authored-by: PJB3005 <pieterjan.briers+git@gmail.com>
This commit is contained in:
@@ -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`.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<T> : 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<T>) (value ?? ""),
|
||||
Text = (ProtoId<T>)(value ?? ""),
|
||||
PlaceHolder = _loc.GetString("vv-protoid-id-placeholder"),
|
||||
Editable = !ReadOnly,
|
||||
HorizontalExpand = true,
|
||||
};
|
||||
|
||||
if (!ReadOnly)
|
||||
{
|
||||
lineEdit.OnTextEntered += e =>
|
||||
_lineEdit.OnTextEntered += e =>
|
||||
{
|
||||
var id = (ProtoId<T>)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<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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user