From 899944fcd3e3167998ee7d7437b850483460db02 Mon Sep 17 00:00:00 2001 From: Yoshman29 <81191621+YoshiCrafter29@users.noreply.github.com> Date: Fri, 20 Jan 2023 19:32:34 +0100 Subject: [PATCH] new keybind --- buildnumber.txt | 2 +- source/funkin/cutscenes/DialogueCutscene.hx | 10 +++ source/funkin/cutscenes/ScriptedCutscene.hx | 26 +++++- source/funkin/macros/OptionsMacro.hx | 50 ++++++++++++ source/funkin/menus/MainMenuState.hx | 2 +- source/funkin/options/Options.hx | 79 +------------------ .../funkin/options/keybinds/KeybindSetting.hx | 7 +- .../options/keybinds/KeybindsOptions.hx | 13 ++- source/funkin/system/Controls.hx | 15 ++++ 9 files changed, 120 insertions(+), 84 deletions(-) create mode 100644 source/funkin/cutscenes/DialogueCutscene.hx create mode 100644 source/funkin/macros/OptionsMacro.hx diff --git a/buildnumber.txt b/buildnumber.txt index 8c3d9406..2c9e4a82 100644 --- a/buildnumber.txt +++ b/buildnumber.txt @@ -1 +1 @@ -2097 \ No newline at end of file +2101 \ No newline at end of file diff --git a/source/funkin/cutscenes/DialogueCutscene.hx b/source/funkin/cutscenes/DialogueCutscene.hx new file mode 100644 index 00000000..4829f196 --- /dev/null +++ b/source/funkin/cutscenes/DialogueCutscene.hx @@ -0,0 +1,10 @@ +package funkin.cutscenes; + +class DialogueCutscene extends Cutscene { + public var dialoguePath:String; + + public function new(dialoguePath:String, callback:Void->Void) { + super(callback); + this.dialoguePath = dialoguePath; + } +} \ No newline at end of file diff --git a/source/funkin/cutscenes/ScriptedCutscene.hx b/source/funkin/cutscenes/ScriptedCutscene.hx index 1f49c456..3bc8d977 100644 --- a/source/funkin/cutscenes/ScriptedCutscene.hx +++ b/source/funkin/cutscenes/ScriptedCutscene.hx @@ -47,7 +47,9 @@ class ScriptedCutscene extends Cutscene { script.call("destroy"); super.destroy(); } - + + // VIDEOS + #if REGION public function startVideo(path:String, ?callback:Void->Void) { persistentDraw = false; openSubState(new VideoCutscene(path, function() { @@ -55,4 +57,26 @@ class ScriptedCutscene extends Cutscene { callback(); })); } + + public var isVideoPlaying(get, null):Bool; + + private inline function get_isVideoPlaying() + return subState is VideoCutscene; + #end + + // DIALOGUE + #if REGION + public function startDialogue(path:String, ?callback:Void->Void) { + persistentDraw = true; + openSubState(new VideoCutscene(path, function() { + if (callback != null) + callback(); + })); + } + + public var isDialoguePlaying(get, null):Bool; + + private inline function get_isDialoguePlaying() + return subState is DialogueCutscene; + #end } \ No newline at end of file diff --git a/source/funkin/macros/OptionsMacro.hx b/source/funkin/macros/OptionsMacro.hx new file mode 100644 index 00000000..29e8c867 --- /dev/null +++ b/source/funkin/macros/OptionsMacro.hx @@ -0,0 +1,50 @@ +package funkin.macros; + +#if macro +using StringTools; + +class OptionsMacro { + public static function build():Array { + var fields = Context.getBuildFields(); + + for(f in fields) { + switch(f.kind) { + case FProp(get, set, t, e): + if (f.name.startsWith('SOLO_') && get == "get" && set == "null") { + // Auto-create getters for solo (P1/P2) keybinds + var name = f.name.substr(5); + var getterName = 'get_SOLO_$name'; + var ponename = 'P1_$name'; + var ptwoname = 'P2_$name'; + var newFuncExpr:Expr = macro { + var a:Array = []; + for(e in ${{ + pos: Context.currentPos(), + expr: EConst(CIdent(ponename)) + }}) a.push(e); + for(e in ${{ + pos: Context.currentPos(), + expr: EConst(CIdent(ptwoname)) + }}) a.push(e); + return a; + }; + + fields.push({ + name: getterName, + kind: FFun({ + expr: newFuncExpr, + args: [] + }), + pos: Context.currentPos(), + access: [APrivate, AStatic, AInline] + }); + } + default: + // nothing + } + } + + return fields; + } +} +#end \ No newline at end of file diff --git a/source/funkin/menus/MainMenuState.hx b/source/funkin/menus/MainMenuState.hx index da930d40..2d285b16 100644 --- a/source/funkin/menus/MainMenuState.hx +++ b/source/funkin/menus/MainMenuState.hx @@ -122,7 +122,7 @@ class MainMenuState extends MusicBeatState #if MOD_SUPPORT // make it customisable - if (FlxG.keys.justPressed.TAB) { + if (controls.SWITCHMOD) { openSubState(new ModSwitchMenu()); persistentUpdate = false; persistentDraw = true; diff --git a/source/funkin/options/Options.hx b/source/funkin/options/Options.hx index 60b18f8d..f46fab7d 100644 --- a/source/funkin/options/Options.hx +++ b/source/funkin/options/Options.hx @@ -6,6 +6,7 @@ import openfl.Lib; import flixel.util.FlxSave; import flixel.input.keyboard.FlxKey; +@:build(funkin.macros.OptionsMacro.build()) class Options { @:dox(hide) public static var __save:FlxSave; @@ -41,6 +42,7 @@ class Options public static var P1_BACK:Array = [BACKSPACE]; public static var P1_PAUSE:Array = [ENTER]; public static var P1_RESET:Array = [R]; + public static var P1_SWITCHMOD:Array = [TAB]; /** * PLAYER 2 CONTROLS (ALT) @@ -57,6 +59,7 @@ class Options public static var P2_BACK:Array = [ESCAPE]; public static var P2_PAUSE:Array = [ESCAPE]; public static var P2_RESET:Array = []; + public static var P2_SWITCHMOD:Array = []; /** * SOLO GETTERS @@ -73,82 +76,8 @@ class Options public static var SOLO_BACK(get, null):Array; public static var SOLO_PAUSE(get, null):Array; public static var SOLO_RESET(get, null):Array; + public static var SOLO_SWITCHMOD(get, null):Array; - // GETTERS REGION - #if REGION - private static function get_SOLO_LEFT() { - var a:Array = []; - for(e in P1_LEFT) a.push(e); - for(e in P2_LEFT) a.push(e); - return a; - } - private static function get_SOLO_DOWN() { - var a:Array = []; - for(e in P1_DOWN) a.push(e); - for(e in P2_DOWN) a.push(e); - return a; - } - private static function get_SOLO_UP() { - var a:Array = []; - for(e in P1_UP) a.push(e); - for(e in P2_UP) a.push(e); - return a; - } - private static function get_SOLO_RIGHT() { - var a:Array = []; - for(e in P1_RIGHT) a.push(e); - for(e in P2_RIGHT) a.push(e); - return a; - } - private static function get_SOLO_NOTE_LEFT() { - var a:Array = []; - for(e in P1_NOTE_LEFT) a.push(e); - for(e in P2_NOTE_LEFT) a.push(e); - return a; - } - private static function get_SOLO_NOTE_DOWN() { - var a:Array = []; - for(e in P1_NOTE_DOWN) a.push(e); - for(e in P2_NOTE_DOWN) a.push(e); - return a; - } - private static function get_SOLO_NOTE_UP() { - var a:Array = []; - for(e in P1_NOTE_UP) a.push(e); - for(e in P2_NOTE_UP) a.push(e); - return a; - } - private static function get_SOLO_NOTE_RIGHT() { - var a:Array = []; - for(e in P1_NOTE_RIGHT) a.push(e); - for(e in P2_NOTE_RIGHT) a.push(e); - return a; - } - private static function get_SOLO_ACCEPT() { - var a:Array = []; - for(e in P1_ACCEPT) a.push(e); - for(e in P2_ACCEPT) a.push(e); - return a; - } - private static function get_SOLO_BACK() { - var a:Array = []; - for(e in P1_BACK) a.push(e); - for(e in P2_BACK) a.push(e); - return a; - } - private static function get_SOLO_PAUSE() { - var a:Array = []; - for(e in P1_PAUSE) a.push(e); - for(e in P2_PAUSE) a.push(e); - return a; - } - private static function get_SOLO_RESET() { - var a:Array = []; - for(e in P1_RESET) a.push(e); - for(e in P2_RESET) a.push(e); - return a; - } - #end public static function load() { if (__save == null) __save = new FlxSave(); __save.bind("options"); diff --git a/source/funkin/options/keybinds/KeybindSetting.hx b/source/funkin/options/keybinds/KeybindSetting.hx index 95511f25..023dba9d 100644 --- a/source/funkin/options/keybinds/KeybindSetting.hx +++ b/source/funkin/options/keybinds/KeybindSetting.hx @@ -33,7 +33,6 @@ class KeybindSetting extends FlxTypedSpriteGroup { super(); this.value = value; title = new Alphabet(0, 0, name, true); - title.setPosition(100, 0); add(title); var controlArrayP1:Array = Reflect.field(Options, 'P1_${value}'); @@ -65,6 +64,8 @@ class KeybindSetting extends FlxTypedSpriteGroup { var min = Math.min(icon.scale.x, icon.scale.y); icon.scale.set(min, min); add(icon); + + title.setPosition(100, 0); } setPosition(x, y); @@ -79,9 +80,7 @@ class KeybindSetting extends FlxTypedSpriteGroup { } public function changeKeybind(callback:Void->Void, cancelCallback:Void->Void, p2:Bool = false) { - - var flicker = FlxFlicker.flicker(this, 0, Options.flashingMenu ? 0.06 : 0.15, true, false, function(t) { - }); + var flicker = FlxFlicker.flicker(this, 0, Options.flashingMenu ? 0.06 : 0.15, true, false, function(t) {}); KeybindsOptions.instance.persistentDraw = true; KeybindsOptions.instance.persistentUpdate = false; diff --git a/source/funkin/options/keybinds/KeybindsOptions.hx b/source/funkin/options/keybinds/KeybindsOptions.hx index 4fd06d7b..7bbdae4a 100644 --- a/source/funkin/options/keybinds/KeybindsOptions.hx +++ b/source/funkin/options/keybinds/KeybindsOptions.hx @@ -77,6 +77,15 @@ class KeybindsOptions extends MusicBeatSubstate { control: 'PAUSE' }, ] + }, + { + name: 'Engine', + settings: [ + { + name: 'Switch Mod', + control: 'SWITCHMOD' + }, + ] } ]; @@ -165,9 +174,9 @@ class KeybindsOptions extends MusicBeatSubstate { } } add(alphabets); - changeSelection(1); - add(camFollow); + + changeSelection(1); } public override function destroy() { diff --git a/source/funkin/system/Controls.hx b/source/funkin/system/Controls.hx index 2466146d..ba521410 100644 --- a/source/funkin/system/Controls.hx +++ b/source/funkin/system/Controls.hx @@ -45,6 +45,7 @@ enum abstract Action(String) to String from String { var PAUSE = "pause"; var RESET = "reset"; var CHEAT = "cheat"; + var SWITCHMOD = "switchmod"; } enum Device @@ -73,6 +74,7 @@ enum Control BACK; PAUSE; CHEAT; + SWITCHMOD; } enum KeyboardScheme @@ -120,6 +122,7 @@ class Controls extends FlxActionSet var _pause = new FlxActionDigital(Action.PAUSE); var _reset = new FlxActionDigital(Action.RESET); var _cheat = new FlxActionDigital(Action.CHEAT); + var _switchMod = new FlxActionDigital(Action.SWITCHMOD); #if (haxe >= "4.0.0") var byName:Map = []; @@ -275,6 +278,11 @@ class Controls extends FlxActionSet inline function get_CHEAT() return _cheat.check(); + public var SWITCHMOD(get, never):Bool; + + inline function get_SWITCHMOD() + return _switchMod.check(); + public function new(name, scheme = None) { super(name); @@ -310,6 +318,7 @@ class Controls extends FlxActionSet add(_pause); add(_reset); add(_cheat); + add(_switchMod); for (action in digitalActions) byName[action.name] = action; @@ -365,6 +374,7 @@ class Controls extends FlxActionSet case PAUSE: _pause; case RESET: _reset; case CHEAT: _cheat; + case SWITCHMOD: _switchMod; } } @@ -426,6 +436,8 @@ class Controls extends FlxActionSet func(_reset, JUST_PRESSED); case CHEAT: func(_cheat, JUST_PRESSED); + case SWITCHMOD: + func(_switchMod, JUST_PRESSED); } } @@ -580,6 +592,7 @@ class Controls extends FlxActionSet inline bindKeys(Control.BACK, Options.SOLO_BACK); inline bindKeys(Control.PAUSE, Options.SOLO_PAUSE); inline bindKeys(Control.RESET, Options.SOLO_RESET); + inline bindKeys(Control.SWITCHMOD, Options.SOLO_SWITCHMOD); case Duo(true): inline bindKeys(Control.UP, Options.P1_UP); inline bindKeys(Control.DOWN, Options.P1_DOWN); @@ -593,6 +606,7 @@ class Controls extends FlxActionSet inline bindKeys(Control.BACK, Options.P1_BACK); inline bindKeys(Control.PAUSE, Options.P1_PAUSE); inline bindKeys(Control.RESET, Options.P1_RESET); + inline bindKeys(Control.SWITCHMOD, Options.P1_SWITCHMOD); case Duo(false): inline bindKeys(Control.UP, Options.P2_UP); inline bindKeys(Control.DOWN, Options.P2_DOWN); @@ -606,6 +620,7 @@ class Controls extends FlxActionSet inline bindKeys(Control.BACK, Options.P2_BACK); inline bindKeys(Control.PAUSE, Options.P2_PAUSE); inline bindKeys(Control.RESET, Options.P2_RESET); + inline bindKeys(Control.SWITCHMOD, Options.P2_SWITCHMOD); case None: // nothing case Custom: // nothing }