diff --git a/source/MainMenuState.hx b/source/MainMenuState.hx index 58494cc47..75fab2853 100644 --- a/source/MainMenuState.hx +++ b/source/MainMenuState.hx @@ -1,8 +1,6 @@ package; import NGio; - -import flixel.ui.FlxButton; import flixel.FlxG; import flixel.FlxObject; import flixel.FlxSprite; @@ -14,26 +12,26 @@ import flixel.group.FlxGroup.FlxTypedGroup; import flixel.text.FlxText; import flixel.tweens.FlxEase; import flixel.tweens.FlxTween; +import flixel.ui.FlxButton; import flixel.util.FlxColor; import flixel.util.FlxTimer; import lime.app.Application; +import ui.AtlasMenuList; +import ui.MenuList; +import ui.OptionsState; +import ui.PreferencesMenu; +import ui.Prompt; + +using StringTools; #if desktop import Discord.DiscordClient; #end - #if newgrounds import io.newgrounds.NG; import ui.NgPrompt; #end -import ui.AtlasMenuList; -import ui.MenuList; -import ui.OptionsState; -import ui.Prompt; - -using StringTools; - class MainMenuState extends MusicBeatState { var menuItems:MainMenuList; @@ -80,7 +78,8 @@ class MainMenuState extends MusicBeatState magenta.visible = false; magenta.antialiasing = true; magenta.color = 0xFFfd719b; - add(magenta); + if (PreferencesMenu.preferences.get('flashing-menu')) + add(magenta); // magenta.scrollFactor.set(); menuItems = new MainMenuList(); @@ -90,25 +89,23 @@ class MainMenuState extends MusicBeatState { FlxFlicker.flicker(magenta, 1.1, 0.15, false, true); }); - - - - menuItems.enabled = false;// disable for intro - menuItems.createItem('story mode', function () startExitState(new StoryMenuState())); - menuItems.createItem('freeplay', function () startExitState(new FreeplayState())); + + menuItems.enabled = false; // disable for intro + menuItems.createItem('story mode', function() startExitState(new StoryMenuState())); + menuItems.createItem('freeplay', function() startExitState(new FreeplayState())); // addMenuItem('options', function () startExitState(new OptionMenu())); #if CAN_OPEN_LINKS - var hasPopupBlocker = #if web true #else false #end; - menuItems.createItem('donate', selectDonate, hasPopupBlocker); + var hasPopupBlocker = #if web true #else false #end; + menuItems.createItem('donate', selectDonate, hasPopupBlocker); #end - menuItems.createItem('options', function () startExitState(new OptionsState())); + menuItems.createItem('options', function() startExitState(new OptionsState())); // #if newgrounds // if (NGio.isLoggedIn) // menuItems.createItem("logout", selectLogout); // else // menuItems.createItem("login", selectLogin); // #end - + // center vertically var spacing = 160; var top = (FlxG.height - (spacing * (menuItems.length - 1))) / 2; @@ -131,24 +128,24 @@ class MainMenuState extends MusicBeatState super.create(); } - + override function finishTransIn() { super.finishTransIn(); - + menuItems.enabled = true; - + // #if newgrounds // if (NGio.savedSessionFailed) // showSavedSessionFailed(); // #end } - + function onMenuItemChange(selected:MenuItem) { camFollow.setPosition(selected.getGraphicMidpoint().x, selected.getGraphicMidpoint().y); } - + #if CAN_OPEN_LINKS function selectDonate() { @@ -159,23 +156,23 @@ class MainMenuState extends MusicBeatState #end } #end - + #if newgrounds function selectLogin() { openNgPrompt(NgPrompt.showLogin()); } - + function selectLogout() { openNgPrompt(NgPrompt.showLogout()); } - + function showSavedSessionFailed() { openNgPrompt(NgPrompt.showSavedSessionFailed()); } - + /** * Calls openPrompt and redraws the login/logout button * @param prompt @@ -186,16 +183,16 @@ class MainMenuState extends MusicBeatState var onPromptClose = checkLoginStatus; if (onClose != null) { - onPromptClose = function () + onPromptClose = function() { checkLoginStatus(); onClose(); } } - + openPrompt(prompt, onPromptClose); } - + function checkLoginStatus() { var prevLoggedIn = menuItems.has("logout"); @@ -205,20 +202,20 @@ class MainMenuState extends MusicBeatState menuItems.resetItem("logout", "login", selectLogin); } #end - + public function openPrompt(prompt:Prompt, onClose:Void->Void) { menuItems.enabled = false; - prompt.closeCallback = function () + prompt.closeCallback = function() { menuItems.enabled = true; if (onClose != null) onClose(); } - + openSubState(prompt); } - + function startExitState(state:FlxState) { var duration = 0.4; @@ -226,14 +223,14 @@ class MainMenuState extends MusicBeatState { if (menuItems.selectedIndex != item.ID) { - FlxTween.tween(item, {alpha: 0}, duration, { ease: FlxEase.quadOut }); + FlxTween.tween(item, {alpha: 0}, duration, {ease: FlxEase.quadOut}); } else { item.visible = false; } }); - + new FlxTimer().start(duration, function(_) FlxG.switchState(state)); } @@ -254,29 +251,29 @@ class MainMenuState extends MusicBeatState private class MainMenuList extends MenuTypedList { public var atlas:FlxAtlasFrames; - - public function new () + + public function new() { atlas = Paths.getSparrowAtlas('main_menu'); super(Vertical); - } - + 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; item.ID = length; - + return addItem(name, item); } - + override function destroy() { super.destroy(); atlas = null; } } + private class MainMenuItem extends AtlasMenuItem { 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); scrollFactor.set(); } - + override function changeAnim(anim:String) { super.changeAnim(anim); @@ -292,4 +289,4 @@ private class MainMenuItem extends AtlasMenuItem centerOrigin(); offset.copyFrom(origin); } -} \ No newline at end of file +} diff --git a/source/TitleState.hx b/source/TitleState.hx index 114753464..8d31350f8 100644 --- a/source/TitleState.hx +++ b/source/TitleState.hx @@ -17,6 +17,7 @@ import flixel.util.FlxTimer; import lime.app.Application; import openfl.Assets; import shaderslmfao.ColorSwap; +import ui.PreferencesMenu; using StringTools; @@ -59,6 +60,8 @@ class TitleState extends MusicBeatState super.create(); + PreferencesMenu.initPrefs(); + FlxG.save.bind('funkin', 'ninjamuffin99'); PlayerSettings.init(); Highscore.load(); diff --git a/source/ui/PreferencesMenu.hx b/source/ui/PreferencesMenu.hx index e5afbf9fd..b82300519 100644 --- a/source/ui/PreferencesMenu.hx +++ b/source/ui/PreferencesMenu.hx @@ -1,7 +1,11 @@ package ui; import flixel.FlxG; +import flixel.FlxSprite; +import flixel.group.FlxGroup; +import flixel.util.FlxColor; import ui.AtlasText.AtlasFont; +import ui.TextMenuList.TextMenuItem; class PreferencesMenu extends ui.OptionsState.Page { @@ -9,6 +13,8 @@ class PreferencesMenu extends ui.OptionsState.Page var items:TextMenuList; + var checkboxes:Array = []; + public function new() { super(); @@ -16,6 +22,14 @@ class PreferencesMenu extends ui.OptionsState.Page createPrefItem('naughtyness', 'censor-naughty', 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 @@ -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()); } + 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? */ @@ -53,7 +82,7 @@ class PreferencesMenu extends ui.OptionsState.Page 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) { @@ -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; + } +} diff --git a/source/ui/TextMenuList.hx b/source/ui/TextMenuList.hx index d1c617b17..c507ae864 100644 --- a/source/ui/TextMenuList.hx +++ b/source/ui/TextMenuList.hx @@ -5,11 +5,11 @@ import ui.MenuList; class TextMenuList extends MenuTypedList { - public function new (navControls:NavControls = Vertical, ?wrapMode) + public function new(navControls:NavControls = Vertical, ?wrapMode) { super(navControls, wrapMode); } - + 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); @@ -20,7 +20,7 @@ class TextMenuList extends MenuTypedList class TextMenuItem extends TextTypedMenuItem { - 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); setEmptyBackground(); @@ -29,12 +29,12 @@ class TextMenuItem extends TextTypedMenuItem class TextTypedMenuItem extends MenuTypedItem { - 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); } - - override function setItem(name:String, ?callback:Void -> Void) + + override function setItem(name:String, ?callback:Void->Void) { if (label != null) { @@ -43,14 +43,14 @@ class TextTypedMenuItem extends MenuTypedItem width = label.width; height = label.height; } - + super.setItem(name, callback); } - + override function set_label(value:T):T { super.set_label(value); setItem(name, callback); return value; } -} \ No newline at end of file +}