Funkin/source/MainMenuState.hx

233 lines
5.3 KiB
Haxe
Raw Normal View History

2020-10-31 21:11:14 -04:00
package;
import flixel.FlxG;
import flixel.FlxObject;
import flixel.FlxSprite;
2021-02-12 01:20:20 -05:00
import flixel.addons.transition.FlxTransitionableState;
2020-10-31 21:11:14 -04:00
import flixel.effects.FlxFlicker;
import flixel.graphics.frames.FlxAtlasFrames;
import flixel.group.FlxGroup.FlxTypedGroup;
2020-11-06 21:17:27 -05:00
import flixel.text.FlxText;
2020-10-31 21:11:14 -04:00
import flixel.tweens.FlxEase;
import flixel.tweens.FlxTween;
2020-11-06 21:17:27 -05:00
import flixel.util.FlxColor;
2020-12-15 22:00:22 -05:00
import io.newgrounds.NG;
2020-11-06 21:17:27 -05:00
import lime.app.Application;
2020-10-31 21:11:14 -04:00
2020-12-25 03:40:01 -05:00
using StringTools;
2020-10-31 21:11:14 -04:00
class MainMenuState extends MusicBeatState
{
var curSelected:Int = 0;
var menuItems:FlxTypedGroup<FlxSprite>;
2020-11-03 04:12:13 -05:00
#if !switch
2021-02-24 18:32:51 -05:00
var optionShit:Array<String> = ['story mode', 'freeplay', 'donate', 'options'];
2020-11-03 04:12:13 -05:00
#else
var optionShit:Array<String> = ['story mode', 'freeplay'];
#end
2020-10-31 21:11:14 -04:00
var magenta:FlxSprite;
var camFollow:FlxObject;
override function create()
{
2021-02-12 01:20:20 -05:00
transIn = FlxTransitionableState.defaultTransIn;
transOut = FlxTransitionableState.defaultTransOut;
if (!FlxG.sound.music.playing)
{
2021-02-08 16:34:48 -05:00
FlxG.sound.playMusic(Paths.music('freakyMenu'));
}
2020-10-31 21:11:14 -04:00
persistentUpdate = persistentDraw = true;
2021-02-08 16:34:48 -05:00
var bg:FlxSprite = new FlxSprite(-80).loadGraphic(Paths.image('menuBG'));
2020-10-31 21:11:14 -04:00
bg.scrollFactor.x = 0;
bg.scrollFactor.y = 0.17;
2020-10-31 21:11:14 -04:00
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);
2021-02-08 16:34:48 -05:00
magenta = new FlxSprite(-80).loadGraphic(Paths.image('menuDesat'));
2020-10-31 21:11:14 -04:00
magenta.scrollFactor.x = 0;
magenta.scrollFactor.y = 0.17;
2020-10-31 21:11:14 -04:00
magenta.setGraphicSize(Std.int(magenta.width * 1.1));
magenta.updateHitbox();
magenta.screenCenter();
magenta.visible = false;
magenta.antialiasing = true;
2020-11-06 21:17:27 -05:00
magenta.color = 0xFFfd719b;
2020-10-31 21:11:14 -04:00
add(magenta);
// magenta.scrollFactor.set();
menuItems = new FlxTypedGroup<FlxSprite>();
add(menuItems);
2021-02-08 16:34:48 -05:00
var tex = Paths.getSparrowAtlas('FNF_main_menu_assets');
2020-10-31 21:11:14 -04:00
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);
2020-12-13 02:45:36 -05:00
var versionShit:FlxText = new FlxText(5, FlxG.height - 18, 0, "v" + Application.current.meta.get('version'), 12);
2020-11-06 21:17:27 -05:00
versionShit.scrollFactor.set();
versionShit.setFormat("VCR OSD Mono", 16, FlxColor.WHITE, LEFT, FlxTextBorderStyle.OUTLINE, FlxColor.BLACK);
add(versionShit);
2020-12-25 00:17:21 -05:00
// NG.core.calls.event.logEvent('swag').send();
2020-12-15 22:00:22 -05:00
2020-10-31 21:11:14 -04:00
changeItem();
super.create();
}
2020-11-01 14:16:22 -05:00
var selectedSomethin:Bool = false;
2020-10-31 21:11:14 -04:00
override function update(elapsed:Float)
{
if (FlxG.sound.music.volume < 0.8)
{
FlxG.sound.music.volume += 0.5 * FlxG.elapsed;
}
2020-11-01 14:16:22 -05:00
if (!selectedSomethin)
2020-10-31 21:11:14 -04:00
{
2020-11-01 14:16:22 -05:00
if (controls.UP_P)
{
2021-02-08 16:34:48 -05:00
FlxG.sound.play(Paths.sound('scrollMenu'));
2020-11-01 14:16:22 -05:00
changeItem(-1);
}
2020-10-31 21:11:14 -04:00
2020-11-01 14:16:22 -05:00
if (controls.DOWN_P)
{
2021-02-08 16:34:48 -05:00
FlxG.sound.play(Paths.sound('scrollMenu'));
2020-11-01 14:16:22 -05:00
changeItem(1);
}
2020-10-31 21:11:14 -04:00
2020-11-01 14:16:22 -05:00
if (controls.BACK)
2020-10-31 21:11:14 -04:00
{
2020-11-01 14:16:22 -05:00
FlxG.switchState(new TitleState());
2020-10-31 21:11:14 -04:00
}
2020-11-01 14:16:22 -05:00
if (controls.ACCEPT)
2020-10-31 21:11:14 -04:00
{
2020-11-01 14:16:22 -05:00
if (optionShit[curSelected] == 'donate')
{
2020-11-24 22:53:48 -05:00
#if linux
Sys.command('/usr/bin/xdg-open', ["https://ninja-muffin24.itch.io/funkin", "&"]);
2020-11-24 22:53:48 -05:00
#else
2020-11-01 14:16:22 -05:00
FlxG.openURL('https://ninja-muffin24.itch.io/funkin');
2020-11-24 22:53:48 -05:00
#end
2020-11-01 14:16:22 -05:00
}
else
{
selectedSomethin = true;
2021-02-08 16:34:48 -05:00
FlxG.sound.play(Paths.sound('confirmMenu'));
2020-10-31 21:11:14 -04:00
2020-11-01 14:16:22 -05:00
FlxFlicker.flicker(magenta, 1.1, 0.15, false);
2020-10-31 21:11:14 -04:00
2020-11-01 14:16:22 -05:00
menuItems.forEach(function(spr:FlxSprite)
2020-10-31 21:11:14 -04:00
{
2020-11-01 14:16:22 -05:00
if (curSelected != spr.ID)
2020-10-31 21:11:14 -04:00
{
2020-11-01 14:16:22 -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 21:11:14 -04:00
{
2020-11-01 14:16:22 -05:00
var daChoice:String = optionShit[curSelected];
switch (daChoice)
{
case 'story mode':
FlxG.switchState(new StoryMenuState());
2020-11-07 15:52:21 -05:00
trace("Story Menu Selected");
2020-11-01 14:16:22 -05:00
case 'freeplay':
FlxG.switchState(new FreeplayState());
2020-11-25 03:22:22 -05:00
2020-11-07 15:52:21 -05:00
trace("Freeplay Menu Selected");
2020-11-25 03:22:22 -05:00
2020-11-06 21:17:27 -05:00
case 'options':
2021-02-24 18:32:51 -05:00
FlxTransitionableState.skipNextTransIn = true;
FlxTransitionableState.skipNextTransOut = true;
2020-11-06 21:17:27 -05:00
FlxG.switchState(new OptionsMenu());
2020-11-01 14:16:22 -05:00
}
});
}
});
}
2020-10-31 21:11:14 -04:00
}
}
2020-11-01 14:16:22 -05:00
super.update(elapsed);
2020-10-31 21:11:14 -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)
{
camFollow.setPosition(spr.getGraphicMidpoint().x, spr.getGraphicMidpoint().y);
spr.animation.play('selected');
2020-10-31 21:11:14 -04:00
}
spr.updateHitbox();
if(spr.animation.curAnim.name == 'selected')
{
switch(optionShit[curSelected])
{
case 'story mode':
spr.offset.y += 26;
case 'freeplay':
spr.offset.y += 28;
case 'donate':
spr.offset.y += 21;
case 'options':
spr.offset.y += 26;
}
}
2020-10-31 21:11:14 -04:00
});
}
}