Skip to content

Commit 46bd677

Browse files
authored
Merge pull request #228 from patrikjuvonen/issue-9896
0009896: add a master volume level setting
2 parents 1c57763 + 51aafcc commit 46bd677

File tree

7 files changed

+294
-94
lines changed

7 files changed

+294
-94
lines changed

Client/core/CClientVariables.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ void CClientVariables::ValidateValues(void)
252252
ClampValue("chat_position_vertical", Chat::Position::Vertical::TOP, Chat::Position::Vertical::BOTTOM);
253253
ClampValue("chat_text_alignment", Chat::Text::Align::LEFT, Chat::Text::Align::RIGHT);
254254
ClampValue("text_scale", 0.8f, 3.0f);
255+
ClampValue("mastervolume", 0.0f, 1.0f);
255256
ClampValue("mtavolume", 0.0f, 1.0f);
256257
ClampValue("voicevolume", 0.0f, 1.0f);
257258
ClampValue("mapalpha", 0, 255);
@@ -309,6 +310,7 @@ void CClientVariables::LoadDefaults(void)
309310
DEFAULT("fly_with_mouse", false); // flying with mouse controls
310311
DEFAULT("steer_with_mouse", false); // steering with mouse controls
311312
DEFAULT("classic_controls", false); // classic/standard controls
313+
DEFAULT("mastervolume", 1.0f); // master volume
312314
DEFAULT("mtavolume", 1.0f); // custom sound's volume
313315
DEFAULT("voicevolume", 1.0f); // voice chat output volume
314316
DEFAULT("mapalpha", 155); // map alpha
@@ -334,6 +336,7 @@ void CClientVariables::LoadDefaults(void)
334336
DEFAULT("multimon_fullscreen_minimize", 1); // 0-off 1-on
335337
DEFAULT("vertical_aim_sensitivity", 0.0015f); // 0.0015f is GTA default setting
336338
DEFAULT("process_priority", 0); // 0-normal 1-above normal 2-high
339+
DEFAULT("mute_master_when_minimized", 0); // 0-off 1-on
337340
DEFAULT("mute_sfx_when_minimized", 0); // 0-off 1-on
338341
DEFAULT("mute_radio_when_minimized", 0); // 0-off 1-on
339342
DEFAULT("mute_mta_when_minimized", 0); // 0-off 1-on

Client/core/CCore.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ CCore::~CCore(void)
185185
// Destroy tray icon
186186
delete m_pTrayIcon;
187187

188+
// This will set the GTA volume to the GTA volume value in the settings,
189+
// and is not affected by the master volume setting.
190+
m_pLocalGUI->GetMainMenu()->GetSettingsWindow()->ResetGTAVolume();
191+
188192
// Delete the mod manager
189193
delete m_pModManager;
190194
SAFE_DELETE(m_pMessageBox);

Client/core/CSettings.cpp

Lines changed: 235 additions & 78 deletions
Large diffs are not rendered by default.

Client/core/CSettings.h

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -212,20 +212,26 @@ class CSettings
212212
CGUILabel* m_pCachePathLabel;
213213
CGUILabel* m_pCachePathValue;
214214
CGUIButton* m_pCachePathShowButton;
215+
CGUILabel* m_pLabelMasterVolume;
215216
CGUILabel* m_pLabelRadioVolume;
216217
CGUILabel* m_pLabelSFXVolume;
217218
CGUILabel* m_pLabelMTAVolume;
218219
CGUILabel* m_pLabelVoiceVolume;
220+
CGUILabel* m_pLabelMasterVolumeValue;
219221
CGUILabel* m_pLabelRadioVolumeValue;
220222
CGUILabel* m_pLabelSFXVolumeValue;
221223
CGUILabel* m_pLabelMTAVolumeValue;
222224
CGUILabel* m_pLabelVoiceVolumeValue;
225+
CGUIScrollBar* m_pAudioMasterVolume;
223226
CGUIScrollBar* m_pAudioRadioVolume;
224227
CGUIScrollBar* m_pAudioSFXVolume;
225228
CGUIScrollBar* m_pAudioMTAVolume;
226229
CGUIScrollBar* m_pAudioVoiceVolume;
230+
CGUILabel* m_pAudioRadioLabel;
227231
CGUICheckBox* m_pCheckBoxAudioEqualizer;
228232
CGUICheckBox* m_pCheckBoxAudioAutotune;
233+
CGUILabel* m_pAudioMuteLabel;
234+
CGUICheckBox* m_pCheckBoxMuteMaster;
229235
CGUICheckBox* m_pCheckBoxMuteSFX;
230236
CGUICheckBox* m_pCheckBoxMuteRadio;
231237
CGUICheckBox* m_pCheckBoxMuteMTA;
@@ -336,10 +342,16 @@ class CSettings
336342
bool OnBrightnessChanged(CGUIElement* pElement);
337343
bool OnAnisotropicChanged(CGUIElement* pElement);
338344
bool OnMapAlphaChanged(CGUIElement* pElement);
345+
bool OnMasterVolumeChanged(CGUIElement* pElement);
339346
bool OnRadioVolumeChanged(CGUIElement* pElement);
340347
bool OnSFXVolumeChanged(CGUIElement* pElement);
341348
bool OnMTAVolumeChanged(CGUIElement* pElement);
342349
bool OnVoiceVolumeChanged(CGUIElement* pElement);
350+
bool OnMasterMuteMinimizedChanged(CGUIElement* pElement);
351+
bool OnRadioMuteMinimizedChanged(CGUIElement* pElement);
352+
bool OnSFXMuteMinimizedChanged(CGUIElement* pElement);
353+
bool OnMTAMuteMinimizedChanged(CGUIElement* pElement);
354+
bool OnVoiceMuteMinimizedChanged(CGUIElement* pElement);
343355
bool OnChatRedChanged(CGUIElement* pElement);
344356
bool OnChatGreenChanged(CGUIElement* pElement);
345357
bool OnChatBlueChanged(CGUIElement* pElement);
@@ -392,28 +404,43 @@ class CSettings
392404
int GetMilliseconds(CGUIEdit* pEdit);
393405
void SetMilliseconds(CGUIEdit* pEdit, int milliseconds);
394406

407+
void ResetGTAVolume();
408+
void SetRadioVolume(float fVolume);
409+
void SetSFXVolume(float fVolume);
410+
395411
unsigned int m_uiCaptureKey;
396412
bool m_bCaptureKey;
397413
bool m_bCaptureAxis;
398414

399415
bool m_bIsModLoaded;
400416

401-
unsigned char m_ucOldRadioVolume;
402-
unsigned char m_ucOldSFXVolume;
403-
float m_fOldMTAVolume;
404-
float m_fOldVoiceVolume;
417+
float m_fRadioVolume;
418+
float m_fSFXVolume;
405419

406-
CGUIListItem* m_pSelectedBind;
420+
float m_fOldMasterVolume;
421+
float m_fOldRadioVolume;
422+
float m_fOldSFXVolume;
423+
float m_fOldMTAVolume;
424+
float m_fOldVoiceVolume;
407425

408-
DWORD m_dwFrameCount;
409-
bool m_bShownVolumetricShadowsWarning;
410-
bool m_bShownAllowScreenUploadMessage;
411-
int m_iMaxAnisotropic;
426+
bool m_bOldMuteMaster;
427+
bool m_bOldMuteSFX;
428+
bool m_bOldMuteRadio;
429+
bool m_bOldMuteMTA;
430+
bool m_bOldMuteVoice;
412431

432+
bool m_bMuteMaster;
413433
bool m_bMuteSFX;
414434
bool m_bMuteRadio;
415435
bool m_bMuteMTA;
416436
bool m_bMuteVoice;
417437

438+
CGUIListItem* m_pSelectedBind;
439+
440+
DWORD m_dwFrameCount;
441+
bool m_bShownVolumetricShadowsWarning;
442+
bool m_bShownAllowScreenUploadMessage;
443+
int m_iMaxAnisotropic;
444+
418445
std::list<SKeyBindSection*> m_pKeyBindSections;
419446
};

Client/mods/deathmatch/logic/CClientGame.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3909,14 +3909,16 @@ void CClientGame::IdleHandler(void)
39093909
CLuaArguments Arguments;
39103910
m_pRootEntity->CallEvent("onClientMinimize", Arguments, false);
39113911

3912-
// Apply mute on minimize options
3913-
if (g_pCore->GetCVars()->GetValue<bool>("mute_sfx_when_minimized"))
3914-
g_pGame->GetAudio()->SetEffectsMasterVolume(0);
3912+
bool bMuteAll = g_pCore->GetCVars()->GetValue<bool>("mute_master_when_minimized");
39153913

3916-
if (g_pCore->GetCVars()->GetValue<bool>("mute_radio_when_minimized"))
3914+
// Apply mute on minimize options
3915+
if (bMuteAll || g_pCore->GetCVars()->GetValue<bool>("mute_radio_when_minimized"))
39173916
g_pGame->GetAudio()->SetMusicMasterVolume(0);
39183917

3919-
if (g_pCore->GetCVars()->GetValue<bool>("mute_mta_when_minimized"))
3918+
if (bMuteAll || g_pCore->GetCVars()->GetValue<bool>("mute_sfx_when_minimized"))
3919+
g_pGame->GetAudio()->SetEffectsMasterVolume(0);
3920+
3921+
if (bMuteAll || g_pCore->GetCVars()->GetValue<bool>("mute_mta_when_minimized"))
39203922
m_pManager->GetSoundManager()->SetMinimizeMuted(true);
39213923
}
39223924
}

Client/mods/deathmatch/logic/CClientPlayerVoice.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ CClientPlayerVoice::CClientPlayerVoice(CClientPlayer* pPlayer, CVoiceRecorder* p
3535
// Get initial voice volume
3636
m_fVolume = 1.0f;
3737
g_pCore->GetCVars()->Get("voicevolume", m_fVolumeScale);
38+
m_fVolumeScale *= g_pCore->GetCVars()->GetValue<float>("mastervolume", 1.0f);
3839

3940
m_fVolume = m_fVolume * m_fVolumeScale;
4041

@@ -114,6 +115,7 @@ void CClientPlayerVoice::DoPulse(void)
114115
m_CS.Lock();
115116
float fPreviousVolume = 0.0f;
116117
g_pCore->GetCVars()->Get("voicevolume", fPreviousVolume);
118+
fPreviousVolume *= g_pCore->GetCVars()->GetValue<float>("mastervolume", 1.0f);
117119
m_CS.Unlock();
118120

119121
if (fPreviousVolume != m_fVolumeScale && m_pPlayer->IsLocalPlayer() == false)

Client/mods/deathmatch/logic/CClientSoundManager.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,20 +258,25 @@ int CClientSoundManager::GetFxEffectFromName(const std::string& strEffectName)
258258

259259
void CClientSoundManager::UpdateVolume()
260260
{
261-
// set our master sound volume if the cvar changed
261+
// set our mta sound volume if mtavolume or mastervolume cvar changed
262262
float fValue = 0.0f;
263+
263264
if (!m_bMinimizeMuted)
264265
{
266+
float fMasterVolume = g_pCore->GetCVars()->GetValue<float>("mastervolume", 1.0f);
267+
265268
if (g_pCore->GetCVars()->Get("mtavolume", fValue))
266269
{
270+
fValue *= fMasterVolume;
271+
267272
if (fValue * 10000 == BASS_GetConfig(BASS_CONFIG_GVOL_STREAM))
268273
return;
269274

270275
fValue = std::max(0.0f, std::min(1.0f, fValue));
271276
}
272277
else
273278
{
274-
fValue = 1.0f;
279+
fValue = fMasterVolume;
275280
}
276281
}
277282

0 commit comments

Comments
 (0)