From 9db79167ebce8964e3cf63e8f09964538d4a67fe Mon Sep 17 00:00:00 2001 From: Yoshman29 Date: Thu, 13 Oct 2022 13:45:32 +0200 Subject: [PATCH] some stuff needs fixing --- buildnumber.txt | 2 +- source/funkin/options/KeybindsOptions.hx | 74 ++++++++++++++++++++---- source/funkin/ui/Alphabet.hx | 27 +++++---- 3 files changed, 79 insertions(+), 24 deletions(-) diff --git a/buildnumber.txt b/buildnumber.txt index a99c3866..c954f9c6 100644 --- a/buildnumber.txt +++ b/buildnumber.txt @@ -1 +1 @@ -380 \ No newline at end of file +394 \ No newline at end of file diff --git a/source/funkin/options/KeybindsOptions.hx b/source/funkin/options/KeybindsOptions.hx index 1b821d1d..3de4412f 100644 --- a/source/funkin/options/KeybindsOptions.hx +++ b/source/funkin/options/KeybindsOptions.hx @@ -1,6 +1,8 @@ package funkin.options; +import flixel.effects.FlxFlicker; import funkin.system.Controls; +import funkin.options.Options; import flixel.group.FlxSpriteGroup.FlxTypedSpriteGroup; import flixel.addons.transition.FlxTransitionableState; import flixel.group.FlxGroup.FlxTypedGroup; @@ -61,6 +63,7 @@ class KeybindsOptions extends MusicBeatState { ]; public var curSelected:Int = -1; + public var canSelect:Bool = true; public var alphabets:FlxTypedGroup; public var bg:FlxSprite; public var coloredBG:FlxSprite; @@ -141,13 +144,32 @@ class KeybindsOptions extends MusicBeatState { } else coloredBG.alpha = lerp(coloredBG.alpha, 0, 0.0625); - changeSelection((controls.UP_P ? -1 : 0) + (controls.DOWN_P ? 1 : 0)); + + super.update(elapsed); + if (canSelect) { + changeSelection((controls.UP_P ? -1 : 0) + (controls.DOWN_P ? 1 : 0)); + if (controls.BACK) { + FlxTransitionableState.skipNextTransIn = true; + FlxTransitionableState.skipNextTransOut = true; + FlxG.switchState(new OptionsMenu()); + controls.setKeyboardScheme(Solo); + return; + } - if (controls.BACK) { - FlxTransitionableState.skipNextTransIn = true; - FlxTransitionableState.skipNextTransOut = true; - FlxG.switchState(new OptionsMenu()); + if (controls.ACCEPT) { + if (alphabets.members[curSelected] != null) { + canSelect = false; + CoolUtil.playMenuSFX(1); + FlxFlicker.flicker(alphabets.members[curSelected], 0.4, 0.1, true, false, function(t) { + alphabets.members[curSelected].changeKeybind(false); + }); + } + } + } else { + if (alphabets.members[curSelected].changingKeybind < 0) + canSelect = true; } + } public function changeSelection(change:Int) { @@ -176,10 +198,14 @@ class KeybindSetting extends FlxTypedSpriteGroup { public var bind2:Alphabet; public var icon:FlxSprite; + public var changingKeybind:Int = -1; + public var value:String; + public var option1:Null; public var option2:Null; public function new(x:Float, y:Float, name:String, value:String, ?sparrowIcon:String, ?sparrowAnim:String) { super(); + this.value = value; title = new Alphabet(0, 0, name, true); title.setPosition(100, 0); add(title); @@ -219,13 +245,37 @@ class KeybindSetting extends FlxTypedSpriteGroup { setPosition(x, y); } + public override function update(elapsed:Float) { + super.update(elapsed); + if (changingKeybind >= 0) { + var key:FlxKey = FlxG.keys.firstJustReleased(); + if (cast(key, Int) <= 0) return; + if (key == ESCAPE && !FlxG.keys.pressed.SHIFT) { + changingKeybind = -1; + return; + } + if (changingKeybind == 0) { + option1 = key; + Reflect.setField(Options, 'P1_$value', [option1]); + } else { + option2 = key; + Reflect.setField(Options, 'P2_$value', [option2]); + } + changingKeybind = -1; + updateText(); + return; + } + } + + public function changeKeybind(p2:Bool = false) { + FlxG.state.persistentDraw = true; + FlxG.state.persistentUpdate = true; + + changingKeybind = p2 ? 1 : 0; + } + public function updateText() { - // TODO: Fix Alphabet!! - @:privateAccess - bind1._finalText = '${CoolUtil.keyToString(option1)}'; - @:privateAccess - bind2._finalText = '${CoolUtil.keyToString(option2)}'; - bind1.addText(); - bind2.addText(); + bind1.text = '${CoolUtil.keyToString(option1)}'; + bind2.text = '${CoolUtil.keyToString(option2)}'; } } \ No newline at end of file diff --git a/source/funkin/ui/Alphabet.hx b/source/funkin/ui/Alphabet.hx index f0a79ed1..34d88826 100644 --- a/source/funkin/ui/Alphabet.hx +++ b/source/funkin/ui/Alphabet.hx @@ -71,8 +71,7 @@ class Alphabet extends FlxSpriteGroup { super(x, y); - _finalText = text; - this.text = text; + _finalText = this.text = text; isBold = bold; var alphabetPath = Paths.xml("alphabet"); @@ -117,24 +116,20 @@ class Alphabet extends FlxSpriteGroup var xPos:Float = 0; for (character in splitWords) { - if (character == " " || character == "-") - lastWasSpace = true; + lastWasSpace = character == " "; if (lastSprite != null) xPos = lastSprite.x + lastSprite.width - x; - if (lastWasSpace) - { - xPos += 40; - lastWasSpace = false; - } - var letter:AlphaCharacter = new AlphaCharacter(xPos, 0); if (isBold) letter.createBold(character); else letter.createLetter(character); + // anim not found + if (!letter.visible) + xPos += 40; add(letter); lastSprite = letter; @@ -251,6 +246,8 @@ class Alphabet extends FlxSpriteGroup override function update(elapsed:Float) { + super.update(elapsed); + if (isMenuItem) { var scaledY = FlxMath.remapToRange(targetY, 0, 1, 0, 1.3); @@ -259,7 +256,15 @@ class Alphabet extends FlxSpriteGroup x = CoolUtil.fpsLerp(x, (targetY * 20) + 90, 0.16); } - super.update(elapsed); + if (text != _finalText) { + _finalText = text; + for(e in members) + e.destroy(); + @:privateAccess + group.members = []; + lastSprite = null; + addText(); + } } }