From 1f81e9282795806a856d614595751708aea9a70c Mon Sep 17 00:00:00 2001 From: EliteMasterEric Date: Thu, 21 Mar 2024 00:38:52 -0400 Subject: [PATCH] Scrapped the weird FlxAltasSprite stuff and just used a tween. Also fixed some bugs with story menu --- source/funkin/graphics/FunkinSprite.hx | 12 +++- .../graphics/adobeanimate/FlxAtlasSprite.hx | 1 - source/funkin/ui/freeplay/AlbumRoll.hx | 63 ++++++++++++------- source/funkin/ui/freeplay/FreeplayState.hx | 12 +--- source/funkin/ui/story/StoryMenuState.hx | 41 ++++++------ 5 files changed, 73 insertions(+), 56 deletions(-) diff --git a/source/funkin/graphics/FunkinSprite.hx b/source/funkin/graphics/FunkinSprite.hx index 03382f757..d703a8ac0 100644 --- a/source/funkin/graphics/FunkinSprite.hx +++ b/source/funkin/graphics/FunkinSprite.hx @@ -3,6 +3,7 @@ package funkin.graphics; import flixel.FlxSprite; import flixel.util.FlxColor; import flixel.graphics.FlxGraphic; +import flixel.tweens.FlxTween; /** * An FlxSprite with additional functionality. @@ -217,7 +218,7 @@ class FunkinSprite extends FlxSprite } /** - * Ensure scale is applied when cloning a sprite. + * Ensure scale is applied when cloning a sprite.R * The default `clone()` method acts kinda weird TBH. * @return A clone of this sprite. */ @@ -230,4 +231,13 @@ class FunkinSprite extends FlxSprite return result; } + + public override function destroy():Void + { + frames = null; + // Cancel all tweens so they don't continue to run on a destroyed sprite. + // This prevents crashes. + FlxTween.cancelTweensOf(this); + super.destroy(); + } } diff --git a/source/funkin/graphics/adobeanimate/FlxAtlasSprite.hx b/source/funkin/graphics/adobeanimate/FlxAtlasSprite.hx index ec8c8413c..c5a3a3771 100644 --- a/source/funkin/graphics/adobeanimate/FlxAtlasSprite.hx +++ b/source/funkin/graphics/adobeanimate/FlxAtlasSprite.hx @@ -21,7 +21,6 @@ class FlxAtlasSprite extends FlxAnimate ShowPivot: #if debug false #else false #end, Antialiasing: true, ScrollFactor: null, - OverrideGraphics: [], // Offset: new FlxPoint(0, 0), // This is just FlxSprite.offset }; diff --git a/source/funkin/ui/freeplay/AlbumRoll.hx b/source/funkin/ui/freeplay/AlbumRoll.hx index f0c759666..507e0b662 100644 --- a/source/funkin/ui/freeplay/AlbumRoll.hx +++ b/source/funkin/ui/freeplay/AlbumRoll.hx @@ -1,12 +1,15 @@ package funkin.ui.freeplay; -import flixel.graphics.FlxGraphic; +import flixel.FlxSprite; import flixel.group.FlxSpriteGroup; import flixel.util.FlxSort; +import flixel.tweens.FlxTween; +import flixel.util.FlxTimer; +import flixel.tweens.FlxEase; import funkin.data.freeplay.AlbumRegistry; -import funkin.graphics.adobeanimate.FlxAtlasSprite; import funkin.graphics.FunkinSprite; import funkin.util.SortUtil; +import openfl.utils.Assets; /** * The graphic for the album roll in the FreeplayState. @@ -31,10 +34,12 @@ class AlbumRoll extends FlxSpriteGroup return value; } - var albumArt:FlxAtlasSprite; + var albumArt:FunkinSprite; var albumTitle:FunkinSprite; var difficultyStars:DifficultyStars; + var _exitMovers:Null; + var albumData:Album; public function new() @@ -42,7 +47,7 @@ class AlbumRoll extends FlxSpriteGroup super(); albumTitle = new FunkinSprite(947, 491); - albumTitle.visible = false; + albumTitle.visible = true; albumTitle.zIndex = 200; add(albumTitle); @@ -69,28 +74,32 @@ class AlbumRoll extends FlxSpriteGroup return; }; - var albumArtGraphics:Array = [null, albumData.getAlbumArtGraphic()]; - if (albumArt != null) { + FlxTween.cancelTweensOf(albumArt); albumArt.visible = false; - albumArt.anim.stop(); albumArt.destroy(); remove(albumArt); } - // I wasn't able to get replacing to work properly on an existing object, - // so I just throw the old one in the trash and make a new one. - albumArt = new FlxAtlasSprite(640, 360, Paths.animateAtlas('freeplay/albumRoll'), - { - OverrideGraphics: albumArtGraphics, - }); + // Paths.animateAtlas('freeplay/albumRoll'), + albumArt = FunkinSprite.create(1500, 360, albumData.getAlbumArtAssetKey()); + albumArt.setGraphicSize(262, 262); // Magic number for size IG albumArt.zIndex = 100; playIntro(); add(albumArt); - albumTitle.loadGraphic(Paths.image(albumData.getAlbumTitleAssetKey())); + applyExitMovers(); + + if (Assets.exists(Paths.image(albumData.getAlbumTitleAssetKey()))) + { + albumTitle.loadGraphic(Paths.image(albumData.getAlbumTitleAssetKey())); + } + else + { + albumTitle.visible = false; + } refresh(); } @@ -104,8 +113,19 @@ class AlbumRoll extends FlxSpriteGroup * Apply exit movers for the album roll. * @param exitMovers The exit movers to apply. */ - public function applyExitMovers(exitMovers:FreeplayState.ExitMoverData):Void + public function applyExitMovers(?exitMovers:FreeplayState.ExitMoverData):Void { + if (exitMovers == null) + { + exitMovers = _exitMovers; + } + else + { + _exitMovers = exitMovers; + } + + if (exitMovers == null) return; + exitMovers.set([albumArt], { x: FlxG.width, @@ -141,10 +161,12 @@ class AlbumRoll extends FlxSpriteGroup public function playIntro():Void { albumArt.visible = true; - albumArt.anim.play(''); - albumArt.anim.onComplete = function() { - albumArt.anim.pause(); - }; + FlxTween.tween(albumArt, {x: 950, y: 320, angle: -340}, 0.5, {ease: FlxEase.quintOut}); + + albumTitle.visible = false; + new FlxTimer().start(0.75, function(_) { + showTitle(); + }); } public function setDifficultyStars(?difficulty:Int):Void @@ -154,9 +176,6 @@ class AlbumRoll extends FlxSpriteGroup difficultyStars.difficulty = difficulty; } - /** - * Make the album title graphic visible. - */ public function showTitle():Void { albumTitle.visible = true; diff --git a/source/funkin/ui/freeplay/FreeplayState.hx b/source/funkin/ui/freeplay/FreeplayState.hx index 8d7ecb556..fc11eec28 100644 --- a/source/funkin/ui/freeplay/FreeplayState.hx +++ b/source/funkin/ui/freeplay/FreeplayState.hx @@ -465,7 +465,7 @@ class FreeplayState extends MusicBeatSubState albumRoll.playIntro(); - new FlxTimer().start(1, function(_) { + new FlxTimer().start(0.75, function(_) { albumRoll.showTitle(); }); @@ -861,16 +861,6 @@ class FreeplayState extends MusicBeatSubState changeDiff(1); } - // TODO: DEBUG REMOVE THIS - if (FlxG.keys.justPressed.P) - { - var newParams:FreeplayStateParams = - { - character: currentCharacter == 'bf' ? 'pico' : 'bf', - }; - openSubState(new funkin.ui.transition.StickerSubState(null, (sticker) -> new funkin.ui.freeplay.FreeplayState(newParams, sticker))); - } - if (controls.BACK && !typing.hasFocus) { FlxTween.globalManager.clear(); diff --git a/source/funkin/ui/story/StoryMenuState.hx b/source/funkin/ui/story/StoryMenuState.hx index 60a6defdd..9ce110c73 100644 --- a/source/funkin/ui/story/StoryMenuState.hx +++ b/source/funkin/ui/story/StoryMenuState.hx @@ -1,37 +1,33 @@ package funkin.ui.story; -import funkin.ui.mainmenu.MainMenuState; -import funkin.save.Save; -import funkin.save.Save.SaveScoreData; -import openfl.utils.Assets; import flixel.addons.transition.FlxTransitionableState; import flixel.FlxSprite; import flixel.group.FlxGroup.FlxTypedGroup; import flixel.text.FlxText; -import flixel.addons.transition.FlxTransitionableState; import flixel.tweens.FlxEase; -import funkin.graphics.FunkinSprite; -import funkin.ui.MusicBeatState; import flixel.tweens.FlxTween; import flixel.util.FlxColor; import flixel.util.FlxTimer; -import funkin.data.level.LevelRegistry; import funkin.audio.FunkinSound; +import funkin.data.level.LevelRegistry; +import funkin.data.song.SongRegistry; +import funkin.graphics.FunkinSprite; import funkin.modding.events.ScriptEvent; import funkin.modding.events.ScriptEventDispatcher; -import funkin.play.PlayState; import funkin.play.PlayStatePlaylist; -import funkin.ui.mainmenu.MainMenuState; import funkin.play.song.Song; -import funkin.data.song.SongData.SongMusicData; -import funkin.data.song.SongRegistry; -import funkin.util.MathUtil; +import funkin.save.Save; +import funkin.save.Save.SaveScoreData; +import funkin.ui.mainmenu.MainMenuState; +import funkin.ui.MusicBeatState; import funkin.ui.transition.LoadingState; import funkin.ui.transition.StickerSubState; +import funkin.util.MathUtil; +import openfl.utils.Assets; class StoryMenuState extends MusicBeatState { - static final DEFAULT_BACKGROUND_COLOR:FlxColor = FlxColor.fromString("#F9CF51"); + static final DEFAULT_BACKGROUND_COLOR:FlxColor = FlxColor.fromString('#F9CF51'); static final BACKGROUND_HEIGHT:Int = 400; var currentDifficultyId:String = 'normal'; @@ -166,25 +162,25 @@ class StoryMenuState extends MusicBeatState updateProps(); tracklistText = new FlxText(FlxG.width * 0.05, levelBackground.x + levelBackground.height + 100, 0, "Tracks", 32); - tracklistText.setFormat("VCR OSD Mono", 32); + tracklistText.setFormat('VCR OSD Mono', 32); tracklistText.alignment = CENTER; - tracklistText.color = 0xFFe55777; + tracklistText.color = 0xFFE55777; add(tracklistText); scoreText = new FlxText(10, 10, 0, 'HIGH SCORE: 42069420'); - scoreText.setFormat("VCR OSD Mono", 32); + scoreText.setFormat('VCR OSD Mono', 32); scoreText.zIndex = 1000; add(scoreText); modeText = new FlxText(10, 10, 0, 'Base Game Levels [TAB to switch]'); - modeText.setFormat("VCR OSD Mono", 32); + modeText.setFormat('VCR OSD Mono', 32); modeText.screenCenter(X); modeText.visible = hasModdedLevels(); modeText.zIndex = 1000; add(modeText); levelTitleText = new FlxText(FlxG.width * 0.7, 10, 0, 'LEVEL 1'); - levelTitleText.setFormat("VCR OSD Mono", 32, FlxColor.WHITE, RIGHT); + levelTitleText.setFormat('VCR OSD Mono', 32, FlxColor.WHITE, RIGHT); levelTitleText.alpha = 0.7; levelTitleText.zIndex = 1000; add(levelTitleText); @@ -217,7 +213,7 @@ class StoryMenuState extends MusicBeatState #if discord_rpc // Updating Discord Rich Presence - DiscordClient.changePresence("In the Menus", null); + DiscordClient.changePresence('In the Menus', null); #end } @@ -307,7 +303,7 @@ class StoryMenuState extends MusicBeatState changeDifficulty(0); } - override function update(elapsed:Float) + override function update(elapsed:Float):Void { Conductor.instance.update(); @@ -552,10 +548,13 @@ class StoryMenuState extends MusicBeatState FlxTransitionableState.skipNextTransIn = false; FlxTransitionableState.skipNextTransOut = false; + var targetVariation:String = targetSong.getFirstValidVariation(PlayStatePlaylist.campaignDifficulty); + LoadingState.loadPlayState( { targetSong: targetSong, targetDifficulty: PlayStatePlaylist.campaignDifficulty, + targetVariation: targetVariation }, true); }); }