From df2a5f05d865919d90fb39c889825ead5ec5c740 Mon Sep 17 00:00:00 2001 From: Laserlicht <13953785+Laserlicht@users.noreply.github.com> Date: Sun, 10 Dec 2023 14:49:27 +0100 Subject: [PATCH] audio mute on focus lost setting --- Mods/vcmi/config/vcmi/english.json | 4 +++- Mods/vcmi/config/vcmi/german.json | 2 ++ client/eventsSDL/InputHandler.cpp | 4 ++-- client/windows/settings/GeneralOptionsTab.cpp | 9 ++++++++ config/schemas/settings.json | 7 +++++- .../widgets/settings/generalOptionsTab.json | 22 +++++++++++++++++++ 6 files changed, 44 insertions(+), 4 deletions(-) diff --git a/Mods/vcmi/config/vcmi/english.json b/Mods/vcmi/config/vcmi/english.json index 242099ee7..141973013 100644 --- a/Mods/vcmi/config/vcmi/english.json +++ b/Mods/vcmi/config/vcmi/english.json @@ -114,6 +114,8 @@ "vcmi.systemOptions.enableUiEnhancementsButton.help" : "{Interface Enhancements}\n\nToggle various quality of life interface improvements. Such as a backpack button etc. Disable to have a more classic experience.", "vcmi.systemOptions.enableLargeSpellbookButton.hover" : "Large Spell Book", "vcmi.systemOptions.enableLargeSpellbookButton.help" : "{Large Spell Book}\n\nEnables larger spell book that fits more spells per page. Spell book page change animation does not work with this setting enabled.", + "vcmi.systemOptions.audioMuteFocus.hover" : "Mute on inactivity", + "vcmi.systemOptions.audioMuteFocus.help" : "{Mute on inactivity}\n\nMute audio on inactive window focus. Exceptions are ingame messages and new turn sound.", "vcmi.adventureOptions.infoBarPick.hover" : "Show Messages in Info Panel", "vcmi.adventureOptions.infoBarPick.help" : "{Show Messages in Info Panel}\n\nWhenever possible, game messages from visiting map objects will be shown in the info panel, instead of popping up in a separate window.", @@ -258,7 +260,7 @@ "vcmi.optionsTab.simturnsMin.help" : "Play simultaneously for specified number of days. Contacts between players during this period are blocked", "vcmi.optionsTab.simturnsMax.help" : "Play simultaneously for specified number of days or until contact with another player", "vcmi.optionsTab.simturnsAI.help" : "{Simultaneous AI Turns}\nExperimental option. Allows AI players to act at the same time as human player when simultaneous turns are enabled.", - + "vcmi.optionsTab.turnTime.select" : "Select turn timer preset", "vcmi.optionsTab.turnTime.unlimited" : "Unlimited turn time", "vcmi.optionsTab.turnTime.classic.1" : "Classic timer: 1 minute", diff --git a/Mods/vcmi/config/vcmi/german.json b/Mods/vcmi/config/vcmi/german.json index 07d13f06d..ed1c11a51 100644 --- a/Mods/vcmi/config/vcmi/german.json +++ b/Mods/vcmi/config/vcmi/german.json @@ -114,6 +114,8 @@ "vcmi.systemOptions.enableUiEnhancementsButton.help" : "{Interface Verbesserungen}\n\nSchaltet verschiedene Interface Verbesserungen um. Wie z.B. ein Rucksack-Button, etc. Deaktivieren, um ein klassischeres Erlebnis zu haben.", "vcmi.systemOptions.enableLargeSpellbookButton.hover" : "Großes Zauberbuch", "vcmi.systemOptions.enableLargeSpellbookButton.help" : "{Großes Zauberbuch}\n\nErmöglicht ein größeres Zauberbuch, in das mehr Zaubersprüche pro Seite passen. Die Animation des Seitenwechsels im Zauberbuch funktioniert nicht, wenn diese Einstellung aktiviert ist.", + "vcmi.systemOptions.audioMuteFocus.hover" : "Stumm bei Inaktivität", + "vcmi.systemOptions.audioMuteFocus.help" : "{Stumm bei Inaktivität}\n\nSchaltet Audio bei inaktiven Fenster-Fokus stumm. Ausnahmen sind Ingame-Nachrichten und der Neuer-Zug-Sound.", "vcmi.adventureOptions.infoBarPick.hover" : "Meldungen im Infobereich anzeigen", "vcmi.adventureOptions.infoBarPick.help" : "{Meldungen im Infobereich anzeigen}\n\nWann immer möglich, werden Spielnachrichten von besuchten Kartenobjekten in der Infoleiste angezeigt, anstatt als Popup-Fenster zu erscheinen", diff --git a/client/eventsSDL/InputHandler.cpp b/client/eventsSDL/InputHandler.cpp index 2db1020a9..adfbbde07 100644 --- a/client/eventsSDL/InputHandler.cpp +++ b/client/eventsSDL/InputHandler.cpp @@ -170,7 +170,7 @@ void InputHandler::preprocessEvent(const SDL_Event & ev) case SDL_WINDOWEVENT_FOCUS_GAINED: { boost::mutex::scoped_lock interfaceLock(GH.interfaceMutex); - if(settings["general"]["enableUiEnhancements"].Bool()) { + if(settings["general"]["audioMuteFocus"].Bool()) { CCS->musich->setVolume(settings["general"]["music"].Integer()); CCS->soundh->setVolume(settings["general"]["sound"].Integer()); } @@ -179,7 +179,7 @@ void InputHandler::preprocessEvent(const SDL_Event & ev) case SDL_WINDOWEVENT_FOCUS_LOST: { boost::mutex::scoped_lock interfaceLock(GH.interfaceMutex); - if(settings["general"]["enableUiEnhancements"].Bool()) { + if(settings["general"]["audioMuteFocus"].Bool()) { CCS->musich->setVolume(0); CCS->soundh->setVolume(0); } diff --git a/client/windows/settings/GeneralOptionsTab.cpp b/client/windows/settings/GeneralOptionsTab.cpp index c4a6ec84b..82d455c3d 100644 --- a/client/windows/settings/GeneralOptionsTab.cpp +++ b/client/windows/settings/GeneralOptionsTab.cpp @@ -167,6 +167,11 @@ GeneralOptionsTab::GeneralOptionsTab() setBoolSetting("gameTweaks", "enableLargeSpellbook", value); }); + addCallback("audioMuteFocusChanged", [](bool value) + { + setBoolSetting("general", "audioMuteFocus", value); + }); + //moved from "other" tab that is disabled for now to avoid excessible tabs with barely any content addCallback("availableCreaturesAsDwellingChanged", [=](int value) { @@ -215,6 +220,10 @@ GeneralOptionsTab::GeneralOptionsTab() if (enableLargeSpellbookCheckbox) enableLargeSpellbookCheckbox->setSelected(settings["gameTweaks"]["enableLargeSpellbook"].Bool()); + std::shared_ptr audioMuteFocusCheckbox = widget("audioMuteFocusCheckbox"); + if (audioMuteFocusCheckbox) + audioMuteFocusCheckbox->setSelected(settings["general"]["audioMuteFocus"].Bool()); + std::shared_ptr musicSlider = widget("musicSlider"); musicSlider->scrollTo(CCS->musich->getVolume()); diff --git a/config/schemas/settings.json b/config/schemas/settings.json index c65cf374d..0ea20d327 100644 --- a/config/schemas/settings.json +++ b/config/schemas/settings.json @@ -39,7 +39,8 @@ "useSavePrefix", "savePrefix", "startTurnAutosave", - "enableUiEnhancements" + "enableUiEnhancements", + "audioMuteFocus" ], "properties" : { "playerName" : { @@ -131,6 +132,10 @@ "enableUiEnhancements" : { "type": "boolean", "default": true + }, + "audioMuteFocus" : { + "type": "boolean", + "default": false } } }, diff --git a/config/widgets/settings/generalOptionsTab.json b/config/widgets/settings/generalOptionsTab.json index 41d3b57a8..42348177e 100644 --- a/config/widgets/settings/generalOptionsTab.json +++ b/config/widgets/settings/generalOptionsTab.json @@ -180,6 +180,28 @@ "type": "labelCentered", "position": {"x": 565, "y": 158} }, + { + "type" : "verticalLayout", + "customType" : "labelDescription", + "position" : {"x": 415, "y": 202}, + "items" : [ + { + "text": "vcmi.systemOptions.audioMuteFocus.hover" + } + ] + }, + { + "type" : "verticalLayout", + "customType" : "checkbox", + "position" : {"x": 380, "y": 200}, + "items" : [ + { + "name": "audioMuteFocusCheckbox", + "help": "vcmi.systemOptions.audioMuteFocus", + "callback": "audioMuteFocusChanged" + } + ] + }, /////////////////////////////////////// Bottom section - Towns Settings { "type" : "verticalLayout",