Door Remote now shows Mode in UI (#26162)

* Prep for DoorRemote Status

* Door Remote Mode Messages

* plural opens and closes

* never trust webedits

---------

Co-authored-by: Plykiya <plykiya@protonmail.com>
This commit is contained in:
Plykiya
2024-03-21 17:19:52 -07:00
committed by GitHub
parent de6fc4033a
commit e627a0d24b
7 changed files with 151 additions and 67 deletions

View File

@@ -1,74 +1,40 @@
using Content.Server.Administration.Logs;
using Robust.Shared.Player;
using Content.Shared.Interaction;
using Content.Shared.Popups;
using Content.Shared.Doors.Components;
using Content.Shared.Doors.Systems;
using Content.Shared.Physics;
using Content.Shared.Access.Components;
using Content.Server.Doors.Systems;
using Content.Server.Power.EntitySystems;
using Content.Shared.Database;
using Content.Shared.Interaction.Events;
using Content.Shared.Examine;
using static Content.Server.Remotes.DoorRemoteComponent;
using Content.Shared.Remotes.EntitySystems;
using Content.Shared.Remotes.Components;
namespace Content.Server.Remotes
namespace Content.Shared.Remotes
{
public sealed class DoorRemoteSystem : EntitySystem
public sealed class DoorRemoteSystem : SharedDoorRemoteSystem
{
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
[Dependency] private readonly AirlockSystem _airlock = default!;
[Dependency] private readonly SharedPopupSystem _popupSystem = default!;
[Dependency] private readonly DoorSystem _doorSystem = default!;
[Dependency] private readonly SharedInteractionSystem _interactionSystem = default!;
[Dependency] private readonly ExamineSystemShared _examine = default!;
// I'm so sorry [Dependency] private readonly SharedAirlockSystem _sharedAirlockSystem = default!;
public override void Initialize()
{
SubscribeLocalEvent<DoorRemoteComponent, UseInHandEvent>(OnInHandActivation);
base.Initialize();
SubscribeLocalEvent<DoorRemoteComponent, BeforeRangedInteractEvent>(OnBeforeInteract);
}
public void OnInHandActivation(EntityUid user, DoorRemoteComponent component, UseInHandEvent args)
{
string switchMessageId;
switch (component.Mode)
{
case OperatingMode.OpenClose:
component.Mode = OperatingMode.ToggleBolts;
switchMessageId = "door-remote-switch-state-toggle-bolts";
break;
// Skip toggle bolts mode and move on from there (to emergency access)
case OperatingMode.ToggleBolts:
component.Mode = OperatingMode.ToggleEmergencyAccess;
switchMessageId = "door-remote-switch-state-toggle-emergency-access";
break;
// Skip ToggleEmergencyAccess mode and move on from there (to door toggle)
case OperatingMode.ToggleEmergencyAccess:
component.Mode = OperatingMode.OpenClose;
switchMessageId = "door-remote-switch-state-open-close";
break;
default:
throw new InvalidOperationException(
$"{nameof(DoorRemoteComponent)} had invalid mode {component.Mode}");
}
ShowPopupToUser(switchMessageId, args.User);
}
private void OnBeforeInteract(EntityUid uid, DoorRemoteComponent component, BeforeRangedInteractEvent args)
private void OnBeforeInteract(Entity<DoorRemoteComponent> entity, ref BeforeRangedInteractEvent args)
{
bool isAirlock = TryComp<AirlockComponent>(args.Target, out var airlockComp);
if (args.Handled
|| args.Target == null
|| !TryComp<DoorComponent>(args.Target, out var doorComp) // If it isn't a door we don't use it
// Only able to control doors if they are within your vision and within your max range.
// Not affected by mobs or machines anymore.
// Only able to control doors if they are within your vision and within your max range.
// Not affected by mobs or machines anymore.
|| !_examine.InRangeUnOccluded(args.User, args.Target.Value, SharedInteractionSystem.MaxRaycastRange, null))
{
return;
}
@@ -77,7 +43,7 @@ namespace Content.Server.Remotes
if (!this.IsPowered(args.Target.Value, EntityManager))
{
ShowPopupToUser("door-remote-no-power", args.User);
Popup.PopupEntity(Loc.GetString("door-remote-no-power"), args.User, args.User);
return;
}
@@ -87,11 +53,11 @@ namespace Content.Server.Remotes
&& !_doorSystem.HasAccess(args.Target.Value, args.User, doorComp, accessComponent))
{
_doorSystem.Deny(args.Target.Value, doorComp, args.User);
ShowPopupToUser("door-remote-denied", args.User);
Popup.PopupEntity(Loc.GetString("door-remote-denied"), args.User, args.User);
return;
}
switch (component.Mode)
switch (entity.Comp.Mode)
{
case OperatingMode.OpenClose:
// Note we provide args.User here to TryToggleDoor as the "user"
@@ -120,11 +86,8 @@ namespace Content.Server.Remotes
break;
default:
throw new InvalidOperationException(
$"{nameof(DoorRemoteComponent)} had invalid mode {component.Mode}");
$"{nameof(DoorRemoteComponent)} had invalid mode {entity.Comp.Mode}");
}
}
private void ShowPopupToUser(string messageId, EntityUid user) =>
_popupSystem.PopupEntity(Loc.GetString(messageId), user, user);
}
}