From 730c320fa072aca3c08dd578c45e2cd96dea75dc Mon Sep 17 00:00:00 2001 From: CharlesCatYT Date: Mon, 27 Nov 2023 20:52:49 -0500 Subject: [PATCH] main menu rewrite & expanded paths image fail info --- source/backend/Paths.hx | 4 +- source/states/MainMenuState.hx | 196 +++++++++++++++------------------ 2 files changed, 89 insertions(+), 111 deletions(-) diff --git a/source/backend/Paths.hx b/source/backend/Paths.hx index 66bd64a..757279a 100644 --- a/source/backend/Paths.hx +++ b/source/backend/Paths.hx @@ -260,7 +260,7 @@ class Paths } public static var currentTrackedAssets:Map = []; - static public function image(key:String, ?library:String = null, ?allowGPU:Bool = true):FlxGraphic + static public function image(key:String, ?library:String = null, ?allowGPU:Bool = true, ?posInfos:haxe.PosInfos):FlxGraphic { var bitmap:BitmapData = null; var file:String = null; @@ -293,7 +293,7 @@ class Paths if(retVal != null) return retVal; } - trace('oh no its returning null NOOOO ($file)'); + trace('Image with key "$key" could not be found' + (library == null ? '' : ' in the library "$library"') + '! ' + '(${posInfos.fileName}, ${posInfos.lineNumber})'); return null; } diff --git a/source/states/MainMenuState.hx b/source/states/MainMenuState.hx index c288f69..9b09bd0 100644 --- a/source/states/MainMenuState.hx +++ b/source/states/MainMenuState.hx @@ -47,9 +47,8 @@ class MainMenuState extends MusicBeatState { public static var menuJunk:MainMenuData; var menuItems:FlxTypedGroup; - private var camGame:FlxCamera; - public static var quotes:Array = [ + final quotes:Array = [ #if html5 "You're on web. Why the FUCK are you on web? You can't get even decent easter eggs, bitch." #elseif debug @@ -76,7 +75,7 @@ class MainMenuState extends MusicBeatState { #end ]; - var optionShit:Array = [ + final optionShit:Array = [ 'story_mode', 'freeplay', #if MODS_ALLOWED 'mods', #end @@ -91,8 +90,7 @@ class MainMenuState extends MusicBeatState { var magenta:FlxSprite; var camFollow:FlxObject; - override function create() - { + override function create() { #if MODS_ALLOWED Mods.pushGlobalMods(); #end @@ -111,8 +109,12 @@ class MainMenuState extends MusicBeatState { persistentUpdate = persistentDraw = true; - var yScroll:Float = Math.max(0.25 - (0.05 * (optionShit.length - 4)), 0.1); - var bg:FlxSprite = new FlxSprite(-80).loadGraphic(Paths.image('menuDesat')); + FlxG.mouse.visible = true; + + final yScroll:Float = Math.max(0.25 - (0.05 * (optionShit.length - 4)), 0.1); + + final bg:FlxSprite = new FlxSprite(-80).loadGraphic(Paths.image('menuBG')); + bg.active = false; bg.antialiasing = ClientPrefs.data.antialiasing; bg.scrollFactor.set(0, yScroll); bg.setGraphicSize(Std.int(bg.width * 1.175)); @@ -121,9 +123,10 @@ class MainMenuState extends MusicBeatState { add(bg); camFollow = new FlxObject(0, 0, 1, 1); - add(camFollow); + //add(camFollow); magenta = new FlxSprite(-80).loadGraphic(Paths.image('menuDesat')); + magenta.active = false; magenta.antialiasing = ClientPrefs.data.antialiasing; magenta.scrollFactor.set(0, yScroll); magenta.setGraphicSize(Std.int(magenta.width * 1.175)); @@ -144,12 +147,11 @@ class MainMenuState extends MusicBeatState { menuItems = new FlxTypedGroup(); add(menuItems); - var scale:Float = 1; + final scale:Float = 1; - for (i in 0...optionShit.length) - { - var offset:Float = 108 - (Math.max(optionShit.length, 4) - 4) * 80; - var menuItem:FlxSprite = new FlxSprite(100, (i * 140) + offset); + for (i in 0...optionShit.length) { + final offset:Float = 108 - (Math.max(optionShit.length, 4) - 4) * 80; + final menuItem:FlxSprite = new FlxSprite(0, (i * 140) + offset); menuItem.antialiasing = ClientPrefs.data.antialiasing; menuItem.scale.x = scale; menuItem.scale.y = scale; @@ -157,8 +159,6 @@ class MainMenuState extends MusicBeatState { menuItem.animation.addByPrefix('idle', optionShit[i] + " basic", 24); menuItem.animation.addByPrefix('selected', optionShit[i] + " white", 24); menuItem.animation.play('idle'); - menuItem.ID = i; - //menuItem.screenCenter(X); menuItems.add(menuItem); var scr:Float = (optionShit.length - 4) * 0.135; if(optionShit.length < 6) scr = 0; @@ -179,29 +179,33 @@ class MainMenuState extends MusicBeatState { FlxG.camera.follow(camFollow, null, 0); - var versionShit:FlxText = new FlxText(12, FlxG.height - 84, 0, 'Psych Engine v$psychEngineVersion', 12); - versionShit.scrollFactor.set(); - versionShit.setFormat(Paths.font("vcr.ttf"), 16, FlxColor.WHITE, LEFT, FlxTextBorderStyle.OUTLINE, FlxColor.BLACK); - add(versionShit); - var versionShit:FlxText = new FlxText(12, FlxG.height - 64, 0, menuJunk.versionText, 12); - versionShit.scrollFactor.set(); - versionShit.setFormat(Paths.font("vcr.ttf"), 16, FlxColor.WHITE, LEFT, FlxTextBorderStyle.OUTLINE, FlxColor.BLACK); - add(versionShit); - var versionShit:FlxText = new FlxText(12, FlxG.height - 44, 0, "Friday Night Funkin' v" + Application.current.meta.get('version'), 12); - versionShit.scrollFactor.set(); - versionShit.setFormat(Paths.font("vcr.ttf"), 16, FlxColor.WHITE, LEFT, FlxTextBorderStyle.OUTLINE, FlxColor.BLACK); - add(versionShit); - var versionShit:FlxText = new FlxText(12, FlxG.height - 24, 0, quotes[Std.random(quotes.length)], 12); - versionShit.scrollFactor.set(); - versionShit.setFormat(Paths.font("vcr.ttf"), 16, FlxColor.WHITE, LEFT, FlxTextBorderStyle.OUTLINE, FlxColor.BLACK); - add(versionShit); + final versionShit1:FlxText = new FlxText(12, FlxG.height - 84, 0, 'Psych Engine v$psychEngineVersion', 12); + versionShit1.active = false; + versionShit1.scrollFactor.set(); + versionShit1.setFormat(Paths.font("vcr.ttf"), 16, FlxColor.WHITE, LEFT, FlxTextBorderStyle.OUTLINE, FlxColor.BLACK); + add(versionShit1); + final versionShit2:FlxText = new FlxText(12, FlxG.height - 64, 0, menuJunk.versionText, 12); + versionShit2.active = false; + versionShit2.scrollFactor.set(); + versionShit2.setFormat(Paths.font("vcr.ttf"), 16, FlxColor.WHITE, LEFT, FlxTextBorderStyle.OUTLINE, FlxColor.BLACK); + add(versionShit2); + final versionShit3:FlxText = new FlxText(12, FlxG.height - 44, 0, "Friday Night Funkin' v" + Application.current.meta.get('version'), 12); + versionShit3.active = false; + versionShit3.scrollFactor.set(); + versionShit3.setFormat(Paths.font("vcr.ttf"), 16, FlxColor.WHITE, LEFT, FlxTextBorderStyle.OUTLINE, FlxColor.BLACK); + add(versionShit3); + final versionShit4:FlxText = new FlxText(12, FlxG.height - 24, 0, quotes[Std.random(quotes.length)], 12); + versionShit4.active = false; + versionShit4.scrollFactor.set(); + versionShit4.setFormat(Paths.font("vcr.ttf"), 16, FlxColor.WHITE, LEFT, FlxTextBorderStyle.OUTLINE, FlxColor.BLACK); + add(versionShit4); changeItem(); #if ACHIEVEMENTS_ALLOWED // Unlocks "Freaky on a Friday Night" achievement if it's a Friday and between 18:00 PM and 23:59 PM - var leDate = Date.now(); - if (leDate.getDay() == 5 && leDate.getHours() >= 18) Achievements.unlock(menuJunk.fridayAchieve); + final leDate = Date.now(); + if (leDate.getDay() == 5 && leDate.getHours() >= 18) Achievements.unlock('friday_night_play'); #if MODS_ALLOWED Achievements.reloadList(); @@ -223,91 +227,73 @@ class MainMenuState extends MusicBeatState { var selectedSomethin:Bool = false; var colorTimer:Float = 0; - override function update(elapsed:Float) - { - if (FlxG.sound.music.volume < 0.8) - { + override function update(elapsed:Float) { + if(FlxG.sound.music.volume < 0.8){ FlxG.sound.music.volume += 0.5 * elapsed; if(FreeplayState.vocals != null) FreeplayState.vocals.volume += 0.5 * elapsed; } FlxG.camera.followLerp = FlxMath.bound(elapsed * 9 * (FlxG.updateFramerate / 60), 0, 1); - if (!selectedSomethin) - { - if (controls.UI_UP_P) - { + if (!selectedSomethin) { + if (controls.UI_UP_P || controls.UI_DOWN_P) { FlxG.sound.play(Paths.sound('scrollMenu')); - changeItem(-1); + changeItem(controls.UI_UP_P ? -1 : 1); } - if (controls.UI_DOWN_P) - { - FlxG.sound.play(Paths.sound('scrollMenu')); - changeItem(1); + for (item in menuItems.members) { + final itemIndex:Int = menuItems.members.indexOf(item); + + if (FlxG.mouse.overlaps(item) && curSelected != itemIndex) { + curSelected = itemIndex; + FlxG.sound.play(Paths.sound('scrollMenu')); + changeItem(); + break; + } } - if (controls.BACK) - { + if (controls.BACK) { selectedSomethin = true; FlxG.sound.play(Paths.sound('cancelMenu')); MusicBeatState.switchState(new TitleState()); } - if (controls.ACCEPT) - { - if (optionShit[curSelected] == 'donate') - CoolUtil.browserLoad(menuJunk.discordLink); //foxacord, it's hidden as donate, cuz foxas parents may watch the gameplay footage when released pfffft - else - { + if (controls.ACCEPT || (FlxG.mouse.overlaps(menuItems.members[curSelected]) && FlxG.mouse.justPressed)) { + if(optionShit[curSelected] == 'donate') CoolUtil.browserLoad(menuJunk.discordLink); //foxacord, it's hidden as donate, cuz foxas parents may watch the gameplay footage when released pfffft, lets hope they wont see this line of code :) + else { selectedSomethin = true; FlxG.sound.play(Paths.sound('confirmMenu')); if(ClientPrefs.data.flashing) FlxFlicker.flicker(magenta, 1.1, 0.15, false); - menuItems.forEach(function(spr:FlxSprite) - { - if (curSelected != spr.ID) - { - FlxTween.tween(spr, {alpha: 0}, 0.4, { - ease: FlxEase.quadOut, - onComplete: function(twn:FlxTween) - { - spr.kill(); - } + for (item in menuItems.members) { + final itemIndex:Int = menuItems.members.indexOf(item); + + if(curSelected != itemIndex) { + FlxTween.tween(item, {alpha: 0}, 0.4, { + ease: FlxEase.quadOut, + onComplete: function(twn:FlxTween) item.destroy() }); - } - else - { - FlxFlicker.flicker(spr, 1, 0.06, false, false, function(flick:FlxFlicker) - { - var daChoice:String = optionShit[curSelected]; - - switch (daChoice) - { - case 'story_mode': - MusicBeatState.switchState(new StoryMenuState()); - case 'freeplay': - MusicBeatState.switchState(new FreeplayState()); - #if MODS_ALLOWED - case 'mods': - MusicBeatState.switchState(new ModsMenuState()); - #end - case 'awards': - MusicBeatState.switchState(new AchievementsMenuState()); - case 'credits': - MusicBeatState.switchState(new CreditsState()); + }else{ + FlxFlicker.flicker(item, 1, 0.06, false, false, function(flick:FlxFlicker) { + final daChoice:String = optionShit[curSelected]; + + switch (daChoice) { + case 'story_mode': MusicBeatState.switchState(new StoryMenuState()); + case 'freeplay': MusicBeatState.switchState(new FreeplayState()); + #if MODS_ALLOWED case 'mods': MusicBeatState.switchState(new ModsMenuState()); #end + case 'awards': MusicBeatState.switchState(new AchievementsMenuState()); + case 'credits': MusicBeatState.switchState(new CreditsState()); case 'options': MusicBeatState.switchState(new OptionsState()); OptionsState.onPlayState = false; - if (PlayState.SONG != null) - { + if(PlayState.SONG != null){ PlayState.SONG.arrowSkin = null; PlayState.SONG.splashSkin = null; } } }); } - }); + } } } #if desktop @@ -328,28 +314,20 @@ class MainMenuState extends MusicBeatState { }); } - function changeItem(huh:Int = 0) - { - curSelected += huh; - - if (curSelected >= menuItems.length) curSelected = 0; - if (curSelected < 0) curSelected = menuItems.length - 1; - - menuItems.forEach(function(spr:FlxSprite) - { - spr.animation.play('idle'); - spr.updateHitbox(); - - if (spr.ID == curSelected) - { - spr.animation.play('selected'); + function changeItem(?huh:Int = 0) { + curSelected = FlxMath.wrap(curSelected + huh, 0, menuItems.length - 1); + for (item in menuItems.members) { + final itemIndex:Int = menuItems.members.indexOf(item); + if(curSelected != itemIndex) { + item.animation.play('idle', true); + item.updateHitbox(); + }else{ + item.animation.play('selected'); var add:Float = 0; - if(menuItems.length > 4) { - add = menuItems.length * 8; - } - camFollow.setPosition(spr.getGraphicMidpoint().x, spr.getGraphicMidpoint().y - add); - spr.centerOffsets(); + if(menuItems.length > 4) add = menuItems.length * 8; + camFollow.setPosition(item.getGraphicMidpoint().x, item.getGraphicMidpoint().y - add); + item.centerOffsets(); } - }); + } } }