Skip to content

Commit

Permalink
[ENHANCEMENT] Prevent accidental selecting when tabbing back in (#513)
Browse files Browse the repository at this point in the history
* prevent accidental selecting

* made something better

---------

Co-authored-by: ⍚~Nex <[email protected]>
  • Loading branch information
TechnikTil and NexIsDumb authored Jan 2, 2025
1 parent f90782d commit 300f38d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 14 additions & 0 deletions source/funkin/backend/system/Main.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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();
}
Expand All @@ -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;
}
}
2 changes: 1 addition & 1 deletion source/funkin/options/OptionsScreen.hx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class OptionsScreen extends FlxTypedSpriteGroup<OptionType> {

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);
Expand Down

0 comments on commit 300f38d

Please sign in to comment.