Funkin/source/MainMenuState.hx

186 lines
4.3 KiB
Haxe
Raw Normal View History

2020-10-31 00:25:23 -04:00
package;
import flixel.FlxG;
import flixel.FlxObject;
import flixel.FlxSprite;
import flixel.effects.FlxFlicker;
import flixel.graphics.frames.FlxAtlasFrames;
import flixel.group.FlxGroup.FlxTypedGroup;
import flixel.text.FlxText;
2020-10-31 00:25:23 -04:00
import flixel.tweens.FlxEase;
import flixel.tweens.FlxTween;
import flixel.util.FlxColor;
import lime.app.Application;
2020-10-31 00:25:23 -04:00
class MainMenuState extends MusicBeatState
{
var curSelected:Int = 0;
var menuItems:FlxTypedGroup<FlxSprite>;
2020-11-06 06:17:40 -05:00
var optionShit:Array<String> = ['story mode', 'freeplay', 'donate'];
2020-10-31 00:25:23 -04:00
var magenta:FlxSprite;
var camFollow:FlxObject;
override function create()
{
persistentUpdate = persistentDraw = true;
var bg:FlxSprite = new FlxSprite(-80).loadGraphic(AssetPaths.menuBG__png);
bg.scrollFactor.x = 0;
bg.scrollFactor.y = 0.18;
bg.setGraphicSize(Std.int(bg.width * 1.1));
bg.updateHitbox();
bg.screenCenter();
bg.antialiasing = true;
add(bg);
camFollow = new FlxObject(0, 0, 1, 1);
add(camFollow);
magenta = new FlxSprite(-80).loadGraphic(AssetPaths.menuDesat__png);
2020-10-31 06:07:22 -04:00
magenta.scrollFactor.x = 0;
magenta.scrollFactor.y = 0.18;
magenta.setGraphicSize(Std.int(magenta.width * 1.1));
magenta.updateHitbox();
magenta.screenCenter();
2020-10-31 00:25:23 -04:00
magenta.visible = false;
2020-10-31 06:07:22 -04:00
magenta.antialiasing = true;
magenta.color = 0xFFfd719b;
2020-10-31 00:25:23 -04:00
add(magenta);
2020-10-31 06:07:22 -04:00
// magenta.scrollFactor.set();
2020-10-31 00:25:23 -04:00
menuItems = new FlxTypedGroup<FlxSprite>();
add(menuItems);
var tex = FlxAtlasFrames.fromSparrow(AssetPaths.FNF_main_menu_assets__png, AssetPaths.FNF_main_menu_assets__xml);
for (i in 0...optionShit.length)
{
var menuItem:FlxSprite = new FlxSprite(0, 60 + (i * 160));
menuItem.frames = tex;
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:FlxText = new FlxText(5, FlxG.height - 18, 0, "v" + Application.current.meta.get('version'));
versionShit.scrollFactor.set();
versionShit.setFormat("VCR OSD Mono", 16, FlxColor.WHITE, LEFT, FlxTextBorderStyle.OUTLINE, FlxColor.BLACK);
add(versionShit);
2020-10-31 00:25:23 -04:00
changeItem();
super.create();
}
2020-11-01 04:55:02 -05:00
var selectedSomethin:Bool = false;
2020-10-31 00:25:23 -04:00
override function update(elapsed:Float)
{
2020-11-01 04:55:02 -05:00
if (!selectedSomethin)
2020-10-31 15:53:58 -04:00
{
2020-11-01 04:55:02 -05:00
if (controls.UP_P)
{
FlxG.sound.play('assets/sounds/scrollMenu' + TitleState.soundExt);
changeItem(-1);
}
2020-10-31 00:25:23 -04:00
2020-11-01 04:55:02 -05:00
if (controls.DOWN_P)
{
FlxG.sound.play('assets/sounds/scrollMenu' + TitleState.soundExt);
changeItem(1);
}
2020-10-31 00:25:23 -04:00
2020-11-01 04:55:02 -05:00
if (controls.BACK)
2020-10-31 00:25:23 -04:00
{
2020-11-01 04:55:02 -05:00
FlxG.switchState(new TitleState());
2020-10-31 00:25:23 -04:00
}
2020-11-01 04:55:02 -05:00
if (controls.ACCEPT)
2020-10-31 00:25:23 -04:00
{
2020-11-01 04:55:02 -05:00
if (optionShit[curSelected] == 'donate')
{
FlxG.openURL('https://ninja-muffin24.itch.io/funkin');
}
else
{
selectedSomethin = true;
FlxG.sound.play('assets/sounds/confirmMenu' + TitleState.soundExt);
2020-10-31 15:53:58 -04:00
2020-11-01 04:55:02 -05:00
FlxFlicker.flicker(magenta, 1.1, 0.15, false);
2020-10-31 00:25:23 -04:00
2020-11-01 04:55:02 -05:00
menuItems.forEach(function(spr:FlxSprite)
2020-10-31 00:25:23 -04:00
{
2020-11-01 04:55:02 -05:00
if (curSelected != spr.ID)
2020-10-31 00:25:23 -04:00
{
2020-11-01 04:55:02 -05:00
FlxTween.tween(spr, {alpha: 0}, 0.4, {
ease: FlxEase.quadOut,
onComplete: function(twn:FlxTween)
{
spr.kill();
}
});
}
else
{
FlxFlicker.flicker(spr, 1, 0.06, false, false, function(flick:FlxFlicker)
2020-10-31 00:25:23 -04:00
{
2020-11-01 04:55:02 -05:00
var daChoice:String = optionShit[curSelected];
switch (daChoice)
{
case 'story mode':
FlxG.switchState(new StoryMenuState());
case 'freeplay':
FlxG.switchState(new FreeplayState());
case 'options':
FlxG.switchState(new OptionsMenu());
2020-11-01 04:55:02 -05:00
}
});
}
});
}
2020-10-31 00:25:23 -04:00
}
}
2020-11-01 04:55:02 -05:00
super.update(elapsed);
2020-10-31 00:25:23 -04:00
menuItems.forEach(function(spr:FlxSprite)
{
spr.screenCenter(X);
});
}
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();
});
}
}