diff --git a/Content.Server/Eye/Blinding/ActivatableUIRequiresVisionComponent.cs b/Content.Server/Eye/Blinding/ActivatableUIRequiresVisionComponent.cs new file mode 100644 index 0000000000..8f8c7f0fb0 --- /dev/null +++ b/Content.Server/Eye/Blinding/ActivatableUIRequiresVisionComponent.cs @@ -0,0 +1,8 @@ +namespace Content.Server.Eye.Blinding +{ + [RegisterComponent] + public sealed class ActivatableUIRequiresVisionComponent : Component + { + } +} + diff --git a/Content.Server/Eye/Blinding/ActivatableUIRequiresVisionSystem.cs b/Content.Server/Eye/Blinding/ActivatableUIRequiresVisionSystem.cs new file mode 100644 index 0000000000..5a6156aaa8 --- /dev/null +++ b/Content.Server/Eye/Blinding/ActivatableUIRequiresVisionSystem.cs @@ -0,0 +1,60 @@ +using Content.Shared.Eye.Blinding; +using Content.Server.UserInterface; +using Content.Server.Popups; +using Robust.Shared.Player; +using Robust.Server.GameObjects; + +namespace Content.Server.Eye.Blinding +{ + public sealed class ActivatableUIRequiresVisionSystem : EntitySystem + { + [Dependency] private readonly ActivatableUISystem _activatableUISystem = default!; + [Dependency] private readonly PopupSystem _popupSystem = default!; + [Dependency] private readonly UserInterfaceSystem _userInterfaceSystem = default!; + + public override void Initialize() + { + base.Initialize(); + SubscribeLocalEvent(OnOpenAttempt); + SubscribeLocalEvent(OnBlindnessChanged); + } + + private void OnOpenAttempt(EntityUid uid, ActivatableUIRequiresVisionComponent component, ActivatableUIOpenAttemptEvent args) + { + if (args.Cancelled) + return; + + if (TryComp(args.User, out var blindable) && blindable.Sources > 0) + { + _popupSystem.PopupCursor(Loc.GetString("blindness-fail-attempt"), Filter.Entities(args.User), Shared.Popups.PopupType.MediumCaution); + args.Cancel(); + } + } + + private void OnBlindnessChanged(EntityUid uid, BlindableComponent component, BlindnessChangedEvent args) + { + if (!args.Blind) + return; + + if (!TryComp(uid, out var actor)) + return; + + var uiList = _userInterfaceSystem.GetAllUIsForSession(actor.PlayerSession); + if (uiList == null) + return; + + Queue closeList = new(); // foreach collection modified moment + + foreach (var ui in uiList) + { + if (HasComp(ui.Owner)) + closeList.Enqueue(ui); + } + + foreach (var ui in closeList) + { + _userInterfaceSystem.CloseUi(ui, actor.PlayerSession); + } + } + } +} diff --git a/Content.Shared/Eye/Blinding/SharedBlindingSystem.cs b/Content.Shared/Eye/Blinding/SharedBlindingSystem.cs index 41fff76fbc..fbbc76967b 100644 --- a/Content.Shared/Eye/Blinding/SharedBlindingSystem.cs +++ b/Content.Shared/Eye/Blinding/SharedBlindingSystem.cs @@ -103,9 +103,21 @@ namespace Content.Shared.Eye.Blinding if (!Resolve(uid, ref blindable, false)) return; + var oldSources = blindable.Sources; + blindable.Sources += amount; blindable.Sources = Math.Max(blindable.Sources, 0); + if (oldSources == 0 && blindable.Sources > 0) + { + var ev = new BlindnessChangedEvent(true); + RaiseLocalEvent(uid, ev, false); + } else if (blindable.Sources == 0 && oldSources > 0) + { + var ev = new BlindnessChangedEvent(false); + RaiseLocalEvent(uid, ev, false); + } + Dirty(blindable); } @@ -152,4 +164,17 @@ namespace Content.Shared.Eye.Blinding Magnitude = magnitude; } } + + /// + /// You became blind or lost blindess, not just changed # of sources. + /// + public sealed class BlindnessChangedEvent : EntityEventArgs + { + public bool Blind; + + public BlindnessChangedEvent(bool blind) + { + Blind = blind; + } + } } diff --git a/Resources/Locale/en-US/eye/blindness.ftl b/Resources/Locale/en-US/eye/blindness.ftl new file mode 100644 index 0000000000..b1ce8d7dde --- /dev/null +++ b/Resources/Locale/en-US/eye/blindness.ftl @@ -0,0 +1 @@ +blindness-fail-attempt = You can't do that if you're blind! diff --git a/Resources/Prototypes/Entities/Structures/Machines/Computers/computers.yml b/Resources/Prototypes/Entities/Structures/Machines/Computers/computers.yml index e081701f8f..eda1798033 100644 --- a/Resources/Prototypes/Entities/Structures/Machines/Computers/computers.yml +++ b/Resources/Prototypes/Entities/Structures/Machines/Computers/computers.yml @@ -687,6 +687,7 @@ - type: ActivatableUI key: enum.SurveillanceCameraMonitorUiKey.Key - type: ActivatableUIRequiresPower + - type: ActivatableUIRequiresVision - type: Transform anchored: true - type: UserInterface @@ -721,6 +722,7 @@ - type: ActivatableUI key: enum.SurveillanceCameraMonitorUiKey.Key - type: ActivatableUIRequiresPower + - type: ActivatableUIRequiresVision - type: Transform anchored: true - type: UserInterface