[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>
This commit is contained in:
Til
2025-01-02 15:56:33 +01:00
committed by GitHub
co-authored by ⍚~Nex
parent f90782d712
commit 300f38d290
2 changed files with 15 additions and 1 deletions
+14
View File
@@ -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;
}
}
+1 -1
View File
@@ -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);