From 4327194d273a0ead6a23258bcf6677fef3eb32e1 Mon Sep 17 00:00:00 2001 From: def Date: Fri, 9 Oct 2020 23:14:20 +0200 Subject: [PATCH] Add GUI & Game sound volume sliders As requested by Pipou --- src/engine/shared/config_variables.h | 2 ++ src/game/client/components/menus_settings.cpp | 22 ++++++++++++++++++ src/game/client/components/sounds.cpp | 23 ++++++++++++++++--- src/game/client/components/sounds.h | 2 ++ 4 files changed, 46 insertions(+), 3 deletions(-) diff --git a/src/engine/shared/config_variables.h b/src/engine/shared/config_variables.h index 2bcbc45c4..c78498006 100644 --- a/src/engine/shared/config_variables.h +++ b/src/engine/shared/config_variables.h @@ -81,6 +81,8 @@ MACRO_CONFIG_INT(SndEnable, snd_enable, 1, 0, 1, CFGFLAG_SAVE | CFGFLAG_CLIENT, MACRO_CONFIG_INT(SndMusic, snd_enable_music, 0, 0, 1, CFGFLAG_SAVE | CFGFLAG_CLIENT, "Play background music") MACRO_CONFIG_INT(SndVolume, snd_volume, 100, 0, 100, CFGFLAG_SAVE | CFGFLAG_CLIENT, "Sound volume") MACRO_CONFIG_INT(SndDevice, snd_device, -1, 0, 0, CFGFLAG_SAVE | CFGFLAG_CLIENT, "(deprecated) Sound device to use") +MACRO_CONFIG_INT(SndChatSoundVolume, snd_chat_volume, 100, 0, 100, CFGFLAG_SAVE | CFGFLAG_CLIENT, "Chat sound volume") +MACRO_CONFIG_INT(SndGameSoundVolume, snd_game_volume, 100, 0, 100, CFGFLAG_SAVE | CFGFLAG_CLIENT, "Game sound volume") MACRO_CONFIG_INT(SndMapSoundVolume, snd_ambient_volume, 70, 0, 100, CFGFLAG_SAVE | CFGFLAG_CLIENT, "Map Sound sound volume") MACRO_CONFIG_INT(SndBackgroundMusicVolume, snd_background_music_volume, 50, 0, 100, CFGFLAG_SAVE | CFGFLAG_CLIENT, "Background music sound volume") diff --git a/src/game/client/components/menus_settings.cpp b/src/game/client/components/menus_settings.cpp index da45f4a1e..0be6fb216 100644 --- a/src/game/client/components/menus_settings.cpp +++ b/src/game/client/components/menus_settings.cpp @@ -1278,6 +1278,28 @@ void CMenus::RenderSettingsSound(CUIRect MainView) g_Config.m_SndVolume = (int)(DoScrollbarH(&g_Config.m_SndVolume, &Button, g_Config.m_SndVolume / 100.0f) * 100.0f); } + // volume slider game sounds + { + CUIRect Button, Label; + MainView.HSplitTop(5.0f, &Button, &MainView); + MainView.HSplitTop(20.0f, &Button, &MainView); + Button.VSplitLeft(190.0f, &Label, &Button); + Button.HMargin(2.0f, &Button); + UI()->DoLabelScaled(&Label, Localize("Game sound volume"), 14.0f, -1); + g_Config.m_SndGameSoundVolume = (int)(DoScrollbarH(&g_Config.m_SndGameSoundVolume, &Button, g_Config.m_SndGameSoundVolume / 100.0f) * 100.0f); + } + + // volume slider gui sounds + { + CUIRect Button, Label; + MainView.HSplitTop(5.0f, &Button, &MainView); + MainView.HSplitTop(20.0f, &Button, &MainView); + Button.VSplitLeft(190.0f, &Label, &Button); + Button.HMargin(2.0f, &Button); + UI()->DoLabelScaled(&Label, Localize("Chat sound volume"), 14.0f, -1); + g_Config.m_SndChatSoundVolume = (int)(DoScrollbarH(&g_Config.m_SndChatSoundVolume, &Button, g_Config.m_SndChatSoundVolume / 100.0f) * 100.0f); + } + // volume slider map sounds { CUIRect Button, Label; diff --git a/src/game/client/components/sounds.cpp b/src/game/client/components/sounds.cpp index f1d2634ec..a91be587b 100644 --- a/src/game/client/components/sounds.cpp +++ b/src/game/client/components/sounds.cpp @@ -58,13 +58,15 @@ int CSounds::GetSampleId(int SetId) void CSounds::OnInit() { // setup sound channels + m_GuiSoundVolume = g_Config.m_SndChatSoundVolume / 100.0f; + m_GameSoundVolume = g_Config.m_SndGameSoundVolume / 100.0f; m_MapSoundVolume = g_Config.m_SndMapSoundVolume / 100.0f; m_BackgroundMusicVolume = g_Config.m_SndBackgroundMusicVolume / 100.0f; - Sound()->SetChannel(CSounds::CHN_GUI, 1.0f, 0.0f); + Sound()->SetChannel(CSounds::CHN_GUI, m_GuiSoundVolume, 0.0f); Sound()->SetChannel(CSounds::CHN_MUSIC, m_BackgroundMusicVolume, 1.0f); - Sound()->SetChannel(CSounds::CHN_WORLD, 0.9f, 1.0f); - Sound()->SetChannel(CSounds::CHN_GLOBAL, 1.0f, 0.0f); + Sound()->SetChannel(CSounds::CHN_WORLD, 0.9f * m_GameSoundVolume, 1.0f); + Sound()->SetChannel(CSounds::CHN_GLOBAL, m_GameSoundVolume, 0.0f); Sound()->SetChannel(CSounds::CHN_MAPSOUND, m_MapSoundVolume, 1.0f); Sound()->SetListenerPos(0.0f, 0.0f); @@ -115,6 +117,21 @@ void CSounds::OnRender() Sound()->SetListenerPos(m_pClient->m_pCamera->m_Center.x, m_pClient->m_pCamera->m_Center.y); // update volume + float NewGuiSoundVol = g_Config.m_SndChatSoundVolume / 100.0f; + if(NewGuiSoundVol != m_GuiSoundVolume) + { + m_GuiSoundVolume = NewGuiSoundVol; + Sound()->SetChannel(CSounds::CHN_GUI, m_GuiSoundVolume, 1.0f); + } + + float NewGameSoundVol = g_Config.m_SndGameSoundVolume / 100.0f; + if(NewGameSoundVol != m_GameSoundVolume) + { + m_GameSoundVolume = NewGameSoundVol; + Sound()->SetChannel(CSounds::CHN_WORLD, 0.9f * m_GameSoundVolume, 1.0f); + Sound()->SetChannel(CSounds::CHN_GLOBAL, m_GameSoundVolume, 1.0f); + } + float NewMapSoundVol = g_Config.m_SndMapSoundVolume / 100.0f; if(NewMapSoundVol != m_MapSoundVolume) { diff --git a/src/game/client/components/sounds.h b/src/game/client/components/sounds.h index 2b4f94768..d61667401 100644 --- a/src/game/client/components/sounds.h +++ b/src/game/client/components/sounds.h @@ -34,6 +34,8 @@ class CSounds : public CComponent int GetSampleId(int SetId); + float m_GuiSoundVolume; + float m_GameSoundVolume; float m_MapSoundVolume; float m_BackgroundMusicVolume;