Desk bells can be rung with activate (#24047)
* Desk bells can be rung with activate Important * Remove obsoletions too while I'm at it.
This commit is contained in:
committed by
GitHub
parent
055d62f560
commit
f191c90999
@@ -76,4 +76,10 @@ public sealed partial class InteractionPopupComponent : Component
|
|||||||
|
|
||||||
[ViewVariables(VVAccess.ReadWrite)]
|
[ViewVariables(VVAccess.ReadWrite)]
|
||||||
public TimeSpan LastInteractTime;
|
public TimeSpan LastInteractTime;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// If set to true, activate interactions will also trigger the component.
|
||||||
|
/// </summary>
|
||||||
|
[DataField]
|
||||||
|
public bool OnActivate;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,16 +20,36 @@ public sealed class InteractionPopupSystem : EntitySystem
|
|||||||
[Dependency] private readonly MobStateSystem _mobStateSystem = default!;
|
[Dependency] private readonly MobStateSystem _mobStateSystem = default!;
|
||||||
[Dependency] private readonly PopupSystem _popupSystem = default!;
|
[Dependency] private readonly PopupSystem _popupSystem = default!;
|
||||||
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
||||||
|
[Dependency] private readonly SharedTransformSystem _transform = default!;
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
SubscribeLocalEvent<InteractionPopupComponent, InteractHandEvent>(OnInteractHand);
|
SubscribeLocalEvent<InteractionPopupComponent, InteractHandEvent>(OnInteractHand);
|
||||||
|
SubscribeLocalEvent<InteractionPopupComponent, ActivateInWorldEvent>(OnActivateInWorld);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnActivateInWorld(EntityUid uid, InteractionPopupComponent component, ActivateInWorldEvent args)
|
||||||
|
{
|
||||||
|
if (!component.OnActivate)
|
||||||
|
return;
|
||||||
|
|
||||||
|
SharedInteract(uid, component, args, args.Target, args.User);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnInteractHand(EntityUid uid, InteractionPopupComponent component, InteractHandEvent args)
|
private void OnInteractHand(EntityUid uid, InteractionPopupComponent component, InteractHandEvent args)
|
||||||
{
|
{
|
||||||
if (args.Handled || args.User == args.Target)
|
SharedInteract(uid, component, args, args.Target, args.User);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SharedInteract(
|
||||||
|
EntityUid uid,
|
||||||
|
InteractionPopupComponent component,
|
||||||
|
HandledEntityEventArgs args,
|
||||||
|
EntityUid target,
|
||||||
|
EntityUid user)
|
||||||
|
{
|
||||||
|
if (args.Handled || user == target)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
//Handling does nothing and this thing annoyingly plays way too often.
|
//Handling does nothing and this thing annoyingly plays way too often.
|
||||||
@@ -64,7 +84,7 @@ public sealed class InteractionPopupSystem : EntitySystem
|
|||||||
sfx = component.InteractSuccessSound;
|
sfx = component.InteractSuccessSound;
|
||||||
|
|
||||||
if (component.InteractSuccessSpawn != null)
|
if (component.InteractSuccessSpawn != null)
|
||||||
Spawn(component.InteractSuccessSpawn, Transform(uid).MapPosition);
|
Spawn(component.InteractSuccessSpawn, _transform.GetMapCoordinates(uid));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -75,25 +95,25 @@ public sealed class InteractionPopupSystem : EntitySystem
|
|||||||
sfx = component.InteractFailureSound;
|
sfx = component.InteractFailureSound;
|
||||||
|
|
||||||
if (component.InteractFailureSpawn != null)
|
if (component.InteractFailureSpawn != null)
|
||||||
Spawn(component.InteractFailureSpawn, Transform(uid).MapPosition);
|
Spawn(component.InteractFailureSpawn, _transform.GetMapCoordinates(uid));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (component.MessagePerceivedByOthers != null)
|
if (component.MessagePerceivedByOthers != null)
|
||||||
{
|
{
|
||||||
var msgOthers = Loc.GetString(component.MessagePerceivedByOthers,
|
var msgOthers = Loc.GetString(component.MessagePerceivedByOthers,
|
||||||
("user", Identity.Entity(args.User, EntityManager)), ("target", Identity.Entity(uid, EntityManager)));
|
("user", Identity.Entity(user, EntityManager)), ("target", Identity.Entity(uid, EntityManager)));
|
||||||
_popupSystem.PopupEntity(msg, uid, args.User);
|
_popupSystem.PopupEntity(msg, uid, user);
|
||||||
_popupSystem.PopupEntity(msgOthers, uid, Filter.PvsExcept(args.User, entityManager: EntityManager), true);
|
_popupSystem.PopupEntity(msgOthers, uid, Filter.PvsExcept(user, entityManager: EntityManager), true);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
_popupSystem.PopupEntity(msg, uid, args.User); //play only for the initiating entity.
|
_popupSystem.PopupEntity(msg, uid, user); //play only for the initiating entity.
|
||||||
|
|
||||||
if (sfx is not null) //not all cases will have sound.
|
if (sfx is not null) //not all cases will have sound.
|
||||||
{
|
{
|
||||||
if (component.SoundPerceivedByOthers)
|
if (component.SoundPerceivedByOthers)
|
||||||
_audio.PlayPvs(sfx, args.Target); //play for everyone in range
|
_audio.PlayPvs(sfx, target); //play for everyone in range
|
||||||
else
|
else
|
||||||
_audio.PlayEntity(sfx, Filter.Entities(args.User, args.Target), args.Target, true); //play only for the initiating entity and its target.
|
_audio.PlayEntity(sfx, Filter.Entities(user, target), target, true); //play only for the initiating entity and its target.
|
||||||
}
|
}
|
||||||
|
|
||||||
component.LastInteractTime = curTime;
|
component.LastInteractTime = curTime;
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
params:
|
params:
|
||||||
variation: 0.03
|
variation: 0.03
|
||||||
volume: 3
|
volume: 3
|
||||||
|
onActivate: true
|
||||||
- type: EmitSoundOnUse
|
- type: EmitSoundOnUse
|
||||||
sound:
|
sound:
|
||||||
collection: DeskBell
|
collection: DeskBell
|
||||||
|
|||||||
Reference in New Issue
Block a user