From 2db374988c91c6ce5f932b9cee1ba251cbfb22e5 Mon Sep 17 00:00:00 2001 From: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Date: Wed, 17 Apr 2024 19:27:00 +1000 Subject: [PATCH] Added Jukebox (#26736) * Added Jukebox, along with music for jukebox * Fixed Jukebox meta.json copyright * Removed songs I couldn't find a license for. * Renamed files to solve check failures from spaces * Added missing attributions.yml * Fixed lack of description in Jukebox * Jukebox is now constructable. * Change Jukebox menu to FancyWindow * Moved Jukebox messages out of jukebox component * Removed Jukebox OnValueChanged. * JukeboxComp now uses AutoGenerateComponentState * Removed state code, since it's auto generated * Fixed various Jukebox code to match conventions. * Updated Standard.yml to match changed song list. * fixes * Jukebox workin * Fix * Polishing * Finalising * Revert * bad * jukey * Reviews * name * Update submodule to 218.2.0 --------- Co-authored-by: iNVERTED --- .../Jukebox/JukeboxBoundUserInterface.cs | 119 +++++++++++++ Content.Client/Audio/Jukebox/JukeboxMenu.xaml | 18 ++ .../Audio/Jukebox/JukeboxMenu.xaml.cs | 166 ++++++++++++++++++ Content.Client/Audio/Jukebox/JukeboxSystem.cs | 153 ++++++++++++++++ Content.Server/Audio/Jukebox/JukeboxSystem.cs | 152 ++++++++++++++++ .../Audio/Jukebox/JukeboxComponent.cs | 80 +++++++++ .../Audio/Jukebox/JukeboxPrototype.cs | 23 +++ Content.Shared/Audio/Jukebox/JukeboxUi.cs | 11 ++ .../Audio/Jukebox/SharedJukeboxSystem.cs | 8 + Resources/Audio/Jukebox/attributions.yml | 22 +++ Resources/Audio/Jukebox/constellations.ogg | Bin 0 -> 848147 bytes Resources/Audio/Jukebox/drifting.ogg | Bin 0 -> 915591 bytes Resources/Audio/Jukebox/flip-flap.ogg | Bin 0 -> 1522765 bytes Resources/Audio/Jukebox/sector11.ogg | Bin 0 -> 2118480 bytes Resources/Audio/Jukebox/starlight.ogg | Bin 0 -> 1575072 bytes Resources/Audio/Jukebox/title3.ogg | Bin 0 -> 2240764 bytes .../Locale/en-US/jukebox/jukebox-menu.ftl | 5 + .../Prototypes/Catalog/Jukebox/Standard.yml | 35 ++++ .../Circuitboards/Machine/production.yml | 16 +- .../Entities/Structures/Machines/jukebox.yml | 59 +++++++ .../Entities/Structures/Machines/lathe.yml | 1 + .../Prototypes/Recipes/Lathes/electronics.yml | 8 + .../Prototypes/Research/civilianservices.yml | 1 + .../Structures/Machines/jukebox.rsi/meta.json | 31 ++++ .../Structures/Machines/jukebox.rsi/off.png | Bin 0 -> 770 bytes .../Structures/Machines/jukebox.rsi/on.png | Bin 0 -> 673 bytes .../Machines/jukebox.rsi/select.png | Bin 0 -> 1339 bytes 27 files changed, 907 insertions(+), 1 deletion(-) create mode 100644 Content.Client/Audio/Jukebox/JukeboxBoundUserInterface.cs create mode 100644 Content.Client/Audio/Jukebox/JukeboxMenu.xaml create mode 100644 Content.Client/Audio/Jukebox/JukeboxMenu.xaml.cs create mode 100644 Content.Client/Audio/Jukebox/JukeboxSystem.cs create mode 100644 Content.Server/Audio/Jukebox/JukeboxSystem.cs create mode 100644 Content.Shared/Audio/Jukebox/JukeboxComponent.cs create mode 100644 Content.Shared/Audio/Jukebox/JukeboxPrototype.cs create mode 100644 Content.Shared/Audio/Jukebox/JukeboxUi.cs create mode 100644 Content.Shared/Audio/Jukebox/SharedJukeboxSystem.cs create mode 100644 Resources/Audio/Jukebox/attributions.yml create mode 100644 Resources/Audio/Jukebox/constellations.ogg create mode 100644 Resources/Audio/Jukebox/drifting.ogg create mode 100644 Resources/Audio/Jukebox/flip-flap.ogg create mode 100644 Resources/Audio/Jukebox/sector11.ogg create mode 100644 Resources/Audio/Jukebox/starlight.ogg create mode 100644 Resources/Audio/Jukebox/title3.ogg create mode 100644 Resources/Locale/en-US/jukebox/jukebox-menu.ftl create mode 100644 Resources/Prototypes/Catalog/Jukebox/Standard.yml create mode 100644 Resources/Prototypes/Entities/Structures/Machines/jukebox.yml create mode 100644 Resources/Textures/Structures/Machines/jukebox.rsi/meta.json create mode 100644 Resources/Textures/Structures/Machines/jukebox.rsi/off.png create mode 100644 Resources/Textures/Structures/Machines/jukebox.rsi/on.png create mode 100644 Resources/Textures/Structures/Machines/jukebox.rsi/select.png diff --git a/Content.Client/Audio/Jukebox/JukeboxBoundUserInterface.cs b/Content.Client/Audio/Jukebox/JukeboxBoundUserInterface.cs new file mode 100644 index 0000000000..072730d65d --- /dev/null +++ b/Content.Client/Audio/Jukebox/JukeboxBoundUserInterface.cs @@ -0,0 +1,119 @@ +using Content.Shared.Audio.Jukebox; +using Robust.Client.Audio; +using Robust.Client.Player; +using Robust.Shared.Audio.Components; +using Robust.Shared.Player; +using Robust.Shared.Prototypes; + +namespace Content.Client.Audio.Jukebox; + +public sealed class JukeboxBoundUserInterface : BoundUserInterface +{ + [Dependency] private readonly IPlayerManager _player = default!; + [Dependency] private readonly IPrototypeManager _protoManager = default!; + + [ViewVariables] + private JukeboxMenu? _menu; + + public JukeboxBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) + { + IoCManager.InjectDependencies(this); + } + + protected override void Open() + { + base.Open(); + + _menu = new JukeboxMenu(); + _menu.OnClose += Close; + _menu.OpenCentered(); + + _menu.OnPlayPressed += args => + { + if (args) + { + SendMessage(new JukeboxPlayingMessage()); + } + else + { + SendMessage(new JukeboxPauseMessage()); + } + }; + + _menu.OnStopPressed += () => + { + SendMessage(new JukeboxStopMessage()); + }; + + _menu.OnSongSelected += SelectSong; + + _menu.SetTime += SetTime; + PopulateMusic(); + Reload(); + } + + /// + /// Reloads the attached menu if it exists. + /// + public void Reload() + { + if (_menu == null || !EntMan.TryGetComponent(Owner, out JukeboxComponent? jukebox)) + return; + + _menu.SetAudioStream(jukebox.AudioStream); + + if (_protoManager.TryIndex(jukebox.SelectedSongId, out var songProto)) + { + var length = EntMan.System().GetAudioLength(songProto.Path.Path.ToString()); + _menu.SetSelectedSong(songProto.Name, (float) length.TotalSeconds); + } + else + { + _menu.SetSelectedSong(string.Empty, 0f); + } + } + + public void PopulateMusic() + { + _menu?.Populate(_protoManager.EnumeratePrototypes()); + } + + public void SelectSong(ProtoId songid) + { + SendMessage(new JukeboxSelectedMessage(songid)); + } + + public void SetTime(float time) + { + var sentTime = time; + + // You may be wondering, what the fuck is this + // Well we want to be able to predict the playback slider change, of which there are many ways to do it + // We can't just use SendPredictedMessage because it will reset every tick and audio updates every frame + // so it will go BRRRRT + // Using ping gets us close enough that it SHOULD, MOST OF THE TIME, fall within the 0.1 second tolerance + // that's still on engine so our playback position never gets corrected. + if (EntMan.TryGetComponent(Owner, out JukeboxComponent? jukebox) && + EntMan.TryGetComponent(jukebox.AudioStream, out AudioComponent? audioComp)) + { + audioComp.PlaybackPosition = time; + } + + SendMessage(new JukeboxSetTimeMessage(sentTime)); + } + + protected override void Dispose(bool disposing) + { + base.Dispose(disposing); + if (!disposing) + return; + + if (_menu == null) + return; + + _menu.OnClose -= Close; + _menu.Dispose(); + _menu = null; + } +} + diff --git a/Content.Client/Audio/Jukebox/JukeboxMenu.xaml b/Content.Client/Audio/Jukebox/JukeboxMenu.xaml new file mode 100644 index 0000000000..e8d39a9b11 --- /dev/null +++ b/Content.Client/Audio/Jukebox/JukeboxMenu.xaml @@ -0,0 +1,18 @@ + + + + + + +