From ef3b8019996c3f14c69846c98545862c83cc830e Mon Sep 17 00:00:00 2001 From: BeaR Date: Sun, 12 Oct 2014 17:02:47 +0200 Subject: [PATCH] Add volume slider for map sounds --- src/engine/shared/config_variables.h | 1 + src/game/client/components/menus_settings.cpp | 12 ++++++++++++ src/game/client/components/sounds.cpp | 12 +++++++++++- src/game/client/components/sounds.h | 2 ++ 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/engine/shared/config_variables.h b/src/engine/shared/config_variables.h index 45cd536b1..b9b5404c9 100644 --- a/src/engine/shared/config_variables.h +++ b/src/engine/shared/config_variables.h @@ -68,6 +68,7 @@ MACRO_CONFIG_INT(SndEnable, snd_enable, 1, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "S 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(SndAmbientVolume, snd_ambient_volume, 70, 0, 100, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Ambient sound volume") MACRO_CONFIG_INT(SndNonactiveMute, snd_nonactive_mute, 0, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "") MACRO_CONFIG_INT(SndGame, snd_game, 1, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Enable game sounds") diff --git a/src/game/client/components/menus_settings.cpp b/src/game/client/components/menus_settings.cpp index b5642bcfe..e0291c52a 100644 --- a/src/game/client/components/menus_settings.cpp +++ b/src/game/client/components/menus_settings.cpp @@ -1054,6 +1054,18 @@ void CMenus::RenderSettingsSound(CUIRect MainView) g_Config.m_SndVolume = (int)(DoScrollbarH(&g_Config.m_SndVolume, &Button, g_Config.m_SndVolume/100.0f)*100.0f); MainView.HSplitTop(20.0f, 0, &MainView); } + + // volume slider map 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("Ambient volume"), 14.0f, -1); + g_Config.m_SndAmbientVolume = (int)(DoScrollbarH(&g_Config.m_SndAmbientVolume, &Button, g_Config.m_SndAmbientVolume/100.0f)*100.0f); + MainView.HSplitTop(20.0f, 0, &MainView); + } } class CLanguage diff --git a/src/game/client/components/sounds.cpp b/src/game/client/components/sounds.cpp index 3a16173e6..b662cae7e 100644 --- a/src/game/client/components/sounds.cpp +++ b/src/game/client/components/sounds.cpp @@ -64,11 +64,13 @@ int CSounds::GetSampleId(int SetId) void CSounds::OnInit() { // setup sound channels + m_AmbientVolume = g_Config.m_SndAmbientVolume/100.0f; + Sound()->SetChannel(CSounds::CHN_GUI, 1.0f, 0.0f); Sound()->SetChannel(CSounds::CHN_MUSIC, 1.0f, 0.0f); Sound()->SetChannel(CSounds::CHN_WORLD, 0.9f, 1.0f); Sound()->SetChannel(CSounds::CHN_GLOBAL, 1.0f, 0.0f); - Sound()->SetChannel(CSounds::CHN_AMBIENT, 0.7f, 1.0f); + Sound()->SetChannel(CSounds::CHN_AMBIENT, m_AmbientVolume, 1.0f); Sound()->SetListenerPos(0.0f, 0.0f); @@ -120,6 +122,14 @@ void CSounds::OnRender() // set listner pos Sound()->SetListenerPos(m_pClient->m_pCamera->m_Center.x, m_pClient->m_pCamera->m_Center.y); + // update volume + float NewAmbientVol = g_Config.m_SndAmbientVolume/100.0f; + if(NewAmbientVol != m_AmbientVolume) + { + m_AmbientVolume = NewAmbientVol; + Sound()->SetChannel(CSounds::CHN_AMBIENT, m_AmbientVolume, 1.0f); + } + // play sound from queue if(m_QueuePos > 0) { diff --git a/src/game/client/components/sounds.h b/src/game/client/components/sounds.h index 51e5279be..bf3ca822e 100644 --- a/src/game/client/components/sounds.h +++ b/src/game/client/components/sounds.h @@ -23,6 +23,8 @@ class CSounds : public CComponent int GetSampleId(int SetId); + float m_AmbientVolume; + public: // sound channels enum