forked from RMC-14/RMC-14
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add selectable sounds system (RMC-14#5517)
- Loading branch information
1 parent
89df888
commit 2605450
Showing
4 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
Content.Shared/_RMC14/SelectableSounds/RMCSelectableSoundsComponent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using Robust.Shared.GameStates; | ||
using Robust.Shared.Audio; | ||
|
||
namespace Content.Shared._RMC14.SelectableSounds; | ||
|
||
/// <summary> | ||
/// A component which lets you toggle sounds on things like an EmitSoundOnUseComponent with a verb | ||
/// </summary> | ||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState] | ||
public sealed partial class RMCSelectableSoundsComponent : Component | ||
{ | ||
[DataField, AutoNetworkedField] | ||
public Dictionary<LocId, SoundSpecifier> Sounds = new(); | ||
} |
56 changes: 56 additions & 0 deletions
56
Content.Shared/_RMC14/SelectableSounds/RMCSelectableSoundsSystem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using Content.Shared._RMC14.Sound; | ||
using Content.Shared.Popups; | ||
using Content.Shared.Sound.Components; | ||
using Content.Shared.Verbs; | ||
using Robust.Shared.Collections; | ||
|
||
namespace Content.Shared._RMC14.SelectableSounds; | ||
|
||
public sealed class RMCSelectableSoundsSystem : EntitySystem | ||
{ | ||
[Dependency] private readonly SharedPopupSystem _popup = default!; | ||
|
||
public override void Initialize() | ||
{ | ||
base.Initialize(); | ||
|
||
SubscribeLocalEvent<RMCSelectableSoundsComponent, GetVerbsEvent<AlternativeVerb>>(OnGetAltVerbs); | ||
} | ||
|
||
private void OnGetAltVerbs(Entity<RMCSelectableSoundsComponent> ent, ref GetVerbsEvent<AlternativeVerb> args) | ||
{ | ||
if (!args.CanAccess || !args.CanInteract || args.Hands == null) | ||
return; | ||
|
||
var user = args.User; | ||
var verbs = new ValueList<AlternativeVerb>(); | ||
|
||
foreach (var soundEntry in ent.Comp.Sounds) | ||
{ | ||
var name = Loc.GetString(soundEntry.Key); | ||
var sound = soundEntry.Value; | ||
|
||
var newVerb = new AlternativeVerb() | ||
{ | ||
Text = name, | ||
IconEntity = GetNetEntity(ent.Owner), | ||
Category = VerbCategory.SelectType, | ||
Act = () => | ||
{ | ||
if (TryComp<EmitSoundOnUseComponent>(ent.Owner, out var use)) | ||
use.Sound = sound; | ||
|
||
if (TryComp<EmitSoundOnActionComponent>(ent.Owner, out var action)) | ||
action.Sound = sound; | ||
|
||
var msg = Loc.GetString("rmc-sound-select", ("sound", name)); | ||
_popup.PopupClient(msg, user, user); | ||
}, | ||
}; | ||
|
||
verbs.Add(newVerb); | ||
} | ||
|
||
args.Verbs.UnionWith(verbs); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
rmc-sound-select = Changed sound to: {$sound} | ||
rmc-sound-select-whistle = Trench Whistle | ||
rmc-sound-select-crowbar = Crowbar | ||
rmc-sound-select-detector = Motion Detector |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
- type: entity | ||
parent: RMCWhistle | ||
id: RMCDebugSoundDevice | ||
name: unknown device | ||
description: "???" | ||
suffix: DO NOT MAP | ||
components: | ||
- type: Sprite | ||
sprite: Objects/Devices/declaration_of_war.rsi | ||
state: declarator | ||
color: Blue | ||
- type: RMCSelectableSounds | ||
sounds: | ||
rmc-sound-select-whistle: # Loc ID | ||
collection: TrenchWhistle | ||
rmc-sound-select-crowbar: | ||
path: /Audio/_RMC14/Handling/crowbar_pickup.ogg | ||
rmc-sound-select-detector: | ||
path: /Audio/_RMC14/Effects/motion_detector.ogg |