From 6fb517059d97064fd4fd93025e6fd63f03c58848 Mon Sep 17 00:00:00 2001 From: Cameron Taylor Date: Mon, 10 Apr 2023 14:44:32 -0400 Subject: [PATCH] proper load/deload on freeplay and story --- source/funkin/PauseSubState.hx | 18 +++++------------ source/funkin/StoryMenuState.hx | 30 +++++++++++++++++++++++++---- source/funkin/ui/StickerSubState.hx | 29 +++++++++++++++++++++++++--- 3 files changed, 57 insertions(+), 20 deletions(-) diff --git a/source/funkin/PauseSubState.hx b/source/funkin/PauseSubState.hx index f5a236678..747335943 100644 --- a/source/funkin/PauseSubState.hx +++ b/source/funkin/PauseSubState.hx @@ -222,20 +222,12 @@ class PauseSubState extends MusicBeatSubstate item.alpha = 0.6; } - FlxTween.tween(bg, {alpha: 1}, 0.4, - { - ease: FlxEase.quartInOut, - onComplete: function(_) { - FlxTransitionableState.skipNextTransIn = true; - FlxTransitionableState.skipNextTransOut = true; + FlxTransitionableState.skipNextTransIn = true; + FlxTransitionableState.skipNextTransOut = true; - FlxG.cameras.list[1].alpha = 0; // bullshit for the UI camera??? - - if (PlayState.isStoryMode) FlxG.switchState(new StoryMenuState()); - else - FlxG.switchState(new FreeplayState()); - } - }); + if (PlayState.isStoryMode) openSubState(new funkin.ui.StickerSubState(null, STORY)); + else + openSubState(new funkin.ui.StickerSubState()); } } diff --git a/source/funkin/StoryMenuState.hx b/source/funkin/StoryMenuState.hx index 7e2be322d..d9640d620 100644 --- a/source/funkin/StoryMenuState.hx +++ b/source/funkin/StoryMenuState.hx @@ -15,6 +15,7 @@ import funkin.play.PlayState; import funkin.play.song.SongData.SongDataParser; import lime.net.curl.CURLCode; import openfl.Assets; +import funkin.ui.StickerSubState; #if discord_rpc import Discord.DiscordClient; #end @@ -86,6 +87,18 @@ class StoryMenuState extends MusicBeatState var yellowBG:FlxSprite; // not actually, yellow, lol! var targetColor:Int = 0xFFF9CF51; + var stickerSubState:StickerSubState; + + public function new(?stickers:StickerSubState = null) + { + if (stickers != null) + { + stickerSubState = stickers; + } + + super(); + } + override function create() { transIn = FlxTransitionableState.defaultTransIn; @@ -96,6 +109,17 @@ class StoryMenuState extends MusicBeatState if (!FlxG.sound.music.playing) FlxG.sound.playMusic(Paths.music('freakyMenu')); } + if (stickerSubState != null) + { + this.persistentUpdate = true; + this.persistentDraw = true; + + openSubState(stickerSubState); + stickerSubState.degenStickers(); + + // resetSubState(); + } + persistentUpdate = persistentDraw = true; scoreText = new FlxText(10, 10, 0, "SCORE: 49324858", 36); @@ -293,8 +317,7 @@ class StoryMenuState extends MusicBeatState difficultySelectors.visible = weekUnlocked[curWeek]; - grpLocks.forEach(function(lock:FlxSprite) - { + grpLocks.forEach(function(lock:FlxSprite) { lock.y = grpWeekText.members[lock.ID].y; }); @@ -380,8 +403,7 @@ class StoryMenuState extends MusicBeatState }; SongLoad.curDiff = PlayState.storyDifficulty_NEW; - new FlxTimer().start(1, function(tmr:FlxTimer) - { + new FlxTimer().start(1, function(tmr:FlxTimer) { LoadingState.loadAndSwitchState(new PlayState(), true); }); } diff --git a/source/funkin/ui/StickerSubState.hx b/source/funkin/ui/StickerSubState.hx index 0b5999f6b..dfcb10b79 100644 --- a/source/funkin/ui/StickerSubState.hx +++ b/source/funkin/ui/StickerSubState.hx @@ -23,13 +23,20 @@ class StickerSubState extends MusicBeatSubstate // yes... a damn OpenFL sprite!!! public var dipshit:Sprite; - public function new(?oldStickers:Array):Void + var nextState:NEXTSTATE = FREEPLAY; + + public function new(?oldStickers:Array, ?nextState:NEXTSTATE = FREEPLAY):Void { super(); + this.nextState = nextState; + grpStickers = new FlxTypedGroup(); add(grpStickers); + // makes the stickers on the most recent camera, which is more often than not... a UI camera!! + grpStickers.cameras = [FlxG.cameras.list[FlxG.cameras.list.length - 1]]; + if (oldStickers != null) { for (sticker in oldStickers) @@ -46,6 +53,8 @@ class StickerSubState extends MusicBeatSubstate public function degenStickers():Void { + grpStickers.cameras = FlxG.cameras.list; + if (dipshit != null) { FlxG.removeChild(dipshit); @@ -130,14 +139,22 @@ class StickerSubState extends MusicBeatSubstate dipshit = new Sprite(); var scrn:BitmapData = new BitmapData(FlxG.width, FlxG.height, true, 0x00000000); var mat:Matrix = new Matrix(); - scrn.draw(FlxG.camera.canvas, mat); + scrn.draw(grpStickers.cameras[0].canvas, mat); var bitmap:Bitmap = new Bitmap(scrn); dipshit.addChild(bitmap); FlxG.addChildBelowMouse(dipshit); - FlxG.switchState(new FreeplayState(this)); + switch (nextState) + { + case FREEPLAY: + FlxG.switchState(new FreeplayState(this)); + case STORY: + FlxG.switchState(new StoryMenuState(this)); + default: + FlxG.switchState(new FreeplayState(this)); + } } // sticky.angle *= FlxG.random.float(0, 0.05); @@ -277,3 +294,9 @@ typedef StickerShit = stickers:Map>, stickerPacks:Map> } + +enum abstract NEXTSTATE(String) +{ + var FREEPLAY = 'freeplay'; + var STORY = 'story'; +}