Remove some BUI boilerplate (#28399)

* Remove some BUI boilerplate

- The disposals overrides got removed due to the helper method handling it.
- Replace window creation with CreateWindow helper.
- Fixed some stinky code which would cause exceptions.

* More

* moar

* weh

* done

* More BUIs

* More updates

* weh

* moar

* look who it is

* weh

* merge

* weh

* fixes
This commit is contained in:
metalgearsloth
2024-07-20 15:40:16 +10:00
committed by GitHub
parent 4aba9ec131
commit cbf329a82d
137 changed files with 1094 additions and 1753 deletions

View File

@@ -1,5 +1,6 @@
using Content.Shared.Pinpointer;
using JetBrains.Annotations;
using Robust.Client.UserInterface;
namespace Content.Client.Pinpointer.UI;
@@ -16,19 +17,16 @@ public sealed class NavMapBeaconBoundUserInterface : BoundUserInterface
protected override void Open()
{
base.Open();
_window = new NavMapBeaconWindow(Owner);
_window.OpenCentered();
_window.OnClose += Close;
_window = this.CreateWindow<NavMapBeaconWindow>();
if (EntMan.TryGetComponent(Owner, out NavMapBeaconComponent? beacon))
{
_window.SetEntity(Owner, beacon);
}
_window.OnApplyButtonPressed += (label, enabled, color) =>
{
SendMessage(new NavMapBeaconConfigureBuiMessage(label, enabled, color));
};
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
_window?.Dispose();
}
}

View File

@@ -10,36 +10,35 @@ namespace Content.Client.Pinpointer.UI;
[GenerateTypedNameReferences]
public sealed partial class NavMapBeaconWindow : FancyWindow
{
[Dependency] private readonly IEntityManager _entityManager = default!;
private string? _defaultLabel;
private bool _defaultEnabled;
private Color _defaultColor;
public event Action<string?, bool, Color>? OnApplyButtonPressed;
public NavMapBeaconWindow(EntityUid beaconEntity)
public NavMapBeaconWindow()
{
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);
if (!_entityManager.TryGetComponent<NavMapBeaconComponent>(beaconEntity, out var navMap))
return;
VisibleButton.OnPressed += args => UpdateVisibleButton(args.Button.Pressed);
LabelLineEdit.OnTextChanged += OnTextChanged;
ColorSelector.OnColorChanged += _ => TryEnableApplyButton();
TryEnableApplyButton();
ApplyButton.OnPressed += OnApplyPressed;
}
public void SetEntity(EntityUid uid, NavMapBeaconComponent navMap)
{
_defaultLabel = navMap.Text;
_defaultEnabled = navMap.Enabled;
_defaultColor = navMap.Color;
UpdateVisibleButton(navMap.Enabled);
VisibleButton.OnPressed += args => UpdateVisibleButton(args.Button.Pressed);
LabelLineEdit.Text = navMap.Text ?? string.Empty;
LabelLineEdit.OnTextChanged += OnTextChanged;
ColorSelector.Color = navMap.Color;
ColorSelector.OnColorChanged += _ => TryEnableApplyButton();
TryEnableApplyButton();
ApplyButton.OnPressed += OnApplyPressed;
}
private void UpdateVisibleButton(bool value)

View File

@@ -1,4 +1,4 @@
using Robust.Client.GameObjects;
using Robust.Client.UserInterface;
namespace Content.Client.Pinpointer.UI;
@@ -14,7 +14,6 @@ public sealed class StationMapBoundUserInterface : BoundUserInterface
protected override void Open()
{
base.Open();
_window?.Close();
EntityUid? gridUid = null;
if (EntMan.TryGetComponent<TransformComponent>(Owner, out var xform))
@@ -22,14 +21,8 @@ public sealed class StationMapBoundUserInterface : BoundUserInterface
gridUid = xform.GridUid;
}
_window = new StationMapWindow(gridUid, Owner);
_window.OpenCentered();
_window.OnClose += Close;
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
_window?.Dispose();
_window = this.CreateWindow<StationMapWindow>();
_window.Title = EntMan.GetComponent<MetaDataComponent>(Owner).EntityName;
_window.Set(gridUid, Owner);
}
}

View File

@@ -9,19 +9,18 @@ namespace Content.Client.Pinpointer.UI;
[GenerateTypedNameReferences]
public sealed partial class StationMapWindow : FancyWindow
{
public StationMapWindow(EntityUid? mapUid, EntityUid? trackedEntity)
public StationMapWindow()
{
RobustXamlLoader.Load(this);
}
public void Set(EntityUid? mapUid, EntityUid? trackedEntity)
{
NavMapScreen.MapUid = mapUid;
if (trackedEntity != null)
NavMapScreen.TrackedCoordinates.Add(new EntityCoordinates(trackedEntity.Value, Vector2.Zero), (true, Color.Cyan));
if (IoCManager.Resolve<IEntityManager>().TryGetComponent<MetaDataComponent>(mapUid, out var metadata))
{
Title = metadata.EntityName;
}
NavMapScreen.ForceNavMapUpdate();
}
}

View File

@@ -1,4 +1,4 @@
using Robust.Client.GameObjects;
using Robust.Client.UserInterface;
namespace Content.Client.Pinpointer.UI;
@@ -14,22 +14,15 @@ public sealed class UntrackedStationMapBoundUserInterface : BoundUserInterface
protected override void Open()
{
base.Open();
_window?.Close();
EntityUid? gridUid = null;
// TODO: What this just looks like it's been copy-pasted wholesale from StationMapBoundUserInterface?
if (EntMan.TryGetComponent<TransformComponent>(Owner, out var xform))
{
gridUid = xform.GridUid;
}
_window = new StationMapWindow(gridUid, null);
_window.OpenCentered();
_window.OnClose += Close;
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
_window?.Dispose();
_window = this.CreateWindow<StationMapWindow>();
_window.Set(gridUid, Owner);
}
}