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 Content.Shared.Pinpointer;
using JetBrains.Annotations;
using Robust.Client.UserInterface;
namespace Content.Client.Pinpointer.UI;
@@ -17,16 +16,19 @@ public sealed class NavMapBeaconBoundUserInterface : BoundUserInterface
protected override void Open()
{
base.Open();
_window = this.CreateWindow<NavMapBeaconWindow>();
if (EntMan.TryGetComponent(Owner, out NavMapBeaconComponent? beacon))
{
_window.SetEntity(Owner, beacon);
}
_window = new NavMapBeaconWindow(Owner);
_window.OpenCentered();
_window.OnClose += Close;
_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,35 +10,36 @@ 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()
public NavMapBeaconWindow(EntityUid beaconEntity)
{
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);
VisibleButton.OnPressed += args => UpdateVisibleButton(args.Button.Pressed);
LabelLineEdit.OnTextChanged += OnTextChanged;
ColorSelector.OnColorChanged += _ => TryEnableApplyButton();
TryEnableApplyButton();
ApplyButton.OnPressed += OnApplyPressed;
}
public void SetEntity(EntityUid uid, NavMapBeaconComponent navMap)
{
if (!_entityManager.TryGetComponent<NavMapBeaconComponent>(beaconEntity, out var navMap))
return;
_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.UserInterface;
using Robust.Client.GameObjects;
namespace Content.Client.Pinpointer.UI;
@@ -14,6 +14,7 @@ public sealed class StationMapBoundUserInterface : BoundUserInterface
protected override void Open()
{
base.Open();
_window?.Close();
EntityUid? gridUid = null;
if (EntMan.TryGetComponent<TransformComponent>(Owner, out var xform))
@@ -21,8 +22,14 @@ public sealed class StationMapBoundUserInterface : BoundUserInterface
gridUid = xform.GridUid;
}
_window = this.CreateWindow<StationMapWindow>();
_window.Title = EntMan.GetComponent<MetaDataComponent>(Owner).EntityName;
_window.Set(gridUid, Owner);
_window = new StationMapWindow(gridUid, Owner);
_window.OpenCentered();
_window.OnClose += Close;
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
_window?.Dispose();
}
}

View File

@@ -9,18 +9,19 @@ namespace Content.Client.Pinpointer.UI;
[GenerateTypedNameReferences]
public sealed partial class StationMapWindow : FancyWindow
{
public StationMapWindow()
public StationMapWindow(EntityUid? mapUid, EntityUid? trackedEntity)
{
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.UserInterface;
using Robust.Client.GameObjects;
namespace Content.Client.Pinpointer.UI;
@@ -14,15 +14,22 @@ 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 = this.CreateWindow<StationMapWindow>();
_window.Set(gridUid, Owner);
_window = new StationMapWindow(gridUid, null);
_window.OpenCentered();
_window.OnClose += Close;
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
_window?.Dispose();
}
}