Skip to content

Commit 300f38d

Browse files
[ENHANCEMENT] Prevent accidental selecting when tabbing back in (#513)
* prevent accidental selecting * made something better --------- Co-authored-by: ⍚~Nex <87421482+NexIsDumb@users.noreply.github.com>
1 parent f90782d commit 300f38d

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

source/funkin/backend/system/Main.hx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ class Main extends Sprite
4949

5050
public static var game:FunkinGame;
5151

52+
/**
53+
* The time since the game was focused last time in seconds.
54+
*/
55+
public static var timeSinceFocus(get, never):Float;
5256
public static var time:Int = 0;
5357

5458
// You can pretty much ignore everything from here on - your code should go in your states.
@@ -152,6 +156,7 @@ class Main extends Sprite
152156
Conductor.init();
153157
AudioSwitchFix.init();
154158
EventManager.init();
159+
FlxG.signals.focusGained.add(onFocus);
155160
FlxG.signals.preStateSwitch.add(onStateSwitch);
156161
FlxG.signals.postStateSwitch.add(onStateSwitchPost);
157162

@@ -190,6 +195,10 @@ class Main extends Sprite
190195
{asset: diamond, width: 32, height: 32}, new FlxRect(-200, -200, FlxG.width * 1.4, FlxG.height * 1.4));
191196
}
192197

198+
public static function onFocus() {
199+
_tickFocused = FlxG.game.ticks;
200+
}
201+
193202
private static function onStateSwitch() {
194203
scaleMode.resetSize();
195204
}
@@ -209,4 +218,9 @@ class Main extends Sprite
209218

210219
MemoryUtil.clearMajor();
211220
}
221+
222+
private static var _tickFocused:Float = 0;
223+
public static function get_timeSinceFocus():Float {
224+
return (FlxG.game.ticks - _tickFocused) / 1000;
225+
}
212226
}

source/funkin/options/OptionsScreen.hx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class OptionsScreen extends FlxTypedSpriteGroup<OptionType> {
4545

4646
if (members.length > 0) {
4747
members[curSelected].selected = true;
48-
if (controls.ACCEPT || FlxG.mouse.justReleased)
48+
if (controls.ACCEPT || (FlxG.mouse.justReleased && Main.timeSinceFocus > 0.25))
4949
members[curSelected].onSelect();
5050
if (controls.LEFT_P)
5151
members[curSelected].onChangeSelection(-1);

0 commit comments

Comments
 (0)