From 739455022d357c22834a2e0850e9996627700983 Mon Sep 17 00:00:00 2001 From: ItzFireable Date: Tue, 12 Oct 2021 20:16:01 +0300 Subject: [PATCH] More keybinds (Volume, pause/reset, fullscreen) --- source/Caching.hx | 5 ++++ source/Controls.hx | 6 ++--- source/KeyBindMenu.hx | 57 +++++++++++++++++++++++++++++++---------- source/KeyBinds.hx | 59 ++++++++++++++++++++++++++++++++++++++++--- source/PlayState.hx | 41 +++++++++++++++++------------- source/TitleState.hx | 4 ++- 6 files changed, 133 insertions(+), 39 deletions(-) diff --git a/source/Caching.hx b/source/Caching.hx index 3df411a3f5..f726695d6b 100644 --- a/source/Caching.hx +++ b/source/Caching.hx @@ -27,6 +27,7 @@ import flixel.math.FlxRect; import flixel.util.FlxColor; import flixel.util.FlxTimer; import flixel.text.FlxText; +import flixel.input.keyboard.FlxKey; using StringTools; @@ -54,6 +55,10 @@ class Caching extends MusicBeatState KadeEngineData.initSave(); + FlxG.sound.muteKeys = [FlxKey.fromString(FlxG.save.data.muteBind)]; + FlxG.sound.volumeDownKeys = [FlxKey.fromString(FlxG.save.data.volDownBind)]; + FlxG.sound.volumeUpKeys = [FlxKey.fromString(FlxG.save.data.volUpBind)]; + FlxG.mouse.visible = false; FlxG.worldBounds.set(0, 0); diff --git a/source/Controls.hx b/source/Controls.hx index 9c63f720d3..a7f5e8e0e4 100644 --- a/source/Controls.hx +++ b/source/Controls.hx @@ -582,7 +582,7 @@ class Controls extends FlxActionSet buttons.set(Control.RIGHT, [FlxGamepadInputID.fromString(FlxG.save.data.gprightBind)]); buttons.set(Control.ACCEPT, [FlxGamepadInputID.A]); buttons.set(Control.BACK, [FlxGamepadInputID.B]); - buttons.set(Control.PAUSE, [FlxGamepadInputID.START]); + buttons.set(Control.PAUSE, [FlxGamepadInputID.fromString(FlxG.save.data.gppauseBind)]); addGamepad(0, buttons); @@ -592,8 +592,8 @@ class Controls extends FlxActionSet inline bindKeys(Control.RIGHT, [FlxKey.fromString(FlxG.save.data.rightBind), FlxKey.RIGHT]); inline bindKeys(Control.ACCEPT, [Z, SPACE, ENTER]); inline bindKeys(Control.BACK, [BACKSPACE, ESCAPE]); - inline bindKeys(Control.PAUSE, [ENTER, ESCAPE]); - inline bindKeys(Control.RESET, [FlxKey.fromString(FlxG.save.data.killBind)]); + inline bindKeys(Control.PAUSE, [FlxKey.fromString(FlxG.save.data.pauseBind)]); + inline bindKeys(Control.RESET, [FlxKey.fromString(FlxG.save.data.resetBind)]); } function removeKeyboard() diff --git a/source/KeyBindMenu.hx b/source/KeyBindMenu.hx index d795c384cf..c8f6c9ed17 100644 --- a/source/KeyBindMenu.hx +++ b/source/KeyBindMenu.hx @@ -30,25 +30,29 @@ class KeyBindMenu extends FlxSubState var keyTextDisplay:FlxText; var keyWarning:FlxText; var warningTween:FlxTween; - var keyText:Array = ["LEFT", "DOWN", "UP", "RIGHT"]; - var defaultKeys:Array = ["A", "S", "W", "D", "R"]; - var defaultGpKeys:Array = ["DPAD_LEFT", "DPAD_DOWN", "DPAD_UP", "DPAD_RIGHT"]; + var keyText:Array = [ + "LEFT", "DOWN", "UP", "RIGHT", "PAUSE", "RESET", "MUTE", "VOLUME UP", "VOLUME DOWN", "FULLSCREEN" + ]; + var defaultKeys:Array = ["A", "S", "W", "D", "ENTER", "R", "NUMPADZERO", "NUMPADMINUS", "NUMPADPLUS", "F"]; + var defaultGpKeys:Array = ["DPAD_LEFT", "DPAD_DOWN", "DPAD_UP", "DPAD_RIGHT", "START", "SELECT"]; var curSelected:Int = 0; var keys:Array = [ - FlxG.save.data.leftBind, - FlxG.save.data.downBind, - FlxG.save.data.upBind, - FlxG.save.data.rightBind + FlxG.save.data.leftBind, FlxG.save.data.downBind, FlxG.save.data.upBind, FlxG.save.data.rightBind, FlxG.save.data.pauseBind, FlxG.save.data.resetBind, + FlxG.save.data.muteBind, FlxG.save.data.volUpBind, FlxG.save.data.volDownBind, FlxG.save.data.fullscreenBind ]; + var gpKeys:Array = [ FlxG.save.data.gpleftBind, FlxG.save.data.gpdownBind, FlxG.save.data.gpupBind, - FlxG.save.data.gprightBind + FlxG.save.data.gprightBind, + FlxG.save.data.gppauseBind, + FlxG.save.data.gpresetBind ]; + var tempKey:String = ""; - var blacklist:Array = ["ESCAPE", "ENTER", "BACKSPACE", "SPACE", "TAB"]; + var blacklist:Array = ["ESCAPE", "BACKSPACE", "SPACE", "TAB"]; var blackBox:FlxSprite; var infoText:FlxText; @@ -82,7 +86,7 @@ class KeyBindMenu extends FlxSubState blackBox = new FlxSprite(0, 0).makeGraphic(FlxG.width, FlxG.height, FlxColor.BLACK); add(blackBox); - infoText = new FlxText(-10, 580, 1280, + infoText = new FlxText(-10, 630, 1280, 'Current Mode: ${KeyBinds.gamepad ? 'GAMEPAD' : 'KEYBOARD'}. Press TAB to switch\n(${KeyBinds.gamepad ? 'RIGHT Trigger' : 'Escape'} to save, ${KeyBinds.gamepad ? 'LEFT Trigger' : 'Backspace'} to leave without saving. ${KeyBinds.gamepad ? 'START To change a keybind' : ''})', 72); infoText.scrollFactor.set(0, 0); @@ -263,10 +267,9 @@ class KeyBindMenu extends FlxSubState if (KeyBinds.gamepad) { - for (i in 0...4) + for (i in 0...6) { var textStart = (i == curSelected) ? "> " : " "; - trace(gpKeys[i]); keyTextDisplay.text += textStart + keyText[i] + ": " + gpKeys[i] + "\n"; } } @@ -277,6 +280,19 @@ class KeyBindMenu extends FlxSubState var textStart = (i == curSelected) ? "> " : " "; keyTextDisplay.text += textStart + keyText[i] + ": " + ((keys[i] != keyText[i]) ? (keys[i] + " / ") : "") + keyText[i] + " ARROW\n"; } + var textStartPause = (4 == curSelected) ? "> " : " "; + keyTextDisplay.text += textStartPause + keyText[4] + ": " + (keys[4]) + "\n"; + + var textStartReset = (5 == curSelected) ? "> " : " "; + keyTextDisplay.text += textStartReset + keyText[5] + ": " + (keys[5]) + "\n"; + + for (i in 6...9) + { + var textStart = (i == curSelected) ? "> " : " "; + keyTextDisplay.text += textStart + keyText[i] + ": " + keys[i] + "\n"; + } + var textStartReset = (9 == curSelected) ? "> " : " "; + keyTextDisplay.text += textStartReset + keyText[9] + ": " + (keys[9]) + "\n"; } keyTextDisplay.screenCenter(); @@ -288,11 +304,24 @@ class KeyBindMenu extends FlxSubState FlxG.save.data.downBind = keys[1]; FlxG.save.data.leftBind = keys[0]; FlxG.save.data.rightBind = keys[3]; + FlxG.save.data.pauseBind = keys[4]; + FlxG.save.data.resetBind = keys[5]; FlxG.save.data.gpupBind = gpKeys[2]; FlxG.save.data.gpdownBind = gpKeys[1]; FlxG.save.data.gpleftBind = gpKeys[0]; FlxG.save.data.gprightBind = gpKeys[3]; + FlxG.save.data.gppauseBind = gpKeys[4]; + FlxG.save.data.gpresetBind = gpKeys[5]; + + FlxG.save.data.muteBind = keys[6]; + FlxG.save.data.volUpBind = keys[7]; + FlxG.save.data.volDownBind = keys[8]; + FlxG.save.data.fullscreenBind = keys[9]; + + FlxG.sound.muteKeys = [FlxKey.fromString(keys[6])]; + FlxG.sound.volumeDownKeys = [FlxKey.fromString(keys[8])]; + FlxG.sound.volumeUpKeys = [FlxKey.fromString(keys[7])]; FlxG.save.flush(); @@ -435,9 +464,9 @@ class KeyBindMenu extends FlxSubState { curSelected += _amount; - if (curSelected > 3) + if (curSelected > 9) curSelected = 0; if (curSelected < 0) - curSelected = 3; + curSelected = 9; } } diff --git a/source/KeyBinds.hx b/source/KeyBinds.hx index 021d6d55a7..c0c0795766 100644 --- a/source/KeyBinds.hx +++ b/source/KeyBinds.hx @@ -19,11 +19,26 @@ class KeyBinds FlxG.save.data.downBind = "S"; FlxG.save.data.leftBind = "A"; FlxG.save.data.rightBind = "D"; - FlxG.save.data.killBind = "R"; + FlxG.save.data.muteBind = "NUMPADZERO"; + FlxG.save.data.volUpBind = "NUMPADPLUS"; + FlxG.save.data.volDownBind = "NUMPADMINUS"; + FlxG.save.data.fullscreenBind = "F"; FlxG.save.data.gpupBind = "DPAD_UP"; FlxG.save.data.gpdownBind = "DPAD_DOWN"; FlxG.save.data.gpleftBind = "DPAD_LEFT"; FlxG.save.data.gprightBind = "DPAD_RIGHT"; + FlxG.save.data.pauseBind = "ENTER"; + FlxG.save.data.gppauseBind = "START"; + FlxG.save.data.resetBind = "R"; + FlxG.save.data.gpresetBind = "SELECT"; + FlxG.save.data.muteBind = "NUMPADZERO"; + FlxG.save.data.volDownBind = "NUMPADMINUS"; + FlxG.save.data.volUpBind = "NUMPADPLUS"; + FlxG.save.data.fullscreenBind = "F"; + + FlxG.sound.muteKeys = ["ZERO", "NUMPADZERO"]; + FlxG.sound.volumeDownKeys = ["MINUS", "NUMPADMINUS"]; + FlxG.sound.volumeUpKeys = ["PLUS", "NUMPADPLUS"]; PlayerSettings.player1.controls.loadKeyBinds(); } @@ -70,10 +85,46 @@ class KeyBinds FlxG.save.data.gprightBind = "DPAD_RIGHT"; trace("No GRIGHT"); } - if (FlxG.save.data.killBind == null) + if (FlxG.save.data.pauseBind == null) + { + FlxG.save.data.pauseBind = "ENTER"; + trace("No ENTER"); + } + if (FlxG.save.data.gppauseBind == null) + { + FlxG.save.data.gppauseBind = "START"; + trace("No ENTER"); + } + if (FlxG.save.data.resetBind == null) + { + FlxG.save.data.resetBind = "R"; + trace("No RESET"); + } + if (FlxG.save.data.gpresetBind == null) + { + FlxG.save.data.gpresetBind = "SELECT"; + trace("No RESET"); + } + // VOLUME CONTROLS !!!! + if (FlxG.save.data.muteBind == null) + { + FlxG.save.data.muteBind = "NUMPADZERO"; + trace("No MUTE"); + } + if (FlxG.save.data.volUpBind == null) + { + FlxG.save.data.volUpBind = "NUMPADPLUS"; + trace("No VOLUP"); + } + if (FlxG.save.data.volDownBind == null) + { + FlxG.save.data.volDownBind = "NUMPADMINUS"; + trace("No VOLDOWN"); + } + if (FlxG.save.data.fullscreenBind == null) { - FlxG.save.data.killBind = "R"; - trace("No KILL"); + FlxG.save.data.fullscreenBind = "F"; + trace("No FULLSCREEN"); } trace('${FlxG.save.data.leftBind}-${FlxG.save.data.downBind}-${FlxG.save.data.upBind}-${FlxG.save.data.rightBind}'); diff --git a/source/PlayState.hx b/source/PlayState.hx index 8281163cb0..1b004ce3b7 100644 --- a/source/PlayState.hx +++ b/source/PlayState.hx @@ -719,25 +719,22 @@ class PlayState extends MusicBeatState if (PlayStateChangeables.useDownscroll) strumLine.y = FlxG.height - 165; - laneunderlayOpponent = new FlxSprite(0, 0).makeGraphic(500, FlxG.height * 2); - laneunderlayOpponent.x += 95; - laneunderlayOpponent.x += ((FlxG.width / 2) * 0); + laneunderlayOpponent = new FlxSprite(0, 0).makeGraphic(110 * 4 + 50, FlxG.height * 2); laneunderlayOpponent.alpha = 1 - FlxG.save.data.laneTransparency; laneunderlayOpponent.color = FlxColor.BLACK; laneunderlayOpponent.scrollFactor.set(); - laneunderlayOpponent.screenCenter(Y); - laneunderlay = new FlxSprite(0, 0).makeGraphic(500, FlxG.height * 2); - laneunderlay.x += 75; - laneunderlay.x += ((FlxG.width / 2) * 1); + laneunderlay = new FlxSprite(0, 0).makeGraphic(110 * 4 + 50, FlxG.height * 2); laneunderlay.alpha = 1 - FlxG.save.data.laneTransparency; laneunderlay.color = FlxColor.BLACK; laneunderlay.scrollFactor.set(); - laneunderlay.screenCenter(Y); if (FlxG.save.data.laneUnderlay && !PlayStateChangeables.Optimize) { - add(laneunderlayOpponent); + if (!FlxG.save.data.middleScroll) + { + add(laneunderlayOpponent); + } add(laneunderlay); } @@ -750,11 +747,13 @@ class PlayState extends MusicBeatState generateStaticArrows(0); generateStaticArrows(1); - if (FlxG.save.data.middleScroll) - { - laneunderlayOpponent.alpha = 0; - laneunderlay.x = playerStrums.members[0].x - 25; - } + // Update lane underlay positions AFTER static arrows :) + + laneunderlay.x = playerStrums.members[0].x - 25; + laneunderlayOpponent.x = cpuStrums.members[0].x - 25; + + laneunderlay.screenCenter(Y); + laneunderlayOpponent.screenCenter(Y); // startCountdown(); @@ -1587,7 +1586,7 @@ class PlayState extends MusicBeatState { songPosBG = new FlxSprite(0, 10).loadGraphic(Paths.loadImage('healthBar')); if (PlayStateChangeables.useDownscroll) - songPosBG.y = FlxG.height * 0.9 + 45; + songPosBG.y = FlxG.height * 0.9 + 35; songPosBG.screenCenter(X); songPosBG.scrollFactor.set(); @@ -2227,7 +2226,13 @@ class PlayState extends MusicBeatState scoreTxt.screenCenter(X); - if (controls.PAUSE && startedCountdown && canPause && !cannotDie) + var pauseBind = FlxKey.fromString(FlxG.save.data.pauseBind); + var gppauseBind = FlxKey.fromString(FlxG.save.data.gppauseBind); + + if ((FlxG.keys.anyJustPressed([pauseBind]) || KeyBinds.gamepad && FlxG.keys.anyJustPressed([gppauseBind])) + && startedCountdown + && canPause + && !cannotDie) { persistentUpdate = false; persistentDraw = true; @@ -2790,7 +2795,9 @@ class PlayState extends MusicBeatState } if (!inCutscene && FlxG.save.data.resetButton) { - if (FlxG.keys.justPressed.R) + var resetBind = FlxKey.fromString(FlxG.save.data.resetBind); + var gpresetBind = FlxKey.fromString(FlxG.save.data.gpresetBind); + if ((FlxG.keys.anyJustPressed([resetBind]) || KeyBinds.gamepad && FlxG.keys.anyJustPressed([gpresetBind]))) { boyfriend.stunned = true; diff --git a/source/TitleState.hx b/source/TitleState.hx index 32960d8baa..6bcfb35f53 100644 --- a/source/TitleState.hx +++ b/source/TitleState.hx @@ -25,6 +25,7 @@ import flixel.util.FlxColor; import flixel.util.FlxTimer; import lime.app.Application; import openfl.Assets; +import flixel.input.keyboard.FlxKey; #if FEATURE_DISCORD import Discord.DiscordClient; #end @@ -227,13 +228,14 @@ class TitleState extends MusicBeatState } var transitioning:Bool = false; + var fullscreenBind = FlxKey.fromString(FlxG.save.data.fullscreenBind); override function update(elapsed:Float) { if (FlxG.sound.music != null) Conductor.songPosition = FlxG.sound.music.time; - if (FlxG.keys.justPressed.F) + if (FlxG.keys.anyJustPressed([fullscreenBind])) { FlxG.fullscreen = !FlxG.fullscreen; }