Skip to content
Permalink
Browse files

Merge pull request #1234 from kav2k/backgroundMute

Background mute
  • Loading branch information
SupSuper committed Nov 28, 2019
2 parents 564f58c + 49ec43c commit c7e1397f46c3d9e8d540eee1ea535856e18a0125
@@ -303,6 +303,9 @@ en-GB:
STR_PREFERRED_VIDEO_SLIDESHOW: "Slideshow"
STR_PREFERRED_FORMAT_AUTO: "Auto"
STR_CURRENT_FORMAT: "Current: {0}"
STR_SOUND_OPTIONS: "Sound Options"
STR_BACKGROUND_MUTE: "Background Mute"
STR_BACKGROUND_MUTE_DESC: "Mutes all sound when the game window is not active."
STR_FORCE_FIRE: "Override Line of Fire"
STR_FORCE_FIRE_DESC: "Enables forcing your soldiers to take a shot when holding CTRL, regardless of line of fire rules."
STR_NO_AUDIO_HARDWARE_DETECTED: "No audio hardware detected"
@@ -303,6 +303,9 @@ en-US:
STR_PREFERRED_VIDEO_SLIDESHOW: "Slideshow"
STR_PREFERRED_FORMAT_AUTO: "Auto"
STR_CURRENT_FORMAT: "Current: {0}"
STR_SOUND_OPTIONS: "Sound Options"
STR_BACKGROUND_MUTE: "Background Mute"
STR_BACKGROUND_MUTE_DESC: "Mutes all sound when the game window is not active."
STR_FORCE_FIRE: "Override Line of Fire"
STR_FORCE_FIRE_DESC: "Enables forcing your soldiers to take a shot when holding CTRL, regardless of line of fire rules."
STR_NO_AUDIO_HARDWARE_DETECTED: "No audio hardware detected"
@@ -140,7 +140,9 @@ void AdlibMusic::play(int) const
void AdlibMusic::player(void *udata, Uint8 *stream, int len)
{
#ifndef __NO_MUSIC
if (Options::musicVolume == 0)
// Read from SDL instead of Options for Background Mute functionality
int musicVolume = Mix_VolumeMusic(-1);
if (musicVolume == 0)
return;
if (Options::musicAlwaysLoop && !func_is_music_playing())
{
@@ -155,7 +157,7 @@ void AdlibMusic::player(void *udata, Uint8 *stream, int len)
int i = std::min(delay, len);
if (i)
{
float volume = Game::volumeExponent(Options::musicVolume);
float volume = Game::volumeExponent(musicVolume);
YM3812UpdateOne(opl[0], (INT16*)stream, i / 2, 2, volume);
YM3812UpdateOne(opl[1], ((INT16*)stream) + 1, i / 2, 2, volume);
stream += i;
@@ -186,17 +186,37 @@ void Game::run()
quit();
break;
case SDL_ACTIVEEVENT:
switch (reinterpret_cast<SDL_ActiveEvent*>(&_event)->state)
// An event other than SDL_APPMOUSEFOCUS change happened.
if (reinterpret_cast<SDL_ActiveEvent*>(&_event)->state & ~SDL_APPMOUSEFOCUS)
{
case SDL_APPACTIVE:
runningState = reinterpret_cast<SDL_ActiveEvent*>(&_event)->gain ? RUNNING : stateRun[Options::pauseMode];
break;
case SDL_APPMOUSEFOCUS:
// We consciously ignore it.
break;
case SDL_APPINPUTFOCUS:
runningState = reinterpret_cast<SDL_ActiveEvent*>(&_event)->gain ? RUNNING : kbFocusRun[Options::pauseMode];
break;
Uint8 currentState = SDL_GetAppState();
// Game is minimized
if (!(currentState & SDL_APPACTIVE))
{
runningState = stateRun[Options::pauseMode];
if (Options::backgroundMute)
{
setVolume(0, 0, 0);
}
}
// Game is not minimized but has no keyboard focus.
else if (!(currentState & SDL_APPINPUTFOCUS))
{
runningState = kbFocusRun[Options::pauseMode];
if (Options::backgroundMute)
{
setVolume(0, 0, 0);
}
}
// Game has keyboard focus.
else
{
runningState = RUNNING;
if (Options::backgroundMute)
{
setVolume(Options::soundVolume, Options::musicVolume, Options::uiVolume);
}
}
}
break;
case SDL_VIDEORESIZE:
@@ -142,6 +142,7 @@ void create()
_info.push_back(OptionInfo("touchEnabled", &touchEnabled, false));
_info.push_back(OptionInfo("rootWindowedMode", &rootWindowedMode, false));
_info.push_back(OptionInfo("lazyLoadResources", &lazyLoadResources, true));
_info.push_back(OptionInfo("backgroundMute", &backgroundMute, false));

// advanced options
_info.push_back(OptionInfo("playIntro", &playIntro, true, "STR_PLAYINTRO", "STR_GENERAL"));
@@ -8,7 +8,7 @@ OPT int displayWidth, displayHeight, maxFrameSkip, baseXResolution, baseYResolut
OPT bool fullscreen, asyncBlit, playIntro, useScaleFilter, useHQXFilter, useXBRZFilter, useOpenGL, checkOpenGLErrors, vSyncForOpenGL, useOpenGLSmoothing,
autosave, allowResize, borderless, debug, debugUi, fpsCounter, newSeedOnLoad, keepAspectRatio, nonSquarePixelRatio,
cursorInBlackBandsInFullscreen, cursorInBlackBandsInWindow, cursorInBlackBandsInBorderlessWindow, maximizeInfoScreens, musicAlwaysLoop, StereoSound, verboseLogging, soldierDiaries, touchEnabled,
rootWindowedMode, lazyLoadResources;
rootWindowedMode, lazyLoadResources, backgroundMute;
OPT std::string language, useOpenGLShader;
OPT KeyboardType keyboardMode;
OPT SaveSort saveOrder;
@@ -24,6 +24,7 @@
#include "../Interface/ComboBox.h"
#include "../Interface/Text.h"
#include "../Interface/TextButton.h"
#include "../Interface/ToggleTextButton.h"
#include "../Interface/Slider.h"
#include "../Engine/Action.h"
#include "../Engine/Options.h"
@@ -48,22 +49,25 @@ OptionsAudioState::OptionsAudioState(OptionsOrigin origin) : OptionsBaseState(or
_txtMusicVolume = new Text(114, 9, 94, 8);
_slrMusicVolume = new Slider(104, 16, 94, 18);

_txtSoundVolume = new Text(114, 9, 206, 8);
_slrSoundVolume = new Slider(104, 16, 206, 18);
_txtSoundVolume = new Text(114, 9, 94, 40);
_slrSoundVolume = new Slider(104, 16, 94, 50);

_txtUiVolume = new Text(114, 9, 94, 40);
_slrUiVolume = new Slider(104, 16, 94, 50);
_txtUiVolume = new Text(114, 9, 94, 72);
_slrUiVolume = new Slider(104, 16, 94, 82);

_txtMusicFormat = new Text(114, 9, 94, 72);
_cbxMusicFormat = new ComboBox(this, 104, 16, 94, 82);
_txtCurrentMusic = new Text(114, 9, 94, 100);
_txtMusicFormat = new Text(114, 9, 206, 40);
_cbxMusicFormat = new ComboBox(this, 104, 16, 206, 50);
_txtCurrentMusic = new Text(114, 9, 206, 68);

_txtSoundFormat = new Text(114, 9, 206, 72);
_cbxSoundFormat = new ComboBox(this, 104, 16, 206, 82);
_txtCurrentSound = new Text(114, 9, 206, 100);
_txtSoundFormat = new Text(114, 9, 206, 82);
_cbxSoundFormat = new ComboBox(this, 104, 16, 206, 92);
_txtCurrentSound = new Text(114, 9, 206, 110);

_txtVideoFormat = new Text(114, 9, 206, 40);
_cbxVideoFormat = new ComboBox(this, 104, 16, 206, 50);
_txtVideoFormat = new Text(114, 9, 206, 8);
_cbxVideoFormat = new ComboBox(this, 104, 16, 206, 18);

_txtOptions = new Text(114, 9, 94, 104);
_btnBackgroundMute = new ToggleTextButton(104, 16, 94, 114);

add(_txtMusicVolume, "text", "audioMenu");
add(_slrMusicVolume, "button", "audioMenu");
@@ -84,6 +88,9 @@ OptionsAudioState::OptionsAudioState(OptionsOrigin origin) : OptionsBaseState(or
add(_cbxSoundFormat, "button", "audioMenu");
add(_cbxVideoFormat, "button", "audioMenu");

add(_txtOptions, "text", "audioMenu");
add(_btnBackgroundMute, "button", "audioMenu");

centerAllSurfaces();

// Set up objects
@@ -177,6 +184,15 @@ OptionsAudioState::OptionsAudioState(OptionsOrigin origin) : OptionsBaseState(or
_txtSoundFormat->setVisible(_origin == OPT_MENU && _game->getMod()->getSoundDefinitions()->empty());
_cbxSoundFormat->setVisible(_origin == OPT_MENU && _game->getMod()->getSoundDefinitions()->empty());
_txtCurrentSound->setVisible(_origin == OPT_MENU && _game->getMod()->getSoundDefinitions()->empty());

_txtOptions->setText(tr("STR_SOUND_OPTIONS"));

_btnBackgroundMute->setText(tr("STR_BACKGROUND_MUTE"));
_btnBackgroundMute->setPressed(Options::backgroundMute);
_btnBackgroundMute->onMouseClick((ActionHandler)&OptionsAudioState::btnBackgroundMuteClick);
_btnBackgroundMute->setTooltip("STR_BACKGROUND_MUTE_DESC");
_btnBackgroundMute->onMouseIn((ActionHandler)&OptionsAudioState::txtTooltipIn);
_btnBackgroundMute->onMouseOut((ActionHandler)&OptionsAudioState::txtTooltipOut);
}

/**
@@ -264,4 +280,13 @@ void OptionsAudioState::cbxSoundFormatChange(Action *)
Options::reload = true;
}

/**
* Updates the Background Mute option.
* @param action Pointer to an action.
*/
void OptionsAudioState::btnBackgroundMuteClick(Action*)
{
Options::backgroundMute = _btnBackgroundMute->getPressed();
}

}
@@ -25,6 +25,7 @@ namespace OpenXcom
class Text;
class ComboBox;
class Slider;
class ToggleTextButton;

/**
* Screen that lets the user configure various
@@ -38,6 +39,8 @@ class OptionsAudioState : public OptionsBaseState
Slider *_slrMusicVolume, *_slrSoundVolume, *_slrUiVolume;
Text *_txtMusicFormat, *_txtCurrentMusic, *_txtSoundFormat, *_txtCurrentSound, *_txtVideoFormat;
ComboBox *_cbxMusicFormat, *_cbxSoundFormat, *_cbxVideoFormat;
Text* _txtOptions;
ToggleTextButton *_btnBackgroundMute;
public:
/// Creates the Audio Options state.
OptionsAudioState(OptionsOrigin origin);
@@ -59,6 +62,8 @@ class OptionsAudioState : public OptionsBaseState
void cbxSoundFormatChange(Action *action);
/// Handler for changing the Video Format combobox.
void cbxVideoFormatChange(Action *action);
/// Handler for clicking the Background Mute button.
void btnBackgroundMuteClick(Action* action);
};

}

0 comments on commit c7e1397

Please sign in to comment.
You can’t perform that action at this time.