package funkin.menus; import funkin.ui.FunkinText; import funkin.options.Options; #if desktop import funkin.system.Discord.DiscordClient; #end import flixel.FlxG; import flixel.FlxObject; import flixel.FlxSprite; import flixel.FlxState; import flixel.addons.transition.FlxTransitionableState; import flixel.effects.FlxFlicker; import flixel.graphics.frames.FlxAtlasFrames; import flixel.group.FlxGroup.FlxTypedGroup; import flixel.text.FlxText; import flixel.tweens.FlxEase; import flixel.tweens.FlxTween; import flixel.util.FlxColor; import lime.app.Application; import funkin.options.OptionsMenu; using StringTools; class MainMenuState extends MusicBeatState { var curSelected:Int = 0; var menuItems:FlxTypedGroup; #if !switch var optionShit:Array = ['story mode', 'freeplay', 'donate', 'options']; #else var optionShit:Array = ['story mode', 'freeplay']; #end var magenta:FlxSprite; var camFollow:FlxObject; override function create() { super.create(); #if desktop // Updating Discord Rich Presence DiscordClient.changePresence("In the Menus", null); #end transIn = FlxTransitionableState.defaultTransIn; transOut = FlxTransitionableState.defaultTransOut; CoolUtil.playMenuSong(); persistentUpdate = persistentDraw = true; var bg:FlxSprite = new FlxSprite(-80).loadAnimatedGraphic(Paths.image('menus/menuBG')); bg.scrollFactor.x = 0; bg.scrollFactor.y = 0.18; bg.scale.set(1.15, 1.15); bg.updateHitbox(); bg.screenCenter(); bg.antialiasing = true; add(bg); camFollow = new FlxObject(0, 0, 1, 1); add(camFollow); magenta = new FlxSprite(-80).loadAnimatedGraphic(Paths.image('menus/menuDesat')); magenta.scrollFactor.x = 0; magenta.scrollFactor.y = 0.18; magenta.scale.set(1.15, 1.15); magenta.updateHitbox(); magenta.screenCenter(); magenta.visible = false; magenta.antialiasing = true; magenta.color = 0xFFfd719b; add(magenta); // magenta.scrollFactor.set(); menuItems = new FlxTypedGroup(); add(menuItems); for (i in 0...optionShit.length) { var menuItem:FlxSprite = new FlxSprite(0, 60 + (i * 160)); menuItem.frames = Paths.getFrames('menus/mainmenu/${optionShit[i]}'); menuItem.animation.addByPrefix('idle', optionShit[i] + " basic", 24); menuItem.animation.addByPrefix('selected', optionShit[i] + " white", 24); menuItem.animation.play('idle'); menuItem.ID = i; menuItem.screenCenter(X); menuItems.add(menuItem); menuItem.scrollFactor.set(); menuItem.antialiasing = true; } FlxG.camera.follow(camFollow, null, 0.06); var versionShit:FunkinText = new FunkinText(5, FlxG.height - 2, 0, 'Codename Engine v${Application.current.meta.get('version')}\nPre-Alpha: Build ${funkin.macros.BuildCounterMacro.getBuildNumber()}\n'); versionShit.scrollFactor.set(); versionShit.y -= versionShit.height; add(versionShit); // NG.core.calls.event.logEvent('swag').send(); changeItem(); } var selectedSomethin:Bool = false; override function update(elapsed:Float) { if (FlxG.sound.music.volume < 0.8) { FlxG.sound.music.volume += 0.5 * FlxG.elapsed; } if (!selectedSomethin) { if (FlxG.keys.justPressed.SEVEN) { FlxG.switchState(new funkin.desktop.DesktopMain()); } if (FlxG.keys.justPressed.F1) { funkin.multitasking.MultiTaskingHandler.openWindow("FreeplayState", new FreeplayState()); } if (controls.UP_P) { CoolUtil.playMenuSFX(0); changeItem(-1); } if (controls.DOWN_P) { CoolUtil.playMenuSFX(0); changeItem(1); } if (controls.BACK) { 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) { selectItem(); } } super.update(elapsed); menuItems.forEach(function(spr:FlxSprite) { spr.screenCenter(X); }); } public override function switchTo(nextState:FlxState):Bool { try { menuItems.forEach(function(spr:FlxSprite) { FlxTween.tween(spr, {alpha: 0}, 0.5, {ease: FlxEase.quintOut}); }); } return super.switchTo(nextState); } function selectItem() { if (optionShit[curSelected] == 'donate') { #if linux Sys.command('/usr/bin/xdg-open', ["https://ninja-muffin24.itch.io/funkin", "&"]); #else FlxG.openURL('https://ninja-muffin24.itch.io/funkin'); #end } else { selectedSomethin = true; CoolUtil.playMenuSFX(1); if (Options.flashingMenu) FlxFlicker.flicker(magenta, 1.1, 0.15, false); menuItems.forEach(function(spr:FlxSprite) { if (spr.ID != curSelected) return; FlxFlicker.flicker(spr, 1, Options.flashingMenu ? 0.06 : 0.15, false, false, function(flick:FlxFlicker) { var daChoice:String = optionShit[curSelected]; switch (daChoice) { case 'story mode': FlxG.switchState(new StoryMenuState()); trace("Story Menu Selected"); case 'freeplay': FlxG.switchState(new FreeplayState()); trace("Freeplay Menu Selected"); case 'options': FlxG.switchState(new OptionsMenu(false)); } }); }); } } function changeItem(huh:Int = 0) { curSelected += huh; if (curSelected >= menuItems.length) curSelected = 0; if (curSelected < 0) curSelected = menuItems.length - 1; menuItems.forEach(function(spr:FlxSprite) { spr.animation.play('idle'); if (spr.ID == curSelected) { spr.animation.play('selected'); camFollow.setPosition(spr.getGraphicMidpoint().x, spr.getGraphicMidpoint().y); } spr.updateHitbox(); spr.centerOffsets(); }); } }