1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2024-11-15 19:33:36 +00:00
Funkin/source/funkin/ui/freeplay/LetterSort.hx

241 lines
6.9 KiB
Haxe
Raw Normal View History

package funkin.ui.freeplay;
2022-09-27 08:37:42 +00:00
import flixel.FlxSprite;
import flixel.group.FlxGroup.FlxTypedGroup;
import flixel.group.FlxGroup;
import flixel.group.FlxSpriteGroup.FlxTypedSpriteGroup;
2023-08-06 20:24:34 +00:00
import flixel.tweens.FlxTween;
import flixel.tweens.FlxEase;
2023-08-06 21:02:37 +00:00
import flixel.util.FlxColor;
2023-08-07 02:20:18 +00:00
import flixel.util.FlxTimer;
import funkin.graphics.adobeanimate.FlxAtlasSprite;
2022-09-27 08:37:42 +00:00
2023-08-07 02:54:55 +00:00
class LetterSort extends FlxTypedSpriteGroup<FlxSprite>
2022-09-27 08:37:42 +00:00
{
public var letters:Array<FreeplayLetter> = [];
2022-09-27 08:37:42 +00:00
2023-08-07 21:58:55 +00:00
// starts at 2, cuz that's the middle letter on start (accounting for fav and #, it should begin at ALL filter)
2023-08-07 21:58:06 +00:00
var curSelection:Int = 2;
2022-09-27 08:37:42 +00:00
public var changeSelectionCallback:String->Void;
2022-09-27 08:37:42 +00:00
2023-08-07 02:54:55 +00:00
var leftArrow:FlxSprite;
var rightArrow:FlxSprite;
2023-08-07 21:58:06 +00:00
var grpSeperators:Array<FlxSprite> = [];
2023-08-07 02:20:18 +00:00
public var inputEnabled:Bool = true;
public function new(x, y)
{
super(x, y);
2022-09-27 08:37:42 +00:00
2023-08-07 02:54:55 +00:00
leftArrow = new FlxSprite(-20, 15).loadGraphic(Paths.image("freeplay/miniArrow"));
// leftArrow.animation.play("arrow");
2023-08-04 22:09:40 +00:00
leftArrow.flipX = true;
add(leftArrow);
2022-09-27 08:37:42 +00:00
2023-08-04 22:09:40 +00:00
for (i in 0...5)
{
var letter:FreeplayLetter = new FreeplayLetter(i * 80, 0, i);
2023-08-07 16:33:12 +00:00
letter.x += 50;
letter.y += 50;
2023-08-09 06:47:22 +00:00
// letter.visible = false;
add(letter);
2022-09-27 08:37:42 +00:00
letters.push(letter);
2022-09-27 08:37:42 +00:00
2023-08-06 21:06:07 +00:00
if (i != 2) letter.scale.x = letter.scale.y = 0.8;
2023-08-06 21:02:37 +00:00
var darkness:Float = Math.abs(i - 2) / 6;
letter.color = letter.color.getDarkened(darkness);
2022-09-27 08:37:42 +00:00
2023-08-04 22:09:40 +00:00
// don't put the last seperator
if (i == 4) continue;
var sep:FlxSprite = new FlxSprite((i * 80) + 60, 20).loadGraphic(Paths.image("freeplay/seperator"));
2023-08-07 02:54:55 +00:00
// sep.animation.play("seperator");
2023-08-06 21:02:37 +00:00
sep.color = letter.color.getDarkened(darkness);
add(sep);
2023-08-07 21:58:06 +00:00
grpSeperators.push(sep);
}
2022-09-27 08:37:42 +00:00
2023-08-07 02:54:55 +00:00
rightArrow = new FlxSprite(380, 15).loadGraphic(Paths.image("freeplay/miniArrow"));
// rightArrow.animation.play("arrow");
2023-08-04 22:09:40 +00:00
add(rightArrow);
2023-08-06 20:24:34 +00:00
changeSelection(0);
}
2022-09-27 08:37:42 +00:00
override function update(elapsed:Float):Void
{
super.update(elapsed);
2022-09-27 08:37:42 +00:00
if (inputEnabled)
{
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):Void
2024-04-17 02:12:07 +00:00
{
doLetterChangeAnims(diff);
var multiPosOrNeg:Float = diff > 0 ? 1 : -1;
// if we're moving left (diff < 0), we want control of the right arrow, and vice versa
var arrowToMove:FlxSprite = diff < 0 ? leftArrow : rightArrow;
arrowToMove.offset.x = 3 * multiPosOrNeg;
new FlxTimer().start(2 / 24, function(_) {
arrowToMove.offset.x = 0;
});
}
/**
* Buncho timers and stuff to move the letters and seperators
* Seperated out so we can call it again on letters with songs within them
* @param diff
*/
function doLetterChangeAnims(diff:Int):Void
{
2023-08-07 21:58:06 +00:00
var ezTimer:Int->FlxSprite->Float->Void = function(frameNum:Int, spr:FlxSprite, offsetNum:Float) {
2023-08-07 21:26:51 +00:00
new FlxTimer().start(frameNum / 24, function(_) {
2023-08-07 21:58:06 +00:00
spr.offset.x = offsetNum;
2023-08-07 21:26:51 +00:00
});
};
2023-08-07 21:58:06 +00:00
var positions:Array<Float> = [-10, -22, 2, 0];
2023-08-07 21:26:51 +00:00
2024-04-17 02:12:07 +00:00
// if we're moving left, we want to move the positions the same amount, but negative direciton
var multiPosOrNeg:Float = diff > 0 ? 1 : -1;
for (sep in grpSeperators)
2023-08-07 02:20:18 +00:00
{
2024-04-17 02:12:07 +00:00
ezTimer(0, sep, positions[0] * multiPosOrNeg);
ezTimer(1, sep, positions[1] * multiPosOrNeg);
ezTimer(2, sep, positions[2] * multiPosOrNeg);
ezTimer(3, sep, positions[3] * multiPosOrNeg);
}
2023-08-07 21:58:06 +00:00
2024-04-17 02:12:07 +00:00
for (index => letter in letters)
{
letter.offset.x = positions[0] * multiPosOrNeg;
new FlxTimer().start(1 / 24, function(_) {
letter.offset.x = positions[1] * multiPosOrNeg;
if (index == 0) letter.visible = false;
});
2023-08-07 21:26:51 +00:00
2023-08-07 02:20:18 +00:00
new FlxTimer().start(2 / 24, function(_) {
2024-04-17 02:12:07 +00:00
letter.offset.x = positions[2] * multiPosOrNeg;
if (index == 0.) letter.visible = true;
2023-08-07 02:20:18 +00:00
});
2023-08-07 21:58:06 +00:00
2024-04-17 02:12:07 +00:00
if (index == 2)
2023-08-07 21:26:51 +00:00
{
2024-04-17 02:12:07 +00:00
ezTimer(3, letter, 0);
// letter.offset.x = 0;
continue;
2023-08-07 21:26:51 +00:00
}
2024-04-17 02:12:07 +00:00
ezTimer(3, letter, positions[3] * multiPosOrNeg);
2023-08-07 02:20:18 +00:00
}
2023-08-06 20:24:34 +00:00
curSelection += diff;
if (curSelection < 0) curSelection = letters[0].regexLetters.length - 1;
if (curSelection >= letters[0].regexLetters.length) curSelection = 0;
2023-08-06 20:24:34 +00:00
for (letter in letters)
2023-08-07 21:58:06 +00:00
letter.changeLetter(diff, curSelection);
2022-09-27 08:37:42 +00:00
if (changeSelectionCallback != null) changeSelectionCallback(letters[2].regexLetters[letters[2].curLetter]); // bullshit and long lol!
}
2022-09-27 08:37:42 +00:00
}
2024-04-17 02:12:07 +00:00
/**
* The actual FlxAtlasSprite for the letters, with their animation code stuff and regex stuff
*/
2023-08-07 02:20:18 +00:00
class FreeplayLetter extends FlxAtlasSprite
2022-09-27 08:37:42 +00:00
{
/**
* A preformatted array of letter strings, for use when doing regex
* ex: ['A-B', 'C-D', 'E-H', 'I-L' ...]
*/
public var regexLetters:Array<String> = [];
/**
* A preformatted array of the letters, for use when accessing symbol animation info
* ex: ['AB', 'CD', 'EH', 'IL' ...]
*/
public var animLetters:Array<String> = [];
/**
* The current letter in the regexLetters array this FreeplayLetter is on
*/
public var curLetter:Int = 0;
2022-09-27 08:37:42 +00:00
public function new(x:Float, y:Float, ?letterInd:Int)
{
2023-08-07 02:20:18 +00:00
super(x, y, Paths.animateAtlas("freeplay/sortedLetters"));
2022-09-27 08:37:42 +00:00
// this is used for the regex
// /^[OR].*/gi doesn't work for showing the song Pico, so now it's
// /^[O-R].*/gi ant it works for displaying Pico
// https://regex101.com/r/bWFPfS/1
// we split by underscores, simply for nice lil convinience
var alphabet:String = 'A-B_C-D_E-H_I-L_M-N_O-R_S_T_U-Z';
regexLetters = alphabet.split('_');
regexLetters.insert(0, 'ALL');
regexLetters.insert(0, 'fav');
regexLetters.insert(0, '#');
// the symbols from flash don't have dashes, so we clean this up for use with animations
// (we don't need to re-export, rule of thumb is to accomodate files named in flash from dave
// until we get him programming classes (and since i cant find the .fla file....))
animLetters = regexLetters.map(animLetter -> animLetter.replace('-', ''));
2022-09-27 08:37:42 +00:00
if (letterInd != null)
{
this.anim.play(animLetters[letterInd] + " move");
2023-08-07 16:33:12 +00:00
this.anim.pause();
curLetter = letterInd;
}
}
2022-09-27 08:37:42 +00:00
2024-04-17 02:12:07 +00:00
/**
* Changes the letter graphic/anim, used in the LetterSort class above
* @param diff -1 or 1, to go left or right in the animation array
* @param curSelection what the current letter selection is, to play the bouncing anim if it matches the current letter
*/
public function changeLetter(diff:Int = 0, ?curSelection:Int):Void
{
curLetter += diff;
2022-09-27 08:37:42 +00:00
if (curLetter < 0) curLetter = regexLetters.length - 1;
if (curLetter >= regexLetters.length) curLetter = 0;
2022-09-27 08:37:42 +00:00
2024-04-17 02:12:07 +00:00
var animName:String = animLetters[curLetter] + ' move';
2023-08-07 21:58:06 +00:00
switch (animLetters[curLetter])
2023-08-07 19:42:38 +00:00
{
case "IL":
2023-08-07 19:42:38 +00:00
animName = "IL move";
case "s":
animName = "S move";
case "t":
animName = "T move";
}
this.anim.play(animName);
2023-08-07 21:58:06 +00:00
if (curSelection != curLetter)
{
this.anim.pause();
}
// updateHitbox();
}
2022-09-27 08:37:42 +00:00
}