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.Robotics;
using Robust.Client.GameObjects;
using Robust.Client.UserInterface;
namespace Content.Client.Robotics.UI;
@@ -16,7 +17,9 @@ public sealed class RoboticsConsoleBoundUserInterface : BoundUserInterface
{
base.Open();
_window = new RoboticsConsoleWindow(Owner);
_window = this.CreateWindow<RoboticsConsoleWindow>();
_window.SetEntity(Owner);
_window.OnDisablePressed += address =>
{
SendMessage(new RoboticsConsoleDisableMessage(address));
@@ -25,9 +28,6 @@ public sealed class RoboticsConsoleBoundUserInterface : BoundUserInterface
{
SendMessage(new RoboticsConsoleDestroyMessage(address));
};
_window.OnClose += Close;
_window.OpenCentered();
}
protected override void UpdateState(BoundUserInterfaceState state)
@@ -37,14 +37,6 @@ public sealed class RoboticsConsoleBoundUserInterface : BoundUserInterface
if (state is not RoboticsConsoleState cast)
return;
_window?.UpdateState(cast);
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (disposing)
_window?.Dispose();
_window.UpdateState(cast);
}
}

View File

@@ -23,11 +23,12 @@ public sealed partial class RoboticsConsoleWindow : FancyWindow
public Action<string>? OnDisablePressed;
public Action<string>? OnDestroyPressed;
private Entity<RoboticsConsoleComponent, LockComponent?> _console;
private string? _selected;
private Dictionary<string, CyborgControlData> _cyborgs = new();
public RoboticsConsoleWindow(EntityUid console)
public EntityUid Entity;
public RoboticsConsoleWindow()
{
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);
@@ -35,9 +36,6 @@ public sealed partial class RoboticsConsoleWindow : FancyWindow
_lock = _entMan.System<LockSystem>();
_sprite = _entMan.System<SpriteSystem>();
_console = (console, _entMan.GetComponent<RoboticsConsoleComponent>(console), null);
_entMan.TryGetComponent(_console, out _console.Comp2);
Cyborgs.OnItemSelected += args =>
{
if (Cyborgs[args.ItemIndex].Metadata is not string address)
@@ -66,6 +64,11 @@ public sealed partial class RoboticsConsoleWindow : FancyWindow
DestroyButton.StyleClasses.Add(StyleBase.ButtonCaution);
}
public void SetEntity(EntityUid uid)
{
Entity = uid;
}
public void UpdateState(RoboticsConsoleState state)
{
_cyborgs = state.Cyborgs;
@@ -81,7 +84,7 @@ public sealed partial class RoboticsConsoleWindow : FancyWindow
PopulateData();
var locked = _lock.IsLocked((_console, _console.Comp2));
var locked = _lock.IsLocked(Entity);
DangerZone.Visible = !locked;
LockedMessage.Visible = locked;
}
@@ -135,13 +138,19 @@ public sealed partial class RoboticsConsoleWindow : FancyWindow
// how the turntables
DisableButton.Disabled = !(data.HasBrain && data.CanDisable);
DestroyButton.Disabled = _timing.CurTime < _console.Comp1.NextDestroy;
}
protected override void FrameUpdate(FrameEventArgs args)
{
base.FrameUpdate(args);
DestroyButton.Disabled = _timing.CurTime < _console.Comp1.NextDestroy;
if (_entMan.TryGetComponent(Entity, out RoboticsConsoleComponent? console))
{
DestroyButton.Disabled = _timing.CurTime < console.NextDestroy;
}
else
{
DestroyButton.Disabled = true;
}
}
}