Files
OldThink/Content.Client/Audio/Jukebox/JukeboxEntry.xaml.cs
Jabak b6d3c050a0 Queue in JukeBox (#640)
* Queue in JukeBox

* Translation JukeBox
2024-08-19 21:11:35 +03:00

128 lines
3.0 KiB
C#

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<JukeboxPrototype?, bool, BaseButton.ButtonEventArgs>? func)
{
if (func == null)
return;
PlayButton.OnPressed += args => {
if (_entryType == JukeboxEntryType.Current)
{
_playPauseState = !_playPauseState;
UpdateLabel();
}
func(_song, _playPauseState, args);
};
}
public void SetOnPressedQueue(Action<JukeboxPrototype?, BaseButton.ButtonEventArgs>? func)
{
if (func == null)
return;
QueueButton.OnPressed += args => {
func(_song, args);
};
}
public void SetOnPressedStop(Action<BaseButton.ButtonEventArgs>? func)
{
StopButton.OnPressed += func;
}
public void SetOnPressedRemove(Action<JukeboxEntry, BaseButton.ButtonEventArgs>? 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,
}
}