Skip to content

Commit

Permalink
Jukeboxes can now be emagged. Renamed a handful of things to be less …
Browse files Browse the repository at this point in the history
…dumb.
  • Loading branch information
Pspritechologist committed Sep 24, 2023
1 parent f2f9c7e commit 79ecdab
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 62 deletions.
21 changes: 21 additions & 0 deletions Content.Client/SimpleStation14/Jukebox/Ui/JukeboxSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Content.Shared.Emag.Systems;
using Content.Shared.SimpleStation14.Jukebox;

namespace Content.Shared.SimpleStation14.Jukebox;

public sealed class SharedJukeBoxSystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<JukeboxComponent, GotEmaggedEvent>(OnEmagged);
}

/// <summary>
/// Handles setting the Jukebox's state to emagged.
/// </summary>
private void OnEmagged(EntityUid jukeBox, JukeboxComponent jukeboxComp, ref GotEmaggedEvent args)
{
args.Handled = true;
}
}
63 changes: 34 additions & 29 deletions Content.Client/SimpleStation14/Jukebox/Ui/JukeboxWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ public JukeboxWindow(JukeboxBoundUserInterface bui, JukeboxComponent jukeboxComp
SerialTitle.SetMessage(Loc.GetString("jukebox-ui-serial-title"));
SerialNumber.Text = jukeboxComp.SerialNumber;

BG_1.PanelOverride = new StyleBoxFlat { BackgroundColor = Color.FromHex(jukeboxComp.JukeboxBG) };
Panel_1.PanelOverride = new StyleBoxFlat { BackgroundColor = Color.FromHex(jukeboxComp.JukeboxPanel) };
Panel_2.PanelOverride = new StyleBoxFlat { BackgroundColor = Color.FromHex(jukeboxComp.JukeboxPanel) };
// Accent_1.PanelOverride = new StyleBoxFlat { BackgroundColor = Color.FromHex(jukeboxComp.JukeboxAccent) };
// Accent_2.PanelOverride = new StyleBoxFlat { BackgroundColor = Color.FromHex(jukeboxComp.JukeboxAccent) };
Accent_3.PanelOverride = new StyleBoxFlat { BackgroundColor = Color.FromHex(jukeboxComp.JukeboxAccent) };
BG_1.PanelOverride = new StyleBoxFlat { BackgroundColor = Color.FromHex(jukeboxComp.JukeboxUiColorBG) };
Panel_1.PanelOverride = new StyleBoxFlat { BackgroundColor = Color.FromHex(jukeboxComp.JukeboxUiColorPanel) };
Panel_2.PanelOverride = new StyleBoxFlat { BackgroundColor = Color.FromHex(jukeboxComp.JukeboxUiColorPanel) };
// Accent_1.PanelOverride = new StyleBoxFlat { BackgroundColor = Color.FromHex(jukeboxComp.JukeboxUiColorAccent) };
// Accent_2.PanelOverride = new StyleBoxFlat { BackgroundColor = Color.FromHex(jukeboxComp.JukeboxUiColorAccent) };
Accent_3.PanelOverride = new StyleBoxFlat { BackgroundColor = Color.FromHex(jukeboxComp.JukeboxUiColorAccent) };

SongName.FontOverride = _resourceCache.GetFont("/Fonts/NotoSans/NotoSans-Regular.ttf", 18);
SongsLabel.FontOverride = _resourceCache.GetFont("/Fonts/NotoSans/NotoSans-Regular.ttf", 22);
Expand Down Expand Up @@ -124,33 +124,38 @@ private void PopulateSongs()

songsToAdd.Sort();

if (_jukeboxComp.Emagged)
songsToAdd.AddRange(_jukeboxComp.EmaggedSongs.OrderBy(song => song).ToList());

foreach (var trackId in songsToAdd)
{
if (!_prototype.TryIndex<JukeboxTrackPrototype>(trackId, out var track))
{
Logger.Error($"No JukeboxTrackPrototype found for {trackId}!");

continue;
}

var newButton = new Button
{
Text = track.Name,
TextAlign = Label.AlignMode.Left,
ClipText = true,
RectClipContent = true,
MaxWidth = 180f,
Margin = new Thickness(0, 0, 0, 4),
};
GenerateSongButton(trackId, false);

newButton.StyleClasses.Add(StyleBase.ButtonOpenLeft);
newButton.OnPressed += _ => OnSongSelected?.Invoke(trackId);
if (_jukeboxComp.Emagged)
foreach (var trackId in _jukeboxComp.EmaggedSongs.OrderBy(song => song).ToList())
GenerateSongButton(trackId, true);
}

SongPickerBox.AddChild(newButton);
private void GenerateSongButton(string trackId, bool illegal)
{
if (!_prototype.TryIndex<JukeboxTrackPrototype>(trackId, out var track))
{
Logger.Error($"No JukeboxTrackPrototype found for {trackId}!");
return;
}

var newButton = new Button
{
Text = track.Name,
TextAlign = Label.AlignMode.Left,
ClipText = true,
RectClipContent = true,
MaxWidth = 180f,
Margin = new Thickness(0, 0, 0, 4),
};

newButton.StyleClasses.Add(StyleBase.ButtonOpenLeft);
if (illegal)
newButton.StyleClasses.Add(StyleBase.ButtonCaution);
newButton.OnPressed += _ => OnSongSelected?.Invoke(track.ID);

SongPickerBox.AddChild(newButton);
}

private void PopulateQueue()
Expand Down
40 changes: 26 additions & 14 deletions Content.Server/SimpleStation14/Jukebox/JukeboxSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Robust.Shared.Prototypes;
using Robust.Shared.Timing;
using Robust.Server.GameObjects;
using Content.Shared.Emag.Systems;

namespace Content.Server.SimpleStation14.Jukebox;

Expand All @@ -24,6 +25,7 @@ public override void Initialize()
SubscribeLocalEvent<JukeboxComponent, ComponentShutdown>(OnComponentShutdown);

SubscribeLocalEvent<JukeboxComponent, PowerChangedEvent>(OnPowerChanged);
SubscribeLocalEvent<JukeboxComponent, GotEmaggedEvent>(OnEmagged);

SubscribeLocalEvent<JukeboxComponent, JukeboxPlayButtonPressedMessage>(OnPlayButtonPressed);
SubscribeLocalEvent<JukeboxComponent, JukeboxSkipButtonPressedMessage>(OnSkipButtonPressed);
Expand Down Expand Up @@ -52,6 +54,16 @@ private void OnComponentShutdown(EntityUid uid, JukeboxComponent component, Comp
Clean(uid, component);
}

/// <summary>
/// Handles setting the Jukebox's state to emagged.
/// </summary>
private void OnEmagged(EntityUid jukeBox, JukeboxComponent jukeboxComp, ref GotEmaggedEvent args)
{
jukeboxComp.Emagged = true;
args.Handled = true;
UpdateState(jukeBox, jukeboxComp);
}

#endregion Event handlers
#region Public functions

Expand All @@ -77,13 +89,13 @@ public void TryQueueSong(EntityUid jukeBox, JukeboxComponent jukeboxComp, string
return;
}

Play(jukeBox, jukeboxComp, song);
TryPlaySong(jukeBox, jukeboxComp, song);
}

/// <summary>
/// Ends the currently playing song in the Jukebox and plays the next song in the queue, if available.
/// </summary>
public void Skip(EntityUid jukeBox, JukeboxComponent jukeboxComp)
public void TrySkipSong(EntityUid jukeBox, JukeboxComponent jukeboxComp)
{
if (!jukeboxComp.CanPlay)
return;
Expand All @@ -95,7 +107,7 @@ public void Skip(EntityUid jukeBox, JukeboxComponent jukeboxComp)
var toPlay = jukeboxComp.NextUp[0]; // Get the first song in the queue.
jukeboxComp.NextUp.RemoveAt(0); // And remove it now so we don't need to UpdateState() twice.

Play(jukeBox, jukeboxComp, toPlay);
TryPlaySong(jukeBox, jukeboxComp, toPlay);

return;
}
Expand All @@ -110,7 +122,7 @@ public void Skip(EntityUid jukeBox, JukeboxComponent jukeboxComp)
/// See <see cref="Stop"/> to stop the Jukebox instead.
/// Pausing a Jukebox will allow it to remember its paused state, even if it gets stopped later.
/// </remarks>
public void Pause(EntityUid jukeBox, JukeboxComponent jukeboxComp)
public void DoPauseSong(EntityUid jukeBox, JukeboxComponent jukeboxComp)
{
if (jukeboxComp.Paused || !jukeboxComp.Playing)
return;
Expand All @@ -123,7 +135,7 @@ public void Pause(EntityUid jukeBox, JukeboxComponent jukeboxComp)
/// <summary>
/// Unpauses the Jukebox and resumes playing the current song from where it was paused.
/// </summary>
public void UnPause(EntityUid jukeBox, JukeboxComponent jukeboxComp)
public void TryUnPauseSong(EntityUid jukeBox, JukeboxComponent jukeboxComp)
{
if (!jukeboxComp.CanPlay)
return;
Expand All @@ -143,24 +155,24 @@ public void UnPause(EntityUid jukeBox, JukeboxComponent jukeboxComp)
/// </summary>
/// <param name="song">The JukeboxTrackPrototype representing the song to be played.</param>
/// <param name="offset">The optional offset from the start of the song to begin playing from.</param>
public void Play(EntityUid jukeBox, JukeboxComponent jukeboxComp, string song, TimeSpan offset = new TimeSpan())
public void TryPlaySong(EntityUid jukeBox, JukeboxComponent jukeboxComp, string song, TimeSpan offset = new TimeSpan())
{
if (!_prototype.TryIndex<JukeboxTrackPrototype>(song, out var songPrototype))
{
Logger.Error($"Jukebox track prototype {song} not found!");

Skip(jukeBox, jukeboxComp);
TrySkipSong(jukeBox, jukeboxComp);
return;
}

Play(jukeBox, jukeboxComp, songPrototype, offset);
TryPlaySong(jukeBox, jukeboxComp, songPrototype, offset);
}

/// <inheritdoc cref="Play(EntityUid, JukeboxComponent, string, TimeSpan)"/>
/// <inheritdoc cref="TryPlaySong(EntityUid, JukeboxComponent, string, TimeSpan)"/>
/// <remarks>
/// Directly takes a <see cref="JukeboxTrackPrototype"/> instead.
/// </remarks>
public void Play(EntityUid jukeBox, JukeboxComponent jukeboxComp, JukeboxTrackPrototype song, TimeSpan offset = new TimeSpan())
public void TryPlaySong(EntityUid jukeBox, JukeboxComponent jukeboxComp, JukeboxTrackPrototype song, TimeSpan offset = new TimeSpan())
{
if (!jukeboxComp.CanPlay)
return;
Expand All @@ -175,7 +187,7 @@ public void UnPause(EntityUid jukeBox, JukeboxComponent jukeboxComp)

jukeboxComp.FinishPlayingTime = _timing.CurTime + song.Duration - offset;

jukeboxComp.CurrentlyPlayingStream = _audio.Play(song.Path, Filter.Broadcast(), jukeBox, true, AudioParams.Default.WithPlayOffset((float)offset.TotalSeconds));
jukeboxComp.CurrentlyPlayingStream = _audio.Play(song.Path, Filter.Broadcast(), jukeBox, true, AudioParams.Default.WithPlayOffset((float) offset.TotalSeconds));

Timer.Spawn((int) (song.Duration.TotalMilliseconds - offset.TotalMilliseconds), () => OnSongEnd(jukeBox, jukeboxComp), jukeboxComp.SongTimerCancel.Token);

Expand Down Expand Up @@ -207,7 +219,7 @@ private void CheckCanPlay(EntityUid uid, JukeboxComponent component)
/// Stops the currently playing song and sets the Jukebox to a stopped state.
/// </summary>
/// <remarks>
/// See <see cref="Pause"/> to pause the Jukebox instead.
/// See <see cref="DoPauseSong"/> to pause the Jukebox instead.
/// </remarks>
private void Stop(EntityUid jukeBox, JukeboxComponent jukeboxComp)
{
Expand Down Expand Up @@ -280,7 +292,7 @@ private void TryRestart(EntityUid jukeBox, JukeboxComponent jukeboxComp)

jukeboxComp.StoppedTime = null;

Play(jukeBox, jukeboxComp, jukeboxComp.CurrentlyPlayingTrack, timeLeftBeforeFinished);
TryPlaySong(jukeBox, jukeboxComp, jukeboxComp.CurrentlyPlayingTrack, timeLeftBeforeFinished);

return;
}
Expand All @@ -301,7 +313,7 @@ private void UpdateState(EntityUid jukeBox, JukeboxComponent jukeboxComp, bool p
/// </summary>
private void OnSongEnd(EntityUid jukeBox, JukeboxComponent jukeboxComp)
{
Skip(jukeBox, jukeboxComp);
TrySkipSong(jukeBox, jukeboxComp);
}

#endregion Private functions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ private void OnPlayButtonPressed(EntityUid jukeBox, JukeboxComponent jukeboxComp
{
if (jukeboxComp.Paused)
{
UnPause(jukeBox, jukeboxComp);
TryUnPauseSong(jukeBox, jukeboxComp);
}
else
{
Pause(jukeBox, jukeboxComp);
DoPauseSong(jukeBox, jukeboxComp);
}
}

Expand All @@ -36,7 +36,7 @@ private void OnPlayButtonPressed(EntityUid jukeBox, JukeboxComponent jukeboxComp
/// </summary>
private void OnSkipButtonPressed(EntityUid jukeBox, JukeboxComponent jukeboxComp, JukeboxSkipButtonPressedMessage msg)
{
Skip(jukeBox, jukeboxComp);
TrySkipSong(jukeBox, jukeboxComp);
}

/// <summary>
Expand Down
16 changes: 8 additions & 8 deletions Content.Shared/SimpleStation14/Jukebox/JukeboxComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@ public sealed partial class JukeboxComponent : Component
/// A colour to be used in the Jukebox's UI.
/// Should be based on the sprite.
/// </summary>
[DataField("jukeboxBG")]
public string JukeboxBG { get; set; } = "#602C00";
[DataField("jukeboxUiColorBG")]
public string JukeboxUiColorBG { get; set; } = "#602C00";

/// <inheritdoc cref="JukeboxBG"/>
[DataField("jukeboxPanel")]
public string JukeboxPanel { get; } = "#480F0F";
/// <inheritdoc cref="JukeboxUiColorBG"/>
[DataField("jukeboxUiColorPanel")]
public string JukeboxUiColorPanel { get; } = "#480F0F";

/// <inheritdoc cref="JukeboxBG"/>
[DataField("jukeboxAccent")]
public string JukeboxAccent { get; } = "#20181B";
/// <inheritdoc cref="JukeboxUiColorBG"/>
[DataField("jukeboxUiColorAccent")]
public string JukeboxUiColorAccent { get; } = "#20181B";

/// <summary>
/// The currently playing audio stream.
Expand Down
6 changes: 0 additions & 6 deletions Content.Shared/SimpleStation14/Jukebox/JukeboxSystem.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
using System.Collections.Generic;
using Content.Shared.SimpleStation14.Prototypes;
using Robust.Shared.Audio;
using Robust.Shared.Player;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
using Robust.Shared.Timing;

namespace Content.Shared.SimpleStation14.Jukebox;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
songs:
- DanyaVodovozFunkOMatic
- DanyaVodovozGoinOn
- DanyaVodovozOffTheGrid
- DanyaVodovozPlanetOfTheAmazons
emaggedSongs:
- DanyaVodovozGuacamole
- DanyaVodovozJazzFunkMySoul
- DanyaVodovozMothToAFlame
- DanyaVodovozNightInBrazil
- DanyaVodovozOffTheGrid
- DanyaVodovozPlanetOfTheAmazons
- type: ActivatableUI
key: enum.JukeboxUiKey.Key
- type: ActivatableUIRequiresPower
Expand Down

0 comments on commit 79ecdab

Please sign in to comment.