Files
CodenameEngine/source/funkin/menus/MainMenuState.hx
T
lunarcleint 014be749e6 Squashed commit of the following:
commit 4987983dc6e655183b34258fed905be2fba73e0a
Author: lunarcleint <88809950+lunarcleint@users.noreply.github.com>
Date:   Mon Apr 1 06:32:22 2024 -0700

    fix charter bug

commit 1135b53d4d4ab48fb74a9d5693579d0a2e4923db
Author: lunarcleint <88809950+lunarcleint@users.noreply.github.com>
Date:   Mon Apr 1 00:46:53 2024 -0700

    small changes

commit 102931f3511c9f0423cf887ebf91eaeeb1024abe
Author: lunarcleint <88809950+lunarcleint@users.noreply.github.com>
Date:   Sun Mar 31 23:03:03 2024 -0700

    update spelling mistakes

commit 87ad53ae91bc8b4d3b49af3ebb8c07db9f13765b
Author: lunarcleint <88809950+lunarcleint@users.noreply.github.com>
Date:   Sun Mar 31 22:40:48 2024 -0700

    Chart editor updates

commit 8f7cae8a80a681158ff125c3e2547c9fd4dee7c1
Author: NeeEoo <NeeEoo@users.noreply.github.com>
Date:   Mon Apr 1 07:03:30 2024 +0200

    Redesigned Chart Editor

commit dbb94ba3bd8455a91883d6e5b59b25da87aefa32
Author: NeeEoo <NeeEoo@users.noreply.github.com>
Date:   Mon Apr 1 02:20:57 2024 +0200

    Added Stage Editor
2024-04-01 06:44:28 -07:00

207 lines
5.3 KiB
Haxe

package funkin.menus;
import haxe.Json;
import funkin.backend.FunkinText;
import funkin.menus.credits.CreditsMain;
import flixel.FlxState;
import flixel.effects.FlxFlicker;
import flixel.text.FlxText;
import flixel.tweens.FlxTween;
import flixel.util.FlxColor;
import lime.app.Application;
import funkin.backend.scripting.events.*;
import funkin.options.OptionsMenu;
using StringTools;
class MainMenuState extends MusicBeatState
{
var curSelected:Int = 0;
var menuItems:FlxTypedGroup<FlxSprite>;
var optionShit:Array<String> = CoolUtil.coolTextFile(Paths.txt("config/menuItems"));
var magenta:FlxSprite;
var camFollow:FlxObject;
public var canAccessDebugMenus:Bool = true;
override function create()
{
super.create();
DiscordUtil.call("onMenuLoaded", ["Main Menu"]);
CoolUtil.playMenuSong();
var bg:FlxSprite = new FlxSprite(-80).loadAnimatedGraphic(Paths.image('menus/menuBG'));
add(bg);
camFollow = new FlxObject(0, 0, 1, 1);
add(camFollow);
magenta = new FlxSprite(-80).loadAnimatedGraphic(Paths.image('menus/menuDesat'));
magenta.visible = false;
magenta.color = 0xFFfd719b;
add(magenta);
for(bg in [bg, magenta]) {
bg.scrollFactor.set(0, 0.18);
bg.scale.set(1.15, 1.15);
bg.updateHitbox();
bg.screenCenter();
bg.antialiasing = true;
}
menuItems = new FlxTypedGroup<FlxSprite>();
add(menuItems);
for (i=>option in optionShit)
{
var menuItem:FlxSprite = new FlxSprite(0, 60 + (i * 130));
menuItem.frames = Paths.getFrames('menus/mainmenu/${option}');
menuItem.animation.addByPrefix('idle', option + " basic", 24);
menuItem.animation.addByPrefix('selected', option + " white", 24);
menuItem.animation.play('idle');
menuItem.scale.set(0.8, 0.8);
if (option == "visual novel") {
menuItem.scale.set(0.7, 0.7);
menuItem.y += 8;
}
menuItem.updateHitbox();
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')}\nCommit ${funkin.backend.system.macros.GitCommitMacro.commitNumber} (${funkin.backend.system.macros.GitCommitMacro.commitHash})\n[TAB] Open Mods menu\n');
versionShit.y -= versionShit.height;
versionShit.scrollFactor.set();
add(versionShit);
changeItem();
}
var selectedSomethin:Bool = false;
override function update(elapsed:Float)
{
if (FlxG.sound.music.volume < 0.8)
FlxG.sound.music.volume += 0.5 * elapsed;
if (!selectedSomethin)
{
if (canAccessDebugMenus) {
if (FlxG.keys.justPressed.SEVEN) {
persistentUpdate = false;
persistentDraw = true;
openSubState(new funkin.editors.EditorPicker());
}
/*
if (FlxG.keys.justPressed.SEVEN)
FlxG.switchState(new funkin.desktop.DesktopMain());
if (FlxG.keys.justPressed.EIGHT) {
CoolUtil.safeSaveFile("chart.json", Json.stringify(funkin.backend.chart.Chart.parse("dadbattle", "hard")));
}
*/
}
if (controls.UP_P)
changeItem(-1);
if (controls.DOWN_P)
changeItem(1);
if (controls.BACK)
FlxG.switchState(new TitleState());
#if MOD_SUPPORT
if (controls.SWITCHMOD) {
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() {
selectedSomethin = true;
CoolUtil.playMenuSFX(CONFIRM);
if (Options.flashingMenu) FlxFlicker.flicker(magenta, 1.1, 0.15, false);
FlxFlicker.flicker(menuItems.members[curSelected], 1, Options.flashingMenu ? 0.06 : 0.15, false, false, function(flick:FlxFlicker)
{
var daChoice:String = optionShit[curSelected];
var event = event("onSelectItem", EventManager.get(NameEvent).recycle(daChoice));
if (event.cancelled) return;
switch (daChoice)
{
case 'story mode': FlxG.switchState(new StoryMenuState());
case 'visual novel': FlxG.switchState(new VisualNovel());
case 'freeplay': FlxG.switchState(new FreeplayState());
case 'donate': FlxG.switchState(new CreditsMain());
case 'options': FlxG.switchState(new OptionsMenu());
}
});
}
function changeItem(huh:Int = 0)
{
var event = event("onChangeItem", EventManager.get(MenuChangeEvent).recycle(curSelected, FlxMath.wrap(curSelected + huh, 0, menuItems.length-1), huh, huh != 0));
if (event.cancelled) return;
curSelected = event.value;
if (event.playMenuSFX)
CoolUtil.playMenuSFX(SCROLL, 0.7);
menuItems.forEach(function(spr:FlxSprite)
{
spr.animation.play('idle');
if (spr.ID == curSelected)
{
spr.animation.play('selected');
var mid = spr.getGraphicMidpoint();
camFollow.setPosition(mid.x, mid.y);
mid.put();
}
spr.updateHitbox();
spr.centerOffsets();
if (spr.ID == optionShit.indexOf("visual novel") && spr.ID == curSelected)
spr.offset.y += 26; // this sprite really weird -lunar
});
}
}