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

@@ -2,12 +2,15 @@
using Content.Shared.Crayon;
using Content.Shared.Decals;
using Robust.Client.GameObjects;
using Robust.Client.UserInterface;
using Robust.Shared.Prototypes;
namespace Content.Client.Crayon.UI
{
public sealed class CrayonBoundUserInterface : BoundUserInterface
{
[Dependency] private readonly IPrototypeManager _protoManager = default!;
[ViewVariables]
private CrayonWindow? _menu;
@@ -18,15 +21,29 @@ namespace Content.Client.Crayon.UI
protected override void Open()
{
base.Open();
_menu = new CrayonWindow(this);
_menu.OnClose += Close;
var prototypeManager = IoCManager.Resolve<IPrototypeManager>();
var crayonDecals = prototypeManager.EnumeratePrototypes<DecalPrototype>().Where(x => x.Tags.Contains("crayon"));
_menu.Populate(crayonDecals);
_menu = this.CreateWindow<CrayonWindow>();
_menu.OnColorSelected += SelectColor;
_menu.OnSelected += Select;
PopulateCrayons();
_menu.OpenCenteredLeft();
}
private void PopulateCrayons()
{
var crayonDecals = _protoManager.EnumeratePrototypes<DecalPrototype>().Where(x => x.Tags.Contains("crayon"));
_menu?.Populate(crayonDecals);
}
public override void OnProtoReload(PrototypesReloadedEventArgs args)
{
base.OnProtoReload(args);
if (!args.WasModified<DecalPrototype>())
return;
PopulateCrayons();
}
protected override void UpdateState(BoundUserInterfaceState state)
{
base.UpdateState(state);
@@ -43,16 +60,5 @@ namespace Content.Client.Crayon.UI
{
SendMessage(new CrayonColorMessage(color));
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (disposing)
{
_menu?.Close();
_menu = null;
}
}
}
}