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

@@ -18,9 +18,10 @@ namespace Content.Client.ParticleAccelerator.UI
{
public sealed class ParticleAcceleratorControlMenu : BaseWindow
{
private readonly ShaderInstance _greyScaleShader;
[Dependency] private readonly IPrototypeManager _protoManager = default!;
[Dependency] private readonly IResourceCache _cache = default!;
private readonly ParticleAcceleratorBoundUserInterface _owner;
private readonly ShaderInstance _greyScaleShader;
private readonly Label _drawLabel;
private readonly FastNoiseLite _drawNoiseGenerator;
@@ -50,19 +51,21 @@ namespace Content.Client.ParticleAccelerator.UI
private bool _shouldContinueAnimating;
private int _maxStrength = 3;
public ParticleAcceleratorControlMenu(ParticleAcceleratorBoundUserInterface owner)
public event Action<bool>? OnOverallState;
public event Action<ParticleAcceleratorPowerState>? OnPowerState;
public event Action? OnScanPartsRequested;
public ParticleAcceleratorControlMenu()
{
SetSize = new Vector2(400, 320);
_greyScaleShader = IoCManager.Resolve<IPrototypeManager>().Index<ShaderPrototype>("Greyscale").Instance();
_greyScaleShader = _protoManager.Index<ShaderPrototype>("Greyscale").Instance();
_owner = owner;
_drawNoiseGenerator = new();
_drawNoiseGenerator.SetFractalType(FastNoiseLite.FractalType.FBm);
_drawNoiseGenerator.SetFrequency(0.5f);
var resourceCache = IoCManager.Resolve<IResourceCache>();
var font = resourceCache.GetFont("/Fonts/Boxfont-round/Boxfont Round.ttf", 13);
var panelTex = resourceCache.GetTexture("/Textures/Interface/Nano/button.svg.96dpi.png");
var font = _cache.GetFont("/Fonts/Boxfont-round/Boxfont Round.ttf", 13);
var panelTex = _cache.GetTexture("/Textures/Interface/Nano/button.svg.96dpi.png");
MouseFilter = MouseFilterMode.Stop;
@@ -112,7 +115,8 @@ namespace Content.Client.ParticleAccelerator.UI
Text = Loc.GetString("particle-accelerator-control-menu-off-button"),
StyleClasses = { StyleBase.ButtonOpenRight },
};
_offButton.OnPressed += args => owner.SendEnableMessage(false);
_offButton.OnPressed += args => OnOverallState?.Invoke(false);
_onButton = new Button
{
@@ -120,7 +124,7 @@ namespace Content.Client.ParticleAccelerator.UI
Text = Loc.GetString("particle-accelerator-control-menu-on-button"),
StyleClasses = { StyleBase.ButtonOpenLeft },
};
_onButton.OnPressed += args => owner.SendEnableMessage(true);
_onButton.OnPressed += args => OnOverallState?.Invoke(true);
var closeButton = new TextureButton
{
@@ -316,7 +320,7 @@ namespace Content.Client.ParticleAccelerator.UI
}
});
_scanButton.OnPressed += args => _owner.SendScanPartsMessage();
_scanButton.OnPressed += args => OnScanPartsRequested?.Invoke();
_alarmControl.AnimationCompleted += s =>
{
@@ -332,7 +336,7 @@ namespace Content.Client.ParticleAccelerator.UI
PASegmentControl Segment(string name)
{
return new(this, resourceCache, name);
return new(this, _cache, name);
}
UpdateUI(false, false, false, false);
@@ -368,7 +372,7 @@ namespace Content.Client.ParticleAccelerator.UI
}
_stateSpinBox.SetButtonDisabled(true);
_owner.SendPowerStateMessage(newState);
OnPowerState?.Invoke(newState);
}
protected override DragMode GetDragModeFor(Vector2 relativeMousePos)