Skip to content

Commit

Permalink
Implement sound VV
Browse files Browse the repository at this point in the history
No params yet because I'm lazy but paths and collections work.
  • Loading branch information
metalgearsloth committed Mar 16, 2024
1 parent 69706b0 commit d3a258a
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 0 deletions.
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);
return control;
}

if (type == typeof(ViewVariablesBlobMembers.ServerKeyValuePairToken) ||
type.IsGenericType && type.GetGenericTypeDefinition() == typeof(KeyValuePair<,>))
{
Expand Down
98 changes: 98 additions & 0 deletions Robust.Client/ViewVariables/Editors/VVPropEditorSoundSpecifier.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
12 changes: 12 additions & 0 deletions Robust.Server/ViewVariables/ServerViewVariablesManager.cs
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,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;
}
Expand Down
16 changes: 16 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 @@ -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
Expand Down
14 changes: 14 additions & 0 deletions Robust.Shared/ViewVariables/ViewVariablesBlob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,20 @@ public override string ToString()
}
}

[Serializable, NetSerializable]
public sealed class SoundSpecifierReferenceToken : ReferenceToken
{
/// <summary>
/// Type of the underlying soundspecifier
/// </summary>
public string Variant;

/// <summary>
/// Value of the underlying soundspecifier
/// </summary>
public string Value;
}

/// <summary>
/// Token used to indicate "this is a prototype reference, but I can't send the actual reference over".
/// </summary>
Expand Down

0 comments on commit d3a258a

Please sign in to comment.