Skip to content

Commit 200a289

Browse files
committed
Added setting to mute audio on focus loss
1 parent d992d0c commit 200a289

File tree

8 files changed

+56
-3
lines changed

8 files changed

+56
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,6 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
8585

8686
- New `Attachable` INI and Lua (R/W) properties `InheritsVelWhenDetached` and `InheritsAngularVelWhenDetached`, which determine how much of these velocities an attachable inherits from its parent when detached. Defaults to 1.
8787

88-
- New GPU Renderer using OpenGL+Raylib, draw now takes 0ms in pretty much every instance.
89-
9088
- New Z Order for scene layers and primitives: Background layer sits at z=100, Terrain Background at z=50, Terrain color and MO color at z=0, GUIs sit at z=-100, allowed z range is [-200, +200], in the future this'll be expanded to MO draw as well.
9189
- Added Lua-accessible bitmap manipulation functions to `MOSprite`s:
9290
```
@@ -138,6 +136,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
138136
```
139137
Original bindings with no scale argument are untouched and can be called as they were.
140138

139+
- New option to mute audio when the game window loses focus.
140+
141141
</details>
142142

143143
<details><summary><b>Changed</b></summary>
@@ -152,6 +152,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
152152
Savefiles have the extension `.ccsave`, but their underlying format is really just a `.zip` file. This can be opened and modified as before with any zip file viewer.
153153
These savefiles can be safely renamed and moved without breaking the savegame, unlike before.
154154

155+
- New GPU Renderer using now OpenGL + Raylib, dramatically improving draw performance. Draw now takes a negligible amount of time.
156+
155157
- All vanilla scenario activities have had their settings polished, respecting settings which make sense and disabling settings which don't.
156158
You can now have fog of war in the test scene, and can no longer require path to orbit in Zero-G Diggers-Only One Man Army.
157159

Data/Base.rte/GUIs/SettingsGUI.ini

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,20 @@ Anchor = Left, Top
713713
Checked = Unchecked
714714
Text = Mute
715715

716+
[CheckboxMuteAudioOnFocusLoss]
717+
ControlType = CHECKBOX
718+
Parent = CollectionBoxAudioSettings
719+
X = 145
720+
Y = 189
721+
Width = 120
722+
Height = 20
723+
Visible = True
724+
Enabled = True
725+
Name = CheckboxMuteAudioOnFocusLoss
726+
Anchor = Middle, Top
727+
Checked = Unchecked
728+
Text = Mute On Focus Loss?
729+
716730
///////////////////////////////////////////////////////////////////////
717731
// Input Settings Menu
718732

Data/Base.rte/GUIs/SettingsPauseGUI.ini

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,20 @@ Anchor = Left, Top
714714
Checked = Unchecked
715715
Text = Mute
716716

717+
[CheckboxMuteAudioOnFocusLoss]
718+
ControlType = CHECKBOX
719+
Parent = CollectionBoxAudioSettings
720+
X = 145
721+
Y = 189
722+
Width = 120
723+
Height = 20
724+
Visible = True
725+
Enabled = True
726+
Name = CheckboxMuteAudioOnFocusLoss
727+
Anchor = Middle, Top
728+
Checked = Unchecked
729+
Text = Mute On Focus Loss?
730+
717731
///////////////////////////////////////////////////////////////////////
718732
// Input Settings Menu
719733

Source/Managers/AudioMan.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "SoundContainer.h"
1010
#include "GUISound.h"
1111
#include "PresetMan.h"
12+
#include "WindowMan.h"
1213
#include "SoundSet.h"
1314

1415
#include <cstring>
@@ -138,9 +139,14 @@ void AudioMan::Destroy() {
138139

139140
void AudioMan::Update() {
140141
if (m_AudioEnabled) {
141-
142142
FMOD_RESULT status = FMOD_OK;
143143

144+
if (m_MuteAudioOnFocusLoss && !g_WindowMan.AnyWindowHasFocus()) {
145+
m_MasterChannelGroup->setMute(true);
146+
} else {
147+
m_MasterChannelGroup->setMute(m_MuteMaster);
148+
}
149+
144150
float globalPitch = 1.0F;
145151

146152
float timeScale = g_TimerMan.GetTimeScale();

Source/Managers/AudioMan.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,14 @@ namespace RTE {
151151
}
152152
}
153153

154+
/// Gets whether to mute all audio when the game loses focus.
155+
/// @returns Whether to mute all audio when the game loses focus.
156+
bool GetMuteAudioOnFocusLoss() const { return m_MuteAudioOnFocusLoss; }
157+
158+
/// Sets whether to mute all audio when the game loses focus.
159+
/// @param mute Whether to mute all audio when the game loses focus.
160+
void SetMuteAudioOnFocusLoss(bool mute) { m_MuteAudioOnFocusLoss = mute; }
161+
154162
/// Gets the global pitch scalar value for all sounds and music.
155163
/// @return The current pitch scalar. Will be > 0.
156164
float GetGlobalPitch() const { return m_GlobalPitch; }
@@ -326,6 +334,7 @@ namespace RTE {
326334
bool m_MuteMaster; //!< Whether all the audio is muted.
327335
bool m_MuteMusic; //!< Whether the music channel is muted.
328336
bool m_MuteSounds; //!< Whether all the sound effects channels are muted.
337+
bool m_MuteAudioOnFocusLoss; //!< Whether audio should be muted when the game loses focus.
329338
float m_MasterVolume; //!< Global volume of all audio.
330339
float m_MusicVolume; //!< Global music volume.
331340
float m_SoundsVolume; //!< Global sounds effects volume.

Source/Managers/SettingsMan.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ int SettingsMan::ReadProperty(const std::string_view& propName, Reader& reader)
121121
MatchProperty("MuteMusic", { reader >> g_AudioMan.m_MuteMusic; });
122122
MatchProperty("SoundVolume", { g_AudioMan.SetSoundsVolume(std::stof(reader.ReadPropValue()) / 100.0F); });
123123
MatchProperty("MuteSounds", { reader >> g_AudioMan.m_MuteSounds; });
124+
MatchProperty("MuteAudioOnFocusLoss", { reader >> g_AudioMan.m_MuteAudioOnFocusLoss; });
124125
MatchProperty("SoundPanningEffectStrength", {
125126
reader >> g_AudioMan.m_SoundPanningEffectStrength;
126127

@@ -230,6 +231,7 @@ int SettingsMan::Save(Writer& writer) const {
230231
writer.NewPropertyWithValue("MuteMusic", g_AudioMan.m_MuteMusic);
231232
writer.NewPropertyWithValue("SoundVolume", g_AudioMan.m_SoundsVolume * 100);
232233
writer.NewPropertyWithValue("MuteSounds", g_AudioMan.m_MuteSounds);
234+
writer.NewPropertyWithValue("MuteAudioOnFocusLoss", g_AudioMan.m_MuteAudioOnFocusLoss);
233235
writer.NewPropertyWithValue("SoundPanningEffectStrength", g_AudioMan.m_SoundPanningEffectStrength);
234236

235237
//////////////////////////////////////////////////

Source/Menus/SettingsAudioGUI.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ SettingsAudioGUI::SettingsAudioGUI(GUIControlManager* parentControlManager) :
2828
m_SoundMuteCheckbox = dynamic_cast<GUICheckbox*>(m_GUIControlManager->GetControl("CheckboxMuteSound"));
2929
m_SoundMuteCheckbox->SetCheck(g_AudioMan.GetSoundsMuted());
3030

31+
m_MuteOnFocusLossCheckbox = dynamic_cast<GUICheckbox*>(m_GUIControlManager->GetControl("CheckboxMuteAudioOnFocusLoss"));
32+
m_MuteOnFocusLossCheckbox->SetCheck(g_AudioMan.GetMuteAudioOnFocusLoss());
33+
3134
UpdateMasterVolumeControls();
3235
UpdateMusicVolumeControls();
3336
UpdateSoundVolumeControls();
@@ -81,6 +84,8 @@ void SettingsAudioGUI::HandleInputEvents(GUIEvent& guiEvent) {
8184
g_AudioMan.SetMusicMuted(m_MusicMuteCheckbox->GetCheck());
8285
} else if (guiEvent.GetControl() == m_SoundMuteCheckbox) {
8386
g_AudioMan.SetSoundsMuted(m_SoundMuteCheckbox->GetCheck());
87+
} else if (guiEvent.GetControl() == m_MuteOnFocusLossCheckbox) {
88+
g_AudioMan.SetMuteAudioOnFocusLoss(m_MuteOnFocusLossCheckbox->GetCheck());
8489
}
8590
}
8691
}

Source/Menus/SettingsAudioGUI.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ namespace RTE {
4343
GUILabel* m_SoundVolumeLabel;
4444
GUISlider* m_SoundVolumeSlider;
4545
GUICheckbox* m_SoundMuteCheckbox;
46+
GUICheckbox* m_MuteOnFocusLossCheckbox;
4647

4748
#pragma region Audio Settings Handling
4849
/// Updates the position of the master volume slider and volume value label, based on what the AudioMan is currently set to.

0 commit comments

Comments
 (0)