From 9b53f111a263722c13060a7ba7853dc41a6afd3b Mon Sep 17 00:00:00 2001 From: Cameron Taylor <cameron.taylor.ninja@gmail.com> Date: Fri, 30 Oct 2020 14:18:26 -0700 Subject: [PATCH] UI and menu bullshit --- Project.xml | 2 + source/MenuItem.hx | 35 ++++++++++++++ source/StoryMenuState.hx | 102 +++++++++++++++++++++++++++++++++++++++ source/TitleState.hx | 2 +- 4 files changed, 140 insertions(+), 1 deletion(-) create mode 100644 source/MenuItem.hx create mode 100644 source/StoryMenuState.hx diff --git a/Project.xml b/Project.xml index 3eb374045..b40d81b5c 100644 --- a/Project.xml +++ b/Project.xml @@ -41,6 +41,8 @@ <assets path="assets/sounds" include="*.mp3" if="web" /> <assets path="assets/sounds" include="*.ogg" unless="web" /> + <assets path="assets/fonts/vcr.ttf" embed="true" /> + <!-- _______________________________ Libraries ______________________________ --> diff --git a/source/MenuItem.hx b/source/MenuItem.hx new file mode 100644 index 000000000..9908caa02 --- /dev/null +++ b/source/MenuItem.hx @@ -0,0 +1,35 @@ +package; + +import flixel.FlxSprite; +import flixel.graphics.frames.FlxAtlasFrames; +import flixel.group.FlxSpriteGroup; + +class MenuItem extends FlxSpriteGroup +{ + public function new(x:Float, y:Float, week:Int = 0, unlocked:Bool = false) + { + super(x, y); + + var tex = FlxAtlasFrames.fromSparrow(AssetPaths.campaign_menu_UI_assets__png, AssetPaths.campaign_menu_UI_assets__xml); + + var week:FlxSprite = new FlxSprite(); + week.frames = tex; + week.animation.addByPrefix('week0', "WEEK1 select", 24); + week.animation.addByPrefix('week1', "week2 select", 24); + add(week); + + week.animation.play('week' + week); + week.updateHitbox(); + + if (!unlocked) + { + week.alpha = 0.6; + + var lock:FlxSprite = new FlxSprite(week.frameWidth + 5); + lock.frames = tex; + lock.animation.addByPrefix('lock', 'lock'); + lock.animation.play('lock'); + add(lock); + } + } +} diff --git a/source/StoryMenuState.hx b/source/StoryMenuState.hx new file mode 100644 index 000000000..f4003cb96 --- /dev/null +++ b/source/StoryMenuState.hx @@ -0,0 +1,102 @@ +package; + +import flixel.FlxG; +import flixel.FlxSprite; +import flixel.graphics.frames.FlxAtlasFrames; +import flixel.text.FlxText; + +using StringTools; + +class StoryMenuState extends MusicBeatState +{ + var scoreText:FlxText; + + var weekData:Array<Dynamic> = [['Tutorial', 'Bopeebo', 'Fresh', 'Dad Battle'], ['Spookeez', 'South', 'Monster']]; + + var curWeek:Int = 0; + + var txtTracklist:FlxText; + + override function create() + { + scoreText = new FlxText(10, 10, 0, "SCORE: 49324858", 36); + scoreText.setFormat("VCR OSD Mono", 32); + add(scoreText); + + 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); + add(rankText); + + 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); + + 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); + add(weekThing); + } + + add(yellowBG); + + 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); + + updateText(); + + super.create(); + } + + override function update(elapsed:Float) + { + // scoreText.setFormat('VCR OSD Mono', 32); + // scoreText.text = "Score SHIT"; + // FlxG.watch.addQuick('font', scoreText.font); + + if (controls.UP_P) + changeWeek(-1); + if (controls.DOWN_P) + changeWeek(1); + + super.update(elapsed); + } + + function changeWeek(change:Int = 0):Void + { + curWeek += change; + + if (curWeek >= weekData.length) + curWeek = 0; + if (curWeek < 0) + curWeek = weekData.length - 1; + + updateText(); + } + + function updateText() + { + txtTracklist.text = "Tracks\n"; + + var stringThing:Array<String> = weekData[curWeek]; + + for (i in stringThing) + { + txtTracklist.text += "\n" + i; + } + + txtTracklist.text.toUpperCase(); + + txtTracklist.screenCenter(X); + txtTracklist.x -= FlxG.width * 0.35; + } +} diff --git a/source/TitleState.hx b/source/TitleState.hx index cf25c47fb..beb3c9d64 100644 --- a/source/TitleState.hx +++ b/source/TitleState.hx @@ -41,7 +41,7 @@ class TitleState extends MusicBeatState super.create(); #if SKIP_TO_PLAYSTATE - FlxG.switchState(new FreeplayState()); + FlxG.switchState(new StoryMenuState()); #else startIntro(); #end