2022-03-08 03:13:53 -05:00
|
|
|
package funkin.freeplayStuff;
|
2021-10-21 17:40:53 -04:00
|
|
|
|
|
|
|
import flixel.FlxSprite;
|
|
|
|
import flixel.graphics.frames.FlxAtlasFrames;
|
|
|
|
import flixel.group.FlxSpriteGroup.FlxTypedSpriteGroup;
|
|
|
|
import flixel.group.FlxSpriteGroup;
|
|
|
|
import flixel.math.FlxMath;
|
|
|
|
import flixel.math.FlxPoint;
|
|
|
|
import flixel.text.FlxText;
|
2023-08-06 16:24:34 -04:00
|
|
|
import flixel.util.FlxTimer;
|
2023-08-11 21:45:34 -04:00
|
|
|
import funkin.shaderslmfao.Grayscale;
|
2021-10-21 17:40:53 -04:00
|
|
|
|
|
|
|
class SongMenuItem extends FlxSpriteGroup
|
|
|
|
{
|
2023-01-22 22:25:45 -05:00
|
|
|
var capsule:FlxSprite;
|
2023-08-08 14:35:07 -04:00
|
|
|
var pixelIcon:FlxSprite;
|
2023-01-22 22:25:45 -05:00
|
|
|
|
|
|
|
public var selected(default, set):Bool = false;
|
|
|
|
|
|
|
|
public var songTitle:String = "Test";
|
|
|
|
|
|
|
|
public var songText:FlxText;
|
|
|
|
public var favIcon:FlxSprite;
|
2023-08-11 05:20:25 -04:00
|
|
|
public var ranking:FlxSprite;
|
|
|
|
|
|
|
|
var ranks:Array<String> = ["fail", "average", "great", "excellent", "perfect"];
|
2023-01-22 22:25:45 -05:00
|
|
|
|
2023-08-11 21:45:34 -04:00
|
|
|
// lol...
|
|
|
|
var diffRanks:Array<String> = [
|
|
|
|
"00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "14", "15"
|
|
|
|
];
|
|
|
|
|
2023-01-22 22:25:45 -05:00
|
|
|
public var targetPos:FlxPoint = new FlxPoint();
|
|
|
|
public var doLerp:Bool = false;
|
|
|
|
public var doJumpIn:Bool = false;
|
|
|
|
|
2023-03-15 21:05:15 -04:00
|
|
|
public var doJumpOut:Bool = false;
|
|
|
|
|
2023-08-06 16:24:34 -04:00
|
|
|
public var onConfirm:Void->Void;
|
2023-08-11 21:45:34 -04:00
|
|
|
public var diffGrayscale:Grayscale;
|
2023-08-06 16:24:34 -04:00
|
|
|
|
2023-08-08 14:35:07 -04:00
|
|
|
public function new(x:Float, y:Float, song:String, ?character:String)
|
2023-01-22 22:25:45 -05:00
|
|
|
{
|
|
|
|
super(x, y);
|
|
|
|
|
|
|
|
this.songTitle = song;
|
|
|
|
|
|
|
|
capsule = new FlxSprite();
|
|
|
|
capsule.frames = Paths.getSparrowAtlas('freeplay/freeplayCapsule');
|
|
|
|
capsule.animation.addByPrefix('selected', 'mp3 capsule w backing0', 24);
|
|
|
|
capsule.animation.addByPrefix('unselected', 'mp3 capsule w backing NOT SELECTED', 24);
|
|
|
|
// capsule.animation
|
|
|
|
add(capsule);
|
|
|
|
|
2023-08-11 05:20:25 -04:00
|
|
|
var rank:String = FlxG.random.getObject(ranks);
|
|
|
|
|
|
|
|
ranking = new FlxSprite(capsule.width * 0.78, 30);
|
|
|
|
ranking.loadGraphic(Paths.image("freeplay/ranks/" + rank));
|
|
|
|
ranking.scale.x = ranking.scale.y = realScaled;
|
|
|
|
ranking.alpha = 0.75;
|
|
|
|
add(ranking);
|
|
|
|
|
2023-08-11 21:45:34 -04:00
|
|
|
diffGrayscale = new Grayscale(1);
|
|
|
|
|
|
|
|
var diffRank = new FlxSprite(145, 90).loadGraphic(Paths.image("freeplay/diffRankings/diff" + FlxG.random.getObject(diffRanks)));
|
|
|
|
diffRank.shader = diffGrayscale;
|
|
|
|
add(diffRank);
|
|
|
|
|
2023-08-11 05:20:25 -04:00
|
|
|
switch (rank)
|
|
|
|
{
|
|
|
|
case "perfect":
|
|
|
|
ranking.x -= 10;
|
|
|
|
}
|
|
|
|
|
2023-08-04 17:10:27 -04:00
|
|
|
songText = new FlxText(capsule.width * 0.23, 40, 0, songTitle, Std.int(40 * realScaled));
|
2023-01-22 22:25:45 -05:00
|
|
|
songText.font = "5by7";
|
|
|
|
songText.color = 0xFF43C1EA;
|
|
|
|
add(songText);
|
|
|
|
|
2023-08-08 14:35:07 -04:00
|
|
|
pixelIcon = new FlxSprite(80, 35);
|
|
|
|
pixelIcon.makeGraphic(32, 32, 0x00000000);
|
|
|
|
pixelIcon.antialiasing = false;
|
2023-08-09 02:47:22 -04:00
|
|
|
pixelIcon.active = false;
|
2023-08-08 14:35:07 -04:00
|
|
|
add(pixelIcon);
|
|
|
|
|
|
|
|
if (character != null) setCharacter(character);
|
|
|
|
|
2023-08-04 18:09:40 -04:00
|
|
|
favIcon = new FlxSprite(400, 40);
|
2023-01-22 22:25:45 -05:00
|
|
|
favIcon.frames = Paths.getSparrowAtlas('freeplay/favHeart');
|
|
|
|
favIcon.animation.addByPrefix('fav', "favorite heart", 24, false);
|
|
|
|
favIcon.animation.play('fav');
|
|
|
|
favIcon.setGraphicSize(60, 60);
|
|
|
|
add(favIcon);
|
|
|
|
|
|
|
|
selected = selected; // just to kickstart the set_selected
|
|
|
|
}
|
|
|
|
|
2023-08-09 02:47:22 -04:00
|
|
|
public function init(x:Float, y:Float, song:String, ?character:String)
|
|
|
|
{
|
|
|
|
this.x = x;
|
|
|
|
this.y = y;
|
|
|
|
this.songTitle = song;
|
|
|
|
songText.text = this.songTitle;
|
|
|
|
if (character != null) setCharacter(character);
|
|
|
|
|
|
|
|
selected = selected;
|
|
|
|
}
|
|
|
|
|
2023-08-08 14:35:07 -04:00
|
|
|
/**
|
|
|
|
* [Description]
|
|
|
|
* @param char Should be songCharacter, and will get translated to the correct path via switch
|
|
|
|
*/
|
|
|
|
public function setCharacter(char:String)
|
|
|
|
{
|
|
|
|
var charPath:String = "freeplay/icons/";
|
|
|
|
|
|
|
|
switch (char)
|
|
|
|
{
|
|
|
|
case "monster-christmas":
|
|
|
|
charPath += "monsterpixel";
|
|
|
|
case "mom":
|
|
|
|
charPath += "mommypixel";
|
|
|
|
case "dad":
|
|
|
|
charPath += "daddypixel";
|
|
|
|
default:
|
|
|
|
charPath += char + "pixel";
|
|
|
|
}
|
|
|
|
|
|
|
|
pixelIcon.loadGraphic(Paths.image(charPath));
|
|
|
|
pixelIcon.setGraphicSize(Std.int(pixelIcon.width * 2));
|
|
|
|
// pixelIcon.updateHitbox();
|
|
|
|
}
|
|
|
|
|
2023-03-15 21:05:15 -04:00
|
|
|
var frameInTicker:Float = 0;
|
|
|
|
var frameInTypeBeat:Int = 0;
|
|
|
|
|
|
|
|
var frameOutTicker:Float = 0;
|
|
|
|
var frameOutTypeBeat:Int = 0;
|
2023-01-22 22:25:45 -05:00
|
|
|
|
|
|
|
var xFrames:Array<Float> = [1.7, 1.8, 0.85, 0.85, 0.97, 0.97, 1];
|
|
|
|
var xPosLerpLol:Array<Float> = [0.9, 0.4, 0.16, 0.16, 0.22, 0.22, 0.245]; // NUMBERS ARE JANK CUZ THE SCALING OR WHATEVER
|
2023-03-15 21:05:15 -04:00
|
|
|
var xPosOutLerpLol:Array<Float> = [0.245, 0.75, 0.98, 0.98, 1.2]; // NUMBERS ARE JANK CUZ THE SCALING OR WHATEVER
|
2023-01-22 22:25:45 -05:00
|
|
|
|
2023-08-04 16:19:48 -04:00
|
|
|
public final realScaled:Float = 0.8;
|
|
|
|
|
2023-08-06 16:24:34 -04:00
|
|
|
public function initJumpIn(maxTimer:Float, ?force:Bool):Void
|
|
|
|
{
|
2023-08-09 02:47:22 -04:00
|
|
|
frameInTypeBeat = 0;
|
|
|
|
|
2023-08-06 16:24:34 -04:00
|
|
|
new FlxTimer().start((1 / 24) * maxTimer, function(doShit) {
|
|
|
|
doJumpIn = true;
|
|
|
|
});
|
|
|
|
|
|
|
|
new FlxTimer().start((0.09 * maxTimer) + 0.85, function(lerpTmr) {
|
|
|
|
doLerp = true;
|
|
|
|
});
|
|
|
|
|
2023-08-09 02:47:22 -04:00
|
|
|
if (force)
|
2023-08-06 16:24:34 -04:00
|
|
|
{
|
2023-08-09 02:47:22 -04:00
|
|
|
alpha = 1;
|
|
|
|
songText.visible = true;
|
2023-08-06 16:24:34 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-08-09 02:47:22 -04:00
|
|
|
new FlxTimer().start((xFrames.length / 24) * 2.5, function(_) {
|
|
|
|
songText.visible = true;
|
|
|
|
alpha = 1;
|
|
|
|
});
|
2023-08-06 16:24:34 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-09 02:47:22 -04:00
|
|
|
public function forcePosition()
|
|
|
|
{
|
|
|
|
alpha = 1;
|
|
|
|
doLerp = true;
|
|
|
|
doJumpIn = false;
|
|
|
|
doJumpOut = false;
|
|
|
|
|
|
|
|
frameInTypeBeat = xFrames.length;
|
|
|
|
frameOutTypeBeat = 0;
|
|
|
|
|
|
|
|
capsule.scale.x = xFrames[frameInTypeBeat - 1];
|
|
|
|
capsule.scale.y = 1 / xFrames[frameInTypeBeat - 1];
|
|
|
|
// x = FlxG.width * xPosLerpLol[Std.int(Math.min(frameInTypeBeat - 1, xPosLerpLol.length - 1))];
|
|
|
|
|
|
|
|
x = targetPos.x;
|
|
|
|
y = targetPos.y;
|
|
|
|
|
|
|
|
capsule.scale.x *= realScaled;
|
|
|
|
capsule.scale.y *= realScaled;
|
|
|
|
|
|
|
|
songText.visible = true;
|
|
|
|
}
|
|
|
|
|
2023-01-22 22:25:45 -05:00
|
|
|
override function update(elapsed:Float)
|
|
|
|
{
|
|
|
|
if (doJumpIn)
|
|
|
|
{
|
2023-03-15 21:05:15 -04:00
|
|
|
frameInTicker += elapsed;
|
|
|
|
|
|
|
|
if (frameInTicker >= 1 / 24 && frameInTypeBeat < xFrames.length)
|
|
|
|
{
|
|
|
|
frameInTicker = 0;
|
|
|
|
|
2023-08-08 14:35:07 -04:00
|
|
|
capsule.scale.x = xFrames[frameInTypeBeat];
|
|
|
|
capsule.scale.y = 1 / xFrames[frameInTypeBeat];
|
2023-03-15 21:05:15 -04:00
|
|
|
x = FlxG.width * xPosLerpLol[Std.int(Math.min(frameInTypeBeat, xPosLerpLol.length - 1))];
|
|
|
|
|
2023-08-08 14:35:07 -04:00
|
|
|
capsule.scale.x *= realScaled;
|
|
|
|
capsule.scale.y *= realScaled;
|
2023-08-04 16:19:48 -04:00
|
|
|
|
2023-03-15 21:05:15 -04:00
|
|
|
frameInTypeBeat += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (doJumpOut)
|
|
|
|
{
|
|
|
|
frameOutTicker += elapsed;
|
2023-01-22 22:25:45 -05:00
|
|
|
|
2023-03-15 21:05:15 -04:00
|
|
|
if (frameOutTicker >= 1 / 24 && frameOutTypeBeat < xFrames.length)
|
2023-01-22 22:25:45 -05:00
|
|
|
{
|
2023-03-15 21:05:15 -04:00
|
|
|
frameOutTicker = 0;
|
2023-01-22 22:25:45 -05:00
|
|
|
|
2023-08-08 14:35:07 -04:00
|
|
|
capsule.scale.x = xFrames[frameOutTypeBeat];
|
|
|
|
capsule.scale.y = 1 / xFrames[frameOutTypeBeat];
|
2023-03-15 21:05:15 -04:00
|
|
|
x = FlxG.width * xPosOutLerpLol[Std.int(Math.min(frameOutTypeBeat, xPosOutLerpLol.length - 1))];
|
2023-01-22 22:25:45 -05:00
|
|
|
|
2023-08-08 14:35:07 -04:00
|
|
|
capsule.scale.x *= realScaled;
|
|
|
|
capsule.scale.y *= realScaled;
|
2023-08-04 16:19:48 -04:00
|
|
|
|
2023-03-15 21:05:15 -04:00
|
|
|
frameOutTypeBeat += 1;
|
2023-01-22 22:25:45 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (doLerp)
|
|
|
|
{
|
|
|
|
x = CoolUtil.coolLerp(x, targetPos.x, 0.3);
|
|
|
|
y = CoolUtil.coolLerp(y, targetPos.y, 0.4);
|
|
|
|
}
|
|
|
|
|
|
|
|
super.update(elapsed);
|
|
|
|
}
|
|
|
|
|
2023-08-04 17:10:27 -04:00
|
|
|
public function intendedY(index:Int):Float
|
|
|
|
{
|
2023-08-04 18:09:40 -04:00
|
|
|
return (index * ((height * realScaled) + 10)) + 120;
|
2023-08-04 17:10:27 -04:00
|
|
|
}
|
|
|
|
|
2023-01-22 22:25:45 -05:00
|
|
|
function set_selected(value:Bool):Bool
|
|
|
|
{
|
|
|
|
// cute one liners, lol!
|
2023-08-11 21:45:34 -04:00
|
|
|
diffGrayscale.setAmount(value ? 0 : 0.8);
|
2023-01-22 22:25:45 -05:00
|
|
|
songText.alpha = value ? 1 : 0.6;
|
|
|
|
capsule.offset.x = value ? 0 : -5;
|
|
|
|
capsule.animation.play(value ? "selected" : "unselected");
|
2023-08-11 05:20:25 -04:00
|
|
|
ranking.alpha = value ? 1 : 0.7;
|
|
|
|
ranking.color = value ? 0xFFFFFFFF : 0xFFAAAAAA;
|
2023-01-22 22:25:45 -05:00
|
|
|
return value;
|
|
|
|
}
|
2021-10-21 17:40:53 -04:00
|
|
|
}
|