Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement sound VV #4966

Merged
merged 5 commits into from
Mar 24, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ END TEMPLATE-->

### New features

*None yet*
* Implement basic VV for SoundSpecifiers.

### Bugfixes

Expand Down
3 changes: 3 additions & 0 deletions Resources/Locale/en-US/vv.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
vv-sound-none = None
vv-sound-path = Path
vv-sound-collection = Collection
8 changes: 8 additions & 0 deletions Robust.Client/ViewVariables/ClientViewVariablesManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -222,6 +223,13 @@ public VVPropEditor PropertyFor(Type? type)
return new VVPropEditorTimeSpan();
}

if (typeof(SoundSpecifier).IsAssignableFrom(type))
{
var control = new VVPropEditorSoundSpecifier();
IoCManager.InjectDependencies(control);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldnt it be better to have this in the constructor of the control

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too late other code already code it.

return control;
}

if (type == typeof(ViewVariablesBlobMembers.ServerKeyValuePairToken) ||
type.IsGenericType && type.GetGenericTypeDefinition() == typeof(KeyValuePair<,>))
{
Expand Down
104 changes: 104 additions & 0 deletions Robust.Client/ViewVariables/Editors/VVPropEditorSoundSpecifier.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
using System.Numerics;
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;

public sealed class VVPropEditorSoundSpecifier : VVPropEditor
{
[Dependency] private readonly IPrototypeManager _protoManager = default!;
[Dependency] private readonly IResourceManager _resManager = 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"), 1);
typeButton.AddItem(Loc.GetString("vv-sound-path"), 2);

var editBox = new LineEdit()
{
HorizontalExpand = true,
Editable = !ReadOnly,
};

var controls = new BoxContainer()
{
Orientation = BoxContainer.LayoutOrientation.Vertical,
Children =
{
typeButton,
editBox
},
SetSize = new Vector2(384f, 64f)
};

if (value != null)
{
switch (value)
{
case SoundCollectionSpecifier collection:
typeButton.SelectId(1);
editBox.Text = collection.Collection ?? string.Empty;
break;
case SoundPathSpecifier path:
typeButton.SelectId(2);
editBox.Text = path.Path.ToString();
break;
}
}

typeButton.OnItemSelected += args =>
{
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 =>
{
if (string.IsNullOrEmpty(args.Text))
return;

switch (typeButton.SelectedId)
{
case 1:
if (!_protoManager.HasIndex<SoundCollectionPrototype>(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:
return;
}
};

return controls;
}
}
12 changes: 12 additions & 0 deletions Robust.Server/Audio/AudioSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ public override (EntityUid Entity, AudioComponent Component)? PlayGlobal(string
/// <inheritdoc />
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}");
Expand All @@ -96,6 +99,9 @@ public override (EntityUid Entity, AudioComponent Component)? PlayEntity(string
/// <inheritdoc />
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}");
Expand All @@ -111,6 +117,9 @@ public override (EntityUid Entity, AudioComponent Component)? PlayPvs(string fil
/// <inheritdoc />
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}");
Expand All @@ -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}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -296,7 +297,6 @@ private bool TryReinterpretValue(object? input, [NotNullWhen(true)] out object?

output = prototype;
return true;

default:
return false;
}
Expand Down
4 changes: 4 additions & 0 deletions Robust.Server/ViewVariables/ViewVariablesTrait.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -96,6 +97,9 @@ public virtual bool TryModifyProperty(object[] property, object value)
if (value is EntityUid uid)
return IoCManager.Resolve<IEntityManager>().GetComponentOrNull<MetaDataComponent>(uid)?.NetEntity ?? NetEntity.Invalid;

if (value is SoundSpecifier)
return value;

var valType = value.GetType();
if (!valType.IsValueType)
{
Expand Down
Loading