Skip to content

Commit

Permalink
Jukebox update (#2018)
Browse files Browse the repository at this point in the history
* jukebox update start

* Dexler pochini

* add comments

* comment boombox

* fix conversations

* Update Content.Server/Audio/Jukebox/JukeboxSystem.cs

Co-authored-by: Stalen <33173619+stalengd@users.noreply.github.com>

---------

Co-authored-by: Stalen <33173619+stalengd@users.noreply.github.com>
  • Loading branch information
Surani1 and stalengd authored Oct 9, 2024
1 parent 4ebe9b6 commit 4f9821a
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 1 deletion.
9 changes: 9 additions & 0 deletions Content.Client/Audio/Jukebox/JukeboxBoundUserInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ protected override void Open()
_menu.OnSongSelected += SelectSong;

_menu.SetTime += SetTime;

_menu.SetGain += SetGain; //ss220-jukebox-tweak-end
PopulateMusic();
Reload();
}
Expand Down Expand Up @@ -97,5 +99,12 @@ public void SetTime(float time)

SendMessage(new JukeboxSetTimeMessage(sentTime));
}

//ss220-jukebox-tweak-begin
public void SetGain(float gain)
{
SendMessage(new JukeboxSetGainMessage(gain));
}
//ss220-jukebox-tweak-end
}

6 changes: 6 additions & 0 deletions Content.Client/Audio/Jukebox/JukeboxMenu.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
<BoxContainer Margin="4 0" Orientation="Vertical">
<ItemList Name="MusicList" SelectMode="Button" Margin="3 3 3 3"
HorizontalExpand="True" VerticalExpand="True" SizeFlagsStretchRatio="8"/>
<!-- SS220-jukebox-tweak-begin -->
<BoxContainer Orientation="Vertical">
<Label Name="Volume" Text="{Loc 'jukebox-menu-slidervolume'}" />
<Slider Name="VolumeSlider" HorizontalExpand="True" />
</BoxContainer>
<!-- SS220-jukebox-tweak-end -->
<BoxContainer Orientation="Vertical">
<Label Name="SongSelected" Text="{Loc 'jukebox-menu-selectedsong'}" />
<Label Name="SongName" Text="---" />
Expand Down
20 changes: 20 additions & 0 deletions Content.Client/Audio/Jukebox/JukeboxMenu.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Audio.Components;
using Robust.Shared.Audio.Systems; //ss220-jukebox-tweak
using Robust.Shared.Input;
using Robust.Shared.Prototypes;
using Robust.Shared.Timing;
Expand All @@ -30,6 +31,7 @@ public sealed partial class JukeboxMenu : FancyWindow
public event Action? OnStopPressed;
public event Action<ProtoId<JukeboxPrototype>>? OnSongSelected;
public event Action<float>? SetTime;
public event Action<float>? SetGain; //SS220-jukebox-tweak

private EntityUid? _audio;

Expand Down Expand Up @@ -63,6 +65,11 @@ public JukeboxMenu()
PlaybackSlider.OnReleased += PlaybackSliderKeyUp;

SetPlayPauseButton(_audioSystem.IsPlaying(_audio), force: true);

//SS220-jukebox-tweak-begin
VolumeSlider.OnReleased += VolumeSliderKeyUp;
VolumeSlider.MaxValue = 1;
//SS220-jukebox-tweak-end
}

public JukeboxMenu(AudioSystem audioSystem)
Expand All @@ -73,6 +80,12 @@ public JukeboxMenu(AudioSystem audioSystem)
public void SetAudioStream(EntityUid? audio)
{
_audio = audio;
//ss220-jukebox-tweak-begin
if (_entManager.TryGetComponent(_audio, out AudioComponent? audioComp))
{
VolumeSlider.Value = SharedAudioSystem.VolumeToGain(audioComp.Volume);
}
//ss220-jukebox-tweak-end
}

private void PlaybackSliderKeyUp(Slider args)
Expand All @@ -81,6 +94,13 @@ private void PlaybackSliderKeyUp(Slider args)
_lockTimer = 0.5f;
}

//SS220-jukebox-tweak-begin
private void VolumeSliderKeyUp(Slider args)
{
SetGain?.Invoke(VolumeSlider.Value);
}
//SS220-jukebox-tweak-end

/// <summary>
/// Re-populates the list of jukebox prototypes available.
/// </summary>
Expand Down
14 changes: 13 additions & 1 deletion Content.Server/Audio/Jukebox/JukeboxSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public override void Initialize()
SubscribeLocalEvent<JukeboxComponent, JukeboxPauseMessage>(OnJukeboxPause);
SubscribeLocalEvent<JukeboxComponent, JukeboxStopMessage>(OnJukeboxStop);
SubscribeLocalEvent<JukeboxComponent, JukeboxSetTimeMessage>(OnJukeboxSetTime);
SubscribeLocalEvent<JukeboxComponent, JukeboxSetGainMessage>(OnJukeboxSetGain); //ss220-jukebox-tweak
SubscribeLocalEvent<JukeboxComponent, ComponentInit>(OnComponentInit);
SubscribeLocalEvent<JukeboxComponent, ComponentShutdown>(OnComponentShutdown);

Expand Down Expand Up @@ -56,7 +57,8 @@ private void OnJukeboxPlay(EntityUid uid, JukeboxComponent component, ref Jukebo
return;
}

component.AudioStream = Audio.PlayPvs(jukeboxProto.Path, uid, AudioParams.Default.WithMaxDistance(10f))?.Entity;
component.AudioStream = Audio.PlayPvs(jukeboxProto.Path, uid, AudioParams.Default.WithVolume(SharedAudioSystem.GainToVolume(component.Gain)).WithMaxDistance(10f))?.Entity;
//SS220-jukebox-tweak я ебать насрал
Dirty(uid, component);
}
}
Expand All @@ -75,6 +77,16 @@ private void OnJukeboxSetTime(EntityUid uid, JukeboxComponent component, Jukebox
}
}

//SS220-jukebox-tweak-begin
private void OnJukeboxSetGain(EntityUid uid, JukeboxComponent component, JukeboxSetGainMessage args)
{
var gain = Math.Clamp(args.Gain, 0f, 1f);
Audio.SetGain(component.AudioStream, gain);
component.Gain = gain;
Dirty(uid, component);
}
//SS220-jukebox-tweak-end

private void OnPowerChanged(Entity<JukeboxComponent> entity, ref PowerChangedEvent args)
{
TryUpdateVisualState(entity);
Expand Down
13 changes: 13 additions & 0 deletions Content.Shared/Audio/Jukebox/JukeboxComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ public sealed partial class JukeboxComponent : Component

[ViewVariables]
public float SelectAccumulator;

//ss220-jukebox-tweak-begin
[DataField, AutoNetworkedField]
public float Gain = 1;
//ss220-jukebox-tweak-end
}

[Serializable, NetSerializable]
Expand All @@ -60,6 +65,14 @@ public sealed class JukeboxSetTimeMessage(float songTime) : BoundUserInterfaceMe
public float SongTime { get; } = songTime;
}

//ss220-jukebox-tweak-begin
[Serializable, NetSerializable]
public sealed class JukeboxSetGainMessage(float gain) : BoundUserInterfaceMessage
{
public float Gain { get; } = gain;
}
//ss220-jukebox-tweak-end

[Serializable, NetSerializable]
public enum JukeboxVisuals : byte
{
Expand Down
1 change: 1 addition & 0 deletions Resources/Locale/en-US/ss220/jukebox/jukebox-menu.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
jukebox-menu-slidervolume = Volume:
1 change: 1 addition & 0 deletions Resources/Locale/ru-RU/ss220/jukebox/jukebox-menu.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
jukebox-menu-slidervolume = Громкость звука:

0 comments on commit 4f9821a

Please sign in to comment.