* Fix ActivatableUIRequiresPowerCellComponent stopping power draw when one of two people closes the UI. Also fixes it to check UiKey properly. * Remove unnecessary CrewManifestViewer on PDAs This is for a pop-up crew manifest UI, which the PDA doesn't use. * Fix BoundUIClosedEvents that didn't check UI key/not correctly at least. Uses the new helper method in engine. * Fix drone (cargo shuttle) pilot console UI breaking if two people open it and one person closes it. * Fixes for disposal router/tagger UI. Code was badly copy pasted without changing identifiers, never worked. Also cleaned up some of the logic (text trimming, sounds). Also removed the "refuse to work if you have something in your active hand" check like why. * Avoid running most ActivatableUIComponent logic when closing a UI via toggle Activating the UI while it's already open closes it via toggle. Except it still ran 99% of the "attempting to open" logic which makes no sense. This probably fixes a bug or some other dumb behavior somewhere. * Bitch
81 lines
2.9 KiB
C#
81 lines
2.9 KiB
C#
using Content.Server.PowerCell;
|
|
using Content.Shared.PowerCell;
|
|
using Robust.Shared.Containers;
|
|
|
|
namespace Content.Server.UserInterface;
|
|
|
|
public sealed partial class ActivatableUISystem
|
|
{
|
|
[Dependency] private readonly PowerCellSystem _cell = default!;
|
|
|
|
private void InitializePower()
|
|
{
|
|
SubscribeLocalEvent<ActivatableUIRequiresPowerCellComponent, ActivatableUIOpenAttemptEvent>(OnBatteryOpenAttempt);
|
|
SubscribeLocalEvent<ActivatableUIRequiresPowerCellComponent, BoundUIOpenedEvent>(OnBatteryOpened);
|
|
SubscribeLocalEvent<ActivatableUIRequiresPowerCellComponent, BoundUIClosedEvent>(OnBatteryClosed);
|
|
|
|
SubscribeLocalEvent<PowerCellDrawComponent, EntRemovedFromContainerMessage>(OnPowerCellRemoved);
|
|
}
|
|
|
|
private void OnPowerCellRemoved(EntityUid uid, PowerCellDrawComponent component, EntRemovedFromContainerMessage args)
|
|
{
|
|
_cell.SetPowerCellDrawEnabled(uid, false);
|
|
|
|
if (HasComp<ActivatableUIRequiresPowerCellComponent>(uid) &&
|
|
TryComp<ActivatableUIComponent>(uid, out var activatable) &&
|
|
activatable.Key != null)
|
|
{
|
|
_uiSystem.TryCloseAll(uid, activatable.Key);
|
|
}
|
|
}
|
|
|
|
private void OnBatteryOpened(EntityUid uid, ActivatableUIRequiresPowerCellComponent component, BoundUIOpenedEvent args)
|
|
{
|
|
var activatable = Comp<ActivatableUIComponent>(uid);
|
|
|
|
if (!args.UiKey.Equals(activatable.Key))
|
|
return;
|
|
|
|
_cell.SetPowerCellDrawEnabled(uid, true);
|
|
}
|
|
|
|
private void OnBatteryClosed(EntityUid uid, ActivatableUIRequiresPowerCellComponent component, BoundUIClosedEvent args)
|
|
{
|
|
var activatable = Comp<ActivatableUIComponent>(uid);
|
|
|
|
if (!args.UiKey.Equals(activatable.Key))
|
|
return;
|
|
|
|
// Stop drawing power if this was the last person with the UI open.
|
|
if (!_uiSystem.IsUiOpen(uid, activatable.Key))
|
|
_cell.SetPowerCellDrawEnabled(uid, false);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Call if you want to check if the UI should close due to a recent battery usage.
|
|
/// </summary>
|
|
public void CheckUsage(EntityUid uid, ActivatableUIComponent? active = null, ActivatableUIRequiresPowerCellComponent? component = null, PowerCellDrawComponent? draw = null)
|
|
{
|
|
if (!Resolve(uid, ref component, ref draw, ref active, false) || active.Key == null)
|
|
return;
|
|
|
|
if (_cell.HasCharge(uid, draw.UseRate))
|
|
return;
|
|
|
|
_uiSystem.TryCloseAll(uid, active.Key);
|
|
}
|
|
|
|
private void OnBatteryOpenAttempt(EntityUid uid, ActivatableUIRequiresPowerCellComponent component, ActivatableUIOpenAttemptEvent args)
|
|
{
|
|
if (!TryComp<PowerCellDrawComponent>(uid, out var draw))
|
|
return;
|
|
|
|
// Check if we have the appropriate drawrate / userate to even open it.
|
|
if (args.Cancelled || !_cell.HasCharge(uid, MathF.Max(draw.DrawRate, draw.UseRate), user: args.User))
|
|
{
|
|
args.Cancel();
|
|
return;
|
|
}
|
|
}
|
|
}
|