Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions project.hxp
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,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.
Expand Down Expand Up @@ -857,6 +864,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);
Expand Down
21 changes: 21 additions & 0 deletions source/funkin/InitState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,10 @@ class InitState extends FlxState
});
#end

#if FEATURE_LOST_FOCUS_VOLUME
FlxG.signals.focusLost.add(onLostFocus);
FlxG.signals.focusGained.add(onGainFocus);
#end
//
// ANDROID SETUP
//
Expand Down Expand Up @@ -287,6 +291,23 @@ class InitState extends FlxState
#end
}

#if FEATURE_LOST_FOCUS_VOLUME
@:noCompletion var _lastFocusVolume:Null<Float>;

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.
*
Expand Down
7 changes: 7 additions & 0 deletions source/funkin/util/Constants.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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"
*/
Expand Down