2020-10-31 21:11:14 -04:00
|
|
|
package;
|
|
|
|
|
2021-02-18 14:58:16 -05:00
|
|
|
import NGio;
|
|
|
|
import flixel.ui.FlxButton;
|
2020-10-31 21:11:14 -04:00
|
|
|
import flixel.FlxG;
|
|
|
|
import flixel.FlxObject;
|
|
|
|
import flixel.FlxSprite;
|
2021-02-15 17:04:08 -05:00
|
|
|
import flixel.FlxState;
|
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;
|
2021-02-15 17:04:08 -05:00
|
|
|
import flixel.util.FlxTimer;
|
2020-11-06 21:17:27 -05:00
|
|
|
import lime.app.Application;
|
2020-10-31 21:11:14 -04:00
|
|
|
|
2021-02-19 23:10:16 -05:00
|
|
|
#if newgrounds
|
|
|
|
import io.newgrounds.NG;
|
|
|
|
#end
|
|
|
|
|
2021-02-15 12:43:51 -05:00
|
|
|
import ui.MenuItemList;
|
2021-02-18 14:58:16 -05:00
|
|
|
import ui.Prompt;
|
2021-02-19 23:10:16 -05:00
|
|
|
import ui.NgPrompt;
|
2021-02-15 12:43:51 -05:00
|
|
|
|
2020-12-25 03:40:01 -05:00
|
|
|
using StringTools;
|
|
|
|
|
2020-10-31 21:11:14 -04:00
|
|
|
class MainMenuState extends MusicBeatState
|
|
|
|
{
|
2021-02-18 14:58:16 -05:00
|
|
|
var menuItems:MainMenuItemList;
|
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;
|
|
|
|
|
2020-12-09 19:47:28 -05:00
|
|
|
if (!FlxG.sound.music.playing)
|
|
|
|
{
|
2021-02-08 16:34:48 -05:00
|
|
|
FlxG.sound.playMusic(Paths.music('freakyMenu'));
|
2020-12-09 19:47:28 -05:00
|
|
|
}
|
|
|
|
|
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.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);
|
|
|
|
|
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.18;
|
|
|
|
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();
|
|
|
|
|
2021-02-18 14:58:16 -05:00
|
|
|
menuItems = new MainMenuItemList('FNF_main_menu_assets');
|
2020-10-31 21:11:14 -04:00
|
|
|
add(menuItems);
|
2021-02-15 12:43:51 -05:00
|
|
|
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;
|
|
|
|
|
2021-02-18 14:58:16 -05:00
|
|
|
menuItems.enabled = false;// disable for intro
|
|
|
|
menuItems.createItem('story mode', function () startExitState(new StoryMenuState()));
|
|
|
|
menuItems.createItem('freeplay', function () startExitState(new FreeplayState()));
|
2021-02-15 12:43:51 -05:00
|
|
|
// addMenuItem('options', function () startExitState(new OptionMenu()));
|
2021-02-19 21:11:33 -05:00
|
|
|
#if CAN_OPEN_LINKS
|
2021-02-18 14:58:16 -05:00
|
|
|
menuItems.createItem('donate', selectDonate, hasPopupBlocker);
|
2021-02-15 12:43:51 -05:00
|
|
|
#end
|
|
|
|
#if newgrounds
|
2021-02-19 21:11:33 -05:00
|
|
|
if (NGio.isLoggedIn)
|
2021-02-18 14:58:16 -05:00
|
|
|
menuItems.createItem("logout", selectLogout);
|
2021-02-15 12:43:51 -05:00
|
|
|
else
|
2021-02-18 14:58:16 -05:00
|
|
|
menuItems.createItem("login", selectLogin);
|
2021-02-15 12:43:51 -05:00
|
|
|
#end
|
|
|
|
|
|
|
|
// center vertically
|
|
|
|
var spacing = 160;
|
|
|
|
var top = (FlxG.height - (spacing * (menuItems.length - 1))) / 2;
|
|
|
|
for (i in 0...menuItems.length)
|
2020-10-31 21:11:14 -04:00
|
|
|
{
|
2021-02-15 12:43:51 -05:00
|
|
|
var menuItem = menuItems.members[i];
|
|
|
|
menuItem.x = FlxG.width / 2;
|
|
|
|
menuItem.y = top + spacing * i;
|
2020-10-31 21:11:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
super.create();
|
|
|
|
}
|
2021-02-15 12:43:51 -05:00
|
|
|
|
2021-02-18 14:58:16 -05:00
|
|
|
override function finishTransIn()
|
|
|
|
{
|
|
|
|
super.finishTransIn();
|
|
|
|
|
|
|
|
menuItems.enabled = true;
|
|
|
|
|
2021-02-19 21:11:33 -05:00
|
|
|
#if newgrounds
|
2021-02-18 14:58:16 -05:00
|
|
|
if (NGio.savedSessionFailed)
|
|
|
|
showSavedSessionFailed();
|
2021-02-19 21:11:33 -05:00
|
|
|
#end
|
2021-02-18 14:58:16 -05:00
|
|
|
}
|
|
|
|
|
2021-02-15 12:43:51 -05:00
|
|
|
function onMenuItemChange(selected:MenuItem)
|
2020-10-31 21:11:14 -04:00
|
|
|
{
|
2021-02-15 12:43:51 -05:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2021-02-18 14:58:16 -05:00
|
|
|
#if newgrounds
|
2021-02-15 12:43:51 -05:00
|
|
|
function selectLogin()
|
|
|
|
{
|
2021-02-19 23:10:16 -05:00
|
|
|
openPrompt(NgPrompt.showLogin(),
|
|
|
|
function onPromptClose() menuItems.resetItem("login", "logout", selectLogout)
|
|
|
|
);
|
2021-02-18 14:58:16 -05:00
|
|
|
}
|
|
|
|
|
2021-02-19 23:10:16 -05:00
|
|
|
function selectLogout()
|
2021-02-18 14:58:16 -05:00
|
|
|
{
|
2021-02-19 23:10:16 -05:00
|
|
|
openPrompt(NgPrompt.showLogout(),
|
|
|
|
function onPromptClose() menuItems.resetItem("logout", "login", selectLogin)
|
2021-02-18 14:58:16 -05:00
|
|
|
);
|
2021-02-15 12:43:51 -05:00
|
|
|
}
|
|
|
|
|
2021-02-19 23:10:16 -05:00
|
|
|
function showSavedSessionFailed()
|
2021-02-15 12:43:51 -05:00
|
|
|
{
|
2021-02-19 23:10:16 -05:00
|
|
|
openPrompt(NgPrompt.showSavedSessionFailed(),
|
|
|
|
function onPromptClose() menuItems.resetItem("login", "logout", selectLogout)
|
|
|
|
);
|
2021-02-15 12:43:51 -05:00
|
|
|
}
|
2021-02-19 23:10:16 -05:00
|
|
|
#end
|
2021-02-19 21:11:33 -05:00
|
|
|
|
2021-02-19 23:10:16 -05:00
|
|
|
public function openPrompt(prompt:Prompt, onClose:Void->Void)
|
2021-02-19 21:11:33 -05:00
|
|
|
{
|
|
|
|
menuItems.enabled = false;
|
|
|
|
prompt.closeCallback = function ()
|
|
|
|
{
|
|
|
|
menuItems.enabled = true;
|
2021-02-19 23:10:16 -05:00
|
|
|
if (onClose != null)
|
|
|
|
onClose();
|
2021-02-19 21:11:33 -05:00
|
|
|
}
|
|
|
|
|
2021-02-19 23:10:16 -05:00
|
|
|
openSubState(prompt);
|
2021-02-19 21:11:33 -05:00
|
|
|
}
|
2021-02-15 12:43:51 -05:00
|
|
|
|
|
|
|
function startExitState(state:FlxState)
|
|
|
|
{
|
|
|
|
var duration = 0.4;
|
|
|
|
menuItems.forEach(function(item)
|
2020-10-31 21:11:14 -04:00
|
|
|
{
|
2021-02-15 12:43:51 -05:00
|
|
|
if (menuItems.selectedIndex != item.ID)
|
2020-10-31 21:11:14 -04:00
|
|
|
{
|
2021-02-15 12:43:51 -05:00
|
|
|
FlxTween.tween(item, {alpha: 0}, duration, { ease: FlxEase.quadOut });
|
2020-10-31 21:11:14 -04:00
|
|
|
}
|
2021-02-15 12:43:51 -05:00
|
|
|
else
|
2020-10-31 21:11:14 -04:00
|
|
|
{
|
2021-02-15 12:43:51 -05:00
|
|
|
item.visible = false;
|
2020-10-31 21:11:14 -04:00
|
|
|
}
|
|
|
|
});
|
2021-02-15 12:43:51 -05:00
|
|
|
|
|
|
|
new FlxTimer().start(duration, function(_) FlxG.switchState(state));
|
2020-10-31 21:11:14 -04:00
|
|
|
}
|
|
|
|
|
2021-02-15 12:43:51 -05:00
|
|
|
override function update(elapsed:Float)
|
2020-10-31 21:11:14 -04:00
|
|
|
{
|
2021-02-15 12:43:51 -05:00
|
|
|
if (FlxG.sound.music.volume < 0.8)
|
2020-10-31 21:11:14 -04:00
|
|
|
{
|
2021-02-15 12:43:51 -05:00
|
|
|
FlxG.sound.music.volume += 0.5 * FlxG.elapsed;
|
|
|
|
}
|
2020-10-31 21:11:14 -04:00
|
|
|
|
2021-02-18 14:58:16 -05:00
|
|
|
if (menuItems.enabled && controls.BACK)
|
2021-02-15 12:43:51 -05:00
|
|
|
FlxG.switchState(new TitleState());
|
2020-10-31 21:11:14 -04:00
|
|
|
|
2021-02-15 12:43:51 -05:00
|
|
|
super.update(elapsed);
|
2020-10-31 21:11:14 -04:00
|
|
|
}
|
|
|
|
}
|
2021-02-18 14:58:16 -05:00
|
|
|
|
|
|
|
private class MainMenuItemList extends MenuTypedItemList<MainMenuItem>
|
|
|
|
{
|
|
|
|
public var atlas:FlxAtlasFrames;
|
|
|
|
|
|
|
|
public function new (atlas)
|
|
|
|
{
|
|
|
|
super(Vertical);
|
|
|
|
|
|
|
|
if (Std.is(atlas, String))
|
|
|
|
this.atlas = Paths.getSparrowAtlas(cast atlas);
|
|
|
|
else
|
|
|
|
this.atlas = cast atlas;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function createItem(x = 0.0, y = 0.0, name:String, callback, fireInstantly = false)
|
|
|
|
{
|
|
|
|
var i = length;
|
|
|
|
var item = new MainMenuItem(x, y, name, atlas, callback);
|
|
|
|
item.fireInstantly = fireInstantly;
|
|
|
|
item.ID = i;
|
|
|
|
|
|
|
|
return addItem(name, item);
|
|
|
|
}
|
|
|
|
|
|
|
|
override function destroy()
|
|
|
|
{
|
|
|
|
super.destroy();
|
|
|
|
atlas = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private class MainMenuItem extends MenuItem
|
|
|
|
{
|
|
|
|
public function new(x = 0.0, y = 0.0, name, atlas, callback)
|
|
|
|
{
|
|
|
|
super(x, y, name, atlas, callback);
|
|
|
|
scrollFactor.set();
|
|
|
|
}
|
|
|
|
|
|
|
|
override function changeAnim(anim:String)
|
|
|
|
{
|
|
|
|
super.changeAnim(anim);
|
|
|
|
// position by center
|
|
|
|
centerOrigin();
|
|
|
|
offset.copyFrom(origin);
|
|
|
|
}
|
|
|
|
}
|