]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
gateway changes (#20304)
authordeltanedas <39013340+deltanedas@users.noreply.github.com>
Mon, 18 Sep 2023 01:09:21 +0000 (02:09 +0100)
committerGitHub <noreply@github.com>
Mon, 18 Sep 2023 01:09:21 +0000 (11:09 +1000)
Co-authored-by: deltanedas <@deltanedas:kde.org>
Content.Client/Gateway/UI/GatewayWindow.xaml.cs
Content.Server/Gateway/Components/GatewayComponent.cs
Content.Server/Gateway/Components/GatewayDestinationComponent.cs
Content.Server/Gateway/Systems/GatewaySystem.cs
Content.Shared/Teleportation/Systems/LinkedEntitySystem.cs
Resources/Locale/en-US/gateway/gateway.ftl

index 00293065dc9952fedd50dd2fe569d1251482e9b6..f2219084321b20210a7b88a5dafabd189eda15b7 100644 (file)
@@ -83,7 +83,7 @@ public sealed partial class GatewayWindow : FancyWindow,
 
             var readyLabel = new Label
             {
-                Text = ReadyText(now, nextReady),
+                Text = ReadyText(now, nextReady, busy),
                 Margin = new Thickness(10f, 0f, 0f, 0f)
             };
             _readyLabels.Add(readyLabel);
@@ -163,13 +163,16 @@ public sealed partial class GatewayWindow : FancyWindow,
             var dest = _destinations[i];
             var nextReady = dest.Item3;
             var busy = dest.Item4;
-            _readyLabels[i].Text = ReadyText(now, nextReady);
+            _readyLabels[i].Text = ReadyText(now, nextReady, busy);
             _openButtons[i].Disabled = _current != null || busy || now < nextReady;
         }
     }
 
-    private string ReadyText(TimeSpan now, TimeSpan nextReady)
+    private string ReadyText(TimeSpan now, TimeSpan nextReady, bool busy)
     {
+        if (busy)
+            return Loc.GetString("gateway-window-already-active");
+
         if (now < nextReady)
         {
             var time = nextReady - now;
index 7e2a76c65593c6bea6b66bdf282c0a909c345c64..5145cb6b08b9afa066adf1255b0baf740f2ba039 100644 (file)
@@ -11,10 +11,25 @@ namespace Content.Server.Gateway.Components;
 public sealed partial class GatewayComponent : Component
 {
     /// <summary>
-    /// Sound to play when opening or closing the portal.
+    /// Sound to play when opening the portal.
     /// </summary>
+    /// <remarks>
+    /// Originally named PortalSound as it was used for opening and closing.
+    /// </remarks>
     [DataField("portalSound")]
-    public SoundSpecifier PortalSound = new SoundPathSpecifier("/Audio/Effects/Lightning/lightningbolt.ogg");
+    public SoundSpecifier OpenSound = new SoundPathSpecifier("/Audio/Effects/Lightning/lightningbolt.ogg");
+
+    /// <summary>
+    /// Sound to play when closing the portal.
+    /// </summary>
+    [DataField]
+    public SoundSpecifier CloseSound = new SoundPathSpecifier("/Audio/Effects/Lightning/lightningbolt.ogg");
+
+    /// <summary>
+    /// Sound to play when trying to open or close the portal and missing access.
+    /// </summary>
+    [DataField]
+    public SoundSpecifier AccessDeniedSound = new SoundPathSpecifier("/Audio/Machines/custom_deny.ogg");
 
     /// <summary>
     /// Every other gateway destination on the server.
@@ -22,19 +37,19 @@ public sealed partial class GatewayComponent : Component
     /// <remarks>
     /// Added on startup and when a new destination portal is created.
     /// </remarks>
-    [ViewVariables]
+    [DataField]
     public HashSet<EntityUid> Destinations = new();
 
     /// <summary>
     /// The time at which the portal will be closed.
     /// </summary>
-    [ViewVariables(VVAccess.ReadWrite), DataField("nextClose", customTypeSerializer:typeof(TimeOffsetSerializer))]
+    [ViewVariables(VVAccess.ReadWrite), DataField(customTypeSerializer: typeof(TimeOffsetSerializer))]
     public TimeSpan NextClose;
 
     /// <summary>
     /// The time at which the portal was last opened.
     /// Only used for UI.
     /// </summary>
-    [ViewVariables]
+    [DataField(customTypeSerializer: typeof(TimeOffsetSerializer))]
     public TimeSpan LastOpen;
 }
index 50aff0b24a4626dbdf9de08cd1a93ecf9b3e4f12..41a41457f20590d25e6e6db329f8b0879e5e2319 100644 (file)
@@ -13,30 +13,36 @@ public sealed partial class GatewayDestinationComponent : Component
     /// Whether this destination is shown in the gateway ui.
     /// If you are making a gateway for an admeme set this once you are ready for players to select it.
     /// </summary>
-    [DataField("enabled"), ViewVariables(VVAccess.ReadWrite)]
+    [DataField, ViewVariables(VVAccess.ReadWrite)]
     public bool Enabled;
 
     /// <summary>
     /// Name as it shows up on the ui of station gateways.
     /// </summary>
-    [DataField("name"), ViewVariables(VVAccess.ReadWrite)]
+    [DataField, ViewVariables(VVAccess.ReadWrite)]
     public string Name = string.Empty;
 
     /// <summary>
     /// Time at which this destination is ready to be linked to.
     /// </summary>
-    [ViewVariables(VVAccess.ReadWrite), DataField("nextReady", customTypeSerializer:typeof(TimeOffsetSerializer))]
+    [ViewVariables(VVAccess.ReadWrite), DataField(customTypeSerializer:typeof(TimeOffsetSerializer))]
     public TimeSpan NextReady;
 
     /// <summary>
     /// How long the portal will be open for after linking.
     /// </summary>
-    [DataField("openTime"), ViewVariables(VVAccess.ReadWrite)]
+    [DataField, ViewVariables(VVAccess.ReadWrite)]
     public TimeSpan OpenTime = TimeSpan.FromSeconds(600);
 
     /// <summary>
     /// How long the destination is not ready for after the portal closes.
     /// </summary>
-    [DataField("cooldown"), ViewVariables(VVAccess.ReadWrite)]
+    [DataField, ViewVariables(VVAccess.ReadWrite)]
     public TimeSpan Cooldown = TimeSpan.FromSeconds(60);
+
+    /// <summary>
+    /// If true, the portal can be closed by alt clicking it.
+    /// </summary>
+    [DataField, ViewVariables(VVAccess.ReadWrite)]
+    public bool Closeable;
 }
index 6fd49129175f7aaa2b3e7e9327ba386e6c01c081..ae00cd378c0756fc84928085eac4086fc8108382 100644 (file)
@@ -1,14 +1,14 @@
 using Content.Server.Gateway.Components;
 using Content.Shared.Access.Systems;
 using Content.Shared.Gateway;
+using Content.Shared.Popups;
 using Content.Shared.Teleportation.Components;
 using Content.Shared.Teleportation.Systems;
+using Content.Shared.Verbs;
 using Robust.Server.GameObjects;
 using Robust.Shared.Audio;
 using Robust.Shared.GameObjects;
 using Robust.Shared.Timing;
-using System.Diagnostics.CodeAnalysis;
-using System.Linq;
 
 namespace Content.Server.Gateway.Systems;
 
@@ -19,6 +19,7 @@ public sealed class GatewaySystem : EntitySystem
     [Dependency] private readonly LinkedEntitySystem _linkedEntity = default!;
     [Dependency] private readonly SharedAppearanceSystem _appearance = default!;
     [Dependency] private readonly SharedAudioSystem _audio = default!;
+    [Dependency] private readonly SharedPopupSystem _popup = default!;
     [Dependency] private readonly UserInterfaceSystem _ui = default!;
 
     public override void Initialize()
@@ -31,6 +32,7 @@ public sealed class GatewaySystem : EntitySystem
 
         SubscribeLocalEvent<GatewayDestinationComponent, ComponentStartup>(OnDestinationStartup);
         SubscribeLocalEvent<GatewayDestinationComponent, ComponentShutdown>(OnDestinationShutdown);
+        SubscribeLocalEvent<GatewayDestinationComponent, GetVerbsEvent<AlternativeVerb>>(OnDestinationGetVerbs);
     }
 
     public override void Update(float frameTime)
@@ -78,7 +80,7 @@ public sealed class GatewaySystem : EntitySystem
             destinations.Add((GetNetEntity(destUid), dest.Name, dest.NextReady, HasComp<PortalComponent>(destUid)));
         }
 
-        GetDestination(uid, out var current);
+        _linkedEntity.GetLink(uid, out var current);
         var state = new GatewayBoundUserInterfaceState(destinations, GetNetEntity(current), comp.NextClose, comp.LastOpen);
         _ui.TrySetUiState(uid, GatewayUiKey.Key, state);
     }
@@ -95,7 +97,7 @@ public sealed class GatewaySystem : EntitySystem
 
         // if the gateway has an access reader check it before allowing opening
         var user = args.Session.AttachedEntity.Value;
-        if (!_accessReader.IsAllowed(user, uid))
+        if (CheckAccess(user, uid))
             return;
 
         // can't link if portal is already open on either side, the destination is invalid or on cooldown
@@ -123,18 +125,21 @@ public sealed class GatewaySystem : EntitySystem
         // close automatically after time is up
         comp.NextClose = comp.LastOpen + destComp.OpenTime;
 
-        _audio.PlayPvs(comp.PortalSound, uid);
-        _audio.PlayPvs(comp.PortalSound, dest);
+        _audio.PlayPvs(comp.OpenSound, uid);
+        _audio.PlayPvs(comp.OpenSound, dest);
 
         UpdateUserInterface(uid, comp);
         UpdateAppearance(uid);
         UpdateAppearance(dest);
     }
 
-    private void ClosePortal(EntityUid uid, GatewayComponent comp)
+    private void ClosePortal(EntityUid uid, GatewayComponent? comp = null)
     {
+        if (!Resolve(uid, ref comp))
+            return;
+
         RemComp<PortalComponent>(uid);
-        if (!GetDestination(uid, out var dest))
+        if (!_linkedEntity.GetLink(uid, out var dest))
             return;
 
         if (TryComp<GatewayDestinationComponent>(dest, out var destComp))
@@ -143,8 +148,8 @@ public sealed class GatewaySystem : EntitySystem
             destComp.NextReady = _timing.CurTime + destComp.Cooldown;
         }
 
-        _audio.PlayPvs(comp.PortalSound, uid);
-        _audio.PlayPvs(comp.PortalSound, dest.Value);
+        _audio.PlayPvs(comp.CloseSound, uid);
+        _audio.PlayPvs(comp.CloseSound, dest.Value);
 
         _linkedEntity.TryUnlink(uid, dest.Value);
         RemComp<PortalComponent>(dest.Value);
@@ -153,22 +158,6 @@ public sealed class GatewaySystem : EntitySystem
         UpdateAppearance(dest.Value);
     }
 
-    private bool GetDestination(EntityUid uid, [NotNullWhen(true)] out EntityUid? dest)
-    {
-        dest = null;
-        if (TryComp<LinkedEntityComponent>(uid, out var linked))
-        {
-            var first = linked.LinkedEntities.FirstOrDefault();
-            if (first != EntityUid.Invalid)
-            {
-                dest = first;
-                return true;
-            }
-        }
-
-        return false;
-    }
-
     private void OnDestinationStartup(EntityUid uid, GatewayDestinationComponent comp, ComponentStartup args)
     {
         var query = EntityQueryEnumerator<GatewayComponent>();
@@ -190,4 +179,47 @@ public sealed class GatewaySystem : EntitySystem
             UpdateUserInterface(gatewayUid, gateway);
         }
     }
+
+    private void OnDestinationGetVerbs(EntityUid uid, GatewayDestinationComponent comp, GetVerbsEvent<AlternativeVerb> args)
+    {
+        if (!comp.Closeable || !args.CanInteract || !args.CanAccess)
+            return;
+
+        // a portal is open so add verb to close it
+        args.Verbs.Add(new AlternativeVerb()
+        {
+            Act = () => TryClose(uid, args.User),
+            Text = Loc.GetString("gateway-close-portal")
+        });
+    }
+
+    private void TryClose(EntityUid uid, EntityUid user)
+    {
+        // portal already closed so cant close it
+        if (!_linkedEntity.GetLink(uid, out var source))
+            return;
+
+        // not allowed to close it
+        if (CheckAccess(user, source.Value))
+            return;
+
+        ClosePortal(source.Value);
+    }
+
+    /// <summary>
+    /// Checks the user's access. Makes popup and plays sound if missing access.
+    /// Returns whether access was missing.
+    /// </summary>
+    private bool CheckAccess(EntityUid user, EntityUid uid, GatewayComponent? comp = null)
+    {
+        if (!Resolve(uid, ref comp))
+            return false;
+
+        if (_accessReader.IsAllowed(user, uid))
+            return false;
+
+        _popup.PopupEntity(Loc.GetString("gateway-access-denied"), user);
+        _audio.PlayPvs(comp.AccessDeniedSound, uid);
+        return true;
+    }
 }
index 12667e488604b80d257a715b70a6d2306c2986d3..73e686e8bdc14e0d0f11679107ba66f1ac7a0e0b 100644 (file)
@@ -1,6 +1,7 @@
-using System.Linq;
 using Content.Shared.Teleportation.Components;
 using Robust.Shared.GameStates;
+using System.Diagnostics.CodeAnalysis;
+using System.Linq;
 
 namespace Content.Shared.Teleportation.Systems;
 
@@ -113,5 +114,25 @@ public sealed class LinkedEntitySystem : EntitySystem
         return success;
     }
 
+    /// <summary>
+    /// Get the first entity this entity is linked to.
+    /// If multiple are linked only the first one is picked.
+    /// </summary>
+    public bool GetLink(EntityUid uid, [NotNullWhen(true)] out EntityUid? dest, LinkedEntityComponent? comp = null)
+    {
+        dest = null;
+        if (!Resolve(uid, ref comp, false))
+            return false;
+
+        var first = comp.LinkedEntities.FirstOrDefault();
+        if (first != default)
+        {
+            dest = first;
+            return true;
+        }
+
+        return false;
+    }
+
     #endregion
 }
index 2e6a75554b23799945ebc589d3a8f5f890180dd4..bebc82b60f6e5d1db1fed11a27306c70b6fc2304 100644 (file)
@@ -1,6 +1,10 @@
 gateway-window-title = Gateway
 gateway-window-ready = Ready!
 gateway-window-ready-in = Ready in: {$time}s
+gateway-window-already-active = Already active
 gateway-window-open-portal = Open Portal
 gateway-window-no-destinations = No destinations found.
 gateway-window-portal-closing = Portal closing
+
+gateway-access-denied = Access denied!
+gateway-close-portal = Close Portal