2023-05-17 02:09:53 +00:00
|
|
|
package funkin.ui.story;
|
|
|
|
|
2023-05-17 20:42:58 +00:00
|
|
|
import flixel.addons.transition.FlxTransitionableState;
|
|
|
|
import flixel.FlxSprite;
|
|
|
|
import flixel.group.FlxGroup.FlxTypedGroup;
|
|
|
|
import flixel.text.FlxText;
|
|
|
|
import flixel.tweens.FlxEase;
|
|
|
|
import flixel.tweens.FlxTween;
|
|
|
|
import flixel.util.FlxColor;
|
|
|
|
import flixel.util.FlxTimer;
|
2024-03-12 03:42:32 +00:00
|
|
|
import funkin.audio.FunkinSound;
|
2024-03-23 19:34:37 +00:00
|
|
|
import funkin.data.story.level.LevelRegistry;
|
2024-03-21 04:38:52 +00:00
|
|
|
import funkin.data.song.SongRegistry;
|
|
|
|
import funkin.graphics.FunkinSprite;
|
2023-05-17 20:42:58 +00:00
|
|
|
import funkin.modding.events.ScriptEvent;
|
|
|
|
import funkin.modding.events.ScriptEventDispatcher;
|
2023-06-06 21:38:31 +00:00
|
|
|
import funkin.play.PlayStatePlaylist;
|
|
|
|
import funkin.play.song.Song;
|
2024-03-21 04:38:52 +00:00
|
|
|
import funkin.save.Save;
|
|
|
|
import funkin.save.Save.SaveScoreData;
|
|
|
|
import funkin.ui.mainmenu.MainMenuState;
|
|
|
|
import funkin.ui.MusicBeatState;
|
2023-11-07 09:04:22 +00:00
|
|
|
import funkin.ui.transition.LoadingState;
|
|
|
|
import funkin.ui.transition.StickerSubState;
|
2024-03-21 04:38:52 +00:00
|
|
|
import funkin.util.MathUtil;
|
|
|
|
import openfl.utils.Assets;
|
2023-05-17 20:42:58 +00:00
|
|
|
|
2023-05-17 02:09:53 +00:00
|
|
|
class StoryMenuState extends MusicBeatState
|
|
|
|
{
|
2024-03-21 04:38:52 +00:00
|
|
|
static final DEFAULT_BACKGROUND_COLOR:FlxColor = FlxColor.fromString('#F9CF51');
|
2023-05-17 02:09:53 +00:00
|
|
|
static final BACKGROUND_HEIGHT:Int = 400;
|
|
|
|
|
|
|
|
var currentDifficultyId:String = 'normal';
|
|
|
|
|
|
|
|
var currentLevelId:String = 'tutorial';
|
|
|
|
var currentLevel:Level;
|
|
|
|
var isLevelUnlocked:Bool;
|
2023-05-17 20:42:58 +00:00
|
|
|
var currentLevelTitle:LevelTitle;
|
2023-05-17 02:09:53 +00:00
|
|
|
|
|
|
|
var highScore:Int = 42069420;
|
|
|
|
var highScoreLerp:Int = 12345678;
|
|
|
|
|
|
|
|
var exitingMenu:Bool = false;
|
2023-05-17 20:42:58 +00:00
|
|
|
var selectedLevel:Bool = false;
|
|
|
|
|
2023-05-17 02:09:53 +00:00
|
|
|
//
|
|
|
|
// RENDER OBJECTS
|
|
|
|
//
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The title of the level at the top.
|
|
|
|
*/
|
|
|
|
var levelTitleText:FlxText;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The score text at the top.
|
|
|
|
*/
|
|
|
|
var scoreText:FlxText;
|
|
|
|
|
2023-06-10 06:56:03 +00:00
|
|
|
/**
|
|
|
|
* The mode text at the top-middle.
|
|
|
|
*/
|
|
|
|
var modeText:FlxText;
|
|
|
|
|
2023-05-17 02:09:53 +00:00
|
|
|
/**
|
|
|
|
* The list of songs on the left.
|
|
|
|
*/
|
|
|
|
var tracklistText:FlxText;
|
|
|
|
|
|
|
|
/**
|
2023-05-17 20:42:58 +00:00
|
|
|
* The titles of the levels in the middle.
|
2023-05-17 02:09:53 +00:00
|
|
|
*/
|
|
|
|
var levelTitles:FlxTypedGroup<LevelTitle>;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The props in the center.
|
|
|
|
*/
|
|
|
|
var levelProps:FlxTypedGroup<LevelProp>;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The background behind the props.
|
|
|
|
*/
|
|
|
|
var levelBackground:FlxSprite;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The left arrow of the difficulty selector.
|
|
|
|
*/
|
|
|
|
var leftDifficultyArrow:FlxSprite;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The right arrow of the difficulty selector.
|
|
|
|
*/
|
|
|
|
var rightDifficultyArrow:FlxSprite;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The text of the difficulty selector.
|
|
|
|
*/
|
|
|
|
var difficultySprite:FlxSprite;
|
|
|
|
|
2024-05-02 16:46:24 +00:00
|
|
|
/**
|
|
|
|
* List of available level IDs.
|
|
|
|
*/
|
|
|
|
var levelList:Array<String> = [];
|
|
|
|
|
2023-05-17 20:42:58 +00:00
|
|
|
var difficultySprites:Map<String, FlxSprite>;
|
|
|
|
|
|
|
|
var stickerSubState:StickerSubState;
|
|
|
|
|
2023-10-12 07:20:21 +00:00
|
|
|
static var rememberedLevelId:Null<String> = null;
|
2023-12-19 06:27:58 +00:00
|
|
|
static var rememberedDifficulty:Null<String> = Constants.DEFAULT_DIFFICULTY;
|
2023-10-12 07:20:21 +00:00
|
|
|
|
2023-05-17 02:09:53 +00:00
|
|
|
public function new(?stickers:StickerSubState = null)
|
|
|
|
{
|
2023-05-17 20:42:58 +00:00
|
|
|
super();
|
|
|
|
|
2023-05-17 02:09:53 +00:00
|
|
|
if (stickers != null)
|
|
|
|
{
|
|
|
|
stickerSubState = stickers;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
override function create():Void
|
|
|
|
{
|
2023-05-17 20:42:58 +00:00
|
|
|
super.create();
|
|
|
|
|
2024-05-02 16:46:24 +00:00
|
|
|
levelList = LevelRegistry.instance.listSortedLevelIds();
|
|
|
|
levelList = levelList.filter(function(id) {
|
|
|
|
var levelData = LevelRegistry.instance.fetchEntry(id);
|
|
|
|
if (levelData == null) return false;
|
|
|
|
|
|
|
|
return levelData.isVisible();
|
|
|
|
});
|
|
|
|
if (levelList.length == 0) levelList = ['tutorial']; // Make sure there's at least one level to display.
|
|
|
|
|
2023-05-17 20:42:58 +00:00
|
|
|
difficultySprites = new Map<String, FlxSprite>();
|
|
|
|
|
2023-05-17 02:09:53 +00:00
|
|
|
transIn = FlxTransitionableState.defaultTransIn;
|
|
|
|
transOut = FlxTransitionableState.defaultTransOut;
|
|
|
|
|
2023-07-02 19:34:34 +00:00
|
|
|
playMenuMusic();
|
2023-05-17 02:09:53 +00:00
|
|
|
|
|
|
|
if (stickerSubState != null)
|
|
|
|
{
|
|
|
|
this.persistentUpdate = true;
|
|
|
|
this.persistentDraw = true;
|
|
|
|
|
|
|
|
openSubState(stickerSubState);
|
|
|
|
stickerSubState.degenStickers();
|
|
|
|
}
|
|
|
|
|
|
|
|
persistentUpdate = persistentDraw = true;
|
|
|
|
|
2023-10-12 07:20:21 +00:00
|
|
|
rememberSelection();
|
|
|
|
|
2024-03-05 05:22:29 +00:00
|
|
|
updateData();
|
|
|
|
|
2023-05-17 02:09:53 +00:00
|
|
|
// Explicitly define the background color.
|
|
|
|
this.bgColor = FlxColor.BLACK;
|
|
|
|
|
|
|
|
levelTitles = new FlxTypedGroup<LevelTitle>();
|
2023-09-12 05:17:15 +00:00
|
|
|
levelTitles.zIndex = 15;
|
2023-05-17 02:09:53 +00:00
|
|
|
add(levelTitles);
|
|
|
|
|
2023-05-17 20:42:58 +00:00
|
|
|
updateBackground();
|
2023-05-17 02:09:53 +00:00
|
|
|
|
2024-01-16 21:49:15 +00:00
|
|
|
var black:FunkinSprite = new FunkinSprite(levelBackground.x, 0).makeSolidColor(FlxG.width, Std.int(400 + levelBackground.y), FlxColor.BLACK);
|
2023-06-27 19:21:09 +00:00
|
|
|
black.zIndex = levelBackground.zIndex - 1;
|
|
|
|
add(black);
|
|
|
|
|
2023-05-17 02:09:53 +00:00
|
|
|
levelProps = new FlxTypedGroup<LevelProp>();
|
2023-05-17 20:42:58 +00:00
|
|
|
levelProps.zIndex = 1000;
|
2023-05-17 02:09:53 +00:00
|
|
|
add(levelProps);
|
|
|
|
|
2023-05-17 20:42:58 +00:00
|
|
|
updateProps();
|
|
|
|
|
|
|
|
tracklistText = new FlxText(FlxG.width * 0.05, levelBackground.x + levelBackground.height + 100, 0, "Tracks", 32);
|
2024-03-21 04:38:52 +00:00
|
|
|
tracklistText.setFormat('VCR OSD Mono', 32);
|
2023-05-17 02:09:53 +00:00
|
|
|
tracklistText.alignment = CENTER;
|
2024-03-21 04:38:52 +00:00
|
|
|
tracklistText.color = 0xFFE55777;
|
2023-05-17 02:09:53 +00:00
|
|
|
add(tracklistText);
|
|
|
|
|
2023-06-10 06:56:03 +00:00
|
|
|
scoreText = new FlxText(10, 10, 0, 'HIGH SCORE: 42069420');
|
2024-03-21 04:38:52 +00:00
|
|
|
scoreText.setFormat('VCR OSD Mono', 32);
|
2023-09-12 05:17:15 +00:00
|
|
|
scoreText.zIndex = 1000;
|
2023-06-10 06:56:03 +00:00
|
|
|
add(scoreText);
|
|
|
|
|
2023-05-17 20:42:58 +00:00
|
|
|
levelTitleText = new FlxText(FlxG.width * 0.7, 10, 0, 'LEVEL 1');
|
2024-03-21 04:38:52 +00:00
|
|
|
levelTitleText.setFormat('VCR OSD Mono', 32, FlxColor.WHITE, RIGHT);
|
2023-05-17 02:09:53 +00:00
|
|
|
levelTitleText.alpha = 0.7;
|
2023-09-12 05:17:15 +00:00
|
|
|
levelTitleText.zIndex = 1000;
|
2023-05-17 02:09:53 +00:00
|
|
|
add(levelTitleText);
|
|
|
|
|
2023-05-17 20:42:58 +00:00
|
|
|
buildLevelTitles();
|
2023-05-17 02:09:53 +00:00
|
|
|
|
2024-05-03 01:37:07 +00:00
|
|
|
leftDifficultyArrow = new FlxSprite(870, 480);
|
2023-05-17 20:42:58 +00:00
|
|
|
leftDifficultyArrow.frames = Paths.getSparrowAtlas('storymenu/ui/arrows');
|
|
|
|
leftDifficultyArrow.animation.addByPrefix('idle', 'leftIdle0');
|
|
|
|
leftDifficultyArrow.animation.addByPrefix('press', 'leftConfirm0');
|
|
|
|
leftDifficultyArrow.animation.play('idle');
|
|
|
|
add(leftDifficultyArrow);
|
2023-05-17 02:09:53 +00:00
|
|
|
|
2023-10-12 07:20:21 +00:00
|
|
|
buildDifficultySprite(Constants.DEFAULT_DIFFICULTY);
|
2023-05-17 20:42:58 +00:00
|
|
|
buildDifficultySprite();
|
|
|
|
|
2024-05-03 01:37:07 +00:00
|
|
|
rightDifficultyArrow = new FlxSprite(1245, leftDifficultyArrow.y);
|
2023-05-17 20:42:58 +00:00
|
|
|
rightDifficultyArrow.frames = leftDifficultyArrow.frames;
|
|
|
|
rightDifficultyArrow.animation.addByPrefix('idle', 'rightIdle0');
|
|
|
|
rightDifficultyArrow.animation.addByPrefix('press', 'rightConfirm0');
|
|
|
|
rightDifficultyArrow.animation.play('idle');
|
|
|
|
add(rightDifficultyArrow);
|
2023-05-17 02:09:53 +00:00
|
|
|
|
|
|
|
add(difficultySprite);
|
|
|
|
|
2023-05-17 20:42:58 +00:00
|
|
|
updateText();
|
|
|
|
changeDifficulty();
|
|
|
|
changeLevel();
|
|
|
|
refresh();
|
|
|
|
|
2023-05-17 02:09:53 +00:00
|
|
|
#if discord_rpc
|
|
|
|
// Updating Discord Rich Presence
|
2024-03-21 04:38:52 +00:00
|
|
|
DiscordClient.changePresence('In the Menus', null);
|
2023-05-17 02:09:53 +00:00
|
|
|
#end
|
|
|
|
}
|
|
|
|
|
2023-10-12 07:20:21 +00:00
|
|
|
function rememberSelection():Void
|
|
|
|
{
|
|
|
|
if (rememberedLevelId != null)
|
|
|
|
{
|
|
|
|
currentLevelId = rememberedLevelId;
|
|
|
|
}
|
|
|
|
if (rememberedDifficulty != null)
|
|
|
|
{
|
|
|
|
currentDifficultyId = rememberedDifficulty;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-02 19:34:34 +00:00
|
|
|
function playMenuMusic():Void
|
|
|
|
{
|
2024-03-23 21:50:48 +00:00
|
|
|
FunkinSound.playMusic('freakyMenu',
|
|
|
|
{
|
|
|
|
overrideExisting: true,
|
|
|
|
restartTrack: false
|
|
|
|
});
|
2023-07-02 19:34:34 +00:00
|
|
|
}
|
|
|
|
|
2023-05-17 20:42:58 +00:00
|
|
|
function updateData():Void
|
|
|
|
{
|
|
|
|
currentLevel = LevelRegistry.instance.fetchEntry(currentLevelId);
|
|
|
|
isLevelUnlocked = currentLevel == null ? false : currentLevel.isUnlocked();
|
|
|
|
}
|
|
|
|
|
2023-10-12 07:20:21 +00:00
|
|
|
function buildDifficultySprite(?diff:String):Void
|
2023-05-17 02:09:53 +00:00
|
|
|
{
|
2023-10-12 07:20:21 +00:00
|
|
|
if (diff == null) diff = currentDifficultyId;
|
2023-05-17 20:42:58 +00:00
|
|
|
remove(difficultySprite);
|
2023-10-12 07:20:21 +00:00
|
|
|
difficultySprite = difficultySprites.get(diff);
|
2023-05-17 20:42:58 +00:00
|
|
|
if (difficultySprite == null)
|
|
|
|
{
|
|
|
|
difficultySprite = new FlxSprite(leftDifficultyArrow.x + leftDifficultyArrow.width + 10, leftDifficultyArrow.y);
|
2023-05-23 00:55:53 +00:00
|
|
|
|
2023-10-12 07:20:21 +00:00
|
|
|
if (Assets.exists(Paths.file('images/storymenu/difficulties/${diff}.xml')))
|
2023-05-23 00:55:53 +00:00
|
|
|
{
|
2023-10-12 07:20:21 +00:00
|
|
|
difficultySprite.frames = Paths.getSparrowAtlas('storymenu/difficulties/${diff}');
|
2023-05-23 00:55:53 +00:00
|
|
|
difficultySprite.animation.addByPrefix('idle', 'idle0', 24, true);
|
2023-11-20 16:12:50 +00:00
|
|
|
if (Preferences.flashingLights) difficultySprite.animation.play('idle');
|
2023-05-23 00:55:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-10-12 07:20:21 +00:00
|
|
|
difficultySprite.loadGraphic(Paths.image('storymenu/difficulties/${diff}'));
|
2023-05-23 00:55:53 +00:00
|
|
|
}
|
|
|
|
|
2023-10-12 07:20:21 +00:00
|
|
|
difficultySprites.set(diff, difficultySprite);
|
2023-05-17 20:42:58 +00:00
|
|
|
|
2023-10-12 07:20:21 +00:00
|
|
|
difficultySprite.x += (difficultySprites.get(Constants.DEFAULT_DIFFICULTY).width - difficultySprite.width) / 2;
|
2023-05-17 20:42:58 +00:00
|
|
|
}
|
|
|
|
difficultySprite.alpha = 0;
|
2023-05-23 00:55:53 +00:00
|
|
|
|
2023-05-17 20:42:58 +00:00
|
|
|
difficultySprite.y = leftDifficultyArrow.y - 15;
|
2023-05-23 00:55:53 +00:00
|
|
|
var targetY:Float = leftDifficultyArrow.y + 10;
|
2023-10-12 07:20:21 +00:00
|
|
|
targetY -= (difficultySprite.height - difficultySprites.get(Constants.DEFAULT_DIFFICULTY).height) / 2;
|
2023-05-23 00:55:53 +00:00
|
|
|
FlxTween.tween(difficultySprite, {y: targetY, alpha: 1}, 0.07);
|
|
|
|
|
2023-05-17 20:42:58 +00:00
|
|
|
add(difficultySprite);
|
2023-05-17 02:09:53 +00:00
|
|
|
}
|
|
|
|
|
2023-05-17 20:42:58 +00:00
|
|
|
function buildLevelTitles():Void
|
2023-05-17 02:09:53 +00:00
|
|
|
{
|
|
|
|
levelTitles.clear();
|
|
|
|
|
2024-05-02 16:46:24 +00:00
|
|
|
for (levelIndex in 0...levelList.length)
|
2023-05-17 02:09:53 +00:00
|
|
|
{
|
2024-05-02 16:46:24 +00:00
|
|
|
var levelId:String = levelList[levelIndex];
|
2023-05-17 02:09:53 +00:00
|
|
|
var level:Level = LevelRegistry.instance.fetchEntry(levelId);
|
2024-05-02 16:46:24 +00:00
|
|
|
if (level == null || !level.isVisible()) continue;
|
|
|
|
|
|
|
|
// TODO: Readd lock icon if unlocked is false.
|
2023-05-17 20:42:58 +00:00
|
|
|
|
|
|
|
var levelTitleItem:LevelTitle = new LevelTitle(0, Std.int(levelBackground.y + levelBackground.height + 10), level);
|
|
|
|
levelTitleItem.targetY = ((levelTitleItem.height + 20) * levelIndex);
|
|
|
|
levelTitleItem.screenCenter(X);
|
2023-05-17 02:09:53 +00:00
|
|
|
levelTitles.add(levelTitleItem);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-21 04:38:52 +00:00
|
|
|
override function update(elapsed:Float):Void
|
2023-05-17 02:09:53 +00:00
|
|
|
{
|
2023-12-14 21:56:20 +00:00
|
|
|
Conductor.instance.update();
|
2023-05-17 02:09:53 +00:00
|
|
|
|
2024-05-29 04:53:32 +00:00
|
|
|
highScoreLerp = Std.int(MathUtil.smoothLerp(highScoreLerp, highScore, elapsed, 0.25));
|
2023-05-17 02:09:53 +00:00
|
|
|
|
2023-05-17 20:42:58 +00:00
|
|
|
scoreText.text = 'LEVEL SCORE: ${Math.round(highScoreLerp)}';
|
|
|
|
|
|
|
|
levelTitleText.text = currentLevel.getTitle();
|
|
|
|
levelTitleText.x = FlxG.width - (levelTitleText.width + 10); // Right align.
|
2023-05-17 02:09:53 +00:00
|
|
|
|
|
|
|
handleKeyPresses();
|
|
|
|
|
|
|
|
super.update(elapsed);
|
|
|
|
}
|
|
|
|
|
|
|
|
function handleKeyPresses():Void
|
|
|
|
{
|
|
|
|
if (!exitingMenu)
|
|
|
|
{
|
2023-05-17 20:42:58 +00:00
|
|
|
if (!selectedLevel)
|
2023-05-17 02:09:53 +00:00
|
|
|
{
|
|
|
|
if (controls.UI_UP_P)
|
|
|
|
{
|
|
|
|
changeLevel(-1);
|
2023-05-23 00:55:53 +00:00
|
|
|
changeDifficulty(0);
|
2023-05-17 02:09:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (controls.UI_DOWN_P)
|
|
|
|
{
|
|
|
|
changeLevel(1);
|
2023-05-23 00:55:53 +00:00
|
|
|
changeDifficulty(0);
|
2023-05-17 02:09:53 +00:00
|
|
|
}
|
|
|
|
|
2024-06-21 15:42:51 +00:00
|
|
|
#if !html5
|
|
|
|
if (FlxG.mouse.wheel != 0)
|
|
|
|
{
|
|
|
|
changeLevel(-Math.round(FlxG.mouse.wheel));
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
if (FlxG.mouse.wheel < 0)
|
|
|
|
{
|
|
|
|
changeLevel(-Math.round(FlxG.mouse.wheel / 8));
|
|
|
|
}
|
|
|
|
else if (FlxG.mouse.wheel > 0)
|
|
|
|
{
|
|
|
|
changeLevel(-Math.round(FlxG.mouse.wheel / 8));
|
|
|
|
}
|
|
|
|
#end
|
|
|
|
|
|
|
|
|
2024-04-23 01:24:44 +00:00
|
|
|
// TODO: Querying UI_RIGHT_P (justPressed) after UI_RIGHT always returns false. Fix it!
|
|
|
|
if (controls.UI_RIGHT_P)
|
|
|
|
{
|
|
|
|
changeDifficulty(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (controls.UI_LEFT_P)
|
|
|
|
{
|
|
|
|
changeDifficulty(-1);
|
|
|
|
}
|
|
|
|
|
2023-05-17 02:09:53 +00:00
|
|
|
if (controls.UI_RIGHT)
|
|
|
|
{
|
2023-05-17 20:42:58 +00:00
|
|
|
rightDifficultyArrow.animation.play('press');
|
2023-05-17 02:09:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-05-17 20:42:58 +00:00
|
|
|
rightDifficultyArrow.animation.play('idle');
|
2023-05-17 02:09:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (controls.UI_LEFT)
|
|
|
|
{
|
2023-05-17 20:42:58 +00:00
|
|
|
leftDifficultyArrow.animation.play('press');
|
2023-05-17 02:09:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-05-17 20:42:58 +00:00
|
|
|
leftDifficultyArrow.animation.play('idle');
|
2023-05-17 02:09:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (controls.ACCEPT)
|
|
|
|
{
|
2023-05-17 20:42:58 +00:00
|
|
|
selectLevel();
|
2023-05-17 02:09:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-17 20:42:58 +00:00
|
|
|
if (controls.BACK && !exitingMenu && !selectedLevel)
|
2023-05-17 02:09:53 +00:00
|
|
|
{
|
2024-03-23 21:50:48 +00:00
|
|
|
FunkinSound.playOnce(Paths.sound('cancelMenu'));
|
2023-05-17 02:09:53 +00:00
|
|
|
exitingMenu = true;
|
2024-02-06 00:46:11 +00:00
|
|
|
FlxG.switchState(() -> new MainMenuState());
|
2023-05-17 02:09:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-17 20:42:58 +00:00
|
|
|
/**
|
|
|
|
* Changes the selected level.
|
|
|
|
* @param change +1 (down), -1 (up)
|
|
|
|
*/
|
|
|
|
function changeLevel(change:Int = 0):Void
|
|
|
|
{
|
|
|
|
var currentIndex:Int = levelList.indexOf(currentLevelId);
|
2024-06-10 16:04:18 +00:00
|
|
|
var prevIndex:Int = currentIndex;
|
2023-05-17 20:42:58 +00:00
|
|
|
|
|
|
|
currentIndex += change;
|
|
|
|
|
|
|
|
// Wrap around
|
|
|
|
if (currentIndex < 0) currentIndex = levelList.length - 1;
|
|
|
|
if (currentIndex >= levelList.length) currentIndex = 0;
|
|
|
|
|
2023-06-27 19:21:09 +00:00
|
|
|
var previousLevelId:String = currentLevelId;
|
2023-05-17 20:42:58 +00:00
|
|
|
currentLevelId = levelList[currentIndex];
|
2023-10-12 07:20:21 +00:00
|
|
|
rememberedLevelId = currentLevelId;
|
2023-05-17 20:42:58 +00:00
|
|
|
|
|
|
|
updateData();
|
|
|
|
|
|
|
|
for (index in 0...levelTitles.members.length)
|
|
|
|
{
|
|
|
|
var item:LevelTitle = levelTitles.members[index];
|
|
|
|
|
2024-02-20 02:40:52 +00:00
|
|
|
item.targetY = (index - currentIndex) * 125 + 480;
|
2023-05-17 20:42:58 +00:00
|
|
|
|
|
|
|
if (index == currentIndex)
|
|
|
|
{
|
|
|
|
currentLevelTitle = item;
|
|
|
|
item.alpha = 1.0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-06-27 19:21:09 +00:00
|
|
|
item.alpha = 0.6;
|
2023-05-17 20:42:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-10 16:04:18 +00:00
|
|
|
if (currentIndex != prevIndex) FunkinSound.playOnce(Paths.sound('scrollMenu'), 0.4);
|
2024-03-27 04:39:48 +00:00
|
|
|
|
2023-05-17 20:42:58 +00:00
|
|
|
updateText();
|
2023-06-27 19:21:09 +00:00
|
|
|
updateBackground(previousLevelId);
|
2023-05-17 20:42:58 +00:00
|
|
|
updateProps();
|
|
|
|
refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Changes the selected difficulty.
|
2023-06-08 20:30:45 +00:00
|
|
|
* @param change +1 (right) to increase difficulty, -1 (left) to decrease difficulty
|
2023-05-17 20:42:58 +00:00
|
|
|
*/
|
|
|
|
function changeDifficulty(change:Int = 0):Void
|
|
|
|
{
|
2024-03-22 06:47:43 +00:00
|
|
|
// "For now, NO erect in story mode" -Dave
|
|
|
|
|
|
|
|
var difficultyList:Array<String> = Constants.DEFAULT_DIFFICULTY_LIST;
|
|
|
|
// Use this line to displays all difficulties
|
|
|
|
// var difficultyList:Array<String> = currentLevel.getDifficulties();
|
2023-05-17 20:42:58 +00:00
|
|
|
var currentIndex:Int = difficultyList.indexOf(currentDifficultyId);
|
|
|
|
|
|
|
|
currentIndex += change;
|
|
|
|
|
|
|
|
// Wrap around
|
|
|
|
if (currentIndex < 0) currentIndex = difficultyList.length - 1;
|
|
|
|
if (currentIndex >= difficultyList.length) currentIndex = 0;
|
|
|
|
|
2023-05-23 00:55:53 +00:00
|
|
|
var hasChanged:Bool = currentDifficultyId != difficultyList[currentIndex];
|
2023-05-17 20:42:58 +00:00
|
|
|
currentDifficultyId = difficultyList[currentIndex];
|
2023-10-12 07:20:21 +00:00
|
|
|
rememberedDifficulty = currentDifficultyId;
|
2023-05-17 20:42:58 +00:00
|
|
|
|
2023-05-23 00:55:53 +00:00
|
|
|
if (difficultyList.length <= 1)
|
|
|
|
{
|
|
|
|
leftDifficultyArrow.visible = false;
|
|
|
|
rightDifficultyArrow.visible = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
leftDifficultyArrow.visible = true;
|
|
|
|
rightDifficultyArrow.visible = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hasChanged)
|
|
|
|
{
|
|
|
|
buildDifficultySprite();
|
2024-03-27 04:39:48 +00:00
|
|
|
FunkinSound.playOnce(Paths.sound('scrollMenu'), 0.4);
|
2023-11-20 16:12:50 +00:00
|
|
|
// Disable the funny music thing for now.
|
|
|
|
// funnyMusicThing();
|
2023-05-23 00:55:53 +00:00
|
|
|
}
|
2024-05-22 09:57:57 +00:00
|
|
|
|
|
|
|
updateText();
|
|
|
|
refresh();
|
2023-05-23 00:55:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
final FADE_OUT_TIME:Float = 1.5;
|
|
|
|
|
|
|
|
function funnyMusicThing():Void
|
|
|
|
{
|
|
|
|
if (currentDifficultyId == "nightmare")
|
|
|
|
{
|
|
|
|
FlxG.sound.music.fadeOut(FADE_OUT_TIME, 0.0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FlxG.sound.music.fadeOut(FADE_OUT_TIME, 1.0);
|
|
|
|
}
|
2023-05-17 20:42:58 +00:00
|
|
|
}
|
|
|
|
|
2023-06-16 21:37:56 +00:00
|
|
|
public override function dispatchEvent(event:ScriptEvent):Void
|
2023-05-17 20:42:58 +00:00
|
|
|
{
|
|
|
|
// super.dispatchEvent(event) dispatches event to module scripts.
|
|
|
|
super.dispatchEvent(event);
|
|
|
|
|
2024-02-13 08:03:11 +00:00
|
|
|
if (levelProps?.members != null && levelProps.members.length > 0)
|
2023-05-17 20:42:58 +00:00
|
|
|
{
|
|
|
|
// Dispatch event to props.
|
2024-02-13 08:03:11 +00:00
|
|
|
for (prop in levelProps.members)
|
2023-05-17 20:42:58 +00:00
|
|
|
{
|
|
|
|
ScriptEventDispatcher.callEvent(prop, event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-05 02:18:40 +00:00
|
|
|
function selectLevel():Void
|
2023-05-17 20:42:58 +00:00
|
|
|
{
|
|
|
|
if (!currentLevel.isUnlocked())
|
|
|
|
{
|
2024-03-23 21:50:48 +00:00
|
|
|
FunkinSound.playOnce(Paths.sound('cancelMenu'));
|
2023-05-17 20:42:58 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (selectedLevel) return;
|
|
|
|
|
|
|
|
selectedLevel = true;
|
|
|
|
|
2024-03-23 21:50:48 +00:00
|
|
|
FunkinSound.playOnce(Paths.sound('confirmMenu'));
|
2023-05-17 20:42:58 +00:00
|
|
|
|
|
|
|
currentLevelTitle.isFlashing = true;
|
|
|
|
|
|
|
|
for (prop in levelProps.members)
|
|
|
|
{
|
|
|
|
prop.playConfirm();
|
|
|
|
}
|
|
|
|
|
2023-06-01 20:00:15 +00:00
|
|
|
Paths.setCurrentLevel(currentLevel.id);
|
|
|
|
|
2023-06-06 21:38:31 +00:00
|
|
|
PlayStatePlaylist.playlistSongIds = currentLevel.getSongs();
|
|
|
|
PlayStatePlaylist.isStoryMode = true;
|
|
|
|
PlayStatePlaylist.campaignScore = 0;
|
2023-05-17 20:42:58 +00:00
|
|
|
|
2023-06-06 21:38:31 +00:00
|
|
|
var targetSongId:String = PlayStatePlaylist.playlistSongIds.shift();
|
2023-05-17 20:42:58 +00:00
|
|
|
|
2023-09-08 21:46:44 +00:00
|
|
|
var targetSong:Song = SongRegistry.instance.fetchEntry(targetSongId);
|
2023-06-06 21:38:31 +00:00
|
|
|
|
|
|
|
PlayStatePlaylist.campaignId = currentLevel.id;
|
|
|
|
PlayStatePlaylist.campaignTitle = currentLevel.getTitle();
|
2023-10-11 21:33:55 +00:00
|
|
|
PlayStatePlaylist.campaignDifficulty = currentDifficultyId;
|
2023-05-17 20:42:58 +00:00
|
|
|
|
2024-03-05 02:18:40 +00:00
|
|
|
Highscore.talliesLevel = new funkin.Highscore.Tallies();
|
|
|
|
|
2023-05-17 20:42:58 +00:00
|
|
|
new FlxTimer().start(1, function(tmr:FlxTimer) {
|
2023-08-02 22:08:49 +00:00
|
|
|
FlxTransitionableState.skipNextTransIn = false;
|
|
|
|
FlxTransitionableState.skipNextTransOut = false;
|
|
|
|
|
2024-03-21 04:38:52 +00:00
|
|
|
var targetVariation:String = targetSong.getFirstValidVariation(PlayStatePlaylist.campaignDifficulty);
|
|
|
|
|
2024-02-17 04:48:43 +00:00
|
|
|
LoadingState.loadPlayState(
|
2023-06-06 21:38:31 +00:00
|
|
|
{
|
|
|
|
targetSong: targetSong,
|
2023-10-11 21:33:55 +00:00
|
|
|
targetDifficulty: PlayStatePlaylist.campaignDifficulty,
|
2024-03-21 04:38:52 +00:00
|
|
|
targetVariation: targetVariation
|
2024-02-17 04:48:43 +00:00
|
|
|
}, true);
|
2023-05-17 20:42:58 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-06-27 19:21:09 +00:00
|
|
|
function updateBackground(?previousLevelId:String = ''):Void
|
2023-05-17 20:42:58 +00:00
|
|
|
{
|
2023-06-27 19:21:09 +00:00
|
|
|
if (levelBackground == null || previousLevelId == '')
|
2023-05-17 20:42:58 +00:00
|
|
|
{
|
2023-06-27 19:21:09 +00:00
|
|
|
// Build a new background and display it immediately.
|
|
|
|
levelBackground = currentLevel.buildBackground();
|
|
|
|
levelBackground.x = 0;
|
|
|
|
levelBackground.y = 56;
|
|
|
|
levelBackground.zIndex = 100;
|
|
|
|
levelBackground.alpha = 1.0; // Not hidden.
|
|
|
|
add(levelBackground);
|
2023-05-17 20:42:58 +00:00
|
|
|
}
|
2023-06-27 19:21:09 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
var previousLevel = LevelRegistry.instance.fetchEntry(previousLevelId);
|
2023-05-17 20:42:58 +00:00
|
|
|
|
2023-06-27 19:21:09 +00:00
|
|
|
if (currentLevel.isBackgroundSimple() && previousLevel.isBackgroundSimple())
|
2023-05-17 20:42:58 +00:00
|
|
|
{
|
2023-06-27 19:21:09 +00:00
|
|
|
var previousColor:FlxColor = previousLevel.getBackgroundColor();
|
|
|
|
var currentColor:FlxColor = currentLevel.getBackgroundColor();
|
|
|
|
if (previousColor != currentColor)
|
|
|
|
{
|
|
|
|
// Both the previous and current level were simple backgrounds.
|
|
|
|
// Fade between colors directly, rather than fading one background out and another in.
|
2024-02-17 09:01:06 +00:00
|
|
|
// cancels potential tween in progress, and tweens from there
|
|
|
|
FlxTween.cancelTweensOf(levelBackground);
|
|
|
|
FlxTween.color(levelBackground, 0.9, levelBackground.color, currentColor, {ease: FlxEase.quartOut});
|
2023-06-27 19:21:09 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Do no fade at all if the colors aren't different.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Either the previous or current level has a complex background.
|
|
|
|
// We need to fade the old background out and the new one in.
|
|
|
|
|
|
|
|
// Reference the old background and fade it out.
|
|
|
|
var oldBackground:FlxSprite = levelBackground;
|
|
|
|
FlxTween.tween(oldBackground, {alpha: 0.0}, 0.6,
|
|
|
|
{
|
|
|
|
ease: FlxEase.linear,
|
|
|
|
onComplete: function(_) {
|
|
|
|
remove(oldBackground);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Build a new background and fade it in.
|
|
|
|
levelBackground = currentLevel.buildBackground();
|
|
|
|
levelBackground.x = 0;
|
|
|
|
levelBackground.y = 56;
|
|
|
|
levelBackground.alpha = 0.0; // Hidden to start.
|
|
|
|
levelBackground.zIndex = 100;
|
|
|
|
add(levelBackground);
|
|
|
|
|
|
|
|
FlxTween.tween(levelBackground, {alpha: 1.0}, 0.6,
|
|
|
|
{
|
|
|
|
ease: FlxEase.linear
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2023-05-17 20:42:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function updateProps():Void
|
|
|
|
{
|
2024-02-17 09:21:03 +00:00
|
|
|
for (ind => prop in currentLevel.buildProps(levelProps.members))
|
2023-05-17 20:42:58 +00:00
|
|
|
{
|
|
|
|
prop.zIndex = 1000;
|
2024-02-17 09:21:03 +00:00
|
|
|
if (levelProps.members[ind] != prop) levelProps.replace(levelProps.members[ind], prop) ?? levelProps.add(prop);
|
2023-05-17 20:42:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
function updateText():Void
|
|
|
|
{
|
|
|
|
tracklistText.text = 'TRACKS\n\n';
|
|
|
|
tracklistText.text += currentLevel.getSongDisplayNames(currentDifficultyId).join('\n');
|
|
|
|
|
|
|
|
tracklistText.screenCenter(X);
|
|
|
|
tracklistText.x -= FlxG.width * 0.35;
|
2023-05-17 02:09:53 +00:00
|
|
|
|
2024-03-04 21:37:42 +00:00
|
|
|
var levelScore:Null<SaveScoreData> = Save.instance.getLevelScore(currentLevelId, currentDifficultyId);
|
2023-10-03 23:14:46 +00:00
|
|
|
highScore = levelScore?.score ?? 0;
|
|
|
|
// levelScore.accuracy
|
2023-05-17 20:42:58 +00:00
|
|
|
}
|
2023-05-17 02:09:53 +00:00
|
|
|
}
|