-
Notifications
You must be signed in to change notification settings - Fork 446
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
metalgearsloth
merged 5 commits into
space-wizards:master
from
metalgearsloth:2024-03-16-sound
Mar 24, 2024
Merged
Implement sound VV #4966
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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 |
---|---|---|
|
@@ -39,7 +39,7 @@ END TEMPLATE--> | |
|
||
### New features | ||
|
||
*None yet* | ||
* Implement basic VV for SoundSpecifiers. | ||
|
||
### Bugfixes | ||
|
||
|
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,3 @@ | ||
vv-sound-none = None | ||
vv-sound-path = Path | ||
vv-sound-collection = Collection |
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
104 changes: 104 additions & 0 deletions
104
Robust.Client/ViewVariables/Editors/VVPropEditorSoundSpecifier.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,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, | ||
metalgearsloth marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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; | ||
} | ||
} |
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
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.