Reapply "Remove some BUI boilerplate" (#30214) (#30219)

* Reapply "Remove some BUI boilerplate" (#30214)

This reverts commit cb0ba66be3.

* Fix gas tank

* Fix PA

* Fix microwave

* Comms console underwrap

* Fix rcd

* log wehs
This commit is contained in:
metalgearsloth
2024-07-21 14:48:13 +10:00
committed by GitHub
parent 87e52e50b4
commit edb05e36bb
137 changed files with 1102 additions and 1757 deletions

View File

@@ -1,6 +1,7 @@
using Content.Client.NetworkConfigurator.Systems;
using Content.Shared.DeviceNetwork;
using Robust.Client.GameObjects;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
namespace Content.Client.NetworkConfigurator;
@@ -35,14 +36,12 @@ public sealed class NetworkConfiguratorBoundUserInterface : BoundUserInterface
switch (UiKey)
{
case NetworkConfiguratorUiKey.List:
_listMenu = new NetworkConfiguratorListMenu(this);
_listMenu.OnClose += Close;
_listMenu = this.CreateWindow<NetworkConfiguratorListMenu>();
_listMenu.ClearButton.OnPressed += _ => OnClearButtonPressed();
_listMenu.OpenCenteredRight();
_listMenu.OnRemoveAddress += OnRemoveButtonPressed;
break;
case NetworkConfiguratorUiKey.Configure:
_configurationMenu = new NetworkConfiguratorConfigurationMenu();
_configurationMenu.OnClose += Close;
_configurationMenu = this.CreateWindow<NetworkConfiguratorConfigurationMenu>();
_configurationMenu.Set.OnPressed += _ => OnConfigButtonPressed(NetworkConfiguratorButtonKey.Set);
_configurationMenu.Add.OnPressed += _ => OnConfigButtonPressed(NetworkConfiguratorButtonKey.Add);
//_configurationMenu.Edit.OnPressed += _ => OnConfigButtonPressed(NetworkConfiguratorButtonKey.Edit);
@@ -50,12 +49,24 @@ public sealed class NetworkConfiguratorBoundUserInterface : BoundUserInterface
_configurationMenu.Copy.OnPressed += _ => OnConfigButtonPressed(NetworkConfiguratorButtonKey.Copy);
_configurationMenu.Show.OnPressed += OnShowPressed;
_configurationMenu.Show.Pressed = _netConfig.ConfiguredListIsTracked(Owner);
_configurationMenu.OpenCentered();
_configurationMenu.OnRemoveAddress += OnRemoveButtonPressed;
break;
case NetworkConfiguratorUiKey.Link:
_linkMenu = new NetworkConfiguratorLinkMenu(this);
_linkMenu.OnClose += Close;
_linkMenu.OpenCentered();
_linkMenu = this.CreateWindow<NetworkConfiguratorLinkMenu>();
_linkMenu.OnLinkDefaults += args =>
{
SendMessage(new NetworkConfiguratorLinksSaveMessage(args));
};
_linkMenu.OnToggleLink += (left, right) =>
{
SendMessage(new NetworkConfiguratorToggleLinkMessage(left, right));
};
_linkMenu.OnClearLinks += () =>
{
SendMessage(new NetworkConfiguratorClearLinksMessage());
};
break;
}
}
@@ -83,16 +94,6 @@ public sealed class NetworkConfiguratorBoundUserInterface : BoundUserInterface
}
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (!disposing) return;
_linkMenu?.Dispose();
_listMenu?.Dispose();
_configurationMenu?.Dispose();
}
private void OnClearButtonPressed()
{
SendMessage(new NetworkConfiguratorClearDevicesMessage());

View File

@@ -9,17 +9,23 @@ namespace Content.Client.NetworkConfigurator;
[GenerateTypedNameReferences]
public sealed partial class NetworkConfiguratorConfigurationMenu : FancyWindow
{
public event Action<string>? OnRemoveAddress;
public NetworkConfiguratorConfigurationMenu()
{
RobustXamlLoader.Load(this);
Clear.StyleClasses.Add(StyleBase.ButtonOpenLeft);
Clear.StyleClasses.Add(StyleNano.StyleClassButtonColorRed);
DeviceList.OnRemoveAddress += args =>
{
OnRemoveAddress?.Invoke(args);
};
}
public void UpdateState(DeviceListUserInterfaceState state)
{
DeviceList.UpdateState(null, state.DeviceList);
DeviceList.UpdateState(state.DeviceList, false);
Count.Text = Loc.GetString("network-configurator-ui-count-label", ("count", state.DeviceList.Count));
}

View File

@@ -7,17 +7,19 @@ namespace Content.Client.NetworkConfigurator;
[GenerateTypedNameReferences]
public sealed partial class NetworkConfiguratorDeviceList : ScrollContainer
{
public void UpdateState(NetworkConfiguratorBoundUserInterface? ui, HashSet<(string address, string name)> devices)
public event Action<string>? OnRemoveAddress;
public void UpdateState(HashSet<(string address, string name)> devices, bool ui)
{
DeviceList.RemoveAllChildren();
foreach (var device in devices)
{
DeviceList.AddChild(BuildDeviceListRow(ui, device));
DeviceList.AddChild(BuildDeviceListRow(device, ui));
}
}
private static BoxContainer BuildDeviceListRow(NetworkConfiguratorBoundUserInterface? ui, (string address, string name) savedDevice)
private BoxContainer BuildDeviceListRow((string address, string name) savedDevice, bool ui)
{
var row = new BoxContainer()
{
@@ -48,10 +50,10 @@ public sealed partial class NetworkConfiguratorDeviceList : ScrollContainer
row.AddChild(name);
row.AddChild(address);
if (ui != null)
if (ui)
{
row.AddChild(removeButton);
removeButton.OnPressed += _ => ui.OnRemoveButtonPressed(savedDevice.address);
removeButton.OnPressed += _ => OnRemoveAddress?.Invoke(savedDevice.address);
}
return row;

View File

@@ -18,20 +18,20 @@ public sealed partial class NetworkConfiguratorLinkMenu : FancyWindow
private readonly LinksRender _links;
private readonly List<SourcePortPrototype> _sources = new();
private readonly List<SinkPortPrototype> _sinks = new();
private readonly NetworkConfiguratorBoundUserInterface _userInterface;
private (ButtonPosition position, string id, int index)? _selectedButton;
private List<(string left, string right)>? _defaults;
public NetworkConfiguratorLinkMenu(NetworkConfiguratorBoundUserInterface userInterface)
public event Action? OnClearLinks;
public event Action<string, string>? OnToggleLink;
public event Action<List<(string left, string right)>>? OnLinkDefaults;
public NetworkConfiguratorLinkMenu()
{
_userInterface = userInterface;
RobustXamlLoader.Load(this);
var footerStyleBox = new StyleBoxFlat()
@@ -52,7 +52,7 @@ public sealed partial class NetworkConfiguratorLinkMenu : FancyWindow
ButtonOk.OnPressed += _ => Close();
ButtonLinkDefault.OnPressed += _ => LinkDefaults();
ButtonClear.OnPressed += _ => _userInterface.SendMessage(new NetworkConfiguratorClearLinksMessage());
ButtonClear.OnPressed += _ => OnClearLinks?.Invoke();
}
public void UpdateState(DeviceLinkUserInterfaceState linkState)
@@ -98,7 +98,7 @@ public sealed partial class NetworkConfiguratorLinkMenu : FancyWindow
if (_defaults == default)
return;
_userInterface.SendMessage(new NetworkConfiguratorLinksSaveMessage(_defaults));
OnLinkDefaults?.Invoke(_defaults);
}
private Button CreateButton(ButtonPosition position, string name, string description, string id, int index)
@@ -138,7 +138,7 @@ public sealed partial class NetworkConfiguratorLinkMenu : FancyWindow
var left = _selectedButton.Value.position == ButtonPosition.Left ? _selectedButton.Value.id : id;
var right = _selectedButton.Value.position == ButtonPosition.Left ? id : _selectedButton.Value.id;
_userInterface.SendMessage(new NetworkConfiguratorToggleLinkMessage(left, right));
OnToggleLink?.Invoke(left, right);
args.Button.Pressed = false;

View File

@@ -9,17 +9,20 @@ namespace Content.Client.NetworkConfigurator;
[GenerateTypedNameReferences]
public sealed partial class NetworkConfiguratorListMenu : FancyWindow
{
private readonly NetworkConfiguratorBoundUserInterface _ui;
public NetworkConfiguratorListMenu(NetworkConfiguratorBoundUserInterface ui)
public event Action<string>? OnRemoveAddress;
public NetworkConfiguratorListMenu()
{
RobustXamlLoader.Load(this);
_ui = ui;
DeviceList.OnRemoveAddress += args =>
{
OnRemoveAddress?.Invoke(args);
};
}
public void UpdateState(NetworkConfiguratorUserInterfaceState state)
{
DeviceCountLabel.Text = Loc.GetString("network-configurator-ui-count-label", ("count", state.DeviceList.Count));
DeviceList.UpdateState(_ui, state.DeviceList);
DeviceList.UpdateState(state.DeviceList, true);
}
}