Revert "Remove some BUI boilerplate" (#30214)

Revert "Remove some BUI boilerplate (#28399)"

This reverts commit cbf329a82d.
This commit is contained in:
Nemanja
2024-07-20 20:42:27 -04:00
committed by GitHub
parent 6d664c9157
commit cb0ba66be3
137 changed files with 1755 additions and 1096 deletions

View File

@@ -1,6 +1,5 @@
using System.Text.RegularExpressions;
using Robust.Client.GameObjects;
using Robust.Client.UserInterface;
using static Content.Shared.Configurable.ConfigurationComponent;
namespace Content.Client.Configurable.UI
@@ -10,6 +9,9 @@ namespace Content.Client.Configurable.UI
[ViewVariables]
private ConfigurationMenu? _menu;
[ViewVariables]
public Regex? Validation { get; internal set; }
public ConfigurationBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{
}
@@ -17,8 +19,10 @@ namespace Content.Client.Configurable.UI
protected override void Open()
{
base.Open();
_menu = this.CreateWindow<ConfigurationMenu>();
_menu.OnConfiguration += SendConfiguration;
_menu = new ConfigurationMenu(this);
_menu.OnClose += Close;
_menu.OpenCentered();
}
protected override void UpdateState(BoundUserInterfaceState state)
@@ -26,7 +30,9 @@ namespace Content.Client.Configurable.UI
base.UpdateState(state);
if (state is not ConfigurationBoundUserInterfaceState configurationState)
{
return;
}
_menu?.Populate(configurationState);
}
@@ -35,12 +41,9 @@ namespace Content.Client.Configurable.UI
{
base.ReceiveMessage(message);
if (_menu == null)
return;
if (message is ValidationUpdateMessage msg)
{
_menu.Validation = new Regex(msg.ValidationString, RegexOptions.Compiled);
Validation = new Regex(msg.ValidationString, RegexOptions.Compiled);
}
}
@@ -48,5 +51,16 @@ namespace Content.Client.Configurable.UI
{
SendMessage(new ConfigurationUpdatedMessage(config));
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (disposing && _menu != null)
{
_menu.OnClose -= Close;
_menu.Close();
}
}
}
}

View File

@@ -1,6 +1,5 @@
using System.Collections.Generic;
using System.Numerics;
using System.Text.RegularExpressions;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
@@ -14,25 +13,23 @@ namespace Content.Client.Configurable.UI
{
public sealed class ConfigurationMenu : DefaultWindow
{
public ConfigurationBoundUserInterface Owner { get; }
private readonly BoxContainer _column;
private readonly BoxContainer _row;
private readonly List<(string name, LineEdit input)> _inputs;
[ViewVariables]
public Regex? Validation { get; internal set; }
public event Action<Dictionary<string, string>>? OnConfiguration;
public ConfigurationMenu()
public ConfigurationMenu(ConfigurationBoundUserInterface owner)
{
MinSize = SetSize = new Vector2(300, 250);
Owner = owner;
_inputs = new List<(string name, LineEdit input)>();
Title = Loc.GetString("configuration-menu-device-title");
var baseContainer = new BoxContainer
BoxContainer baseContainer = new BoxContainer
{
Orientation = LayoutOrientation.Vertical,
VerticalExpand = true,
@@ -119,13 +116,14 @@ namespace Content.Client.Configurable.UI
private void OnConfirm(ButtonEventArgs args)
{
var config = GenerateDictionary(_inputs, "Text");
OnConfiguration?.Invoke(config);
Owner.SendConfiguration(config);
Close();
}
private bool Validate(string value)
{
return Validation?.IsMatch(value) != false;
return Owner.Validation == null || Owner.Validation.IsMatch(value);
}
private Dictionary<string, string> GenerateDictionary(IEnumerable<(string name, LineEdit input)> inputs, string propertyName)