Files
tbd-station-14/Content.Server/Power/EntitySystems/ActivatableUIRequiresPowerSystem.cs
20kdc f6d44be34f Activatable UI component (#5184)
* Transfer most Instrument UI logic to a new component, ActivatableUIComponent

* Move more ActivatableUIComponent stuff to ECS

* ActivatableUI component ignore on client

* ActivatableUI: Get rid of component interfaces where possible

* Add in adminOnly attribute for activatable UIs

This is so that porting #4926 to this will be easier

* Transition Solar Control Computer to ActivatableUI

* Move communications console to ActivatableUI

* Move cargo console to ActivatableUI

* Move ID card console to ActivatableUI

* ActivatableUI: Make things more amiable to entity tests adding components weirdly

* ActivatableUI: Use handling or lack thereof of events properly

* ActivatableUI: component dependency issue resolution stuffs

* ActivatableUISystem: Fix #5258

* More fixes because master did stuffo

* Check for HandDeselectedEvent again because otherwise active-hand check doesn't work

* Move just a bit more code into the system, introduce a workaround for #5258

* Purge the player status detection stuff

* Oh and some obsolete stuff too
2021-11-23 19:19:08 +01:00

54 lines
1.9 KiB
C#

using System.Linq;
using Content.Shared;
using Content.Shared.CCVar;
using Content.Shared.ActionBlocker;
using Content.Shared.Hands;
using Content.Shared.Popups;
using Content.Shared.Standing;
using Content.Shared.Stunnable;
using Content.Shared.Throwing;
using Content.Shared.Interaction;
using Content.Shared.Interaction.Helpers;
using Content.Server.Power.Components;
using Content.Server.UserInterface;
using JetBrains.Annotations;
using Robust.Server.GameObjects;
using Robust.Server.Player;
using Robust.Shared.Configuration;
using Robust.Shared.Localization;
using Robust.Shared.GameObjects;
using Robust.Shared.Network;
using Robust.Shared.IoC;
namespace Content.Server.Power.EntitySystems
{
[UsedImplicitly]
internal sealed class ActivatableUIRequiresPowerSystem : EntitySystem
{
[Dependency] private readonly ActivatableUISystem _activatableUISystem = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<ActivatableUIRequiresPowerComponent, ActivatableUIOpenAttemptEvent>(OnActivate);
SubscribeLocalEvent<ActivatableUIRequiresPowerComponent, PowerChangedEvent>(OnPowerChanged);
}
private void OnActivate(EntityUid uid, ActivatableUIRequiresPowerComponent component, ActivatableUIOpenAttemptEvent args)
{
if (args.Cancelled) return;
if (EntityManager.TryGetComponent<ApcPowerReceiverComponent>(uid, out var power) && !power.Powered)
{
args.User.PopupMessageCursor(Loc.GetString("base-computer-ui-component-not-powered"));
args.Cancel();
}
}
private void OnPowerChanged(EntityUid uid, ActivatableUIRequiresPowerComponent component, PowerChangedEvent args)
{
if (!args.Powered)
_activatableUISystem.CloseAll(uid);
}
}
}