1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2024-11-05 14:24:28 +00:00
Funkin/source/StoryMenuState.hx

233 lines
6.1 KiB
Haxe
Raw Normal View History

2020-10-30 21:18:26 +00:00
package;
import flixel.FlxG;
import flixel.FlxSprite;
import flixel.graphics.frames.FlxAtlasFrames;
2020-10-30 21:55:20 +00:00
import flixel.group.FlxGroup.FlxTypedGroup;
2020-10-30 22:21:34 +00:00
import flixel.group.FlxGroup;
2020-10-30 21:18:26 +00:00
import flixel.text.FlxText;
2020-10-31 01:55:09 +00:00
import flixel.util.FlxTimer;
2020-10-30 21:18:26 +00:00
using StringTools;
class StoryMenuState extends MusicBeatState
{
var scoreText:FlxText;
2020-10-31 01:55:09 +00:00
var weekData:Array<Dynamic> = [['Tutorial', 'Bopeebo', 'Fresh', 'Dadbattle'], ['Spookeez', 'South', 'Monster']];
2020-10-31 04:25:23 +00:00
public static var weekUnlocked:Array<Bool> = [true, false];
2020-10-31 00:09:33 +00:00
var weekCharacters:Array<Dynamic> = [['dad', 'bf', 'gf'], ['spooky', 'bf', 'gf']];
2020-10-30 21:18:26 +00:00
var curWeek:Int = 0;
var txtTracklist:FlxText;
2020-10-30 21:55:20 +00:00
var grpWeekText:FlxTypedGroup<MenuItem>;
2020-10-31 00:09:33 +00:00
var grpWeekCharacters:FlxTypedGroup<MenuCharacter>;
2020-10-30 21:55:20 +00:00
2020-10-30 22:21:34 +00:00
var grpLocks:FlxTypedGroup<FlxSprite>;
var difficultySelectors:FlxGroup;
2020-10-30 21:18:26 +00:00
override function create()
{
2020-10-31 02:33:28 +00:00
persistentUpdate = persistentDraw = true;
2020-10-30 21:18:26 +00:00
scoreText = new FlxText(10, 10, 0, "SCORE: 49324858", 36);
scoreText.setFormat("VCR OSD Mono", 32);
var rankText:FlxText = new FlxText(0, 10);
rankText.text = 'RANK: GREAT';
rankText.setFormat("assets/fonts/vcr.ttf", 32);
rankText.size = scoreText.size;
rankText.screenCenter(X);
var ui_tex = FlxAtlasFrames.fromSparrow(AssetPaths.campaign_menu_UI_assets__png, AssetPaths.campaign_menu_UI_assets__xml);
var yellowBG:FlxSprite = new FlxSprite(0, 56).makeGraphic(FlxG.width, 400, 0xFFF9CF51);
2020-10-30 21:55:20 +00:00
grpWeekText = new FlxTypedGroup<MenuItem>();
add(grpWeekText);
2020-10-31 00:09:33 +00:00
grpWeekCharacters = new FlxTypedGroup<MenuCharacter>();
2020-10-30 22:21:34 +00:00
grpLocks = new FlxTypedGroup<FlxSprite>();
add(grpLocks);
2020-10-30 21:18:26 +00:00
for (i in 0...weekData.length)
{
var unlocked:Bool = true;
if (i == 1)
unlocked = false;
var weekThing:MenuItem = new MenuItem(0, yellowBG.y + yellowBG.height + 10, i, unlocked);
2020-10-30 21:55:20 +00:00
weekThing.y += ((weekThing.height + 20) * i);
weekThing.targetY = i;
grpWeekText.add(weekThing);
weekThing.screenCenter(X);
2020-10-30 22:21:34 +00:00
weekThing.antialiasing = true;
// weekThing.updateHitbox();
if (!weekUnlocked[i])
{
var lock:FlxSprite = new FlxSprite(weekThing.width + 10 + weekThing.x);
lock.frames = ui_tex;
lock.animation.addByPrefix('lock', 'lock');
lock.animation.play('lock');
lock.ID = i;
lock.antialiasing = true;
grpLocks.add(lock);
}
2020-10-30 21:18:26 +00:00
}
2020-10-31 00:09:33 +00:00
for (char in 0...3)
{
var weekCharacterThing:MenuCharacter = new MenuCharacter((FlxG.width * 0.25) * (1 + char) - 150, weekCharacters[curWeek][char]);
weekCharacterThing.y += 70;
weekCharacterThing.antialiasing = true;
switch (weekCharacterThing.character)
{
case 'dad':
weekCharacterThing.setGraphicSize(Std.int(weekCharacterThing.width * 0.5));
weekCharacterThing.updateHitbox();
case 'bf':
weekCharacterThing.setGraphicSize(Std.int(weekCharacterThing.width * 0.9));
weekCharacterThing.updateHitbox();
case 'gf':
weekCharacterThing.setGraphicSize(Std.int(weekCharacterThing.width * 0.5));
weekCharacterThing.updateHitbox();
}
grpWeekCharacters.add(weekCharacterThing);
}
2020-10-30 22:21:34 +00:00
difficultySelectors = new FlxGroup();
add(difficultySelectors);
var leftArrow:FlxSprite = new FlxSprite(grpWeekText.members[0].x + 400, grpWeekText.members[0].y + 10);
leftArrow.frames = ui_tex;
leftArrow.animation.addByPrefix('idle', "arrow left");
leftArrow.animation.play('idle');
difficultySelectors.add(leftArrow);
var sprDifficulty:FlxSprite = new FlxSprite(leftArrow.x + 70, leftArrow.y);
sprDifficulty.frames = ui_tex;
sprDifficulty.animation.addByPrefix('easy', 'EASY');
sprDifficulty.animation.addByPrefix('normal', 'NORMAL');
sprDifficulty.animation.addByPrefix('hard', 'HARD');
sprDifficulty.animation.play('easy');
difficultySelectors.add(sprDifficulty);
var rightArrow:FlxSprite = new FlxSprite(sprDifficulty.x + sprDifficulty.width + 20, sprDifficulty.y);
rightArrow.frames = ui_tex;
rightArrow.animation.addByPrefix('idle', 'arrow right');
rightArrow.animation.play('idle');
difficultySelectors.add(rightArrow);
2020-10-30 21:18:26 +00:00
add(yellowBG);
2020-10-31 00:09:33 +00:00
add(grpWeekCharacters);
2020-10-30 21:18:26 +00:00
txtTracklist = new FlxText(FlxG.width * 0.05, yellowBG.x + yellowBG.height + 100, 0, "Tracks", 32);
txtTracklist.alignment = CENTER;
txtTracklist.font = rankText.font;
txtTracklist.color = 0xFFe55777;
add(txtTracklist);
2020-10-31 00:09:33 +00:00
add(rankText);
add(scoreText);
2020-10-30 21:18:26 +00:00
updateText();
super.create();
}
override function update(elapsed:Float)
{
// scoreText.setFormat('VCR OSD Mono', 32);
// scoreText.text = "Score SHIT";
// FlxG.watch.addQuick('font', scoreText.font);
2020-10-30 22:21:34 +00:00
difficultySelectors.visible = weekUnlocked[curWeek];
grpLocks.forEach(function(lock:FlxSprite)
{
lock.y = grpWeekText.members[lock.ID].y;
});
2020-10-31 01:55:09 +00:00
if (!selectedWeek)
{
if (controls.UP_P)
changeWeek(-1);
if (controls.DOWN_P)
changeWeek(1);
}
if (controls.ACCEPT)
selectWeek();
2020-10-30 21:18:26 +00:00
super.update(elapsed);
}
2020-10-31 01:55:09 +00:00
var selectedWeek:Bool = false;
function selectWeek()
{
if (weekUnlocked[curWeek])
{
grpWeekText.members[curWeek].week.animation.resume();
grpWeekCharacters.members[1].animation.play('bfConfirm');
PlayState.storyPlaylist = weekData[curWeek];
PlayState.isStoryMode = true;
selectedWeek = true;
PlayState.SONG = Song.loadFromJson(PlayState.storyPlaylist[0].toLowerCase());
new FlxTimer().start(1, function(tmr:FlxTimer)
{
FlxG.switchState(new PlayState());
});
}
}
2020-10-30 21:18:26 +00:00
function changeWeek(change:Int = 0):Void
{
curWeek += change;
if (curWeek >= weekData.length)
curWeek = 0;
if (curWeek < 0)
curWeek = weekData.length - 1;
2020-10-30 21:55:20 +00:00
var bullShit:Int = 0;
for (item in grpWeekText.members)
{
item.targetY = bullShit - curWeek;
bullShit++;
}
2020-10-30 21:18:26 +00:00
updateText();
}
function updateText()
{
2020-10-31 01:55:09 +00:00
grpWeekCharacters.members[0].animation.play(weekCharacters[curWeek][0]);
grpWeekCharacters.members[1].animation.play(weekCharacters[curWeek][1]);
grpWeekCharacters.members[2].animation.play(weekCharacters[curWeek][2]);
2020-10-30 21:18:26 +00:00
txtTracklist.text = "Tracks\n";
var stringThing:Array<String> = weekData[curWeek];
for (i in stringThing)
{
txtTracklist.text += "\n" + i;
}
2020-10-30 21:55:20 +00:00
txtTracklist.text = txtTracklist.text.toUpperCase();
2020-10-30 21:18:26 +00:00
txtTracklist.screenCenter(X);
txtTracklist.x -= FlxG.width * 0.35;
}
}