From 300f38d290bb8c31a5c1e67afdf981c644b27f8a Mon Sep 17 00:00:00 2001 From: Til <89487150+TechnikTil@users.noreply.github.com> Date: Thu, 2 Jan 2025 07:56:33 -0700 Subject: [PATCH] [ENHANCEMENT] Prevent accidental selecting when tabbing back in (#513) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * prevent accidental selecting * made something better --------- Co-authored-by: ⍚~Nex <87421482+NexIsDumb@users.noreply.github.com> --- source/funkin/backend/system/Main.hx | 14 ++++++++++++++ source/funkin/options/OptionsScreen.hx | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/source/funkin/backend/system/Main.hx b/source/funkin/backend/system/Main.hx index 78369f607..5795c4a1a 100644 --- a/source/funkin/backend/system/Main.hx +++ b/source/funkin/backend/system/Main.hx @@ -49,6 +49,10 @@ class Main extends Sprite public static var game:FunkinGame; + /** + * The time since the game was focused last time in seconds. + */ + public static var timeSinceFocus(get, never):Float; public static var time:Int = 0; // You can pretty much ignore everything from here on - your code should go in your states. @@ -152,6 +156,7 @@ class Main extends Sprite Conductor.init(); AudioSwitchFix.init(); EventManager.init(); + FlxG.signals.focusGained.add(onFocus); FlxG.signals.preStateSwitch.add(onStateSwitch); FlxG.signals.postStateSwitch.add(onStateSwitchPost); @@ -190,6 +195,10 @@ class Main extends Sprite {asset: diamond, width: 32, height: 32}, new FlxRect(-200, -200, FlxG.width * 1.4, FlxG.height * 1.4)); } + public static function onFocus() { + _tickFocused = FlxG.game.ticks; + } + private static function onStateSwitch() { scaleMode.resetSize(); } @@ -209,4 +218,9 @@ class Main extends Sprite MemoryUtil.clearMajor(); } + + private static var _tickFocused:Float = 0; + public static function get_timeSinceFocus():Float { + return (FlxG.game.ticks - _tickFocused) / 1000; + } } diff --git a/source/funkin/options/OptionsScreen.hx b/source/funkin/options/OptionsScreen.hx index 455808215..b703d994e 100644 --- a/source/funkin/options/OptionsScreen.hx +++ b/source/funkin/options/OptionsScreen.hx @@ -45,7 +45,7 @@ class OptionsScreen extends FlxTypedSpriteGroup { if (members.length > 0) { members[curSelected].selected = true; - if (controls.ACCEPT || FlxG.mouse.justReleased) + if (controls.ACCEPT || (FlxG.mouse.justReleased && Main.timeSinceFocus > 0.25)) members[curSelected].onSelect(); if (controls.LEFT_P) members[curSelected].onChangeSelection(-1);