From 4918c4f6453fd84068cf1503288cd7b5c80e8445 Mon Sep 17 00:00:00 2001 From: Cameron Taylor Date: Tue, 27 Sep 2022 04:37:42 -0400 Subject: [PATCH] alphabetical sorting stuuuuf --- source/funkin/FreeplayState.hx | 77 ++++++++++++---- source/funkin/freeplayStuff/LetterSort.hx | 106 ++++++++++++++++++++++ 2 files changed, 163 insertions(+), 20 deletions(-) create mode 100644 source/funkin/freeplayStuff/LetterSort.hx diff --git a/source/funkin/FreeplayState.hx b/source/funkin/FreeplayState.hx index 6423b4b0b..c2c0e5c8c 100644 --- a/source/funkin/FreeplayState.hx +++ b/source/funkin/FreeplayState.hx @@ -25,6 +25,7 @@ import funkin.Controls.Control; import funkin.freeplayStuff.BGScrollingText; import funkin.freeplayStuff.DJBoyfriend; import funkin.freeplayStuff.FreeplayScore; +import funkin.freeplayStuff.LetterSort; import funkin.freeplayStuff.SongMenuItem; import funkin.play.HealthIcon; import funkin.play.PlayState; @@ -242,6 +243,14 @@ class FreeplayState extends MusicBeatSubstate add(new DifficultySelector(20, grpDifficulties.y - 10, false, controls)); add(new DifficultySelector(325, grpDifficulties.y - 10, true, controls)); + var letterSort:LetterSort = new LetterSort(300, 100); + add(letterSort); + + letterSort.changeSelectionCallback = (str) -> + { + generateSongList(str, true); + }; + new FlxTimer().start(1 / 24, function(handShit) { fnfFreeplay.visible = true; @@ -299,7 +308,7 @@ class FreeplayState extends MusicBeatSubstate typing.callback = function(txt, action) { - generateSongList(new EReg(txt.trim(), "ig")); + // generateSongList(new EReg(txt.trim(), "ig")); trace(action); }; @@ -311,29 +320,48 @@ class FreeplayState extends MusicBeatSubstate super.create(); } - public function generateSongList(?regexp:EReg) + public function generateSongList(?startsWith:String, ?force:Bool = false) { curSelected = 0; grpCapsules.clear(); - var regexp:EReg = regexp; + // var regexp:EReg = regexp; var tempSongs:Array = songs; - if (regexp != null) - tempSongs = songs.filter(item -> regexp.match(item.songName)); - tempSongs.sort(function(a, b):Int + if (startsWith != null) { - var tempA = a.songName.toUpperCase(); - var tempB = b.songName.toUpperCase(); + trace("STARTS WITH: " + startsWith); + switch (startsWith) + { + case "ALL": + case "#": + default: + trace(tempSongs.length); - if (tempA < tempB) - return -1; - else if (tempA > tempB) - return 1; - else - return 0; - }); + tempSongs = tempSongs.filter(str -> + { + return str.songName.toLowerCase().startsWith(startsWith); + }); + trace(tempSongs.length); + } + } + + // if (regexp != null) + // tempSongs = songs.filter(item -> regexp.match(item.songName)); + + // tempSongs.sort(function(a, b):Int + // { + // var tempA = a.songName.toUpperCase(); + // var tempB = b.songName.toUpperCase(); + + // if (tempA < tempB) + // return -1; + // else if (tempA > tempB) + // return 1; + // else + // return 0; + // }); for (i in 0...tempSongs.length) { @@ -355,11 +383,19 @@ class FreeplayState extends MusicBeatSubstate funnyMenu.doLerp = true; }); - new FlxTimer().start(((0.20 * i) / (1 + i)) + 0.75, function(swagShi) + if (!force) + { + new FlxTimer().start(((0.20 * i) / (1 + i)) + 0.75, function(swagShi) + { + funnyMenu.songText.visible = true; + funnyMenu.alpha = 1; + }); + } + else { funnyMenu.songText.visible = true; funnyMenu.alpha = 1; - }); + } grpCapsules.add(funnyMenu); @@ -649,8 +685,8 @@ class FreeplayState extends MusicBeatSubstate curSelected += change; if (curSelected < 0) - curSelected = songs.length - 1; - if (curSelected >= songs.length) + curSelected = grpCapsules.members.length - 1; + if (curSelected >= grpCapsules.members.length) curSelected = 0; // selector.y = (70 * curSelected) + 30; @@ -684,7 +720,8 @@ class FreeplayState extends MusicBeatSubstate capsule.targetPos.y -= 100; // another 100 for good measure } - grpCapsules.members[curSelected].selected = true; + if (grpCapsules.members.length > 0) + grpCapsules.members[curSelected].selected = true; } } diff --git a/source/funkin/freeplayStuff/LetterSort.hx b/source/funkin/freeplayStuff/LetterSort.hx new file mode 100644 index 000000000..b263bc357 --- /dev/null +++ b/source/funkin/freeplayStuff/LetterSort.hx @@ -0,0 +1,106 @@ +package funkin.freeplayStuff; + +import flixel.FlxSprite; +import flixel.group.FlxGroup.FlxTypedGroup; +import flixel.group.FlxGroup; +import flixel.group.FlxSpriteGroup.FlxTypedSpriteGroup; + +class LetterSort extends FlxTypedSpriteGroup +{ + public var letters:Array = []; + + var curSelection:Int = 0; + + public var changeSelectionCallback:String->Void; + + public function new(x, y) + { + super(x, y); + + var leftArrow:FreeplayLetter = new FreeplayLetter(-20, 0); + leftArrow.animation.play("arrow"); + add(leftArrow); + + for (i in 0...6) + { + var letter:FreeplayLetter = new FreeplayLetter(i * 80, 0, i); + add(letter); + + letters.push(letter); + + if (i == 3) + letter.alpha = 0.6; + + var sep:FreeplayLetter = new FreeplayLetter((i * 80) + 50, 0); + sep.animation.play("seperator"); + add(sep); + } + + // changeSelection(-3); + } + + override function update(elapsed:Float) + { + super.update(elapsed); + + if (FlxG.keys.justPressed.E) + changeSelection(1); + if (FlxG.keys.justPressed.Q) + changeSelection(-1); + } + + public function changeSelection(diff:Int = 0) + { + for (letter in letters) + letter.changeLetter(diff); + + if (changeSelectionCallback != null) + changeSelectionCallback(letters[3].arr[letters[3].curLetter]); // bullshit and long lol! + } +} + +class FreeplayLetter extends FlxSprite +{ + public var arr:Array = []; + + public var curLetter:Int = 0; + + public function new(x:Float, y:Float, ?letterInd:Int) + { + super(x, y); + + frames = Paths.getSparrowAtlas("freeplay/letterStuff"); + + var alphabet:String = "abcdefghijklmnopqrstuvwxyz"; + arr = alphabet.split(""); + arr.insert(0, "#"); + arr.insert(0, "ALL"); + arr.insert(0, "fav"); + + for (str in arr) + { + animation.addByPrefix(str, str + " "); // string followed by a space! intentional! + } + + animation.addByPrefix("arrow", "mini arrow"); + animation.addByPrefix("seperator", "seperator"); + + if (letterInd != null) + { + animation.play(arr[letterInd]); + curLetter = letterInd; + } + } + + public function changeLetter(diff:Int = 0) + { + curLetter += diff; + + if (curLetter < 0) + curLetter = arr.length - 1; + if (curLetter >= arr.length) + curLetter = 0; + + animation.play(arr[curLetter]); + } +}