2021-10-21 17:40:53 -04:00
|
|
|
package freeplayStuff;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
class SongMenuItem extends FlxSpriteGroup
|
|
|
|
{
|
|
|
|
var capsule:FlxSprite;
|
|
|
|
|
|
|
|
public var selected(default, set):Bool = false;
|
|
|
|
|
|
|
|
public var songTitle:String = "Test";
|
|
|
|
|
2021-12-04 01:19:25 -05:00
|
|
|
public var songText:FlxText;
|
2021-10-21 17:40:53 -04:00
|
|
|
|
|
|
|
public var targetPos:FlxPoint = new FlxPoint();
|
|
|
|
public var doLerp:Bool = false;
|
|
|
|
|
|
|
|
public function new(x:Float, y:Float, song:String)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
|
|
|
|
songText = new FlxText(120, 40, 0, songTitle, 40);
|
|
|
|
songText.font = "5by7";
|
|
|
|
songText.color = 0xFF43C1EA;
|
|
|
|
add(songText);
|
|
|
|
|
|
|
|
selected = selected; // just to kickstart the set_selected
|
|
|
|
}
|
|
|
|
|
2021-12-04 00:38:45 -05:00
|
|
|
var frameTicker:Float = 0;
|
|
|
|
var frameTypeBeat:Int = 0;
|
|
|
|
|
|
|
|
var xFrames:Array<Float> = [1.6, 1.8, 0.85, 0.85, 0.97, 0.97, 1];
|
|
|
|
var xPosLerpLol:Array<Float> = [0.8, 0.4, 0.16, 0.16, 0.22, 0.22, 0.245]; // NUMBERS ARE JANK CUZ THE SCALING OR WHATEVER
|
|
|
|
|
2021-10-21 17:40:53 -04:00
|
|
|
override function update(elapsed:Float)
|
|
|
|
{
|
|
|
|
if (doLerp)
|
|
|
|
{
|
2021-12-04 00:38:45 -05:00
|
|
|
frameTicker += elapsed;
|
|
|
|
|
|
|
|
if (frameTicker >= 1 / 24 && frameTypeBeat < xFrames.length)
|
|
|
|
{
|
|
|
|
frameTicker = 0;
|
|
|
|
|
|
|
|
scale.x = xFrames[frameTypeBeat];
|
|
|
|
scale.y = 1 / xFrames[frameTypeBeat];
|
|
|
|
x = FlxG.width * xPosLerpLol[Std.int(Math.min(frameTypeBeat, xPosLerpLol.length - 1))];
|
|
|
|
|
|
|
|
frameTypeBeat += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// x = CoolUtil.coolLerp(x, targetPos.x, 0.3);
|
2021-10-21 17:40:53 -04:00
|
|
|
y = CoolUtil.coolLerp(y, targetPos.y, 0.4);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FlxG.keys.justPressed.ALT)
|
|
|
|
selected = false;
|
|
|
|
if (FlxG.keys.justPressed.CONTROL)
|
|
|
|
selected = true;
|
|
|
|
|
|
|
|
super.update(elapsed);
|
|
|
|
}
|
|
|
|
|
|
|
|
function set_selected(value:Bool):Bool
|
|
|
|
{
|
2021-11-29 13:13:48 -05:00
|
|
|
// trace(value);
|
2021-10-21 17:40:53 -04:00
|
|
|
|
|
|
|
// cute one liners, lol!
|
|
|
|
songText.alpha = value ? 1 : 0.6;
|
|
|
|
capsule.offset.x = value ? 0 : -5;
|
|
|
|
capsule.animation.play(value ? "selected" : "unselected");
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
}
|