no flashing menu

This commit is contained in:
Cameron Taylor 2021-03-26 21:22:07 -04:00
parent b470cfc83a
commit 105c05f2e2
4 changed files with 109 additions and 57 deletions

View file

@ -1,8 +1,6 @@
package; package;
import NGio; import NGio;
import flixel.ui.FlxButton;
import flixel.FlxG; import flixel.FlxG;
import flixel.FlxObject; import flixel.FlxObject;
import flixel.FlxSprite; import flixel.FlxSprite;
@ -14,26 +12,26 @@ import flixel.group.FlxGroup.FlxTypedGroup;
import flixel.text.FlxText; import flixel.text.FlxText;
import flixel.tweens.FlxEase; import flixel.tweens.FlxEase;
import flixel.tweens.FlxTween; import flixel.tweens.FlxTween;
import flixel.ui.FlxButton;
import flixel.util.FlxColor; import flixel.util.FlxColor;
import flixel.util.FlxTimer; import flixel.util.FlxTimer;
import lime.app.Application; import lime.app.Application;
import ui.AtlasMenuList;
import ui.MenuList;
import ui.OptionsState;
import ui.PreferencesMenu;
import ui.Prompt;
using StringTools;
#if desktop #if desktop
import Discord.DiscordClient; import Discord.DiscordClient;
#end #end
#if newgrounds #if newgrounds
import io.newgrounds.NG; import io.newgrounds.NG;
import ui.NgPrompt; import ui.NgPrompt;
#end #end
import ui.AtlasMenuList;
import ui.MenuList;
import ui.OptionsState;
import ui.Prompt;
using StringTools;
class MainMenuState extends MusicBeatState class MainMenuState extends MusicBeatState
{ {
var menuItems:MainMenuList; var menuItems:MainMenuList;
@ -80,7 +78,8 @@ class MainMenuState extends MusicBeatState
magenta.visible = false; magenta.visible = false;
magenta.antialiasing = true; magenta.antialiasing = true;
magenta.color = 0xFFfd719b; magenta.color = 0xFFfd719b;
add(magenta); if (PreferencesMenu.preferences.get('flashing-menu'))
add(magenta);
// magenta.scrollFactor.set(); // magenta.scrollFactor.set();
menuItems = new MainMenuList(); menuItems = new MainMenuList();
@ -90,25 +89,23 @@ class MainMenuState extends MusicBeatState
{ {
FlxFlicker.flicker(magenta, 1.1, 0.15, false, true); FlxFlicker.flicker(magenta, 1.1, 0.15, false, true);
}); });
menuItems.enabled = false; // disable for intro
menuItems.createItem('story mode', function() startExitState(new StoryMenuState()));
menuItems.enabled = false;// disable for intro menuItems.createItem('freeplay', function() startExitState(new FreeplayState()));
menuItems.createItem('story mode', function () startExitState(new StoryMenuState()));
menuItems.createItem('freeplay', function () startExitState(new FreeplayState()));
// addMenuItem('options', function () startExitState(new OptionMenu())); // addMenuItem('options', function () startExitState(new OptionMenu()));
#if CAN_OPEN_LINKS #if CAN_OPEN_LINKS
var hasPopupBlocker = #if web true #else false #end; var hasPopupBlocker = #if web true #else false #end;
menuItems.createItem('donate', selectDonate, hasPopupBlocker); menuItems.createItem('donate', selectDonate, hasPopupBlocker);
#end #end
menuItems.createItem('options', function () startExitState(new OptionsState())); menuItems.createItem('options', function() startExitState(new OptionsState()));
// #if newgrounds // #if newgrounds
// if (NGio.isLoggedIn) // if (NGio.isLoggedIn)
// menuItems.createItem("logout", selectLogout); // menuItems.createItem("logout", selectLogout);
// else // else
// menuItems.createItem("login", selectLogin); // menuItems.createItem("login", selectLogin);
// #end // #end
// center vertically // center vertically
var spacing = 160; var spacing = 160;
var top = (FlxG.height - (spacing * (menuItems.length - 1))) / 2; var top = (FlxG.height - (spacing * (menuItems.length - 1))) / 2;
@ -131,24 +128,24 @@ class MainMenuState extends MusicBeatState
super.create(); super.create();
} }
override function finishTransIn() override function finishTransIn()
{ {
super.finishTransIn(); super.finishTransIn();
menuItems.enabled = true; menuItems.enabled = true;
// #if newgrounds // #if newgrounds
// if (NGio.savedSessionFailed) // if (NGio.savedSessionFailed)
// showSavedSessionFailed(); // showSavedSessionFailed();
// #end // #end
} }
function onMenuItemChange(selected:MenuItem) function onMenuItemChange(selected:MenuItem)
{ {
camFollow.setPosition(selected.getGraphicMidpoint().x, selected.getGraphicMidpoint().y); camFollow.setPosition(selected.getGraphicMidpoint().x, selected.getGraphicMidpoint().y);
} }
#if CAN_OPEN_LINKS #if CAN_OPEN_LINKS
function selectDonate() function selectDonate()
{ {
@ -159,23 +156,23 @@ class MainMenuState extends MusicBeatState
#end #end
} }
#end #end
#if newgrounds #if newgrounds
function selectLogin() function selectLogin()
{ {
openNgPrompt(NgPrompt.showLogin()); openNgPrompt(NgPrompt.showLogin());
} }
function selectLogout() function selectLogout()
{ {
openNgPrompt(NgPrompt.showLogout()); openNgPrompt(NgPrompt.showLogout());
} }
function showSavedSessionFailed() function showSavedSessionFailed()
{ {
openNgPrompt(NgPrompt.showSavedSessionFailed()); openNgPrompt(NgPrompt.showSavedSessionFailed());
} }
/** /**
* Calls openPrompt and redraws the login/logout button * Calls openPrompt and redraws the login/logout button
* @param prompt * @param prompt
@ -186,16 +183,16 @@ class MainMenuState extends MusicBeatState
var onPromptClose = checkLoginStatus; var onPromptClose = checkLoginStatus;
if (onClose != null) if (onClose != null)
{ {
onPromptClose = function () onPromptClose = function()
{ {
checkLoginStatus(); checkLoginStatus();
onClose(); onClose();
} }
} }
openPrompt(prompt, onPromptClose); openPrompt(prompt, onPromptClose);
} }
function checkLoginStatus() function checkLoginStatus()
{ {
var prevLoggedIn = menuItems.has("logout"); var prevLoggedIn = menuItems.has("logout");
@ -205,20 +202,20 @@ class MainMenuState extends MusicBeatState
menuItems.resetItem("logout", "login", selectLogin); menuItems.resetItem("logout", "login", selectLogin);
} }
#end #end
public function openPrompt(prompt:Prompt, onClose:Void->Void) public function openPrompt(prompt:Prompt, onClose:Void->Void)
{ {
menuItems.enabled = false; menuItems.enabled = false;
prompt.closeCallback = function () prompt.closeCallback = function()
{ {
menuItems.enabled = true; menuItems.enabled = true;
if (onClose != null) if (onClose != null)
onClose(); onClose();
} }
openSubState(prompt); openSubState(prompt);
} }
function startExitState(state:FlxState) function startExitState(state:FlxState)
{ {
var duration = 0.4; var duration = 0.4;
@ -226,14 +223,14 @@ class MainMenuState extends MusicBeatState
{ {
if (menuItems.selectedIndex != item.ID) if (menuItems.selectedIndex != item.ID)
{ {
FlxTween.tween(item, {alpha: 0}, duration, { ease: FlxEase.quadOut }); FlxTween.tween(item, {alpha: 0}, duration, {ease: FlxEase.quadOut});
} }
else else
{ {
item.visible = false; item.visible = false;
} }
}); });
new FlxTimer().start(duration, function(_) FlxG.switchState(state)); new FlxTimer().start(duration, function(_) FlxG.switchState(state));
} }
@ -254,29 +251,29 @@ class MainMenuState extends MusicBeatState
private class MainMenuList extends MenuTypedList<MainMenuItem> private class MainMenuList extends MenuTypedList<MainMenuItem>
{ {
public var atlas:FlxAtlasFrames; public var atlas:FlxAtlasFrames;
public function new () public function new()
{ {
atlas = Paths.getSparrowAtlas('main_menu'); atlas = Paths.getSparrowAtlas('main_menu');
super(Vertical); super(Vertical);
} }
public function createItem(x = 0.0, y = 0.0, name:String, callback, fireInstantly = false) public function createItem(x = 0.0, y = 0.0, name:String, callback, fireInstantly = false)
{ {
var item = new MainMenuItem(x, y, name, atlas, callback); var item = new MainMenuItem(x, y, name, atlas, callback);
item.fireInstantly = fireInstantly; item.fireInstantly = fireInstantly;
item.ID = length; item.ID = length;
return addItem(name, item); return addItem(name, item);
} }
override function destroy() override function destroy()
{ {
super.destroy(); super.destroy();
atlas = null; atlas = null;
} }
} }
private class MainMenuItem extends AtlasMenuItem private class MainMenuItem extends AtlasMenuItem
{ {
public function new(x = 0.0, y = 0.0, name, atlas, callback) public function new(x = 0.0, y = 0.0, name, atlas, callback)
@ -284,7 +281,7 @@ private class MainMenuItem extends AtlasMenuItem
super(x, y, name, atlas, callback); super(x, y, name, atlas, callback);
scrollFactor.set(); scrollFactor.set();
} }
override function changeAnim(anim:String) override function changeAnim(anim:String)
{ {
super.changeAnim(anim); super.changeAnim(anim);
@ -292,4 +289,4 @@ private class MainMenuItem extends AtlasMenuItem
centerOrigin(); centerOrigin();
offset.copyFrom(origin); offset.copyFrom(origin);
} }
} }

View file

@ -17,6 +17,7 @@ import flixel.util.FlxTimer;
import lime.app.Application; import lime.app.Application;
import openfl.Assets; import openfl.Assets;
import shaderslmfao.ColorSwap; import shaderslmfao.ColorSwap;
import ui.PreferencesMenu;
using StringTools; using StringTools;
@ -59,6 +60,8 @@ class TitleState extends MusicBeatState
super.create(); super.create();
PreferencesMenu.initPrefs();
FlxG.save.bind('funkin', 'ninjamuffin99'); FlxG.save.bind('funkin', 'ninjamuffin99');
PlayerSettings.init(); PlayerSettings.init();
Highscore.load(); Highscore.load();

View file

@ -1,7 +1,11 @@
package ui; package ui;
import flixel.FlxG; import flixel.FlxG;
import flixel.FlxSprite;
import flixel.group.FlxGroup;
import flixel.util.FlxColor;
import ui.AtlasText.AtlasFont; import ui.AtlasText.AtlasFont;
import ui.TextMenuList.TextMenuItem;
class PreferencesMenu extends ui.OptionsState.Page class PreferencesMenu extends ui.OptionsState.Page
{ {
@ -9,6 +13,8 @@ class PreferencesMenu extends ui.OptionsState.Page
var items:TextMenuList; var items:TextMenuList;
var checkboxes:Array<Dynamic> = [];
public function new() public function new()
{ {
super(); super();
@ -16,6 +22,14 @@ class PreferencesMenu extends ui.OptionsState.Page
createPrefItem('naughtyness', 'censor-naughty', false); createPrefItem('naughtyness', 'censor-naughty', false);
createPrefItem('downscroll', 'downscroll', false); createPrefItem('downscroll', 'downscroll', false);
createPrefItem('flashing menu', 'flashing-menu', true);
}
public static function initPrefs():Void
{
preferenceCheck('censor-naughty', false);
preferenceCheck('downscroll', false);
preferenceCheck('flashing-menu', true);
} }
private function createPrefItem(prefName:String, prefString:String, prefValue:Dynamic):Void private function createPrefItem(prefName:String, prefString:String, prefValue:Dynamic):Void
@ -34,9 +48,24 @@ class PreferencesMenu extends ui.OptionsState.Page
} }
}); });
switch (Type.typeof(prefValue).getName())
{
case 'TBool':
createCheckbox(prefString);
default:
trace('swag');
}
trace(Type.typeof(prefValue).getName()); trace(Type.typeof(prefValue).getName());
} }
function createCheckbox(prefString:String)
{
var checkbox:CheckboxThingie = new CheckboxThingie(0, 100 * items.length, preferences.get(prefString));
add(checkbox);
}
/** /**
* Assumes that the preference has already been checked/set? * Assumes that the preference has already been checked/set?
*/ */
@ -53,7 +82,7 @@ class PreferencesMenu extends ui.OptionsState.Page
super.update(elapsed); super.update(elapsed);
} }
private function preferenceCheck(prefString:String, prefValue:Dynamic):Void private static function preferenceCheck(prefString:String, prefValue:Dynamic):Void
{ {
if (preferences.get(prefString) == null) if (preferences.get(prefString) == null)
{ {
@ -66,3 +95,26 @@ class PreferencesMenu extends ui.OptionsState.Page
} }
} }
} }
class CheckboxThingie extends FlxSprite
{
public var daValue(default, set):Bool = false;
public function new(x:Float, y:Float, daValue:Bool = false)
{
super(x, y);
this.daValue = daValue;
makeGraphic(50, 50, FlxColor.WHITE);
}
function set_daValue(value:Bool):Bool
{
if (value)
color = FlxColor.GREEN;
else
color = FlxColor.RED;
return value;
}
}

View file

@ -5,11 +5,11 @@ import ui.MenuList;
class TextMenuList extends MenuTypedList<TextMenuItem> class TextMenuList extends MenuTypedList<TextMenuItem>
{ {
public function new (navControls:NavControls = Vertical, ?wrapMode) public function new(navControls:NavControls = Vertical, ?wrapMode)
{ {
super(navControls, wrapMode); super(navControls, wrapMode);
} }
public function createItem(x = 0.0, y = 0.0, name:String, font:AtlasFont = Bold, callback, fireInstantly = false) public function createItem(x = 0.0, y = 0.0, name:String, font:AtlasFont = Bold, callback, fireInstantly = false)
{ {
var item = new TextMenuItem(x, y, name, font, callback); var item = new TextMenuItem(x, y, name, font, callback);
@ -20,7 +20,7 @@ class TextMenuList extends MenuTypedList<TextMenuItem>
class TextMenuItem extends TextTypedMenuItem<AtlasText> class TextMenuItem extends TextTypedMenuItem<AtlasText>
{ {
public function new (x = 0.0, y = 0.0, name:String, font:AtlasFont = Bold, callback) public function new(x = 0.0, y = 0.0, name:String, font:AtlasFont = Bold, callback)
{ {
super(x, y, new AtlasText(0, 0, name, font), name, callback); super(x, y, new AtlasText(0, 0, name, font), name, callback);
setEmptyBackground(); setEmptyBackground();
@ -29,12 +29,12 @@ class TextMenuItem extends TextTypedMenuItem<AtlasText>
class TextTypedMenuItem<T:AtlasText> extends MenuTypedItem<T> class TextTypedMenuItem<T:AtlasText> extends MenuTypedItem<T>
{ {
public function new (x = 0.0, y = 0.0, label:T, name:String, callback) public function new(x = 0.0, y = 0.0, label:T, name:String, callback)
{ {
super(x, y, label, name, callback); super(x, y, label, name, callback);
} }
override function setItem(name:String, ?callback:Void -> Void) override function setItem(name:String, ?callback:Void->Void)
{ {
if (label != null) if (label != null)
{ {
@ -43,14 +43,14 @@ class TextTypedMenuItem<T:AtlasText> extends MenuTypedItem<T>
width = label.width; width = label.width;
height = label.height; height = label.height;
} }
super.setItem(name, callback); super.setItem(name, callback);
} }
override function set_label(value:T):T override function set_label(value:T):T
{ {
super.set_label(value); super.set_label(value);
setItem(name, callback); setItem(name, callback);
return value; return value;
} }
} }