2021-02-11 01:13:03 -08:00
|
|
|
|
using System.Collections.Generic;
|
2020-10-30 01:16:26 +01:00
|
|
|
|
using System.Text.RegularExpressions;
|
2021-02-11 01:13:03 -08:00
|
|
|
|
using Robust.Client.GameObjects;
|
|
|
|
|
|
using Robust.Shared.GameObjects;
|
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
|
|
|
|
{
|
2021-03-10 14:48:29 +01:00
|
|
|
|
public Regex? Validation { get; internal set; }
|
2020-10-30 01:16:26 +01:00
|
|
|
|
|
2022-08-21 05:38:30 +12:00
|
|
|
|
public ConfigurationBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey)
|
2020-10-30 01:16:26 +01:00
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-03-10 14:48:29 +01:00
|
|
|
|
private ConfigurationMenu? _menu;
|
2020-10-30 01:16:26 +01:00
|
|
|
|
|
|
|
|
|
|
protected override void Open()
|
|
|
|
|
|
{
|
|
|
|
|
|
base.Open();
|
|
|
|
|
|
_menu = new ConfigurationMenu(this);
|
|
|
|
|
|
|
|
|
|
|
|
_menu.OnClose += Close;
|
|
|
|
|
|
_menu.OpenCentered();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override void UpdateState(BoundUserInterfaceState state)
|
|
|
|
|
|
{
|
|
|
|
|
|
base.UpdateState(state);
|
2021-03-10 14:48:29 +01:00
|
|
|
|
|
|
|
|
|
|
if (state is not ConfigurationBoundUserInterfaceState configurationState)
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_menu?.Populate(configurationState);
|
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
|
|
|
|
|
2020-10-30 01:16:26 +01:00
|
|
|
|
if (message is ValidationUpdateMessage msg)
|
|
|
|
|
|
{
|
|
|
|
|
|
Validation = new Regex(msg.ValidationString, RegexOptions.Compiled);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void SendConfiguration(Dictionary<string, string> config)
|
|
|
|
|
|
{
|
|
|
|
|
|
SendMessage(new ConfigurationUpdatedMessage(config));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override void Dispose(bool disposing)
|
|
|
|
|
|
{
|
|
|
|
|
|
base.Dispose(disposing);
|
|
|
|
|
|
|
2021-03-10 14:48:29 +01:00
|
|
|
|
if (disposing && _menu != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
_menu.OnClose -= Close;
|
|
|
|
|
|
_menu.Close();
|
|
|
|
|
|
}
|
2020-10-30 01:16:26 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|