From 7e1e17d54184c1400b4f0e888aa4deee096bbb88 Mon Sep 17 00:00:00 2001 From: PurSnake Date: Fri, 10 Oct 2025 00:43:52 +0300 Subject: [PATCH] Changes --- project.hxp | 9 +++++++++ source/funkin/InitState.hx | 21 +++++++++++++++++++++ source/funkin/save/Save.hx | 2 +- source/funkin/util/Constants.hx | 7 +++++++ 4 files changed, 38 insertions(+), 1 deletion(-) diff --git a/project.hxp b/project.hxp index 24bdeb6b91e..c53ccb5497d 100644 --- a/project.hxp +++ b/project.hxp @@ -298,6 +298,13 @@ class Project extends HXProject */ static final FEATURE_DISCORD_RPC:FeatureFlag = "FEATURE_DISCORD_RPC"; + /** + * `-DFEATURE_LOST_FOCUS_VOLUME` + * If this flag is enabled, the game will reduce application volume, when lost focus. + * Allowed only on Desktop targets. + */ + static final FEATURE_LOST_FOCUS_VOLUME:FeatureFlag = "FEATURE_LOST_FOCUS_VOLUME"; + /** * `-DFEATURE_FILE_DROP` * If this flag is enabled, the game will support dragging and dropping files onto it for various features. @@ -862,6 +869,8 @@ class Project extends HXProject // We don't want testers to accidentally leak songs to their Discord friends! FEATURE_DISCORD_RPC.apply(this, isDesktop() && !FEATURE_DEBUG_FUNCTIONS.isEnabled(this)); + FEATURE_LOST_FOCUS_VOLUME.apply(this, isDesktop()); + // Newgrounds features FEATURE_NEWGROUNDS.apply(this, !isMobile()); FEATURE_NEWGROUNDS_DEBUG.apply(this, false); diff --git a/source/funkin/InitState.hx b/source/funkin/InitState.hx index b2948e5955d..9df9e606386 100644 --- a/source/funkin/InitState.hx +++ b/source/funkin/InitState.hx @@ -217,6 +217,10 @@ class InitState extends FlxState }); #end + #if FEATURE_LOST_FOCUS_VOLUME + FlxG.signals.focusLost.add(onLostFocus); + FlxG.signals.focusGained.add(onGainFocus); + #end // // ANDROID SETUP // @@ -292,6 +296,23 @@ class InitState extends FlxState #end } + #if FEATURE_LOST_FOCUS_VOLUME + @:noCompletion var _lastFocusVolume:Null; + + function onLostFocus() + { + if (FlxG.sound.muted || FlxG.sound.volume == 0 || FlxG.autoPause) return; + _lastFocusVolume = FlxG.sound.volume; + FlxG.sound.volume *= Constants.LOST_FOCUS_VOLUME_MULTIPLIER; + } + + function onGainFocus() + { + if (FlxG.sound.muted || FlxG.autoPause) return; + if (_lastFocusVolume != null) FlxG.sound.volume = _lastFocusVolume; + } + #end + /** * Start the game. * diff --git a/source/funkin/save/Save.hx b/source/funkin/save/Save.hx index 8720fe73cb7..b0f22d15703 100644 --- a/source/funkin/save/Save.hx +++ b/source/funkin/save/Save.hx @@ -1511,4 +1511,4 @@ typedef SaveDataStageEditorOptions = * @default dad */ var ?dadChar:String; -} +} \ No newline at end of file diff --git a/source/funkin/util/Constants.hx b/source/funkin/util/Constants.hx index 73e229613d9..ff009608f93 100644 --- a/source/funkin/util/Constants.hx +++ b/source/funkin/util/Constants.hx @@ -570,6 +570,13 @@ class Constants public static final GHOST_TAP_DELAY:Float = 3 / 8; #end + #if FEATURE_LOST_FOCUS_VOLUME + /** + * How much volume should be reduced on Application Focus Lost. + */ + public static final LOST_FOCUS_VOLUME_MULTIPLIER:Float = 0.5; + #end + /** * Otherwise known as "The FuckCunt Variable" */