using Content.Shared.Audio.Jukebox; using Robust.Client.AutoGenerated; using Robust.Client.UserInterface.XAML; using Robust.Client.UserInterface.Controls; namespace Content.Client.Audio.Jukebox; [GenerateTypedNameReferences] public sealed partial class JukeboxEntry : BoxContainer { private JukeboxPrototype? _song; private bool _playPauseState = true; public bool PlayPauseState { get {return _playPauseState;} set { _playPauseState = value; UpdateLabel(); } } private JukeboxEntryType _entryType; public JukeboxEntryType EntryType { get {return _entryType;} set { _entryType = value; Buttons(); } } public JukeboxEntry() { RobustXamlLoader.Load(this); IoCManager.InjectDependencies(this); Buttons(); } public JukeboxEntry(JukeboxPrototype? song) : this() { SetSong(song); Buttons(); } public void SetSong(JukeboxPrototype? song) { _song = song; if (song == null) { Buttons(); return; } SongName.Text = song.Name; Buttons(); } public void SetOnPressedPlay(Action? func) { if (func == null) return; PlayButton.OnPressed += args => { if (_entryType == JukeboxEntryType.Current) { _playPauseState = !_playPauseState; UpdateLabel(); } func(_song, _playPauseState, args); }; } public void SetOnPressedQueue(Action? func) { if (func == null) return; QueueButton.OnPressed += args => { func(_song, args); }; } public void SetOnPressedStop(Action? func) { StopButton.OnPressed += func; } public void SetOnPressedRemove(Action? func) { if (func == null) return; RemoveButton.OnPressed += args => { func(this, args); }; } private void Buttons() { PlayButton.Visible = _song != null && (_entryType == JukeboxEntryType.List || _entryType == JukeboxEntryType.Current); StopButton.Visible = _song != null && _entryType == JukeboxEntryType.Current; RemoveButton.Visible = _song != null && _entryType == JukeboxEntryType.Queue; QueueButton.Visible = _song != null && _entryType == JukeboxEntryType.List; } private void UpdateLabel() { if (!_playPauseState) { PlayButton.Text = Loc.GetString("jukebox-menu-buttonplay"); } else { PlayButton.Text = Loc.GetString("jukebox-menu-buttonpause"); } } public enum JukeboxEntryType { List, Queue, Current, } }