1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2024-11-12 17:52:45 +00:00
Funkin/source/MainMenuState.hx
2021-02-15 11:43:51 -06:00

166 lines
4 KiB
Haxe

package;
import flixel.util.FlxTimer;
import flixel.FlxState;
import cpp.abi.Abi;
import flixel.FlxG;
import flixel.FlxObject;
import flixel.FlxSprite;
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 io.newgrounds.NG;
import lime.app.Application;
import ui.MenuItemList;
using StringTools;
class MainMenuState extends MusicBeatState
{
var menuItems:MenuItemList;
var magenta:FlxSprite;
var camFollow:FlxObject;
override function create()
{
transIn = FlxTransitionableState.defaultTransIn;
transOut = FlxTransitionableState.defaultTransOut;
if (!FlxG.sound.music.playing)
{
FlxG.sound.playMusic(Paths.music('freakyMenu'));
}
persistentUpdate = persistentDraw = true;
var bg:FlxSprite = new FlxSprite(-80).loadGraphic(Paths.image('menuBG'));
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(Paths.image('menuDesat'));
magenta.scrollFactor.x = 0;
magenta.scrollFactor.y = 0.18;
magenta.setGraphicSize(Std.int(magenta.width * 1.1));
magenta.updateHitbox();
magenta.screenCenter();
magenta.visible = false;
magenta.antialiasing = true;
magenta.color = 0xFFfd719b;
add(magenta);
// magenta.scrollFactor.set();
menuItems = new MenuItemList('FNF_main_menu_assets');
add(menuItems);
menuItems.onChange.add(onMenuItemChange);
menuItems.onAcceptPress.add(function(_)
{
FlxFlicker.flicker(magenta, 1.1, 0.15, false, true);
});
var hasPopupBlocker = #if web true #else false #end;
menuItems.addItem('story mode', function () startExitState(new StoryMenuState()));
menuItems.addItem('freeplay', function () startExitState(new FreeplayState()));
// addMenuItem('options', function () startExitState(new OptionMenu()));
#if (!switch)
menuItems.addItem('donate', selectDonate, hasPopupBlocker);
#end
#if newgrounds
if (NG.core.loggedIn)
menuItems.addItem("logout", selectLogout);
else
menuItems.addItem("login", selectLogin, hasPopupBlocker);
#end
// center vertically
var spacing = 160;
var top = (FlxG.height - (spacing * (menuItems.length - 1))) / 2;
for (i in 0...menuItems.length)
{
var menuItem = menuItems.members[i];
menuItem.x = FlxG.width / 2;
menuItem.y = top + spacing * i;
}
FlxG.camera.follow(camFollow, null, 0.06);
var versionShit:FlxText = new FlxText(5, FlxG.height - 18, 0, "v" + Application.current.meta.get('version'), 12);
versionShit.scrollFactor.set();
versionShit.setFormat("VCR OSD Mono", 16, FlxColor.WHITE, LEFT, FlxTextBorderStyle.OUTLINE, FlxColor.BLACK);
add(versionShit);
// NG.core.calls.event.logEvent('swag').send();
super.create();
}
function onMenuItemChange(selected:MenuItem)
{
camFollow.setPosition(selected.getGraphicMidpoint().x, selected.getGraphicMidpoint().y);
}
function selectDonate()
{
#if linux
Sys.command('/usr/bin/xdg-open', ["https://ninja-muffin24.itch.io/funkin", "&"]);
#else
FlxG.openURL('https://ninja-muffin24.itch.io/funkin');
#end
}
function selectLogin()
{
}
function selectLogout()
{
}
function startExitState(state:FlxState)
{
var duration = 0.4;
menuItems.forEach(function(item)
{
if (menuItems.selectedIndex != item.ID)
{
FlxTween.tween(item, {alpha: 0}, duration, { ease: FlxEase.quadOut });
}
else
{
item.visible = false;
}
});
new FlxTimer().start(duration, function(_) FlxG.switchState(state));
}
override function update(elapsed:Float)
{
if (FlxG.sound.music.volume < 0.8)
{
FlxG.sound.music.volume += 0.5 * FlxG.elapsed;
}
if (menuItems.active && controls.BACK)
FlxG.switchState(new TitleState());
super.update(elapsed);
}
}