Funkin/source/funkin/freeplayStuff/LetterSort.hx

123 lines
3 KiB
Haxe
Raw Normal View History

2022-09-27 04:37:42 -04:00
package funkin.freeplayStuff;
import flixel.FlxSprite;
import flixel.group.FlxGroup.FlxTypedGroup;
import flixel.group.FlxGroup;
import flixel.group.FlxSpriteGroup.FlxTypedSpriteGroup;
2023-08-06 16:24:34 -04:00
import flixel.tweens.FlxTween;
import flixel.tweens.FlxEase;
2023-08-06 17:02:37 -04:00
import flixel.util.FlxColor;
2022-09-27 04:37:42 -04:00
class LetterSort extends FlxTypedSpriteGroup<FreeplayLetter>
{
public var letters:Array<FreeplayLetter> = [];
2022-09-27 04:37:42 -04:00
var curSelection:Int = 0;
2022-09-27 04:37:42 -04:00
public var changeSelectionCallback:String->Void;
2022-09-27 04:37:42 -04:00
public function new(x, y)
{
super(x, y);
2022-09-27 04:37:42 -04:00
2023-08-04 18:09:40 -04:00
var leftArrow:FreeplayLetter = new FreeplayLetter(-20, 20);
leftArrow.animation.play("arrow");
2023-08-04 18:09:40 -04:00
leftArrow.flipX = true;
add(leftArrow);
2022-09-27 04:37:42 -04:00
2023-08-04 18:09:40 -04:00
for (i in 0...5)
{
var letter:FreeplayLetter = new FreeplayLetter(i * 80, 0, i);
2023-08-06 16:24:34 -04:00
letter.ogY = y;
add(letter);
2022-09-27 04:37:42 -04:00
letters.push(letter);
2022-09-27 04:37:42 -04:00
2023-08-06 17:02:37 -04:00
if (i == 2) letter.scale.x = letter.scale.y = 1.2;
var darkness:Float = Math.abs(i - 2) / 6;
letter.color = letter.color.getDarkened(darkness);
2022-09-27 04:37:42 -04:00
2023-08-04 18:09:40 -04:00
// don't put the last seperator
if (i == 4) continue;
2023-08-06 17:02:37 -04:00
var sep:FreeplayLetter = new FreeplayLetter((i * 80) + 55, 20);
sep.animation.play("seperator");
2023-08-06 17:02:37 -04:00
sep.color = letter.color.getDarkened(darkness);
add(sep);
}
2022-09-27 04:37:42 -04:00
2023-08-04 18:09:40 -04:00
var rightArrow:FreeplayLetter = new FreeplayLetter(380, 20);
rightArrow.animation.play("arrow");
add(rightArrow);
2023-08-06 16:24:34 -04:00
changeSelection(0);
}
2022-09-27 04:37:42 -04:00
override function update(elapsed:Float)
{
super.update(elapsed);
2022-09-27 04:37:42 -04:00
if (FlxG.keys.justPressed.E) changeSelection(1);
if (FlxG.keys.justPressed.Q) changeSelection(-1);
}
2022-09-27 04:37:42 -04:00
public function changeSelection(diff:Int = 0)
{
2023-08-06 16:24:34 -04:00
curSelection += diff;
if (curSelection < 0) curSelection = letters.length - 1;
if (curSelection >= letters.length) curSelection = 0;
for (letter in letters)
2023-08-06 16:24:34 -04:00
letter.changeLetter(diff, curSelection);
2022-09-27 04:37:42 -04:00
2023-08-04 18:09:40 -04:00
if (changeSelectionCallback != null) changeSelectionCallback(letters[2].arr[letters[2].curLetter]); // bullshit and long lol!
}
2022-09-27 04:37:42 -04:00
}
class FreeplayLetter extends FlxSprite
{
public var arr:Array<String> = [];
2022-09-27 04:37:42 -04:00
public var curLetter:Int = 0;
2022-09-27 04:37:42 -04:00
2023-08-06 16:24:34 -04:00
public var ogY:Float = 0;
public function new(x:Float, y:Float, ?letterInd:Int)
{
super(x, y);
frames = Paths.getSparrowAtlas("freeplay/letterStuff");
2022-09-27 04:37:42 -04:00
var alphabet:String = "abcdefghijklmnopqrstuvwxyz";
arr = alphabet.split("");
arr.insert(0, "ALL");
2023-08-06 16:24:34 -04:00
arr.insert(0, "#");
arr.insert(0, "fav");
2022-09-27 04:37:42 -04:00
for (str in arr)
{
animation.addByPrefix(str, str + " "); // string followed by a space! intentional!
}
2022-09-27 04:37:42 -04:00
animation.addByPrefix("arrow", "mini arrow");
animation.addByPrefix("seperator", "seperator");
2022-09-27 04:37:42 -04:00
if (letterInd != null)
{
animation.play(arr[letterInd]);
curLetter = letterInd;
}
}
2022-09-27 04:37:42 -04:00
2023-08-06 16:24:34 -04:00
public function changeLetter(diff:Int = 0, ?curSelection:Int)
{
curLetter += diff;
2022-09-27 04:37:42 -04:00
if (curLetter < 0) curLetter = arr.length - 1;
if (curLetter >= arr.length) curLetter = 0;
2022-09-27 04:37:42 -04:00
animation.play(arr[curLetter]);
}
2022-09-27 04:37:42 -04:00
}