2025-04-19 16:20:40 +10:00
|
|
|
|
using System.Numerics;
|
|
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
|
using Content.Shared.Configurable;
|
2024-07-21 14:48:13 +10:00
|
|
|
|
using Robust.Client.UserInterface;
|
2025-04-19 16:20:40 +10:00
|
|
|
|
using Robust.Client.UserInterface.Controls;
|
2022-12-23 23:55:31 -05:00
|
|
|
|
using static Content.Shared.Configurable.ConfigurationComponent;
|
2020-10-30 01:16:26 +01:00
|
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
|
namespace Content.Client.Configurable.UI
|
2020-10-30 01:16:26 +01:00
|
|
|
|
{
|
2022-02-16 00:23:23 -07:00
|
|
|
|
public sealed class ConfigurationBoundUserInterface : BoundUserInterface
|
2020-10-30 01:16:26 +01:00
|
|
|
|
{
|
2023-07-08 09:02:17 -07:00
|
|
|
|
[ViewVariables]
|
|
|
|
|
|
private ConfigurationMenu? _menu;
|
|
|
|
|
|
|
|
|
|
|
|
public ConfigurationBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
|
2020-10-30 01:16:26 +01:00
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override void Open()
|
|
|
|
|
|
{
|
|
|
|
|
|
base.Open();
|
2024-07-21 14:48:13 +10:00
|
|
|
|
_menu = this.CreateWindow<ConfigurationMenu>();
|
|
|
|
|
|
_menu.OnConfiguration += SendConfiguration;
|
2025-04-19 16:20:40 +10:00
|
|
|
|
if (EntMan.TryGetComponent(Owner, out ConfigurationComponent? component))
|
|
|
|
|
|
Refresh((Owner, component));
|
2020-10-30 01:16:26 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-04-19 16:20:40 +10:00
|
|
|
|
public void Refresh(Entity<ConfigurationComponent> entity)
|
2020-10-30 01:16:26 +01:00
|
|
|
|
{
|
2025-04-19 16:20:40 +10:00
|
|
|
|
if (_menu == null)
|
2021-03-10 14:48:29 +01:00
|
|
|
|
return;
|
|
|
|
|
|
|
2025-04-19 16:20:40 +10:00
|
|
|
|
_menu.Column.Children.Clear();
|
|
|
|
|
|
_menu.Inputs.Clear();
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var field in entity.Comp.Config)
|
|
|
|
|
|
{
|
|
|
|
|
|
var label = new Label
|
|
|
|
|
|
{
|
|
|
|
|
|
Margin = new Thickness(0, 0, 8, 0),
|
|
|
|
|
|
Name = field.Key,
|
|
|
|
|
|
Text = field.Key + ":",
|
|
|
|
|
|
VerticalAlignment = Control.VAlignment.Center,
|
|
|
|
|
|
HorizontalExpand = true,
|
|
|
|
|
|
SizeFlagsStretchRatio = .2f,
|
|
|
|
|
|
MinSize = new Vector2(60, 0)
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var input = new LineEdit
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = field.Key + "-input",
|
|
|
|
|
|
Text = field.Value ?? "",
|
|
|
|
|
|
IsValid = _menu.Validate,
|
|
|
|
|
|
HorizontalExpand = true,
|
|
|
|
|
|
SizeFlagsStretchRatio = .8f
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
_menu.Inputs.Add((field.Key, input));
|
|
|
|
|
|
|
|
|
|
|
|
var row = new BoxContainer
|
|
|
|
|
|
{
|
|
|
|
|
|
Orientation = BoxContainer.LayoutOrientation.Horizontal
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
ConfigurationMenu.CopyProperties(_menu.Row, row);
|
|
|
|
|
|
|
|
|
|
|
|
row.AddChild(label);
|
|
|
|
|
|
row.AddChild(input);
|
|
|
|
|
|
_menu.Column.AddChild(row);
|
|
|
|
|
|
}
|
2020-10-30 01:16:26 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override void ReceiveMessage(BoundUserInterfaceMessage message)
|
|
|
|
|
|
{
|
|
|
|
|
|
base.ReceiveMessage(message);
|
2021-03-10 14:48:29 +01:00
|
|
|
|
|
2024-07-21 14:48:13 +10:00
|
|
|
|
if (_menu == null)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
2020-10-30 01:16:26 +01:00
|
|
|
|
if (message is ValidationUpdateMessage msg)
|
|
|
|
|
|
{
|
2024-07-21 14:48:13 +10:00
|
|
|
|
_menu.Validation = new Regex(msg.ValidationString, RegexOptions.Compiled);
|
2020-10-30 01:16:26 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void SendConfiguration(Dictionary<string, string> config)
|
|
|
|
|
|
{
|
|
|
|
|
|
SendMessage(new ConfigurationUpdatedMessage(config));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|