Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jukebox update #2018

Merged
merged 6 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Surani1 marked this conversation as resolved.
Show resolved Hide resolved
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)
{
Audio.SetGain(component.AudioStream, args.Gain);

component.Gain = args.Gain;
Dirty(uid, component);
}
Surani1 marked this conversation as resolved.
Show resolved Hide resolved
//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 = Громкость звука:
Loading