Skip to content

Commit 2605450

Browse files
Add selectable sounds system (RMC-14#5517)
1 parent 89df888 commit 2605450

File tree

4 files changed

+94
-0
lines changed

4 files changed

+94
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using Robust.Shared.GameStates;
2+
using Robust.Shared.Audio;
3+
4+
namespace Content.Shared._RMC14.SelectableSounds;
5+
6+
/// <summary>
7+
/// A component which lets you toggle sounds on things like an EmitSoundOnUseComponent with a verb
8+
/// </summary>
9+
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
10+
public sealed partial class RMCSelectableSoundsComponent : Component
11+
{
12+
[DataField, AutoNetworkedField]
13+
public Dictionary<LocId, SoundSpecifier> Sounds = new();
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
using Content.Shared._RMC14.Sound;
2+
using Content.Shared.Popups;
3+
using Content.Shared.Sound.Components;
4+
using Content.Shared.Verbs;
5+
using Robust.Shared.Collections;
6+
7+
namespace Content.Shared._RMC14.SelectableSounds;
8+
9+
public sealed class RMCSelectableSoundsSystem : EntitySystem
10+
{
11+
[Dependency] private readonly SharedPopupSystem _popup = default!;
12+
13+
public override void Initialize()
14+
{
15+
base.Initialize();
16+
17+
SubscribeLocalEvent<RMCSelectableSoundsComponent, GetVerbsEvent<AlternativeVerb>>(OnGetAltVerbs);
18+
}
19+
20+
private void OnGetAltVerbs(Entity<RMCSelectableSoundsComponent> ent, ref GetVerbsEvent<AlternativeVerb> args)
21+
{
22+
if (!args.CanAccess || !args.CanInteract || args.Hands == null)
23+
return;
24+
25+
var user = args.User;
26+
var verbs = new ValueList<AlternativeVerb>();
27+
28+
foreach (var soundEntry in ent.Comp.Sounds)
29+
{
30+
var name = Loc.GetString(soundEntry.Key);
31+
var sound = soundEntry.Value;
32+
33+
var newVerb = new AlternativeVerb()
34+
{
35+
Text = name,
36+
IconEntity = GetNetEntity(ent.Owner),
37+
Category = VerbCategory.SelectType,
38+
Act = () =>
39+
{
40+
if (TryComp<EmitSoundOnUseComponent>(ent.Owner, out var use))
41+
use.Sound = sound;
42+
43+
if (TryComp<EmitSoundOnActionComponent>(ent.Owner, out var action))
44+
action.Sound = sound;
45+
46+
var msg = Loc.GetString("rmc-sound-select", ("sound", name));
47+
_popup.PopupClient(msg, user, user);
48+
},
49+
};
50+
51+
verbs.Add(newVerb);
52+
}
53+
54+
args.Verbs.UnionWith(verbs);
55+
}
56+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
rmc-sound-select = Changed sound to: {$sound}
2+
3+
rmc-sound-select-whistle = Trench Whistle
4+
rmc-sound-select-crowbar = Crowbar
5+
rmc-sound-select-detector = Motion Detector
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
- type: entity
2+
parent: RMCWhistle
3+
id: RMCDebugSoundDevice
4+
name: unknown device
5+
description: "???"
6+
suffix: DO NOT MAP
7+
components:
8+
- type: Sprite
9+
sprite: Objects/Devices/declaration_of_war.rsi
10+
state: declarator
11+
color: Blue
12+
- type: RMCSelectableSounds
13+
sounds:
14+
rmc-sound-select-whistle: # Loc ID
15+
collection: TrenchWhistle
16+
rmc-sound-select-crowbar:
17+
path: /Audio/_RMC14/Handling/crowbar_pickup.ogg
18+
rmc-sound-select-detector:
19+
path: /Audio/_RMC14/Effects/motion_detector.ogg

0 commit comments

Comments
 (0)