2022-03-08 03:13:53 -05:00
|
|
|
package funkin;
|
2020-10-31 21:11:14 -04:00
|
|
|
|
|
|
|
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;
|
2021-08-23 18:52:38 -04:00
|
|
|
import flixel.input.touch.FlxTouch;
|
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;
|
2021-03-26 21:22:07 -04:00
|
|
|
import flixel.ui.FlxButton;
|
2020-11-06 21:17:27 -05:00
|
|
|
import flixel.util.FlxColor;
|
2021-02-15 17:04:08 -05:00
|
|
|
import flixel.util.FlxTimer;
|
2022-04-15 17:11:01 -04:00
|
|
|
import funkin.NGio;
|
|
|
|
import funkin.modding.events.ScriptEvent.UpdateScriptEvent;
|
|
|
|
import funkin.modding.module.ModuleHandler;
|
2022-03-08 03:13:53 -05:00
|
|
|
import funkin.shaderslmfao.ScreenWipeShader;
|
|
|
|
import funkin.ui.AtlasMenuList;
|
|
|
|
import funkin.ui.MenuList;
|
|
|
|
import funkin.ui.OptionsState;
|
|
|
|
import funkin.ui.PreferencesMenu;
|
|
|
|
import funkin.ui.Prompt;
|
2022-04-15 17:11:01 -04:00
|
|
|
import funkin.util.Constants;
|
|
|
|
import lime.app.Application;
|
|
|
|
import openfl.filters.ShaderFilter;
|
2021-03-26 21:22:07 -04:00
|
|
|
|
|
|
|
using StringTools;
|
2020-10-31 21:11:14 -04:00
|
|
|
|
2021-03-30 00:05:21 -04:00
|
|
|
#if discord_rpc
|
2021-03-23 00:05:46 -04:00
|
|
|
import Discord.DiscordClient;
|
|
|
|
#end
|
2021-02-19 23:10:16 -05:00
|
|
|
#if newgrounds
|
2022-03-08 03:13:53 -05:00
|
|
|
import funkin.ui.NgPrompt;
|
2022-04-15 17:11:01 -04:00
|
|
|
import io.newgrounds.NG;
|
2021-02-19 23:10:16 -05:00
|
|
|
#end
|
|
|
|
|
2020-10-31 21:11:14 -04:00
|
|
|
class MainMenuState extends MusicBeatState
|
|
|
|
{
|
2021-02-21 13:08:30 -05:00
|
|
|
var menuItems:MainMenuList;
|
2020-10-31 21:11:14 -04:00
|
|
|
|
|
|
|
var magenta:FlxSprite;
|
|
|
|
var camFollow:FlxObject;
|
|
|
|
|
|
|
|
override function create()
|
|
|
|
{
|
2021-03-22 10:09:46 -04:00
|
|
|
#if discord_rpc
|
2021-02-27 19:34:49 -05:00
|
|
|
// Updating Discord Rich Presence
|
|
|
|
DiscordClient.changePresence("In the Menus", null);
|
|
|
|
#end
|
|
|
|
|
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-03-22 09:40:32 -04:00
|
|
|
var bg:FlxSprite = new FlxSprite(Paths.image('menuBG'));
|
2020-10-31 21:11:14 -04:00
|
|
|
bg.scrollFactor.x = 0;
|
2021-03-22 23:41:37 -04:00
|
|
|
bg.scrollFactor.y = 0.17;
|
|
|
|
bg.setGraphicSize(Std.int(bg.width * 1.2));
|
2020-10-31 21:11:14 -04:00
|
|
|
bg.updateHitbox();
|
|
|
|
bg.screenCenter();
|
|
|
|
bg.antialiasing = true;
|
|
|
|
add(bg);
|
|
|
|
|
|
|
|
camFollow = new FlxObject(0, 0, 1, 1);
|
|
|
|
add(camFollow);
|
|
|
|
|
2021-03-22 09:40:32 -04:00
|
|
|
magenta = new FlxSprite(Paths.image('menuDesat'));
|
|
|
|
magenta.scrollFactor.x = bg.scrollFactor.x;
|
|
|
|
magenta.scrollFactor.y = bg.scrollFactor.y;
|
|
|
|
magenta.setGraphicSize(Std.int(bg.width));
|
2020-10-31 21:11:14 -04:00
|
|
|
magenta.updateHitbox();
|
2021-03-22 09:40:32 -04:00
|
|
|
magenta.x = bg.x;
|
|
|
|
magenta.y = bg.y;
|
2020-10-31 21:11:14 -04:00
|
|
|
magenta.visible = false;
|
|
|
|
magenta.antialiasing = true;
|
2020-11-06 21:17:27 -05:00
|
|
|
magenta.color = 0xFFfd719b;
|
2021-03-26 21:22:07 -04:00
|
|
|
if (PreferencesMenu.preferences.get('flashing-menu'))
|
|
|
|
add(magenta);
|
2020-10-31 21:11:14 -04:00
|
|
|
// magenta.scrollFactor.set();
|
|
|
|
|
2021-02-21 13:08:30 -05:00
|
|
|
menuItems = new MainMenuList();
|
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(_)
|
|
|
|
{
|
2021-12-06 00:50:50 -05:00
|
|
|
if (_.name == 'freeplay')
|
|
|
|
{
|
|
|
|
magenta.visible = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FlxFlicker.flicker(magenta, 1.1, 0.15, false, true);
|
|
|
|
}
|
2021-02-15 12:43:51 -05:00
|
|
|
});
|
2021-03-26 21:22:07 -04:00
|
|
|
|
2022-04-15 17:11:01 -04:00
|
|
|
menuItems.enabled = true; // can move on intro
|
2021-03-26 21:22:07 -04:00
|
|
|
menuItems.createItem('story mode', function() startExitState(new StoryMenuState()));
|
2021-12-04 20:24:53 -05:00
|
|
|
menuItems.createItem('freeplay', function()
|
|
|
|
{
|
|
|
|
persistentDraw = true;
|
|
|
|
persistentUpdate = false;
|
|
|
|
openSubState(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-03-26 21:22:07 -04:00
|
|
|
var hasPopupBlocker = #if web true #else false #end;
|
2021-04-10 02:53:23 -04:00
|
|
|
|
|
|
|
if (VideoState.seenVideo)
|
|
|
|
menuItems.createItem('kickstarter', selectDonate, hasPopupBlocker);
|
|
|
|
else
|
|
|
|
menuItems.createItem('donate', selectDonate, hasPopupBlocker);
|
2021-02-15 12:43:51 -05:00
|
|
|
#end
|
2021-03-26 21:22:07 -04:00
|
|
|
menuItems.createItem('options', function() startExitState(new OptionsState()));
|
2021-02-23 19:59:36 -05:00
|
|
|
// #if newgrounds
|
|
|
|
// if (NGio.isLoggedIn)
|
|
|
|
// menuItems.createItem("logout", selectLogout);
|
|
|
|
// else
|
|
|
|
// menuItems.createItem("login", selectLogin);
|
|
|
|
// #end
|
2021-03-26 21:22:07 -04:00
|
|
|
|
2021-02-15 12:43:51 -05:00
|
|
|
// 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
|
|
|
}
|
|
|
|
|
2021-05-06 08:08:51 -04:00
|
|
|
FlxG.cameras.reset(new SwagCamera());
|
2020-10-31 21:11:14 -04:00
|
|
|
FlxG.camera.follow(camFollow, null, 0.06);
|
2021-03-22 23:41:37 -04:00
|
|
|
// FlxG.camera.setScrollBounds(bg.x, bg.x + bg.width, bg.y, bg.y + bg.height * 1.2);
|
2020-10-31 21:11:14 -04:00
|
|
|
|
2022-03-13 14:36:03 -04:00
|
|
|
super.create();
|
2022-01-26 00:41:14 -05:00
|
|
|
|
2022-03-13 14:36:03 -04:00
|
|
|
// This has to come AFTER!
|
|
|
|
this.leftWatermarkText.text = Constants.VERSION;
|
|
|
|
this.rightWatermarkText.text = "blablabla test";
|
2020-11-06 21:17:27 -05:00
|
|
|
|
2022-03-13 14:36:03 -04:00
|
|
|
// var versionStr = 'v${Application.current.meta.get('version')}';
|
|
|
|
// versionStr += ' (secret week 8 build do not leak)';
|
|
|
|
//
|
|
|
|
// var versionShit:FlxText = new FlxText(5, FlxG.height - 18, 0, versionStr, 12);
|
|
|
|
// versionShit.scrollFactor.set();
|
|
|
|
// versionShit.setFormat("VCR OSD Mono", 16, FlxColor.WHITE, LEFT, FlxTextBorderStyle.OUTLINE, FlxColor.BLACK);
|
|
|
|
// add(versionShit);
|
2020-12-15 22:00:22 -05:00
|
|
|
|
2022-03-13 14:36:03 -04:00
|
|
|
// NG.core.calls.event.logEvent('swag').send();
|
2020-10-31 21:11:14 -04:00
|
|
|
}
|
2021-03-26 21:22:07 -04:00
|
|
|
|
2021-12-06 00:50:50 -05:00
|
|
|
override function closeSubState()
|
|
|
|
{
|
|
|
|
magenta.visible = false;
|
|
|
|
|
|
|
|
super.closeSubState();
|
|
|
|
}
|
|
|
|
|
2021-02-18 14:58:16 -05:00
|
|
|
override function finishTransIn()
|
|
|
|
{
|
|
|
|
super.finishTransIn();
|
2021-03-26 21:22:07 -04:00
|
|
|
|
2022-04-15 17:11:01 -04:00
|
|
|
// menuItems.enabled = true;
|
2021-03-26 21:22:07 -04:00
|
|
|
|
2021-02-21 13:08:30 -05:00
|
|
|
// #if newgrounds
|
|
|
|
// if (NGio.savedSessionFailed)
|
|
|
|
// showSavedSessionFailed();
|
|
|
|
// #end
|
2021-02-18 14:58:16 -05:00
|
|
|
}
|
2021-03-26 21:22:07 -04: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);
|
|
|
|
}
|
2021-03-26 21:22:07 -04:00
|
|
|
|
2021-03-13 21:11:56 -05:00
|
|
|
#if CAN_OPEN_LINKS
|
2021-02-15 12:43:51 -05:00
|
|
|
function selectDonate()
|
|
|
|
{
|
|
|
|
#if linux
|
2021-04-09 16:37:54 -04:00
|
|
|
// Sys.command('/usr/bin/xdg-open', ["https://ninja-muffin24.itch.io/funkin", "&"]);
|
2021-04-19 02:46:02 -04:00
|
|
|
Sys.command('/usr/bin/xdg-open', [
|
|
|
|
"https://www.kickstarter.com/projects/funkin/friday-night-funkin-the-full-ass-game/",
|
|
|
|
"&"
|
|
|
|
]);
|
2021-02-15 12:43:51 -05:00
|
|
|
#else
|
2021-04-09 16:37:54 -04:00
|
|
|
// FlxG.openURL('https://ninja-muffin24.itch.io/funkin');
|
|
|
|
|
2021-04-19 02:46:02 -04:00
|
|
|
FlxG.openURL('https://www.kickstarter.com/projects/funkin/friday-night-funkin-the-full-ass-game/');
|
2021-02-15 12:43:51 -05:00
|
|
|
#end
|
|
|
|
}
|
2021-03-13 21:11:56 -05:00
|
|
|
#end
|
2021-03-26 21:22:07 -04:00
|
|
|
|
2021-02-18 14:58:16 -05:00
|
|
|
#if newgrounds
|
2021-02-15 12:43:51 -05:00
|
|
|
function selectLogin()
|
|
|
|
{
|
2021-02-21 13:08:30 -05:00
|
|
|
openNgPrompt(NgPrompt.showLogin());
|
2021-02-18 14:58:16 -05:00
|
|
|
}
|
2021-03-26 21:22:07 -04:00
|
|
|
|
2021-02-19 23:10:16 -05:00
|
|
|
function selectLogout()
|
2021-02-18 14:58:16 -05:00
|
|
|
{
|
2021-02-21 13:08:30 -05:00
|
|
|
openNgPrompt(NgPrompt.showLogout());
|
2021-02-15 12:43:51 -05:00
|
|
|
}
|
2021-03-26 21:22:07 -04:00
|
|
|
|
2021-02-19 23:10:16 -05:00
|
|
|
function showSavedSessionFailed()
|
2021-02-15 12:43:51 -05:00
|
|
|
{
|
2021-02-21 13:08:30 -05:00
|
|
|
openNgPrompt(NgPrompt.showSavedSessionFailed());
|
|
|
|
}
|
2021-03-26 21:22:07 -04:00
|
|
|
|
2021-02-21 13:08:30 -05:00
|
|
|
/**
|
|
|
|
* Calls openPrompt and redraws the login/logout button
|
|
|
|
* @param prompt
|
|
|
|
* @param onClose
|
|
|
|
*/
|
|
|
|
public function openNgPrompt(prompt:Prompt, ?onClose:Void->Void)
|
|
|
|
{
|
|
|
|
var onPromptClose = checkLoginStatus;
|
|
|
|
if (onClose != null)
|
|
|
|
{
|
2021-03-26 21:22:07 -04:00
|
|
|
onPromptClose = function()
|
2021-02-21 13:08:30 -05:00
|
|
|
{
|
|
|
|
checkLoginStatus();
|
|
|
|
onClose();
|
|
|
|
}
|
|
|
|
}
|
2021-03-26 21:22:07 -04:00
|
|
|
|
2021-02-21 13:08:30 -05:00
|
|
|
openPrompt(prompt, onPromptClose);
|
|
|
|
}
|
2021-03-26 21:22:07 -04:00
|
|
|
|
2021-02-21 13:08:30 -05:00
|
|
|
function checkLoginStatus()
|
|
|
|
{
|
|
|
|
var prevLoggedIn = menuItems.has("logout");
|
|
|
|
if (prevLoggedIn && !NGio.isLoggedIn)
|
|
|
|
menuItems.resetItem("login", "logout", selectLogout);
|
|
|
|
else if (!prevLoggedIn && NGio.isLoggedIn)
|
|
|
|
menuItems.resetItem("logout", "login", selectLogin);
|
2021-02-15 12:43:51 -05:00
|
|
|
}
|
2021-02-19 23:10:16 -05:00
|
|
|
#end
|
2021-03-26 21:22:07 -04: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;
|
2021-03-26 21:22:07 -04:00
|
|
|
prompt.closeCallback = function()
|
2021-02-19 21:11:33 -05:00
|
|
|
{
|
|
|
|
menuItems.enabled = true;
|
2021-02-19 23:10:16 -05:00
|
|
|
if (onClose != null)
|
|
|
|
onClose();
|
2021-02-19 21:11:33 -05:00
|
|
|
}
|
2021-03-26 21:22:07 -04:00
|
|
|
|
2021-02-19 23:10:16 -05:00
|
|
|
openSubState(prompt);
|
2021-02-19 21:11:33 -05:00
|
|
|
}
|
2021-03-26 21:22:07 -04:00
|
|
|
|
2021-02-15 12:43:51 -05:00
|
|
|
function startExitState(state:FlxState)
|
|
|
|
{
|
2021-03-30 14:52:24 -04:00
|
|
|
menuItems.enabled = false; // disable for exit
|
2021-02-15 12:43:51 -05:00
|
|
|
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-03-26 21:22:07 -04: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-03-26 21:22:07 -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
|
|
|
{
|
2022-03-11 01:30:01 -05:00
|
|
|
super.update(elapsed);
|
|
|
|
|
2021-08-23 18:52:38 -04:00
|
|
|
if (FlxG.onMobile)
|
|
|
|
{
|
|
|
|
var touch:FlxTouch = FlxG.touches.getFirst();
|
|
|
|
|
|
|
|
if (touch != null)
|
|
|
|
{
|
|
|
|
for (item in menuItems)
|
|
|
|
{
|
|
|
|
if (touch.overlaps(item))
|
|
|
|
{
|
|
|
|
if (menuItems.selectedIndex == item.ID && touch.justPressed)
|
|
|
|
menuItems.accept();
|
|
|
|
else
|
|
|
|
menuItems.selectItem(item.ID);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-06 08:08:51 -04:00
|
|
|
// FlxG.camera.followLerp = CoolUtil.camLerpShit(0.06);
|
2021-04-04 13:17:46 -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
|
|
|
{
|
2022-03-13 14:36:03 -04:00
|
|
|
FlxG.sound.music.volume += 0.5 * elapsed;
|
2021-02-15 12:43:51 -05:00
|
|
|
}
|
2020-10-31 21:11:14 -04:00
|
|
|
|
2021-03-30 14:52:24 -04:00
|
|
|
if (_exiting)
|
|
|
|
menuItems.enabled = false;
|
|
|
|
|
|
|
|
if (controls.BACK && menuItems.enabled && !menuItems.busy)
|
2021-04-22 15:36:56 -04:00
|
|
|
{
|
|
|
|
FlxG.sound.play(Paths.sound('cancelMenu'));
|
2021-02-15 12:43:51 -05:00
|
|
|
FlxG.switchState(new TitleState());
|
2021-04-22 15:36:56 -04:00
|
|
|
}
|
2020-10-31 21:11:14 -04:00
|
|
|
}
|
|
|
|
}
|
2021-02-18 14:58:16 -05:00
|
|
|
|
2021-02-21 13:08:30 -05:00
|
|
|
private class MainMenuList extends MenuTypedList<MainMenuItem>
|
2021-02-18 14:58:16 -05:00
|
|
|
{
|
|
|
|
public var atlas:FlxAtlasFrames;
|
2021-03-26 21:22:07 -04:00
|
|
|
|
|
|
|
public function new()
|
2021-02-18 14:58:16 -05:00
|
|
|
{
|
2021-02-21 13:08:30 -05:00
|
|
|
atlas = Paths.getSparrowAtlas('main_menu');
|
2021-02-18 14:58:16 -05:00
|
|
|
super(Vertical);
|
|
|
|
}
|
2021-03-26 21:22:07 -04:00
|
|
|
|
2021-02-18 14:58:16 -05:00
|
|
|
public function createItem(x = 0.0, y = 0.0, name:String, callback, fireInstantly = false)
|
|
|
|
{
|
|
|
|
var item = new MainMenuItem(x, y, name, atlas, callback);
|
|
|
|
item.fireInstantly = fireInstantly;
|
2021-02-21 13:08:30 -05:00
|
|
|
item.ID = length;
|
2021-03-26 21:22:07 -04:00
|
|
|
|
2021-02-18 14:58:16 -05:00
|
|
|
return addItem(name, item);
|
|
|
|
}
|
2021-03-26 21:22:07 -04:00
|
|
|
|
2021-02-18 14:58:16 -05:00
|
|
|
override function destroy()
|
|
|
|
{
|
|
|
|
super.destroy();
|
|
|
|
atlas = null;
|
|
|
|
}
|
|
|
|
}
|
2021-03-26 21:22:07 -04:00
|
|
|
|
2021-02-21 13:08:30 -05:00
|
|
|
private class MainMenuItem extends AtlasMenuItem
|
2021-02-18 14:58:16 -05:00
|
|
|
{
|
|
|
|
public function new(x = 0.0, y = 0.0, name, atlas, callback)
|
|
|
|
{
|
|
|
|
super(x, y, name, atlas, callback);
|
|
|
|
scrollFactor.set();
|
|
|
|
}
|
2021-03-26 21:22:07 -04:00
|
|
|
|
2021-02-18 14:58:16 -05:00
|
|
|
override function changeAnim(anim:String)
|
|
|
|
{
|
|
|
|
super.changeAnim(anim);
|
|
|
|
// position by center
|
|
|
|
centerOrigin();
|
|
|
|
offset.copyFrom(origin);
|
|
|
|
}
|
2021-03-26 21:22:07 -04:00
|
|
|
}
|