Add lobby music volume slider (#12153)

This commit is contained in:
theashtronaut
2022-11-04 00:15:37 +00:00
committed by GitHub
parent 339c47a07a
commit 2856213c80
5 changed files with 54 additions and 9 deletions

View File

@@ -70,6 +70,7 @@ public sealed class BackgroundAudioSystem : EntitySystem
_configManager.OnValueChanged(CCVars.AmbienceVolume, AmbienceCVarChanged); _configManager.OnValueChanged(CCVars.AmbienceVolume, AmbienceCVarChanged);
_configManager.OnValueChanged(CCVars.LobbyMusicEnabled, LobbyMusicCVarChanged); _configManager.OnValueChanged(CCVars.LobbyMusicEnabled, LobbyMusicCVarChanged);
_configManager.OnValueChanged(CCVars.LobbyMusicVolume, LobbyMusicVolumeCVarChanged);
_configManager.OnValueChanged(CCVars.StationAmbienceEnabled, StationAmbienceCVarChanged); _configManager.OnValueChanged(CCVars.StationAmbienceEnabled, StationAmbienceCVarChanged);
_configManager.OnValueChanged(CCVars.SpaceAmbienceEnabled, SpaceAmbienceCVarChanged); _configManager.OnValueChanged(CCVars.SpaceAmbienceEnabled, SpaceAmbienceCVarChanged);
@@ -103,6 +104,7 @@ public sealed class BackgroundAudioSystem : EntitySystem
_configManager.UnsubValueChanged(CCVars.AmbienceVolume, AmbienceCVarChanged); _configManager.UnsubValueChanged(CCVars.AmbienceVolume, AmbienceCVarChanged);
_configManager.UnsubValueChanged(CCVars.LobbyMusicEnabled, LobbyMusicCVarChanged); _configManager.UnsubValueChanged(CCVars.LobbyMusicEnabled, LobbyMusicCVarChanged);
_configManager.UnsubValueChanged(CCVars.LobbyMusicVolume, LobbyMusicVolumeCVarChanged);
_configManager.UnsubValueChanged(CCVars.StationAmbienceEnabled, StationAmbienceCVarChanged); _configManager.UnsubValueChanged(CCVars.StationAmbienceEnabled, StationAmbienceCVarChanged);
_configManager.UnsubValueChanged(CCVars.SpaceAmbienceEnabled, SpaceAmbienceCVarChanged); _configManager.UnsubValueChanged(CCVars.SpaceAmbienceEnabled, SpaceAmbienceCVarChanged);
@@ -248,6 +250,14 @@ public sealed class BackgroundAudioSystem : EntitySystem
} }
} }
private void LobbyMusicVolumeCVarChanged(float volume)
{
if (_stateManager.CurrentState is LobbyState)
{
RestartLobbyMusic();
}
}
private void LobbyMusicCVarChanged(bool musicEnabled) private void LobbyMusicCVarChanged(bool musicEnabled)
{ {
if (!musicEnabled) if (!musicEnabled)
@@ -294,7 +304,8 @@ public sealed class BackgroundAudioSystem : EntitySystem
return; return;
} }
_lobbyStream = _audio.PlayGlobal(file, Filter.Local(), _lobbyParams); _lobbyStream = _audio.PlayGlobal(file, Filter.Local(),
_lobbyParams.WithVolume(_lobbyParams.Volume + _configManager.GetCVar(CCVars.LobbyMusicVolume)));
} }
private void EndLobbyMusic() private void EndLobbyMusic()

View File

@@ -9,7 +9,7 @@
StyleClasses="LabelKeyText"/> StyleClasses="LabelKeyText"/>
<BoxContainer Orientation="Vertical" Margin="0 3 0 0"> <BoxContainer Orientation="Vertical" Margin="0 3 0 0">
<BoxContainer Orientation="Horizontal" Margin="5 0 0 0"> <BoxContainer Orientation="Horizontal" Margin="5 0 0 0">
<Label Text="{Loc 'ui-options-master-volume'}" /> <Label Text="{Loc 'ui-options-master-volume'}" HorizontalExpand="True" />
<Control MinSize="8 0" /> <Control MinSize="8 0" />
<Slider Name="MasterVolumeSlider" <Slider Name="MasterVolumeSlider"
MinValue="0" MinValue="0"
@@ -23,7 +23,7 @@
</BoxContainer> </BoxContainer>
<Control MinSize="0 8" /> <Control MinSize="0 8" />
<BoxContainer Orientation="Horizontal" Margin="5 0 0 0"> <BoxContainer Orientation="Horizontal" Margin="5 0 0 0">
<Label Text="{Loc 'ui-options-midi-volume'}" /> <Label Text="{Loc 'ui-options-midi-volume'}" HorizontalExpand="True" />
<Control MinSize="8 0" /> <Control MinSize="8 0" />
<Slider Name="MidiVolumeSlider" <Slider Name="MidiVolumeSlider"
MinValue="0" MinValue="0"
@@ -36,7 +36,7 @@
<Control MinSize="4 0"/> <Control MinSize="4 0"/>
</BoxContainer> </BoxContainer>
<BoxContainer Orientation="Horizontal" Margin="5 0 0 0"> <BoxContainer Orientation="Horizontal" Margin="5 0 0 0">
<Label Text="{Loc 'ui-options-ambience-volume'}" /> <Label Text="{Loc 'ui-options-ambience-volume'}" HorizontalExpand="True" />
<Control MinSize="8 0" /> <Control MinSize="8 0" />
<Slider Name="AmbienceVolumeSlider" <Slider Name="AmbienceVolumeSlider"
MinValue="0" MinValue="0"
@@ -49,7 +49,20 @@
<Control MinSize="4 0"/> <Control MinSize="4 0"/>
</BoxContainer> </BoxContainer>
<BoxContainer Orientation="Horizontal" Margin="5 0 0 0"> <BoxContainer Orientation="Horizontal" Margin="5 0 0 0">
<Label Text="{Loc 'ui-options-ambience-max-sounds'}" /> <Label Text="{Loc 'ui-options-lobby-volume'}" HorizontalExpand="True" />
<Control MinSize="8 0" />
<Slider Name="LobbyVolumeSlider"
MinValue="0"
MaxValue="200"
HorizontalExpand="True"
MinSize="80 0"
Rounded="True" />
<Control MinSize="8 0" />
<Label Name="LobbyVolumeLabel" MinSize="48 0" Align="Right" />
<Control MinSize="4 0"/>
</BoxContainer>
<BoxContainer Orientation="Horizontal" Margin="5 0 0 0">
<Label Text="{Loc 'ui-options-ambience-max-sounds'}" HorizontalExpand="True" />
<Control MinSize="8 0" /> <Control MinSize="8 0" />
<Slider Name="AmbienceSoundsSlider" <Slider Name="AmbienceSoundsSlider"
MinValue="0" MinValue="0"

View File

@@ -34,6 +34,7 @@ namespace Content.Client.Options.UI.Tabs
MidiVolumeSlider.OnValueChanged += OnMidiVolumeSliderChanged; MidiVolumeSlider.OnValueChanged += OnMidiVolumeSliderChanged;
AmbienceVolumeSlider.OnValueChanged += OnAmbienceVolumeSliderChanged; AmbienceVolumeSlider.OnValueChanged += OnAmbienceVolumeSliderChanged;
AmbienceSoundsSlider.OnValueChanged += OnAmbienceSoundsSliderChanged; AmbienceSoundsSlider.OnValueChanged += OnAmbienceSoundsSliderChanged;
LobbyVolumeSlider.OnValueChanged += OnLobbyVolumeSliderChanged;
LobbyMusicCheckBox.OnToggled += OnLobbyMusicCheckToggled; LobbyMusicCheckBox.OnToggled += OnLobbyMusicCheckToggled;
RestartSoundsCheckBox.OnToggled += OnRestartSoundsCheckToggled; RestartSoundsCheckBox.OnToggled += OnRestartSoundsCheckToggled;
EventMusicCheckBox.OnToggled += OnEventMusicCheckToggled; EventMusicCheckBox.OnToggled += OnEventMusicCheckToggled;
@@ -54,9 +55,15 @@ namespace Content.Client.Options.UI.Tabs
MasterVolumeSlider.OnValueChanged -= OnMasterVolumeSliderChanged; MasterVolumeSlider.OnValueChanged -= OnMasterVolumeSliderChanged;
MidiVolumeSlider.OnValueChanged -= OnMidiVolumeSliderChanged; MidiVolumeSlider.OnValueChanged -= OnMidiVolumeSliderChanged;
AmbienceVolumeSlider.OnValueChanged -= OnAmbienceVolumeSliderChanged; AmbienceVolumeSlider.OnValueChanged -= OnAmbienceVolumeSliderChanged;
LobbyVolumeSlider.OnValueChanged -= OnLobbyVolumeSliderChanged;
base.Dispose(disposing); base.Dispose(disposing);
} }
private void OnLobbyVolumeSliderChanged(Range obj)
{
UpdateChanges();
}
private void OnAmbienceVolumeSliderChanged(Range obj) private void OnAmbienceVolumeSliderChanged(Range obj)
{ {
UpdateChanges(); UpdateChanges();
@@ -111,6 +118,7 @@ namespace Content.Client.Options.UI.Tabs
_cfg.SetCVar(CVars.AudioMasterVolume, MasterVolumeSlider.Value / 100); _cfg.SetCVar(CVars.AudioMasterVolume, MasterVolumeSlider.Value / 100);
_cfg.SetCVar(CVars.MidiVolume, LV100ToDB(MidiVolumeSlider.Value)); _cfg.SetCVar(CVars.MidiVolume, LV100ToDB(MidiVolumeSlider.Value));
_cfg.SetCVar(CCVars.AmbienceVolume, LV100ToDB(AmbienceVolumeSlider.Value)); _cfg.SetCVar(CCVars.AmbienceVolume, LV100ToDB(AmbienceVolumeSlider.Value));
_cfg.SetCVar(CCVars.LobbyMusicVolume, LV100ToDB(LobbyVolumeSlider.Value));
_cfg.SetCVar(CCVars.MaxAmbientSources, (int)AmbienceSoundsSlider.Value); _cfg.SetCVar(CCVars.MaxAmbientSources, (int)AmbienceSoundsSlider.Value);
_cfg.SetCVar(CCVars.LobbyMusicEnabled, LobbyMusicCheckBox.Pressed); _cfg.SetCVar(CCVars.LobbyMusicEnabled, LobbyMusicCheckBox.Pressed);
_cfg.SetCVar(CCVars.RestartSoundsEnabled, RestartSoundsCheckBox.Pressed); _cfg.SetCVar(CCVars.RestartSoundsEnabled, RestartSoundsCheckBox.Pressed);
@@ -132,6 +140,7 @@ namespace Content.Client.Options.UI.Tabs
MasterVolumeSlider.Value = _cfg.GetCVar(CVars.AudioMasterVolume) * 100; MasterVolumeSlider.Value = _cfg.GetCVar(CVars.AudioMasterVolume) * 100;
MidiVolumeSlider.Value = DBToLV100(_cfg.GetCVar(CVars.MidiVolume)); MidiVolumeSlider.Value = DBToLV100(_cfg.GetCVar(CVars.MidiVolume));
AmbienceVolumeSlider.Value = DBToLV100(_cfg.GetCVar(CCVars.AmbienceVolume)); AmbienceVolumeSlider.Value = DBToLV100(_cfg.GetCVar(CCVars.AmbienceVolume));
LobbyVolumeSlider.Value = DBToLV100(_cfg.GetCVar(CCVars.LobbyMusicVolume));
AmbienceSoundsSlider.Value = _cfg.GetCVar(CCVars.MaxAmbientSources); AmbienceSoundsSlider.Value = _cfg.GetCVar(CCVars.MaxAmbientSources);
LobbyMusicCheckBox.Pressed = _cfg.GetCVar(CCVars.LobbyMusicEnabled); LobbyMusicCheckBox.Pressed = _cfg.GetCVar(CCVars.LobbyMusicEnabled);
RestartSoundsCheckBox.Pressed = _cfg.GetCVar(CCVars.RestartSoundsEnabled); RestartSoundsCheckBox.Pressed = _cfg.GetCVar(CCVars.RestartSoundsEnabled);
@@ -163,6 +172,8 @@ namespace Content.Client.Options.UI.Tabs
Math.Abs(MidiVolumeSlider.Value - DBToLV100(_cfg.GetCVar(CVars.MidiVolume))) < 0.01f; Math.Abs(MidiVolumeSlider.Value - DBToLV100(_cfg.GetCVar(CVars.MidiVolume))) < 0.01f;
var isAmbientVolumeSame = var isAmbientVolumeSame =
Math.Abs(AmbienceVolumeSlider.Value - DBToLV100(_cfg.GetCVar(CCVars.AmbienceVolume))) < 0.01f; Math.Abs(AmbienceVolumeSlider.Value - DBToLV100(_cfg.GetCVar(CCVars.AmbienceVolume))) < 0.01f;
var isLobbyVolumeSame =
Math.Abs(LobbyVolumeSlider.Value - DBToLV100(_cfg.GetCVar(CCVars.LobbyMusicVolume))) < 0.01f;
var isAmbientSoundsSame = (int)AmbienceSoundsSlider.Value == _cfg.GetCVar(CCVars.MaxAmbientSources); var isAmbientSoundsSame = (int)AmbienceSoundsSlider.Value == _cfg.GetCVar(CCVars.MaxAmbientSources);
var isLobbySame = LobbyMusicCheckBox.Pressed == _cfg.GetCVar(CCVars.LobbyMusicEnabled); var isLobbySame = LobbyMusicCheckBox.Pressed == _cfg.GetCVar(CCVars.LobbyMusicEnabled);
var isRestartSoundsSame = RestartSoundsCheckBox.Pressed == _cfg.GetCVar(CCVars.RestartSoundsEnabled); var isRestartSoundsSame = RestartSoundsCheckBox.Pressed == _cfg.GetCVar(CCVars.RestartSoundsEnabled);
@@ -170,7 +181,8 @@ namespace Content.Client.Options.UI.Tabs
var isAdminSoundsSame = AdminSoundsCheckBox.Pressed == _cfg.GetCVar(CCVars.AdminSoundsEnabled); var isAdminSoundsSame = AdminSoundsCheckBox.Pressed == _cfg.GetCVar(CCVars.AdminSoundsEnabled);
var isStationAmbienceSame = StationAmbienceCheckBox.Pressed == _cfg.GetCVar(CCVars.StationAmbienceEnabled); var isStationAmbienceSame = StationAmbienceCheckBox.Pressed == _cfg.GetCVar(CCVars.StationAmbienceEnabled);
var isSpaceAmbienceSame = SpaceAmbienceCheckBox.Pressed == _cfg.GetCVar(CCVars.SpaceAmbienceEnabled); var isSpaceAmbienceSame = SpaceAmbienceCheckBox.Pressed == _cfg.GetCVar(CCVars.SpaceAmbienceEnabled);
var isEverythingSame = isMasterVolumeSame && isMidiVolumeSame && isAmbientVolumeSame && isAmbientSoundsSame && isLobbySame && isRestartSoundsSame && isEventSame && isAdminSoundsSame && isStationAmbienceSame && isSpaceAmbienceSame; var isEverythingSame = isMasterVolumeSame && isMidiVolumeSame && isAmbientVolumeSame && isAmbientSoundsSame && isLobbySame && isRestartSoundsSame && isEventSame
&& isAdminSoundsSame && isStationAmbienceSame && isSpaceAmbienceSame && isLobbyVolumeSame;
ApplyButton.Disabled = isEverythingSame; ApplyButton.Disabled = isEverythingSame;
ResetButton.Disabled = isEverythingSame; ResetButton.Disabled = isEverythingSame;
MasterVolumeLabel.Text = MasterVolumeLabel.Text =
@@ -179,6 +191,8 @@ namespace Content.Client.Options.UI.Tabs
Loc.GetString("ui-options-volume-percent", ("volume", MidiVolumeSlider.Value / 100)); Loc.GetString("ui-options-volume-percent", ("volume", MidiVolumeSlider.Value / 100));
AmbienceVolumeLabel.Text = AmbienceVolumeLabel.Text =
Loc.GetString("ui-options-volume-percent", ("volume", AmbienceVolumeSlider.Value / 100)); Loc.GetString("ui-options-volume-percent", ("volume", AmbienceVolumeSlider.Value / 100));
LobbyVolumeLabel.Text =
Loc.GetString("ui-options-volume-percent", ("volume", LobbyVolumeSlider.Value / 100));
AmbienceSoundsLabel.Text = ((int)AmbienceSoundsSlider.Value).ToString(); AmbienceSoundsLabel.Text = ((int)AmbienceSoundsSlider.Value).ToString();
} }
} }

View File

@@ -74,6 +74,12 @@ namespace Content.Shared.CCVar
public static readonly CVarDef<float> AmbienceVolume = public static readonly CVarDef<float> AmbienceVolume =
CVarDef.Create("ambience.volume", 0.0f, CVar.ARCHIVE | CVar.CLIENTONLY); CVarDef.Create("ambience.volume", 0.0f, CVar.ARCHIVE | CVar.CLIENTONLY);
/// <summary>
/// Lobby / round end music volume.
/// </summary>
public static readonly CVarDef<float> LobbyMusicVolume =
CVarDef.Create("ambience.lobby_music_volume", 0.0f, CVar.ARCHIVE | CVar.CLIENTONLY);
/// <summary> /// <summary>
/// Whether to play the station ambience (humming) sound /// Whether to play the station ambience (humming) sound
/// </summary> /// </summary>

View File

@@ -15,6 +15,7 @@ ui-options-default = Default
ui-options-master-volume = Master Volume: ui-options-master-volume = Master Volume:
ui-options-midi-volume = MIDI (Instrument) Volume: ui-options-midi-volume = MIDI (Instrument) Volume:
ui-options-ambience-volume = Ambience volume: ui-options-ambience-volume = Ambience volume:
ui-options-lobby-volume = Lobby & Round-end volume:
ui-options-ambience-max-sounds = Ambience simultaneous sounds: ui-options-ambience-max-sounds = Ambience simultaneous sounds:
ui-options-lobby-music = Lobby & Round-end Music ui-options-lobby-music = Lobby & Round-end Music
ui-options-restart-sounds = Round Restart Sounds ui-options-restart-sounds = Round Restart Sounds