From abc2e5c464c581f429416cb61e24c6408385f063 Mon Sep 17 00:00:00 2001 From: Yoshman29 <81191621+YoshiCrafter29@users.noreply.github.com> Date: Thu, 10 Nov 2022 23:55:57 +0100 Subject: [PATCH] early switch mod menu! --- buildnumber.txt | 2 +- source/funkin/menus/MainMenuState.hx | 9 ++++ source/funkin/menus/ModSwitchMenu.hx | 81 ++++++++++++++++++++++++++++ 3 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 source/funkin/menus/ModSwitchMenu.hx diff --git a/buildnumber.txt b/buildnumber.txt index 11b9a892..1ab8b271 100644 --- a/buildnumber.txt +++ b/buildnumber.txt @@ -1 +1 @@ -1271 \ No newline at end of file +1273 \ No newline at end of file diff --git a/source/funkin/menus/MainMenuState.hx b/source/funkin/menus/MainMenuState.hx index f6b11213..01734ad6 100644 --- a/source/funkin/menus/MainMenuState.hx +++ b/source/funkin/menus/MainMenuState.hx @@ -138,6 +138,15 @@ class MainMenuState extends MusicBeatState FlxG.switchState(new TitleState()); } + #if MOD_SUPPORT + // make it customisable + if (FlxG.keys.justPressed.TAB) { + openSubState(new ModSwitchMenu()); + persistentUpdate = false; + persistentDraw = true; + } + #end + if (controls.ACCEPT) { if (optionShit[curSelected] == 'donate') diff --git a/source/funkin/menus/ModSwitchMenu.hx b/source/funkin/menus/ModSwitchMenu.hx new file mode 100644 index 00000000..2ad8c27b --- /dev/null +++ b/source/funkin/menus/ModSwitchMenu.hx @@ -0,0 +1,81 @@ +package funkin.menus; + +#if MOD_SUPPORT +import flixel.math.FlxMath; +import flixel.group.FlxGroup.FlxTypedGroup; +import funkin.ui.Alphabet; +import haxe.io.Path; +import funkin.mods.ModsFolder; +import sys.FileSystem; +import flixel.tweens.FlxEase; +import flixel.tweens.FlxTween; +import flixel.FlxSprite; +import flixel.FlxG; + +class ModSwitchMenu extends MusicBeatSubstate { + var mods:Array = []; + var alphabets:FlxTypedGroup; + var curSelected:Int = 0; + + public override function create() { + super.create(); + + var bg = new FlxSprite(0, 0).makeGraphic(1, 1, 0xFF000000); + bg.scale.set(FlxG.width, FlxG.height); + bg.updateHitbox(); + add(bg); + + bg.alpha = 0; + FlxTween.tween(bg, {alpha: 0.5}, 0.25, {ease: FlxEase.cubeOut}); + + for(modFolder in FileSystem.readDirectory(ModsFolder.modsPath)) { + if (FileSystem.isDirectory('${ModsFolder.modsPath}${modFolder}')) { + mods.push(modFolder); + } else { + var ext = Path.extension(modFolder).toLowerCase(); + switch(ext) { + case 'zip': + // is a zip mod!! + mods.push(Path.withoutExtension(modFolder)); + default: + trace('$modFolder is not a valid mod folder!!'); + } + } + } + + alphabets = new FlxTypedGroup(); + for(mod in mods) { + var a = new Alphabet(0, 0, mod, true); + a.isMenuItem = true; + alphabets.add(a); + } + add(alphabets); + changeSelection(0, true); + } + + public override function update(elapsed:Float) { + super.update(elapsed); + + changeSelection((controls.DOWN_P ? 1 : 0) + (controls.UP_P ? -1 : 0)); + + if (controls.ACCEPT) { + ModsFolder.switchMod(mods[curSelected]); + close(); + } + } + + public function changeSelection(change:Int, force:Bool = false) { + if (change == 0 && !force) return; + + curSelected = FlxMath.wrap(curSelected + change, 0, alphabets.length-1); + + CoolUtil.playMenuSFX(); + + for(k=>alphabet in alphabets.members) { + alphabet.alpha = 0.6; + alphabet.targetY = k - curSelected; + } + alphabets.members[curSelected].alpha = 1; + } +} +#end \ No newline at end of file