2022-11-08 16:10:13 -05:00
|
|
|
using Content.Shared.Eye.Blinding;
|
2024-02-01 11:45:24 +03:00
|
|
|
using Content.Shared.UserInterface;
|
2022-11-08 16:10:13 -05:00
|
|
|
using Content.Server.Popups;
|
2023-04-29 17:32:14 +12:00
|
|
|
using Content.Shared.Eye.Blinding.Components;
|
|
|
|
|
using Content.Shared.Eye.Blinding.Systems;
|
2022-11-08 16:10:13 -05:00
|
|
|
using Robust.Shared.Player;
|
|
|
|
|
using Robust.Server.GameObjects;
|
|
|
|
|
|
2023-04-23 12:25:12 +10:00
|
|
|
namespace Content.Server.Eye.Blinding;
|
|
|
|
|
|
|
|
|
|
public sealed class ActivatableUIRequiresVisionSystem : EntitySystem
|
2022-11-08 16:10:13 -05:00
|
|
|
{
|
2023-04-23 12:25:12 +10:00
|
|
|
[Dependency] private readonly PopupSystem _popupSystem = default!;
|
|
|
|
|
[Dependency] private readonly UserInterfaceSystem _userInterfaceSystem = default!;
|
|
|
|
|
|
|
|
|
|
public override void Initialize()
|
2022-11-08 16:10:13 -05:00
|
|
|
{
|
2023-04-23 12:25:12 +10:00
|
|
|
base.Initialize();
|
|
|
|
|
SubscribeLocalEvent<ActivatableUIRequiresVisionComponent, ActivatableUIOpenAttemptEvent>(OnOpenAttempt);
|
|
|
|
|
SubscribeLocalEvent<BlindableComponent, BlindnessChangedEvent>(OnBlindnessChanged);
|
|
|
|
|
}
|
2022-11-08 16:10:13 -05:00
|
|
|
|
2023-04-23 12:25:12 +10:00
|
|
|
private void OnOpenAttempt(EntityUid uid, ActivatableUIRequiresVisionComponent component, ActivatableUIOpenAttemptEvent args)
|
|
|
|
|
{
|
|
|
|
|
if (args.Cancelled)
|
|
|
|
|
return;
|
2022-11-08 16:10:13 -05:00
|
|
|
|
2023-04-29 17:32:14 +12:00
|
|
|
if (TryComp<BlindableComponent>(args.User, out var blindable) && blindable.IsBlind)
|
2022-11-08 16:10:13 -05:00
|
|
|
{
|
2023-04-23 12:25:12 +10:00
|
|
|
_popupSystem.PopupCursor(Loc.GetString("blindness-fail-attempt"), args.User, Shared.Popups.PopupType.MediumCaution);
|
|
|
|
|
args.Cancel();
|
2022-11-08 16:10:13 -05:00
|
|
|
}
|
2023-04-23 12:25:12 +10:00
|
|
|
}
|
2022-11-08 16:10:13 -05:00
|
|
|
|
2023-04-29 17:32:14 +12:00
|
|
|
private void OnBlindnessChanged(EntityUid uid, BlindableComponent component, ref BlindnessChangedEvent args)
|
2023-04-23 12:25:12 +10:00
|
|
|
{
|
|
|
|
|
if (!args.Blind)
|
|
|
|
|
return;
|
2022-11-08 16:10:13 -05:00
|
|
|
|
2023-04-23 12:25:12 +10:00
|
|
|
if (!TryComp<ActorComponent>(uid, out var actor))
|
|
|
|
|
return;
|
2022-11-08 16:10:13 -05:00
|
|
|
|
2023-04-23 12:25:12 +10:00
|
|
|
var uiList = _userInterfaceSystem.GetAllUIsForSession(actor.PlayerSession);
|
|
|
|
|
if (uiList == null)
|
|
|
|
|
return;
|
2022-11-08 16:10:13 -05:00
|
|
|
|
2023-09-11 21:20:46 +10:00
|
|
|
Queue<PlayerBoundUserInterface> closeList = new(); // foreach collection modified moment
|
2022-11-08 16:10:13 -05:00
|
|
|
|
2023-04-23 12:25:12 +10:00
|
|
|
foreach (var ui in uiList)
|
|
|
|
|
{
|
|
|
|
|
if (HasComp<ActivatableUIRequiresVisionComponent>(ui.Owner))
|
|
|
|
|
closeList.Enqueue(ui);
|
|
|
|
|
}
|
2022-11-08 16:10:13 -05:00
|
|
|
|
2023-04-23 12:25:12 +10:00
|
|
|
foreach (var ui in closeList)
|
|
|
|
|
{
|
|
|
|
|
_userInterfaceSystem.CloseUi(ui, actor.PlayerSession);
|
2022-11-08 16:10:13 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|