closed door interact popup, resolve #564 (#600)

* closed door interact popup, resolve #564

* tweak

* uh

* removed old comment

* Update attributions.yml

* fix

* Update CP14SharedDoorInteractionPopupSystem.cs

* fixes

---------

Co-authored-by: Ed <96445749+TheShuEd@users.noreply.github.com>
Co-authored-by: Ed <edwardxperia2000@gmail.com>
This commit is contained in:
A.Ne.
2024-11-24 16:54:42 +04:00
committed by GitHub
parent b72c2bfb7b
commit 406f22de3f
9 changed files with 83 additions and 1 deletions

View File

@@ -0,0 +1,24 @@
using Robust.Shared.Audio;
namespace Content.Shared._CP14.Door;
[RegisterComponent, Access(typeof(CP14DoorInteractionPopupSystem))]
public sealed partial class CP14DoorInteractionPopupComponent : Component
{
/// <summary>
/// Time delay between interactions to avoid spam.
/// </summary>
[DataField("interactDelay")]
[ViewVariables(VVAccess.ReadWrite)]
public TimeSpan InteractDelay = TimeSpan.FromSeconds(1.0);
[DataField("interactString")]
public string InteractString = "cp14-closed-door-interact-popup";
[DataField("interactSound")]
public SoundSpecifier InteractSound;
[ViewVariables(VVAccess.ReadWrite)]
public TimeSpan LastInteractTime = TimeSpan.Zero;
}

View File

@@ -0,0 +1,36 @@
using Content.Shared.Interaction;
using Content.Shared.Lock;
using Content.Shared.Popups;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Timing;
namespace Content.Shared._CP14.Door;
public sealed class CP14DoorInteractionPopupSystem : EntitySystem
{
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly SharedPopupSystem _popup = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<CP14DoorInteractionPopupComponent, ActivateInWorldEvent>(OnActivatedInWorld);
}
private void OnActivatedInWorld(Entity<CP14DoorInteractionPopupComponent> door, ref ActivateInWorldEvent args)
{
if (TryComp<LockComponent>(args.Target, out var lockComponent) && !lockComponent.Locked)
return;
var curTime = _timing.CurTime;
if (curTime < door.Comp.LastInteractTime + door.Comp.InteractDelay)
return;
_popup.PopupPredicted(Loc.GetString(door.Comp.InteractString), args.Target, args.Target);
_audio.PlayPredicted(door.Comp.InteractSound, args.Target, args.Target);
door.Comp.LastInteractTime = curTime;
}
}

View File

@@ -0,0 +1,9 @@
- files: ["doorknob_1.ogg"]
license: "CC-BY-3.0"
copyright: 'by Leady.'
source: "https://freesound.org/people/Leady/sounds/12739/"
- files: ["doorknob_2.ogg"]
license: "CC0-1.0"
copyright: 'by BenjaminNelan.'
source: "https://freesound.org/people/BenjaminNelan/sounds/321087/"

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1 @@
cp14-closed-door-interact-popup = Locked.

View File

@@ -0,0 +1 @@
cp14-closed-door-interact-popup = Заперто.

View File

@@ -18,4 +18,10 @@
- type: Lock
locked: false
- type: PlacementReplacement
key: walls
key: walls
- type: CP14DoorInteractionPopup
interactSound:
collection: CP14Doorknob
params:
variation: 0.03
volume: -5

View File

@@ -0,0 +1,5 @@
- type: soundCollection
id: CP14Doorknob
files:
- /Audio/_CP14/Structures/doorknob_1.ogg
- /Audio/_CP14/Structures/doorknob_2.ogg