CatStation/Content.Shared/TurretController/SharedDeployableTurretControllerSystem.cs
Whatstone a88d2c5164
Cleanup: Resolve remaining PopupSystem warnings in Content.Shared (#44685)
* PopupClient to PopupEntity/Coordinates

* PopupPredictedX to PopupEntity/Cursor/Coordinates

* The rest of the damn owl

* nullability fixes

* Buckle cleanup

* cleanup, address PR comments

* ExecutionSystem: one popup method

* correct my filthy lies

* Apply most of ajcm's suggestions

* return user to SharedItemRecallSystem.cs

* Fix lingering Ensnarable broadcast popups

* targeted drain popups

* fix lingering untargeted Guardian popups

I read the comment on GuardianHostRecall.  Oops.

* target stethoscope popups

* fix the PDA vibration popup

* Fix target for encryption key removal popup

* anomaly scanner: args.User, not uid

* disposal unit comment, bcast pda vibration popup
2026-07-16 21:54:33 +00:00

96 lines
3.8 KiB
C#

using Content.Shared.Access;
using Content.Shared.Access.Systems;
using Content.Shared.Popups;
using Content.Shared.Turrets;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Prototypes;
namespace Content.Shared.TurretController;
/// <summary>
/// Oversees entities that can change the component values of linked deployable turrets,
/// specifically their armament and access level exemptions, via an associated UI
/// </summary>
public abstract partial class SharedDeployableTurretControllerSystem : EntitySystem
{
[Dependency] private AccessReaderSystem _accessreader = default!;
[Dependency] private TurretTargetSettingsSystem _turretTargetingSettings = default!;
[Dependency] private SharedUserInterfaceSystem _userInterfaceSystem = default!;
[Dependency] private SharedPopupSystem _popup = default!;
[Dependency] private SharedAudioSystem _audio = default!;
[Dependency] private SharedAppearanceSystem _appearance = default!;
public override void Initialize()
{
base.Initialize();
// Handling of client messages
SubscribeLocalEvent<DeployableTurretControllerComponent, DeployableTurretArmamentSettingChangedMessage>(OnArmamentSettingChanged);
SubscribeLocalEvent<DeployableTurretControllerComponent, DeployableTurretExemptAccessLevelChangedMessage>(OnExemptAccessLevelsChanged);
}
private void OnArmamentSettingChanged(Entity<DeployableTurretControllerComponent> ent, ref DeployableTurretArmamentSettingChangedMessage args)
{
if (IsUserAllowedAccess(ent, args.Actor))
ChangeArmamentSetting(ent, args.ArmamentState, args.Actor);
if (_userInterfaceSystem.TryGetOpenUi(ent.Owner, DeployableTurretControllerUiKey.Key, out var bui))
bui.Update<DeployableTurretControllerBoundInterfaceState>();
}
private void OnExemptAccessLevelsChanged(Entity<DeployableTurretControllerComponent> ent, ref DeployableTurretExemptAccessLevelChangedMessage args)
{
if (IsUserAllowedAccess(ent, args.Actor))
ChangeExemptAccessLevels(ent, args.AccessLevels, args.Enabled, args.Actor);
if (_userInterfaceSystem.TryGetOpenUi(ent.Owner, DeployableTurretControllerUiKey.Key, out var bui))
bui.Update<DeployableTurretControllerBoundInterfaceState>();
}
protected virtual void ChangeArmamentSetting(Entity<DeployableTurretControllerComponent> ent, int armamentState, EntityUid? user = null)
{
ent.Comp.ArmamentState = armamentState;
Dirty(ent);
_appearance.SetData(ent, TurretControllerVisuals.ControlPanel, armamentState);
// Linked turrets are updated on the server side
}
protected virtual void ChangeExemptAccessLevels(
Entity<DeployableTurretControllerComponent> ent,
HashSet<ProtoId<AccessLevelPrototype>> exemptions,
bool enabled,
EntityUid? user = null
)
{
// Update the controller
if (!TryComp<TurretTargetSettingsComponent>(ent, out var targetSettings))
return;
var controller = new Entity<TurretTargetSettingsComponent>(ent, targetSettings);
foreach (var accessLevel in exemptions)
{
if (!ent.Comp.AccessLevels.Contains(accessLevel))
continue;
_turretTargetingSettings.SetAccessLevelExemption(controller, accessLevel, enabled);
}
Dirty(controller);
// Linked turrets are updated on the server side
}
public bool IsUserAllowedAccess(Entity<DeployableTurretControllerComponent> ent, EntityUid user)
{
if (_accessreader.IsAllowed(user, ent))
return true;
_popup.PopupEntity(Loc.GetString("turret-controls-access-denied"), ent, user);
_audio.PlayPredicted(ent.Comp.AccessDeniedSound, ent, user);
return false;
}
}