1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2024-12-12 08:25:13 +00:00
Funkin/source/funkin/freeplayStuff/LetterSort.hx

101 lines
2.3 KiB
Haxe
Raw Normal View History

2022-09-27 08:37:42 +00:00
package funkin.freeplayStuff;
import flixel.FlxSprite;
import flixel.group.FlxGroup.FlxTypedGroup;
import flixel.group.FlxGroup;
import flixel.group.FlxSpriteGroup.FlxTypedSpriteGroup;
class LetterSort extends FlxTypedSpriteGroup<FreeplayLetter>
{
public var letters:Array<FreeplayLetter> = [];
2022-09-27 08:37:42 +00:00
var curSelection:Int = 0;
2022-09-27 08:37:42 +00:00
public var changeSelectionCallback:String->Void;
2022-09-27 08:37:42 +00:00
public function new(x, y)
{
super(x, y);
2022-09-27 08:37:42 +00:00
var leftArrow:FreeplayLetter = new FreeplayLetter(-20, 0);
leftArrow.animation.play("arrow");
add(leftArrow);
2022-09-27 08:37:42 +00:00
for (i in 0...6)
{
var letter:FreeplayLetter = new FreeplayLetter(i * 80, 0, i);
add(letter);
2022-09-27 08:37:42 +00:00
letters.push(letter);
2022-09-27 08:37:42 +00:00
if (i == 3) letter.alpha = 0.6;
2022-09-27 08:37:42 +00:00
var sep:FreeplayLetter = new FreeplayLetter((i * 80) + 50, 0);
sep.animation.play("seperator");
add(sep);
}
2022-09-27 08:37:42 +00:00
// changeSelection(-3);
}
2022-09-27 08:37:42 +00:00
override function update(elapsed:Float)
{
super.update(elapsed);
2022-09-27 08:37:42 +00:00
if (FlxG.keys.justPressed.E) changeSelection(1);
if (FlxG.keys.justPressed.Q) changeSelection(-1);
}
2022-09-27 08:37:42 +00:00
public function changeSelection(diff:Int = 0)
{
for (letter in letters)
letter.changeLetter(diff);
2022-09-27 08:37:42 +00:00
if (changeSelectionCallback != null) changeSelectionCallback(letters[3].arr[letters[3].curLetter]); // bullshit and long lol!
}
2022-09-27 08:37:42 +00:00
}
class FreeplayLetter extends FlxSprite
{
public var arr:Array<String> = [];
2022-09-27 08:37:42 +00:00
public var curLetter:Int = 0;
2022-09-27 08:37:42 +00:00
public function new(x:Float, y:Float, ?letterInd:Int)
{
super(x, y);
2022-09-27 08:37:42 +00:00
frames = Paths.getSparrowAtlas("freeplay/letterStuff");
2022-09-27 08:37:42 +00:00
var alphabet:String = "abcdefghijklmnopqrstuvwxyz";
arr = alphabet.split("");
arr.insert(0, "#");
arr.insert(0, "ALL");
arr.insert(0, "fav");
2022-09-27 08:37:42 +00:00
for (str in arr)
{
animation.addByPrefix(str, str + " "); // string followed by a space! intentional!
}
2022-09-27 08:37:42 +00:00
animation.addByPrefix("arrow", "mini arrow");
animation.addByPrefix("seperator", "seperator");
2022-09-27 08:37:42 +00:00
if (letterInd != null)
{
animation.play(arr[letterInd]);
curLetter = letterInd;
}
}
2022-09-27 08:37:42 +00:00
public function changeLetter(diff:Int = 0)
{
curLetter += diff;
2022-09-27 08:37:42 +00:00
if (curLetter < 0) curLetter = arr.length - 1;
if (curLetter >= arr.length) curLetter = 0;
2022-09-27 08:37:42 +00:00
animation.play(arr[curLetter]);
}
2022-09-27 08:37:42 +00:00
}