Files
tbd-station-14/Content.Client/Power/Generator/PortableGeneratorBoundUserInterface.cs
metalgearsloth cbf329a82d 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
2024-07-20 15:40:16 +10:00

74 lines
1.6 KiB
C#

using Content.Shared.Power.Generator;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
using Robust.Client.UserInterface;
namespace Content.Client.Power.Generator;
[UsedImplicitly]
public sealed class PortableGeneratorBoundUserInterface : BoundUserInterface
{
private GeneratorWindow? _window;
public PortableGeneratorBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{
}
protected override void Open()
{
base.Open();
_window = this.CreateWindow<GeneratorWindow>();
_window.SetEntity(Owner);
_window.OnState += args =>
{
if (args)
{
Start();
}
else
{
Stop();
}
};
_window.OnPower += SetTargetPower;
_window.OnEjectFuel += EjectFuel;
_window.OnSwitchOutput += SwitchOutput;
_window.OpenCenteredLeft();
}
protected override void UpdateState(BoundUserInterfaceState state)
{
if (state is not PortableGeneratorComponentBuiState msg)
return;
_window?.Update(msg);
}
public void SetTargetPower(int target)
{
SendMessage(new PortableGeneratorSetTargetPowerMessage(target));
}
public void Start()
{
SendMessage(new PortableGeneratorStartMessage());
}
public void Stop()
{
SendMessage(new PortableGeneratorStopMessage());
}
public void SwitchOutput()
{
SendMessage(new PortableGeneratorSwitchOutputMessage());
}
public void EjectFuel()
{
SendMessage(new PortableGeneratorEjectFuelMessage());
}
}