Scrapped the weird FlxAltasSprite stuff and just used a tween. Also fixed some bugs with story menu

This commit is contained in:
EliteMasterEric 2024-03-21 00:38:52 -04:00
parent 3975d34b70
commit 1f81e92827
5 changed files with 73 additions and 56 deletions

View file

@ -3,6 +3,7 @@ package funkin.graphics;
import flixel.FlxSprite; import flixel.FlxSprite;
import flixel.util.FlxColor; import flixel.util.FlxColor;
import flixel.graphics.FlxGraphic; import flixel.graphics.FlxGraphic;
import flixel.tweens.FlxTween;
/** /**
* An FlxSprite with additional functionality. * 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. * The default `clone()` method acts kinda weird TBH.
* @return A clone of this sprite. * @return A clone of this sprite.
*/ */
@ -230,4 +231,13 @@ class FunkinSprite extends FlxSprite
return result; 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();
}
} }

View file

@ -21,7 +21,6 @@ class FlxAtlasSprite extends FlxAnimate
ShowPivot: #if debug false #else false #end, ShowPivot: #if debug false #else false #end,
Antialiasing: true, Antialiasing: true,
ScrollFactor: null, ScrollFactor: null,
OverrideGraphics: [],
// Offset: new FlxPoint(0, 0), // This is just FlxSprite.offset // Offset: new FlxPoint(0, 0), // This is just FlxSprite.offset
}; };

View file

@ -1,12 +1,15 @@
package funkin.ui.freeplay; package funkin.ui.freeplay;
import flixel.graphics.FlxGraphic; import flixel.FlxSprite;
import flixel.group.FlxSpriteGroup; import flixel.group.FlxSpriteGroup;
import flixel.util.FlxSort; import flixel.util.FlxSort;
import flixel.tweens.FlxTween;
import flixel.util.FlxTimer;
import flixel.tweens.FlxEase;
import funkin.data.freeplay.AlbumRegistry; import funkin.data.freeplay.AlbumRegistry;
import funkin.graphics.adobeanimate.FlxAtlasSprite;
import funkin.graphics.FunkinSprite; import funkin.graphics.FunkinSprite;
import funkin.util.SortUtil; import funkin.util.SortUtil;
import openfl.utils.Assets;
/** /**
* The graphic for the album roll in the FreeplayState. * The graphic for the album roll in the FreeplayState.
@ -31,10 +34,12 @@ class AlbumRoll extends FlxSpriteGroup
return value; return value;
} }
var albumArt:FlxAtlasSprite; var albumArt:FunkinSprite;
var albumTitle:FunkinSprite; var albumTitle:FunkinSprite;
var difficultyStars:DifficultyStars; var difficultyStars:DifficultyStars;
var _exitMovers:Null<FreeplayState.ExitMoverData>;
var albumData:Album; var albumData:Album;
public function new() public function new()
@ -42,7 +47,7 @@ class AlbumRoll extends FlxSpriteGroup
super(); super();
albumTitle = new FunkinSprite(947, 491); albumTitle = new FunkinSprite(947, 491);
albumTitle.visible = false; albumTitle.visible = true;
albumTitle.zIndex = 200; albumTitle.zIndex = 200;
add(albumTitle); add(albumTitle);
@ -69,28 +74,32 @@ class AlbumRoll extends FlxSpriteGroup
return; return;
}; };
var albumArtGraphics:Array<FlxGraphic> = [null, albumData.getAlbumArtGraphic()];
if (albumArt != null) if (albumArt != null)
{ {
FlxTween.cancelTweensOf(albumArt);
albumArt.visible = false; albumArt.visible = false;
albumArt.anim.stop();
albumArt.destroy(); albumArt.destroy();
remove(albumArt); remove(albumArt);
} }
// I wasn't able to get replacing to work properly on an existing object, // Paths.animateAtlas('freeplay/albumRoll'),
// so I just throw the old one in the trash and make a new one. albumArt = FunkinSprite.create(1500, 360, albumData.getAlbumArtAssetKey());
albumArt = new FlxAtlasSprite(640, 360, Paths.animateAtlas('freeplay/albumRoll'), albumArt.setGraphicSize(262, 262); // Magic number for size IG
{
OverrideGraphics: albumArtGraphics,
});
albumArt.zIndex = 100; albumArt.zIndex = 100;
playIntro(); playIntro();
add(albumArt); add(albumArt);
applyExitMovers();
if (Assets.exists(Paths.image(albumData.getAlbumTitleAssetKey())))
{
albumTitle.loadGraphic(Paths.image(albumData.getAlbumTitleAssetKey())); albumTitle.loadGraphic(Paths.image(albumData.getAlbumTitleAssetKey()));
}
else
{
albumTitle.visible = false;
}
refresh(); refresh();
} }
@ -104,8 +113,19 @@ class AlbumRoll extends FlxSpriteGroup
* Apply exit movers for the album roll. * Apply exit movers for the album roll.
* @param exitMovers The exit movers to apply. * @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], exitMovers.set([albumArt],
{ {
x: FlxG.width, x: FlxG.width,
@ -141,10 +161,12 @@ class AlbumRoll extends FlxSpriteGroup
public function playIntro():Void public function playIntro():Void
{ {
albumArt.visible = true; albumArt.visible = true;
albumArt.anim.play(''); FlxTween.tween(albumArt, {x: 950, y: 320, angle: -340}, 0.5, {ease: FlxEase.quintOut});
albumArt.anim.onComplete = function() {
albumArt.anim.pause(); albumTitle.visible = false;
}; new FlxTimer().start(0.75, function(_) {
showTitle();
});
} }
public function setDifficultyStars(?difficulty:Int):Void public function setDifficultyStars(?difficulty:Int):Void
@ -154,9 +176,6 @@ class AlbumRoll extends FlxSpriteGroup
difficultyStars.difficulty = difficulty; difficultyStars.difficulty = difficulty;
} }
/**
* Make the album title graphic visible.
*/
public function showTitle():Void public function showTitle():Void
{ {
albumTitle.visible = true; albumTitle.visible = true;

View file

@ -465,7 +465,7 @@ class FreeplayState extends MusicBeatSubState
albumRoll.playIntro(); albumRoll.playIntro();
new FlxTimer().start(1, function(_) { new FlxTimer().start(0.75, function(_) {
albumRoll.showTitle(); albumRoll.showTitle();
}); });
@ -861,16 +861,6 @@ class FreeplayState extends MusicBeatSubState
changeDiff(1); 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) if (controls.BACK && !typing.hasFocus)
{ {
FlxTween.globalManager.clear(); FlxTween.globalManager.clear();

View file

@ -1,37 +1,33 @@
package funkin.ui.story; 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.addons.transition.FlxTransitionableState;
import flixel.FlxSprite; import flixel.FlxSprite;
import flixel.group.FlxGroup.FlxTypedGroup; import flixel.group.FlxGroup.FlxTypedGroup;
import flixel.text.FlxText; import flixel.text.FlxText;
import flixel.addons.transition.FlxTransitionableState;
import flixel.tweens.FlxEase; import flixel.tweens.FlxEase;
import funkin.graphics.FunkinSprite;
import funkin.ui.MusicBeatState;
import flixel.tweens.FlxTween; import flixel.tweens.FlxTween;
import flixel.util.FlxColor; import flixel.util.FlxColor;
import flixel.util.FlxTimer; import flixel.util.FlxTimer;
import funkin.data.level.LevelRegistry;
import funkin.audio.FunkinSound; 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.ScriptEvent;
import funkin.modding.events.ScriptEventDispatcher; import funkin.modding.events.ScriptEventDispatcher;
import funkin.play.PlayState;
import funkin.play.PlayStatePlaylist; import funkin.play.PlayStatePlaylist;
import funkin.ui.mainmenu.MainMenuState;
import funkin.play.song.Song; import funkin.play.song.Song;
import funkin.data.song.SongData.SongMusicData; import funkin.save.Save;
import funkin.data.song.SongRegistry; import funkin.save.Save.SaveScoreData;
import funkin.util.MathUtil; import funkin.ui.mainmenu.MainMenuState;
import funkin.ui.MusicBeatState;
import funkin.ui.transition.LoadingState; import funkin.ui.transition.LoadingState;
import funkin.ui.transition.StickerSubState; import funkin.ui.transition.StickerSubState;
import funkin.util.MathUtil;
import openfl.utils.Assets;
class StoryMenuState extends MusicBeatState 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; static final BACKGROUND_HEIGHT:Int = 400;
var currentDifficultyId:String = 'normal'; var currentDifficultyId:String = 'normal';
@ -166,25 +162,25 @@ class StoryMenuState extends MusicBeatState
updateProps(); updateProps();
tracklistText = new FlxText(FlxG.width * 0.05, levelBackground.x + levelBackground.height + 100, 0, "Tracks", 32); 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.alignment = CENTER;
tracklistText.color = 0xFFe55777; tracklistText.color = 0xFFE55777;
add(tracklistText); add(tracklistText);
scoreText = new FlxText(10, 10, 0, 'HIGH SCORE: 42069420'); scoreText = new FlxText(10, 10, 0, 'HIGH SCORE: 42069420');
scoreText.setFormat("VCR OSD Mono", 32); scoreText.setFormat('VCR OSD Mono', 32);
scoreText.zIndex = 1000; scoreText.zIndex = 1000;
add(scoreText); add(scoreText);
modeText = new FlxText(10, 10, 0, 'Base Game Levels [TAB to switch]'); 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.screenCenter(X);
modeText.visible = hasModdedLevels(); modeText.visible = hasModdedLevels();
modeText.zIndex = 1000; modeText.zIndex = 1000;
add(modeText); add(modeText);
levelTitleText = new FlxText(FlxG.width * 0.7, 10, 0, 'LEVEL 1'); 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.alpha = 0.7;
levelTitleText.zIndex = 1000; levelTitleText.zIndex = 1000;
add(levelTitleText); add(levelTitleText);
@ -217,7 +213,7 @@ class StoryMenuState extends MusicBeatState
#if discord_rpc #if discord_rpc
// Updating Discord Rich Presence // Updating Discord Rich Presence
DiscordClient.changePresence("In the Menus", null); DiscordClient.changePresence('In the Menus', null);
#end #end
} }
@ -307,7 +303,7 @@ class StoryMenuState extends MusicBeatState
changeDifficulty(0); changeDifficulty(0);
} }
override function update(elapsed:Float) override function update(elapsed:Float):Void
{ {
Conductor.instance.update(); Conductor.instance.update();
@ -552,10 +548,13 @@ class StoryMenuState extends MusicBeatState
FlxTransitionableState.skipNextTransIn = false; FlxTransitionableState.skipNextTransIn = false;
FlxTransitionableState.skipNextTransOut = false; FlxTransitionableState.skipNextTransOut = false;
var targetVariation:String = targetSong.getFirstValidVariation(PlayStatePlaylist.campaignDifficulty);
LoadingState.loadPlayState( LoadingState.loadPlayState(
{ {
targetSong: targetSong, targetSong: targetSong,
targetDifficulty: PlayStatePlaylist.campaignDifficulty, targetDifficulty: PlayStatePlaylist.campaignDifficulty,
targetVariation: targetVariation
}, true); }, true);
}); });
} }