From d3a258a39a843e16a4fb887dc92def0cf2bba79f Mon Sep 17 00:00:00 2001 From: metalgearsloth Date: Sat, 16 Mar 2024 12:59:37 +1100 Subject: [PATCH 1/4] Implement sound VV No params yet because I'm lazy but paths and collections work. --- .../ClientViewVariablesManager.cs | 8 ++ .../Editors/VVPropEditorSoundSpecifier.cs | 98 +++++++++++++++++++ .../ServerViewVariablesManager.cs | 12 +++ .../ViewVariables/ViewVariablesTrait.cs | 16 +++ .../ViewVariables/ViewVariablesBlob.cs | 14 +++ 5 files changed, 148 insertions(+) create mode 100644 Robust.Client/ViewVariables/Editors/VVPropEditorSoundSpecifier.cs diff --git a/Robust.Client/ViewVariables/ClientViewVariablesManager.cs b/Robust.Client/ViewVariables/ClientViewVariablesManager.cs index f8045ec94d0..74c60b730e4 100644 --- a/Robust.Client/ViewVariables/ClientViewVariablesManager.cs +++ b/Robust.Client/ViewVariables/ClientViewVariablesManager.cs @@ -8,6 +8,7 @@ using Robust.Client.UserInterface.CustomControls; using Robust.Client.ViewVariables.Editors; using Robust.Client.ViewVariables.Instances; +using Robust.Shared.Audio; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Localization; @@ -222,6 +223,13 @@ public VVPropEditor PropertyFor(Type? type) return new VVPropEditorTimeSpan(); } + if (typeof(SoundSpecifier).IsAssignableFrom(type)) + { + var control = new VVPropEditorSoundSpecifier(); + IoCManager.InjectDependencies(control); + return control; + } + if (type == typeof(ViewVariablesBlobMembers.ServerKeyValuePairToken) || type.IsGenericType && type.GetGenericTypeDefinition() == typeof(KeyValuePair<,>)) { diff --git a/Robust.Client/ViewVariables/Editors/VVPropEditorSoundSpecifier.cs b/Robust.Client/ViewVariables/Editors/VVPropEditorSoundSpecifier.cs new file mode 100644 index 00000000000..a0cb4ec0f05 --- /dev/null +++ b/Robust.Client/ViewVariables/Editors/VVPropEditorSoundSpecifier.cs @@ -0,0 +1,98 @@ +using System.Numerics; +using Robust.Client.UserInterface; +using Robust.Client.UserInterface.Controls; +using Robust.Shared.Audio; +using Robust.Shared.IoC; +using Robust.Shared.Localization; +using Robust.Shared.Prototypes; +using Robust.Shared.ViewVariables; + +namespace Robust.Client.ViewVariables.Editors; + +public sealed class VVPropEditorSoundSpecifier : VVPropEditor +{ + [Dependency] private readonly IPrototypeManager _protoManager = default!; + + protected override Control MakeUI(object? value) + { + var typeButton = new OptionButton() + { + Disabled = ReadOnly, + }; + typeButton.AddItem(Loc.GetString("vv-sound-none")); + typeButton.AddItem(Loc.GetString("vv-sound-collection")); + typeButton.AddItem(Loc.GetString("vv-sound-path")); + + var editBox = new LineEdit() + { + HorizontalExpand = true, + Editable = !ReadOnly, + }; + + var controls = new BoxContainer() + { + Orientation = BoxContainer.LayoutOrientation.Vertical, + Children = + { + typeButton, + editBox + }, + SetSize = new Vector2(256f, 64f) + }; + + if (value != null) + { + switch (value) + { + case ViewVariablesBlobMembers.SoundSpecifierReferenceToken token: + switch (token.Variant) + { + case "SoundCollectionSpecifier": + typeButton.Select(1); + editBox.Text = token.Value; + break; + case "SoundPathSpecifier": + typeButton.Select(2); + editBox.Text = token.Value; + break; + } + + break; + case SoundCollectionSpecifier collection: + typeButton.Select(1); + editBox.Text = collection.Collection ?? string.Empty; + break; + case SoundPathSpecifier path: + typeButton.Select(2); + editBox.Text = path.Path.ToString(); + break; + } + } + + typeButton.OnItemSelected += args => + { + typeButton.SelectId(args.Id); + editBox.Text = string.Empty; + }; + + editBox.OnTextEntered += args => + { + if (string.IsNullOrEmpty(args.Text)) + return; + + switch (typeButton.SelectedId) + { + case 1: + ValueChanged(new SoundCollectionSpecifier(args.Text)); + break; + case 2: + ValueChanged(new SoundPathSpecifier(args.Text)); + break; + default: + return; + } + }; + + return controls; + } +} diff --git a/Robust.Server/ViewVariables/ServerViewVariablesManager.cs b/Robust.Server/ViewVariables/ServerViewVariablesManager.cs index 38406613e2a..84f453b1571 100644 --- a/Robust.Server/ViewVariables/ServerViewVariablesManager.cs +++ b/Robust.Server/ViewVariables/ServerViewVariablesManager.cs @@ -3,6 +3,7 @@ using System.Diagnostics.CodeAnalysis; using Robust.Server.Console; using Robust.Server.Player; +using Robust.Shared.Audio; using Robust.Shared.Enums; using Robust.Shared.GameObjects; using Robust.Shared.IoC; @@ -296,7 +297,18 @@ private bool TryReinterpretValue(object? input, [NotNullWhen(true)] out object? output = prototype; return true; + case ViewVariablesBlobMembers.SoundSpecifierReferenceToken sound: + switch (sound.Variant) + { + case "SoundCollectionSpecifier": + output = new SoundCollectionSpecifier(sound.Value); + return true; + case "SoundPathSpecifier": + output = new SoundPathSpecifier(sound.Value); + return true; + } + return false; default: return false; } diff --git a/Robust.Server/ViewVariables/ViewVariablesTrait.cs b/Robust.Server/ViewVariables/ViewVariablesTrait.cs index 15880adbf80..46cfbd55e1f 100644 --- a/Robust.Server/ViewVariables/ViewVariablesTrait.cs +++ b/Robust.Server/ViewVariables/ViewVariablesTrait.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using Robust.Server.ViewVariables.Traits; +using Robust.Shared.Audio; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Network.Messages; @@ -112,6 +113,21 @@ public virtual bool TryModifyProperty(object[] property, object value) }; } + if (typeof(SoundSpecifier).IsAssignableFrom(valType)) + { + return new ViewVariablesBlobMembers.SoundSpecifierReferenceToken() + { + Stringified = PrettyPrint.PrintUserFacing(value), + Variant = valType.Name, + Value = value switch + { + SoundPathSpecifier path => path.Path.ToString(), + SoundCollectionSpecifier collection => collection.Collection, + _ => string.Empty + }, + }; + } + if (valType != typeof(string)) { return new ViewVariablesBlobMembers.ReferenceToken diff --git a/Robust.Shared/ViewVariables/ViewVariablesBlob.cs b/Robust.Shared/ViewVariables/ViewVariablesBlob.cs index c69984f587f..2d400bc02d7 100644 --- a/Robust.Shared/ViewVariables/ViewVariablesBlob.cs +++ b/Robust.Shared/ViewVariables/ViewVariablesBlob.cs @@ -83,6 +83,20 @@ public override string ToString() } } + [Serializable, NetSerializable] + public sealed class SoundSpecifierReferenceToken : ReferenceToken + { + /// + /// Type of the underlying soundspecifier + /// + public string Variant; + + /// + /// Value of the underlying soundspecifier + /// + public string Value; + } + /// /// Token used to indicate "this is a prototype reference, but I can't send the actual reference over". /// From 7c74033d25e959dbcd499430281fa27ab25f1905 Mon Sep 17 00:00:00 2001 From: metalgearsloth Date: Sat, 16 Mar 2024 13:32:25 +1100 Subject: [PATCH 2/4] Fixes --- Resources/Locale/en-US/vv.ftl | 3 ++ .../Editors/VVPropEditorSoundSpecifier.cs | 44 +++++++++++-------- Robust.Server/Audio/AudioSystem.cs | 12 +++++ .../ServerViewVariablesManager.cs | 12 ----- .../ViewVariables/ViewVariablesTrait.cs | 18 ++------ .../ViewVariables/ViewVariablesBlob.cs | 14 ------ 6 files changed, 43 insertions(+), 60 deletions(-) create mode 100644 Resources/Locale/en-US/vv.ftl diff --git a/Resources/Locale/en-US/vv.ftl b/Resources/Locale/en-US/vv.ftl new file mode 100644 index 00000000000..e69181b7c97 --- /dev/null +++ b/Resources/Locale/en-US/vv.ftl @@ -0,0 +1,3 @@ +vv-sound-none = None +vv-sound-path = Path +vv-sound-collection = Collection \ No newline at end of file diff --git a/Robust.Client/ViewVariables/Editors/VVPropEditorSoundSpecifier.cs b/Robust.Client/ViewVariables/Editors/VVPropEditorSoundSpecifier.cs index a0cb4ec0f05..bb91dc4dae1 100644 --- a/Robust.Client/ViewVariables/Editors/VVPropEditorSoundSpecifier.cs +++ b/Robust.Client/ViewVariables/Editors/VVPropEditorSoundSpecifier.cs @@ -2,9 +2,11 @@ using Robust.Client.UserInterface; using Robust.Client.UserInterface.Controls; using Robust.Shared.Audio; +using Robust.Shared.ContentPack; using Robust.Shared.IoC; using Robust.Shared.Localization; using Robust.Shared.Prototypes; +using Robust.Shared.Utility; using Robust.Shared.ViewVariables; namespace Robust.Client.ViewVariables.Editors; @@ -12,6 +14,7 @@ namespace Robust.Client.ViewVariables.Editors; public sealed class VVPropEditorSoundSpecifier : VVPropEditor { [Dependency] private readonly IPrototypeManager _protoManager = default!; + [Dependency] private readonly IResourceManager _resManager = default!; protected override Control MakeUI(object? value) { @@ -19,9 +22,10 @@ protected override Control MakeUI(object? value) { Disabled = ReadOnly, }; + typeButton.AddItem(Loc.GetString("vv-sound-none")); - typeButton.AddItem(Loc.GetString("vv-sound-collection")); - typeButton.AddItem(Loc.GetString("vv-sound-path")); + typeButton.AddItem(Loc.GetString("vv-sound-collection"), 1); + typeButton.AddItem(Loc.GetString("vv-sound-path"), 2); var editBox = new LineEdit() { @@ -37,33 +41,19 @@ protected override Control MakeUI(object? value) typeButton, editBox }, - SetSize = new Vector2(256f, 64f) + SetSize = new Vector2(384f, 64f) }; if (value != null) { switch (value) { - case ViewVariablesBlobMembers.SoundSpecifierReferenceToken token: - switch (token.Variant) - { - case "SoundCollectionSpecifier": - typeButton.Select(1); - editBox.Text = token.Value; - break; - case "SoundPathSpecifier": - typeButton.Select(2); - editBox.Text = token.Value; - break; - } - - break; case SoundCollectionSpecifier collection: - typeButton.Select(1); + typeButton.SelectId(1); editBox.Text = collection.Collection ?? string.Empty; break; case SoundPathSpecifier path: - typeButton.Select(2); + typeButton.SelectId(2); editBox.Text = path.Path.ToString(); break; } @@ -73,6 +63,14 @@ protected override Control MakeUI(object? value) { typeButton.SelectId(args.Id); editBox.Text = string.Empty; + + editBox.Editable = !ReadOnly && typeButton.SelectedId > 0; + + if (typeButton.SelectedId == 0) + { + // Dummy value + ValueChanged(new SoundPathSpecifier("")); + } }; editBox.OnTextEntered += args => @@ -83,9 +81,17 @@ protected override Control MakeUI(object? value) switch (typeButton.SelectedId) { case 1: + if (!_protoManager.HasIndex(args.Text)) + return; + ValueChanged(new SoundCollectionSpecifier(args.Text)); break; case 2: + var path = new ResPath(args.Text); + + if (!_resManager.ContentFileExists(path)) + return; + ValueChanged(new SoundPathSpecifier(args.Text)); break; default: diff --git a/Robust.Server/Audio/AudioSystem.cs b/Robust.Server/Audio/AudioSystem.cs index 7f9a65bdb0e..2e8f43b02bc 100644 --- a/Robust.Server/Audio/AudioSystem.cs +++ b/Robust.Server/Audio/AudioSystem.cs @@ -80,6 +80,9 @@ public override (EntityUid Entity, AudioComponent Component)? PlayGlobal(string /// public override (EntityUid Entity, AudioComponent Component)? PlayEntity(string filename, Filter playerFilter, EntityUid uid, bool recordReplay, AudioParams? audioParams = null) { + if (string.IsNullOrEmpty(filename)) + return null; + if (TerminatingOrDeleted(uid)) { Log.Error($"Tried to play audio on a terminating / deleted entity {ToPrettyString(uid)}. Trace: {Environment.StackTrace}"); @@ -96,6 +99,9 @@ public override (EntityUid Entity, AudioComponent Component)? PlayEntity(string /// public override (EntityUid Entity, AudioComponent Component)? PlayPvs(string filename, EntityUid uid, AudioParams? audioParams = null) { + if (string.IsNullOrEmpty(filename)) + return null; + if (TerminatingOrDeleted(uid)) { Log.Error($"Tried to play audio on a terminating / deleted entity {ToPrettyString(uid)}. Trace: {Environment.StackTrace}"); @@ -111,6 +117,9 @@ public override (EntityUid Entity, AudioComponent Component)? PlayPvs(string fil /// public override (EntityUid Entity, AudioComponent Component)? PlayStatic(string filename, Filter playerFilter, EntityCoordinates coordinates, bool recordReplay, AudioParams? audioParams = null) { + if (string.IsNullOrEmpty(filename)) + return null; + if (TerminatingOrDeleted(coordinates.EntityId)) { Log.Error($"Tried to play coordinates audio on a terminating / deleted entity {ToPrettyString(coordinates.EntityId)}. Trace: {Environment.StackTrace}"); @@ -131,6 +140,9 @@ public override (EntityUid Entity, AudioComponent Component)? PlayStatic(string public override (EntityUid Entity, AudioComponent Component)? PlayPvs(string filename, EntityCoordinates coordinates, AudioParams? audioParams = null) { + if (string.IsNullOrEmpty(filename)) + return null; + if (TerminatingOrDeleted(coordinates.EntityId)) { Log.Error($"Tried to play coordinates audio on a terminating / deleted entity {ToPrettyString(coordinates.EntityId)}. Trace: {Environment.StackTrace}"); diff --git a/Robust.Server/ViewVariables/ServerViewVariablesManager.cs b/Robust.Server/ViewVariables/ServerViewVariablesManager.cs index 84f453b1571..610efe4c47d 100644 --- a/Robust.Server/ViewVariables/ServerViewVariablesManager.cs +++ b/Robust.Server/ViewVariables/ServerViewVariablesManager.cs @@ -297,18 +297,6 @@ private bool TryReinterpretValue(object? input, [NotNullWhen(true)] out object? output = prototype; return true; - case ViewVariablesBlobMembers.SoundSpecifierReferenceToken sound: - switch (sound.Variant) - { - case "SoundCollectionSpecifier": - output = new SoundCollectionSpecifier(sound.Value); - return true; - case "SoundPathSpecifier": - output = new SoundPathSpecifier(sound.Value); - return true; - } - - return false; default: return false; } diff --git a/Robust.Server/ViewVariables/ViewVariablesTrait.cs b/Robust.Server/ViewVariables/ViewVariablesTrait.cs index 46cfbd55e1f..2c65f4bdf3e 100644 --- a/Robust.Server/ViewVariables/ViewVariablesTrait.cs +++ b/Robust.Server/ViewVariables/ViewVariablesTrait.cs @@ -97,6 +97,9 @@ public virtual bool TryModifyProperty(object[] property, object value) if (value is EntityUid uid) return IoCManager.Resolve().GetComponentOrNull(uid)?.NetEntity ?? NetEntity.Invalid; + if (value is SoundSpecifier) + return value; + var valType = value.GetType(); if (!valType.IsValueType) { @@ -113,21 +116,6 @@ public virtual bool TryModifyProperty(object[] property, object value) }; } - if (typeof(SoundSpecifier).IsAssignableFrom(valType)) - { - return new ViewVariablesBlobMembers.SoundSpecifierReferenceToken() - { - Stringified = PrettyPrint.PrintUserFacing(value), - Variant = valType.Name, - Value = value switch - { - SoundPathSpecifier path => path.Path.ToString(), - SoundCollectionSpecifier collection => collection.Collection, - _ => string.Empty - }, - }; - } - if (valType != typeof(string)) { return new ViewVariablesBlobMembers.ReferenceToken diff --git a/Robust.Shared/ViewVariables/ViewVariablesBlob.cs b/Robust.Shared/ViewVariables/ViewVariablesBlob.cs index 2d400bc02d7..c69984f587f 100644 --- a/Robust.Shared/ViewVariables/ViewVariablesBlob.cs +++ b/Robust.Shared/ViewVariables/ViewVariablesBlob.cs @@ -83,20 +83,6 @@ public override string ToString() } } - [Serializable, NetSerializable] - public sealed class SoundSpecifierReferenceToken : ReferenceToken - { - /// - /// Type of the underlying soundspecifier - /// - public string Variant; - - /// - /// Value of the underlying soundspecifier - /// - public string Value; - } - /// /// Token used to indicate "this is a prototype reference, but I can't send the actual reference over". /// From 307cdac424cae95be3df1b258b0880c13759a422 Mon Sep 17 00:00:00 2001 From: metalgearsloth Date: Sat, 16 Mar 2024 13:32:47 +1100 Subject: [PATCH 3/4] rn --- RELEASE-NOTES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 96268ac3d9a..37bf83121ad 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -39,7 +39,7 @@ END TEMPLATE--> ### New features -*None yet* +* Implement basic VV for SoundSpecifiers. ### Bugfixes From a7ca5ce7295664e8db6ca83ae384c75e6138576f Mon Sep 17 00:00:00 2001 From: metalgearsloth Date: Sun, 24 Mar 2024 16:48:56 +1100 Subject: [PATCH 4/4] review --- Robust.Client/Audio/AudioSystem.cs | 39 ++++++++++++------- .../ClientViewVariablesManager.cs | 6 ++- .../Editors/VVPropEditorSoundSpecifier.cs | 14 +++++-- Robust.Server/Audio/AudioSystem.cs | 22 +++++------ .../Audio/Systems/SharedAudioSystem.cs | 22 +++++------ 5 files changed, 60 insertions(+), 43 deletions(-) diff --git a/Robust.Client/Audio/AudioSystem.cs b/Robust.Client/Audio/AudioSystem.cs index dccd639a9b3..d3d33cbe6f9 100644 --- a/Robust.Client/Audio/AudioSystem.cs +++ b/Robust.Client/Audio/AudioSystem.cs @@ -173,7 +173,7 @@ private void OnAudioStartup(EntityUid uid, AudioComponent component, ComponentSt private void SetupSource(Entity entity, AudioResource audioResource, TimeSpan? length = null) { var component = entity.Comp; - + if (TryAudioLimit(component.FileName)) { var newSource = _audio.CreateAudioSource(audioResource); @@ -427,13 +427,13 @@ private bool TryGetAudio(AudioStream stream, [NotNullWhen(true)] out AudioResour return false; } - public override (EntityUid Entity, AudioComponent Component)? PlayPvs(string filename, EntityCoordinates coordinates, + public override (EntityUid Entity, AudioComponent Component)? PlayPvs(string? filename, EntityCoordinates coordinates, AudioParams? audioParams = null) { return PlayStatic(filename, Filter.Local(), coordinates, true, audioParams); } - public override (EntityUid Entity, AudioComponent Component)? PlayPvs(string filename, EntityUid uid, AudioParams? audioParams = null) + public override (EntityUid Entity, AudioComponent Component)? PlayPvs(string? filename, EntityUid uid, AudioParams? audioParams = null) { return PlayEntity(filename, Filter.Local(), uid, true, audioParams); } @@ -460,8 +460,11 @@ public override (EntityUid Entity, AudioComponent Component)? PlayPredicted(Soun /// /// The resource path to the OGG Vorbis file to play. /// - private (EntityUid Entity, AudioComponent Component)? PlayGlobal(string filename, AudioParams? audioParams = null, bool recordReplay = true) + private (EntityUid Entity, AudioComponent Component)? PlayGlobal(string? filename, AudioParams? audioParams = null, bool recordReplay = true) { + if (string.IsNullOrEmpty(filename)) + return null; + if (recordReplay && _replayRecording.IsRecording) { _replayRecording.RecordReplayMessage(new PlayAudioGlobalMessage @@ -493,8 +496,11 @@ public override (EntityUid Entity, AudioComponent Component)? PlayPredicted(Soun /// /// The resource path to the OGG Vorbis file to play. /// The entity "emitting" the audio. - private (EntityUid Entity, AudioComponent Component)? PlayEntity(string filename, EntityUid entity, AudioParams? audioParams = null, bool recordReplay = true) + private (EntityUid Entity, AudioComponent Component)? PlayEntity(string? filename, EntityUid entity, AudioParams? audioParams = null, bool recordReplay = true) { + if (string.IsNullOrEmpty(filename)) + return null; + if (recordReplay && _replayRecording.IsRecording) { _replayRecording.RecordReplayMessage(new PlayAudioEntityMessage @@ -534,8 +540,11 @@ public override (EntityUid Entity, AudioComponent Component)? PlayPredicted(Soun /// The resource path to the OGG Vorbis file to play. /// The coordinates at which to play the audio. /// - private (EntityUid Entity, AudioComponent Component)? PlayStatic(string filename, EntityCoordinates coordinates, AudioParams? audioParams = null, bool recordReplay = true) + private (EntityUid Entity, AudioComponent Component)? PlayStatic(string? filename, EntityCoordinates coordinates, AudioParams? audioParams = null, bool recordReplay = true) { + if (string.IsNullOrEmpty(filename)) + return null; + if (recordReplay && _replayRecording.IsRecording) { _replayRecording.RecordReplayMessage(new PlayAudioPositionalMessage @@ -569,25 +578,25 @@ public override (EntityUid Entity, AudioComponent Component)? PlayPredicted(Soun } /// - public override (EntityUid Entity, AudioComponent Component)? PlayGlobal(string filename, Filter playerFilter, bool recordReplay, AudioParams? audioParams = null) + public override (EntityUid Entity, AudioComponent Component)? PlayGlobal(string? filename, Filter playerFilter, bool recordReplay, AudioParams? audioParams = null) { return PlayGlobal(filename, audioParams); } /// - public override (EntityUid Entity, AudioComponent Component)? PlayEntity(string filename, Filter playerFilter, EntityUid entity, bool recordReplay, AudioParams? audioParams = null) + public override (EntityUid Entity, AudioComponent Component)? PlayEntity(string? filename, Filter playerFilter, EntityUid entity, bool recordReplay, AudioParams? audioParams = null) { return PlayEntity(filename, entity, audioParams); } /// - public override (EntityUid Entity, AudioComponent Component)? PlayStatic(string filename, Filter playerFilter, EntityCoordinates coordinates, bool recordReplay, AudioParams? audioParams = null) + public override (EntityUid Entity, AudioComponent Component)? PlayStatic(string? filename, Filter playerFilter, EntityCoordinates coordinates, bool recordReplay, AudioParams? audioParams = null) { return PlayStatic(filename, coordinates, audioParams); } /// - public override (EntityUid Entity, AudioComponent Component)? PlayGlobal(string filename, ICommonSession recipient, AudioParams? audioParams = null) + public override (EntityUid Entity, AudioComponent Component)? PlayGlobal(string? filename, ICommonSession recipient, AudioParams? audioParams = null) { return PlayGlobal(filename, audioParams); } @@ -603,31 +612,31 @@ public override void LoadStream(Entity entity, T stream) } /// - public override (EntityUid Entity, AudioComponent Component)? PlayGlobal(string filename, EntityUid recipient, AudioParams? audioParams = null) + public override (EntityUid Entity, AudioComponent Component)? PlayGlobal(string? filename, EntityUid recipient, AudioParams? audioParams = null) { return PlayGlobal(filename, audioParams); } /// - public override (EntityUid Entity, AudioComponent Component)? PlayEntity(string filename, ICommonSession recipient, EntityUid uid, AudioParams? audioParams = null) + public override (EntityUid Entity, AudioComponent Component)? PlayEntity(string? filename, ICommonSession recipient, EntityUid uid, AudioParams? audioParams = null) { return PlayEntity(filename, uid, audioParams); } /// - public override (EntityUid Entity, AudioComponent Component)? PlayEntity(string filename, EntityUid recipient, EntityUid uid, AudioParams? audioParams = null) + public override (EntityUid Entity, AudioComponent Component)? PlayEntity(string? filename, EntityUid recipient, EntityUid uid, AudioParams? audioParams = null) { return PlayEntity(filename, uid, audioParams); } /// - public override (EntityUid Entity, AudioComponent Component)? PlayStatic(string filename, ICommonSession recipient, EntityCoordinates coordinates, AudioParams? audioParams = null) + public override (EntityUid Entity, AudioComponent Component)? PlayStatic(string? filename, ICommonSession recipient, EntityCoordinates coordinates, AudioParams? audioParams = null) { return PlayStatic(filename, coordinates, audioParams); } /// - public override (EntityUid Entity, AudioComponent Component)? PlayStatic(string filename, EntityUid recipient, EntityCoordinates coordinates, AudioParams? audioParams = null) + public override (EntityUid Entity, AudioComponent Component)? PlayStatic(string? filename, EntityUid recipient, EntityCoordinates coordinates, AudioParams? audioParams = null) { return PlayStatic(filename, coordinates, audioParams); } diff --git a/Robust.Client/ViewVariables/ClientViewVariablesManager.cs b/Robust.Client/ViewVariables/ClientViewVariablesManager.cs index fb9f4b03624..006042f4dd3 100644 --- a/Robust.Client/ViewVariables/ClientViewVariablesManager.cs +++ b/Robust.Client/ViewVariables/ClientViewVariablesManager.cs @@ -9,6 +9,7 @@ using Robust.Client.ViewVariables.Editors; using Robust.Client.ViewVariables.Instances; using Robust.Shared.Audio; +using Robust.Shared.ContentPack; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Localization; @@ -30,6 +31,8 @@ internal sealed partial class ClientViewVariablesManager : ViewVariablesManager, [Dependency] private readonly IClientNetManager _netManager = default!; [Dependency] private readonly IRobustSerializer _robustSerializer = default!; [Dependency] private readonly IEntityManager _entityManager = default!; + [Dependency] private readonly IPrototypeManager _protoManager = default!; + [Dependency] private readonly IResourceManager _resManager = default!; private uint _nextReqId = 1; private readonly Vector2i _defaultWindowSize = (640, 420); @@ -229,8 +232,7 @@ public VVPropEditor PropertyFor(Type? type) if (typeof(SoundSpecifier).IsAssignableFrom(type)) { - var control = new VVPropEditorSoundSpecifier(); - IoCManager.InjectDependencies(control); + var control = new VVPropEditorSoundSpecifier(_protoManager, _resManager); return control; } diff --git a/Robust.Client/ViewVariables/Editors/VVPropEditorSoundSpecifier.cs b/Robust.Client/ViewVariables/Editors/VVPropEditorSoundSpecifier.cs index bb91dc4dae1..b4b9f3acb20 100644 --- a/Robust.Client/ViewVariables/Editors/VVPropEditorSoundSpecifier.cs +++ b/Robust.Client/ViewVariables/Editors/VVPropEditorSoundSpecifier.cs @@ -13,8 +13,14 @@ namespace Robust.Client.ViewVariables.Editors; public sealed class VVPropEditorSoundSpecifier : VVPropEditor { - [Dependency] private readonly IPrototypeManager _protoManager = default!; - [Dependency] private readonly IResourceManager _resManager = default!; + private readonly IPrototypeManager _protoManager; + private readonly IResourceManager _resManager; + + public VVPropEditorSoundSpecifier(IPrototypeManager protoManager, IResourceManager resManager) + { + _protoManager = protoManager; + _resManager = resManager; + } protected override Control MakeUI(object? value) { @@ -35,13 +41,13 @@ protected override Control MakeUI(object? value) var controls = new BoxContainer() { - Orientation = BoxContainer.LayoutOrientation.Vertical, + Orientation = BoxContainer.LayoutOrientation.Horizontal, Children = { typeButton, editBox }, - SetSize = new Vector2(384f, 64f) + SetSize = new Vector2(384f, 32f) }; if (value != null) diff --git a/Robust.Server/Audio/AudioSystem.cs b/Robust.Server/Audio/AudioSystem.cs index 2b840deeb5f..f89bc0c675e 100644 --- a/Robust.Server/Audio/AudioSystem.cs +++ b/Robust.Server/Audio/AudioSystem.cs @@ -68,7 +68,7 @@ private void AddAudioFilter(EntityUid uid, AudioComponent component, Filter filt } /// - public override (EntityUid Entity, AudioComponent Component)? PlayGlobal(string filename, Filter playerFilter, bool recordReplay, AudioParams? audioParams = null) + public override (EntityUid Entity, AudioComponent Component)? PlayGlobal(string? filename, Filter playerFilter, bool recordReplay, AudioParams? audioParams = null) { var entity = Spawn("Audio", MapCoordinates.Nullspace); var audio = SetupAudio(entity, filename, audioParams); @@ -78,7 +78,7 @@ public override (EntityUid Entity, AudioComponent Component)? PlayGlobal(string } /// - public override (EntityUid Entity, AudioComponent Component)? PlayEntity(string filename, Filter playerFilter, EntityUid uid, bool recordReplay, AudioParams? audioParams = null) + public override (EntityUid Entity, AudioComponent Component)? PlayEntity(string? filename, Filter playerFilter, EntityUid uid, bool recordReplay, AudioParams? audioParams = null) { if (string.IsNullOrEmpty(filename)) return null; @@ -97,7 +97,7 @@ public override (EntityUid Entity, AudioComponent Component)? PlayEntity(string } /// - public override (EntityUid Entity, AudioComponent Component)? PlayPvs(string filename, EntityUid uid, AudioParams? audioParams = null) + public override (EntityUid Entity, AudioComponent Component)? PlayPvs(string? filename, EntityUid uid, AudioParams? audioParams = null) { if (string.IsNullOrEmpty(filename)) return null; @@ -115,7 +115,7 @@ public override (EntityUid Entity, AudioComponent Component)? PlayPvs(string fil } /// - public override (EntityUid Entity, AudioComponent Component)? PlayStatic(string filename, Filter playerFilter, EntityCoordinates coordinates, bool recordReplay, AudioParams? audioParams = null) + public override (EntityUid Entity, AudioComponent Component)? PlayStatic(string? filename, Filter playerFilter, EntityCoordinates coordinates, bool recordReplay, AudioParams? audioParams = null) { if (string.IsNullOrEmpty(filename)) return null; @@ -137,7 +137,7 @@ public override (EntityUid Entity, AudioComponent Component)? PlayStatic(string } /// - public override (EntityUid Entity, AudioComponent Component)? PlayPvs(string filename, EntityCoordinates coordinates, + public override (EntityUid Entity, AudioComponent Component)? PlayPvs(string? filename, EntityCoordinates coordinates, AudioParams? audioParams = null) { if (string.IsNullOrEmpty(filename)) @@ -188,12 +188,12 @@ public override (EntityUid Entity, AudioComponent Component)? PlayPredicted(Soun return audio; } - public override (EntityUid Entity, AudioComponent Component)? PlayGlobal(string filename, ICommonSession recipient, AudioParams? audioParams = null) + public override (EntityUid Entity, AudioComponent Component)? PlayGlobal(string? filename, ICommonSession recipient, AudioParams? audioParams = null) { return PlayGlobal(filename, Filter.SinglePlayer(recipient), false, audioParams); } - public override (EntityUid Entity, AudioComponent Component)? PlayGlobal(string filename, EntityUid recipient, AudioParams? audioParams = null) + public override (EntityUid Entity, AudioComponent Component)? PlayGlobal(string? filename, EntityUid recipient, AudioParams? audioParams = null) { if (TryComp(recipient, out ActorComponent? actor)) return PlayGlobal(filename, actor.PlayerSession, audioParams); @@ -201,12 +201,12 @@ public override (EntityUid Entity, AudioComponent Component)? PlayGlobal(string return null; } - public override (EntityUid Entity, AudioComponent Component)? PlayEntity(string filename, ICommonSession recipient, EntityUid uid, AudioParams? audioParams = null) + public override (EntityUid Entity, AudioComponent Component)? PlayEntity(string? filename, ICommonSession recipient, EntityUid uid, AudioParams? audioParams = null) { return PlayEntity(filename, Filter.SinglePlayer(recipient), uid, false, audioParams); } - public override (EntityUid Entity, AudioComponent Component)? PlayEntity(string filename, EntityUid recipient, EntityUid uid, AudioParams? audioParams = null) + public override (EntityUid Entity, AudioComponent Component)? PlayEntity(string? filename, EntityUid recipient, EntityUid uid, AudioParams? audioParams = null) { if (TryComp(recipient, out ActorComponent? actor)) return PlayEntity(filename, actor.PlayerSession, uid, audioParams); @@ -214,12 +214,12 @@ public override (EntityUid Entity, AudioComponent Component)? PlayEntity(string return null; } - public override (EntityUid Entity, AudioComponent Component)? PlayStatic(string filename, ICommonSession recipient, EntityCoordinates coordinates, AudioParams? audioParams = null) + public override (EntityUid Entity, AudioComponent Component)? PlayStatic(string? filename, ICommonSession recipient, EntityCoordinates coordinates, AudioParams? audioParams = null) { return PlayStatic(filename, Filter.SinglePlayer(recipient), coordinates, false, audioParams); } - public override (EntityUid Entity, AudioComponent Component)? PlayStatic(string filename, EntityUid recipient, EntityCoordinates coordinates, AudioParams? audioParams = null) + public override (EntityUid Entity, AudioComponent Component)? PlayStatic(string? filename, EntityUid recipient, EntityCoordinates coordinates, AudioParams? audioParams = null) { if (TryComp(recipient, out ActorComponent? actor)) return PlayStatic(filename, actor.PlayerSession, coordinates, audioParams); diff --git a/Robust.Shared/Audio/Systems/SharedAudioSystem.cs b/Robust.Shared/Audio/Systems/SharedAudioSystem.cs index e01a6cd0bea..93c609488fa 100644 --- a/Robust.Shared/Audio/Systems/SharedAudioSystem.cs +++ b/Robust.Shared/Audio/Systems/SharedAudioSystem.cs @@ -234,7 +234,7 @@ public TimeSpan GetAudioLength(string filename) /// The resource path to the OGG Vorbis file to play. /// The set of players that will hear the sound. [return: NotNullIfNotNull("filename")] - public abstract (EntityUid Entity, Components.AudioComponent Component)? PlayGlobal(string filename, Filter playerFilter, bool recordReplay, AudioParams? audioParams = null); + public abstract (EntityUid Entity, Components.AudioComponent Component)? PlayGlobal(string? filename, Filter playerFilter, bool recordReplay, AudioParams? audioParams = null); /// /// Play an audio file globally, without position. @@ -253,7 +253,7 @@ public TimeSpan GetAudioLength(string filename) /// The resource path to the OGG Vorbis file to play. /// The player that will hear the sound. [return: NotNullIfNotNull("filename")] - public abstract (EntityUid Entity, Components.AudioComponent Component)? PlayGlobal(string filename, ICommonSession recipient, AudioParams? audioParams = null); + public abstract (EntityUid Entity, Components.AudioComponent Component)? PlayGlobal(string? filename, ICommonSession recipient, AudioParams? audioParams = null); /// /// Play an audio file globally, without position. @@ -274,7 +274,7 @@ public TimeSpan GetAudioLength(string filename) /// The resource path to the OGG Vorbis file to play. /// The player that will hear the sound. [return: NotNullIfNotNull("filename")] - public abstract (EntityUid Entity, Components.AudioComponent Component)? PlayGlobal(string filename, EntityUid recipient, AudioParams? audioParams = null); + public abstract (EntityUid Entity, Components.AudioComponent Component)? PlayGlobal(string? filename, EntityUid recipient, AudioParams? audioParams = null); /// /// Play an audio file globally, without position. @@ -294,7 +294,7 @@ public TimeSpan GetAudioLength(string filename) /// The set of players that will hear the sound. /// The UID of the entity "emitting" the audio. [return: NotNullIfNotNull("filename")] - public abstract (EntityUid Entity, Components.AudioComponent Component)? PlayEntity(string filename, Filter playerFilter, EntityUid uid, bool recordReplay, AudioParams? audioParams = null); + public abstract (EntityUid Entity, Components.AudioComponent Component)? PlayEntity(string? filename, Filter playerFilter, EntityUid uid, bool recordReplay, AudioParams? audioParams = null); /// /// Play an audio file following an entity. @@ -303,7 +303,7 @@ public TimeSpan GetAudioLength(string filename) /// The player that will hear the sound. /// The UID of the entity "emitting" the audio. [return: NotNullIfNotNull("filename")] - public abstract (EntityUid Entity, Components.AudioComponent Component)? PlayEntity(string filename, ICommonSession recipient, EntityUid uid, AudioParams? audioParams = null); + public abstract (EntityUid Entity, Components.AudioComponent Component)? PlayEntity(string? filename, ICommonSession recipient, EntityUid uid, AudioParams? audioParams = null); /// /// Play an audio file following an entity. @@ -312,7 +312,7 @@ public TimeSpan GetAudioLength(string filename) /// The player that will hear the sound. /// The UID of the entity "emitting" the audio. [return: NotNullIfNotNull("filename")] - public abstract (EntityUid Entity, Components.AudioComponent Component)? PlayEntity(string filename, EntityUid recipient, EntityUid uid, AudioParams? audioParams = null); + public abstract (EntityUid Entity, Components.AudioComponent Component)? PlayEntity(string? filename, EntityUid recipient, EntityUid uid, AudioParams? audioParams = null); /// /// Play an audio file following an entity. @@ -378,7 +378,7 @@ public TimeSpan GetAudioLength(string filename) /// The sound specifier that points the audio file(s) that should be played. /// The EntityCoordinates to attach the audio source to. [return: NotNullIfNotNull("filename")] - public abstract (EntityUid Entity, Components.AudioComponent Component)? PlayPvs(string filename, + public abstract (EntityUid Entity, Components.AudioComponent Component)? PlayPvs(string? filename, EntityCoordinates coordinates, AudioParams? audioParams = null); /// @@ -387,7 +387,7 @@ public abstract (EntityUid Entity, Components.AudioComponent Component)? PlayPvs /// The resource path to the OGG Vorbis file to play. /// The UID of the entity "emitting" the audio. [return: NotNullIfNotNull("filename")] - public abstract (EntityUid Entity, Components.AudioComponent Component)? PlayPvs(string filename, EntityUid uid, + public abstract (EntityUid Entity, Components.AudioComponent Component)? PlayPvs(string? filename, EntityUid uid, AudioParams? audioParams = null); /// @@ -419,7 +419,7 @@ public abstract (EntityUid Entity, Components.AudioComponent Component)? PlayPvs /// The set of players that will hear the sound. /// The coordinates at which to play the audio. [return: NotNullIfNotNull("filename")] - public abstract (EntityUid Entity, Components.AudioComponent Component)? PlayStatic(string filename, Filter playerFilter, EntityCoordinates coordinates, bool recordReplay, AudioParams? audioParams = null); + public abstract (EntityUid Entity, Components.AudioComponent Component)? PlayStatic(string? filename, Filter playerFilter, EntityCoordinates coordinates, bool recordReplay, AudioParams? audioParams = null); /// /// Play an audio file at a static position. @@ -428,7 +428,7 @@ public abstract (EntityUid Entity, Components.AudioComponent Component)? PlayPvs /// The player that will hear the sound. /// The coordinates at which to play the audio. [return: NotNullIfNotNull("filename")] - public abstract (EntityUid Entity, Components.AudioComponent Component)? PlayStatic(string filename, ICommonSession recipient, EntityCoordinates coordinates, AudioParams? audioParams = null); + public abstract (EntityUid Entity, Components.AudioComponent Component)? PlayStatic(string? filename, ICommonSession recipient, EntityCoordinates coordinates, AudioParams? audioParams = null); /// /// Play an audio file at a static position. @@ -437,7 +437,7 @@ public abstract (EntityUid Entity, Components.AudioComponent Component)? PlayPvs /// The player that will hear the sound. /// The coordinates at which to play the audio. [return: NotNullIfNotNull("filename")] - public abstract (EntityUid Entity, Components.AudioComponent Component)? PlayStatic(string filename, EntityUid recipient, EntityCoordinates coordinates, AudioParams? audioParams = null); + public abstract (EntityUid Entity, Components.AudioComponent Component)? PlayStatic(string? filename, EntityUid recipient, EntityCoordinates coordinates, AudioParams? audioParams = null); /// /// Play an audio file at a static position.