From ce24ad1a8a9b034dd2d7cb047ab4c3f557289216 Mon Sep 17 00:00:00 2001 From: Cameron Taylor Date: Tue, 30 Apr 2024 00:40:42 -0400 Subject: [PATCH] add fullscreen rebindable keybind across whole game --- source/funkin/InitState.hx | 1 + source/funkin/input/Controls.hx | 20 ++++++++++++++++++++ source/funkin/ui/title/TitleState.hx | 3 +-- source/funkin/util/WindowUtil.hx | 10 ++++++++++ 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/source/funkin/InitState.hx b/source/funkin/InitState.hx index 2377343c3..00d34fadb 100644 --- a/source/funkin/InitState.hx +++ b/source/funkin/InitState.hx @@ -74,6 +74,7 @@ class InitState extends FlxState // // Setup window events (like callbacks for onWindowClose) + // and fullscreen keybind setup WindowUtil.initWindowEvents(); // Disable the thing on Windows where it tries to send a bug report to Microsoft because why do they care? WindowUtil.disableCrashHandler(); diff --git a/source/funkin/input/Controls.hx b/source/funkin/input/Controls.hx index 14b226d88..1983d413b 100644 --- a/source/funkin/input/Controls.hx +++ b/source/funkin/input/Controls.hx @@ -66,6 +66,7 @@ class Controls extends FlxActionSet var _volume_up = new FunkinAction(Action.VOLUME_UP); var _volume_down = new FunkinAction(Action.VOLUME_DOWN); var _volume_mute = new FunkinAction(Action.VOLUME_MUTE); + var _fullscreen = new FunkinAction(Action.FULLSCREEN); var byName:Map = new Map(); @@ -272,6 +273,11 @@ class Controls extends FlxActionSet inline function get_VOLUME_MUTE() return _volume_mute.check(); + public var FULLSCREEN(get, never):Bool; + + inline function get_FULLSCREEN() + return _fullscreen.check(); + public function new(name, scheme:KeyboardScheme = null) { super(name); @@ -296,6 +302,7 @@ class Controls extends FlxActionSet add(_volume_up); add(_volume_down); add(_volume_mute); + add(_fullscreen); for (action in digitalActions) { if (Std.isOfType(action, FunkinAction)) { @@ -399,6 +406,7 @@ class Controls extends FlxActionSet case VOLUME_UP: _volume_up; case VOLUME_DOWN: _volume_down; case VOLUME_MUTE: _volume_mute; + case FULLSCREEN: _fullscreen; } } @@ -474,6 +482,8 @@ class Controls extends FlxActionSet func(_volume_down, JUST_PRESSED); case VOLUME_MUTE: func(_volume_mute, JUST_PRESSED); + case FULLSCREEN: + func(_fullscreen, JUST_PRESSED); } } @@ -668,6 +678,7 @@ class Controls extends FlxActionSet bindKeys(Control.VOLUME_UP, getDefaultKeybinds(scheme, Control.VOLUME_UP)); bindKeys(Control.VOLUME_DOWN, getDefaultKeybinds(scheme, Control.VOLUME_DOWN)); bindKeys(Control.VOLUME_MUTE, getDefaultKeybinds(scheme, Control.VOLUME_MUTE)); + bindKeys(Control.FULLSCREEN, getDefaultKeybinds(scheme, Control.FULLSCREEN)); bindMobileLol(); } @@ -696,6 +707,8 @@ class Controls extends FlxActionSet case Control.VOLUME_UP: return [PLUS, NUMPADPLUS]; case Control.VOLUME_DOWN: return [MINUS, NUMPADMINUS]; case Control.VOLUME_MUTE: return [ZERO, NUMPADZERO]; + case Control.FULLSCREEN: return [FlxKey.F]; + } case Duo(true): switch (control) { @@ -719,6 +732,8 @@ class Controls extends FlxActionSet case Control.VOLUME_UP: return [PLUS]; case Control.VOLUME_DOWN: return [MINUS]; case Control.VOLUME_MUTE: return [ZERO]; + case Control.FULLSCREEN: return [FlxKey.F]; + } case Duo(false): switch (control) { @@ -742,6 +757,8 @@ class Controls extends FlxActionSet case Control.VOLUME_UP: return [NUMPADPLUS]; case Control.VOLUME_DOWN: return [NUMPADMINUS]; case Control.VOLUME_MUTE: return [NUMPADZERO]; + case Control.FULLSCREEN: return []; + } default: // Fallthrough. @@ -876,6 +893,7 @@ class Controls extends FlxActionSet case Control.CUTSCENE_ADVANCE: return [A]; case Control.DEBUG_MENU: return []; case Control.DEBUG_CHART: return []; + case Control.FULLSCREEN: return []; default: // Fallthrough. } @@ -1398,6 +1416,7 @@ enum Control ACCEPT; BACK; PAUSE; + FULLSCREEN; // CUTSCENE CUTSCENE_ADVANCE; // SCREENSHOT @@ -1443,6 +1462,7 @@ enum abstract Action(String) to String from String var BACK = "back"; var PAUSE = "pause"; var RESET = "reset"; + var FULLSCREEN = "fullscreen"; // SCREENSHOT var SCREENSHOT = "screenshot"; // CUTSCENE diff --git a/source/funkin/ui/title/TitleState.hx b/source/funkin/ui/title/TitleState.hx index d122bf7c1..012e3669a 100644 --- a/source/funkin/ui/title/TitleState.hx +++ b/source/funkin/ui/title/TitleState.hx @@ -251,7 +251,7 @@ class TitleState extends MusicBeatState var transitioning:Bool = false; - override function update(elapsed:Float) + override function update(elapsed:Float):Void { FlxG.bitmapLog.add(FlxG.camera.buffer); @@ -286,7 +286,6 @@ class TitleState extends MusicBeatState } if (FlxG.sound.music != null) Conductor.instance.update(FlxG.sound.music.time); - if (FlxG.keys.justPressed.F) FlxG.fullscreen = !FlxG.fullscreen; // do controls.PAUSE | controls.ACCEPT instead? var pressedEnter:Bool = FlxG.keys.justPressed.ENTER; diff --git a/source/funkin/util/WindowUtil.hx b/source/funkin/util/WindowUtil.hx index f73fe11ce..763d84853 100644 --- a/source/funkin/util/WindowUtil.hx +++ b/source/funkin/util/WindowUtil.hx @@ -90,6 +90,16 @@ class WindowUtil openfl.Lib.current.stage.application.onExit.add(function(exitCode:Int) { windowExit.dispatch(exitCode); }); + + openfl.Lib.current.stage.addEventListener(openfl.events.KeyboardEvent.KEY_DOWN, (e:openfl.events.KeyboardEvent) -> { + for (key in PlayerSettings.player1.controls.getKeysForAction(FULLSCREEN)) + { + if (e.keyCode == key) + { + openfl.Lib.application.window.fullscreen = !openfl.Lib.application.window.fullscreen; + } + } + }); } /**