gateway changes (#20304)
Co-authored-by: deltanedas <@deltanedas:kde.org>
This commit is contained in:
@@ -83,7 +83,7 @@ public sealed partial class GatewayWindow : FancyWindow,
|
|||||||
|
|
||||||
var readyLabel = new Label
|
var readyLabel = new Label
|
||||||
{
|
{
|
||||||
Text = ReadyText(now, nextReady),
|
Text = ReadyText(now, nextReady, busy),
|
||||||
Margin = new Thickness(10f, 0f, 0f, 0f)
|
Margin = new Thickness(10f, 0f, 0f, 0f)
|
||||||
};
|
};
|
||||||
_readyLabels.Add(readyLabel);
|
_readyLabels.Add(readyLabel);
|
||||||
@@ -163,13 +163,16 @@ public sealed partial class GatewayWindow : FancyWindow,
|
|||||||
var dest = _destinations[i];
|
var dest = _destinations[i];
|
||||||
var nextReady = dest.Item3;
|
var nextReady = dest.Item3;
|
||||||
var busy = dest.Item4;
|
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;
|
_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)
|
if (now < nextReady)
|
||||||
{
|
{
|
||||||
var time = nextReady - now;
|
var time = nextReady - now;
|
||||||
|
|||||||
@@ -11,10 +11,25 @@ namespace Content.Server.Gateway.Components;
|
|||||||
public sealed partial class GatewayComponent : Component
|
public sealed partial class GatewayComponent : Component
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sound to play when opening or closing the portal.
|
/// Sound to play when opening the portal.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// Originally named PortalSound as it was used for opening and closing.
|
||||||
|
/// </remarks>
|
||||||
[DataField("portalSound")]
|
[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>
|
/// <summary>
|
||||||
/// Every other gateway destination on the server.
|
/// Every other gateway destination on the server.
|
||||||
@@ -22,19 +37,19 @@ public sealed partial class GatewayComponent : Component
|
|||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// Added on startup and when a new destination portal is created.
|
/// Added on startup and when a new destination portal is created.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
[ViewVariables]
|
[DataField]
|
||||||
public HashSet<EntityUid> Destinations = new();
|
public HashSet<EntityUid> Destinations = new();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The time at which the portal will be closed.
|
/// The time at which the portal will be closed.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[ViewVariables(VVAccess.ReadWrite), DataField("nextClose", customTypeSerializer:typeof(TimeOffsetSerializer))]
|
[ViewVariables(VVAccess.ReadWrite), DataField(customTypeSerializer: typeof(TimeOffsetSerializer))]
|
||||||
public TimeSpan NextClose;
|
public TimeSpan NextClose;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The time at which the portal was last opened.
|
/// The time at which the portal was last opened.
|
||||||
/// Only used for UI.
|
/// Only used for UI.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[ViewVariables]
|
[DataField(customTypeSerializer: typeof(TimeOffsetSerializer))]
|
||||||
public TimeSpan LastOpen;
|
public TimeSpan LastOpen;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,30 +13,36 @@ public sealed partial class GatewayDestinationComponent : Component
|
|||||||
/// Whether this destination is shown in the gateway ui.
|
/// 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.
|
/// If you are making a gateway for an admeme set this once you are ready for players to select it.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField("enabled"), ViewVariables(VVAccess.ReadWrite)]
|
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||||
public bool Enabled;
|
public bool Enabled;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Name as it shows up on the ui of station gateways.
|
/// Name as it shows up on the ui of station gateways.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField("name"), ViewVariables(VVAccess.ReadWrite)]
|
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||||
public string Name = string.Empty;
|
public string Name = string.Empty;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Time at which this destination is ready to be linked to.
|
/// Time at which this destination is ready to be linked to.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[ViewVariables(VVAccess.ReadWrite), DataField("nextReady", customTypeSerializer:typeof(TimeOffsetSerializer))]
|
[ViewVariables(VVAccess.ReadWrite), DataField(customTypeSerializer:typeof(TimeOffsetSerializer))]
|
||||||
public TimeSpan NextReady;
|
public TimeSpan NextReady;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// How long the portal will be open for after linking.
|
/// How long the portal will be open for after linking.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField("openTime"), ViewVariables(VVAccess.ReadWrite)]
|
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||||
public TimeSpan OpenTime = TimeSpan.FromSeconds(600);
|
public TimeSpan OpenTime = TimeSpan.FromSeconds(600);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// How long the destination is not ready for after the portal closes.
|
/// How long the destination is not ready for after the portal closes.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField("cooldown"), ViewVariables(VVAccess.ReadWrite)]
|
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||||
public TimeSpan Cooldown = TimeSpan.FromSeconds(60);
|
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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
using Content.Server.Gateway.Components;
|
using Content.Server.Gateway.Components;
|
||||||
using Content.Shared.Access.Systems;
|
using Content.Shared.Access.Systems;
|
||||||
using Content.Shared.Gateway;
|
using Content.Shared.Gateway;
|
||||||
|
using Content.Shared.Popups;
|
||||||
using Content.Shared.Teleportation.Components;
|
using Content.Shared.Teleportation.Components;
|
||||||
using Content.Shared.Teleportation.Systems;
|
using Content.Shared.Teleportation.Systems;
|
||||||
|
using Content.Shared.Verbs;
|
||||||
using Robust.Server.GameObjects;
|
using Robust.Server.GameObjects;
|
||||||
using Robust.Shared.Audio;
|
using Robust.Shared.Audio;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
using Robust.Shared.Timing;
|
using Robust.Shared.Timing;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
|
||||||
using System.Linq;
|
|
||||||
|
|
||||||
namespace Content.Server.Gateway.Systems;
|
namespace Content.Server.Gateway.Systems;
|
||||||
|
|
||||||
@@ -19,6 +19,7 @@ public sealed class GatewaySystem : EntitySystem
|
|||||||
[Dependency] private readonly LinkedEntitySystem _linkedEntity = default!;
|
[Dependency] private readonly LinkedEntitySystem _linkedEntity = default!;
|
||||||
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
||||||
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
||||||
|
[Dependency] private readonly SharedPopupSystem _popup = default!;
|
||||||
[Dependency] private readonly UserInterfaceSystem _ui = default!;
|
[Dependency] private readonly UserInterfaceSystem _ui = default!;
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
@@ -31,6 +32,7 @@ public sealed class GatewaySystem : EntitySystem
|
|||||||
|
|
||||||
SubscribeLocalEvent<GatewayDestinationComponent, ComponentStartup>(OnDestinationStartup);
|
SubscribeLocalEvent<GatewayDestinationComponent, ComponentStartup>(OnDestinationStartup);
|
||||||
SubscribeLocalEvent<GatewayDestinationComponent, ComponentShutdown>(OnDestinationShutdown);
|
SubscribeLocalEvent<GatewayDestinationComponent, ComponentShutdown>(OnDestinationShutdown);
|
||||||
|
SubscribeLocalEvent<GatewayDestinationComponent, GetVerbsEvent<AlternativeVerb>>(OnDestinationGetVerbs);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Update(float frameTime)
|
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)));
|
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);
|
var state = new GatewayBoundUserInterfaceState(destinations, GetNetEntity(current), comp.NextClose, comp.LastOpen);
|
||||||
_ui.TrySetUiState(uid, GatewayUiKey.Key, state);
|
_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
|
// if the gateway has an access reader check it before allowing opening
|
||||||
var user = args.Session.AttachedEntity.Value;
|
var user = args.Session.AttachedEntity.Value;
|
||||||
if (!_accessReader.IsAllowed(user, uid))
|
if (CheckAccess(user, uid))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// can't link if portal is already open on either side, the destination is invalid or on cooldown
|
// 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
|
// close automatically after time is up
|
||||||
comp.NextClose = comp.LastOpen + destComp.OpenTime;
|
comp.NextClose = comp.LastOpen + destComp.OpenTime;
|
||||||
|
|
||||||
_audio.PlayPvs(comp.PortalSound, uid);
|
_audio.PlayPvs(comp.OpenSound, uid);
|
||||||
_audio.PlayPvs(comp.PortalSound, dest);
|
_audio.PlayPvs(comp.OpenSound, dest);
|
||||||
|
|
||||||
UpdateUserInterface(uid, comp);
|
UpdateUserInterface(uid, comp);
|
||||||
UpdateAppearance(uid);
|
UpdateAppearance(uid);
|
||||||
UpdateAppearance(dest);
|
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);
|
RemComp<PortalComponent>(uid);
|
||||||
if (!GetDestination(uid, out var dest))
|
if (!_linkedEntity.GetLink(uid, out var dest))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (TryComp<GatewayDestinationComponent>(dest, out var destComp))
|
if (TryComp<GatewayDestinationComponent>(dest, out var destComp))
|
||||||
@@ -143,8 +148,8 @@ public sealed class GatewaySystem : EntitySystem
|
|||||||
destComp.NextReady = _timing.CurTime + destComp.Cooldown;
|
destComp.NextReady = _timing.CurTime + destComp.Cooldown;
|
||||||
}
|
}
|
||||||
|
|
||||||
_audio.PlayPvs(comp.PortalSound, uid);
|
_audio.PlayPvs(comp.CloseSound, uid);
|
||||||
_audio.PlayPvs(comp.PortalSound, dest.Value);
|
_audio.PlayPvs(comp.CloseSound, dest.Value);
|
||||||
|
|
||||||
_linkedEntity.TryUnlink(uid, dest.Value);
|
_linkedEntity.TryUnlink(uid, dest.Value);
|
||||||
RemComp<PortalComponent>(dest.Value);
|
RemComp<PortalComponent>(dest.Value);
|
||||||
@@ -153,22 +158,6 @@ public sealed class GatewaySystem : EntitySystem
|
|||||||
UpdateAppearance(dest.Value);
|
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)
|
private void OnDestinationStartup(EntityUid uid, GatewayDestinationComponent comp, ComponentStartup args)
|
||||||
{
|
{
|
||||||
var query = EntityQueryEnumerator<GatewayComponent>();
|
var query = EntityQueryEnumerator<GatewayComponent>();
|
||||||
@@ -190,4 +179,47 @@ public sealed class GatewaySystem : EntitySystem
|
|||||||
UpdateUserInterface(gatewayUid, gateway);
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using System.Linq;
|
|
||||||
using Content.Shared.Teleportation.Components;
|
using Content.Shared.Teleportation.Components;
|
||||||
using Robust.Shared.GameStates;
|
using Robust.Shared.GameStates;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace Content.Shared.Teleportation.Systems;
|
namespace Content.Shared.Teleportation.Systems;
|
||||||
|
|
||||||
@@ -113,5 +114,25 @@ public sealed class LinkedEntitySystem : EntitySystem
|
|||||||
return success;
|
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
|
#endregion
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
gateway-window-title = Gateway
|
gateway-window-title = Gateway
|
||||||
gateway-window-ready = Ready!
|
gateway-window-ready = Ready!
|
||||||
gateway-window-ready-in = Ready in: {$time}s
|
gateway-window-ready-in = Ready in: {$time}s
|
||||||
|
gateway-window-already-active = Already active
|
||||||
gateway-window-open-portal = Open Portal
|
gateway-window-open-portal = Open Portal
|
||||||
gateway-window-no-destinations = No destinations found.
|
gateway-window-no-destinations = No destinations found.
|
||||||
gateway-window-portal-closing = Portal closing
|
gateway-window-portal-closing = Portal closing
|
||||||
|
|
||||||
|
gateway-access-denied = Access denied!
|
||||||
|
gateway-close-portal = Close Portal
|
||||||
|
|||||||
Reference in New Issue
Block a user