2022-03-08 03:13:53 -05:00
|
|
|
package funkin.ui;
|
2021-02-21 13:08:30 -05:00
|
|
|
|
2022-03-08 03:13:53 -05:00
|
|
|
import funkin.ui.MenuList;
|
2021-02-21 13:08:30 -05:00
|
|
|
import flixel.graphics.frames.FlxAtlasFrames;
|
|
|
|
|
|
|
|
typedef AtlasAsset = flixel.util.typeLimit.OneOfTwo<String, FlxAtlasFrames>;
|
|
|
|
|
2022-03-29 21:56:04 -04:00
|
|
|
/**
|
|
|
|
* A menulist whose items share a single texture atlas.
|
|
|
|
*/
|
2021-02-21 13:08:30 -05:00
|
|
|
class AtlasMenuList extends MenuTypedList<AtlasMenuItem>
|
|
|
|
{
|
|
|
|
public var atlas:FlxAtlasFrames;
|
2022-03-08 03:13:53 -05:00
|
|
|
|
|
|
|
public function new(atlas, navControls:NavControls = Vertical, ?wrapMode)
|
2021-02-21 13:08:30 -05:00
|
|
|
{
|
2021-03-22 08:48:52 -04:00
|
|
|
super(navControls, wrapMode);
|
2022-03-08 03:13:53 -05:00
|
|
|
|
2021-02-21 13:08:30 -05:00
|
|
|
if (Std.is(atlas, String))
|
|
|
|
this.atlas = Paths.getSparrowAtlas(cast atlas);
|
|
|
|
else
|
|
|
|
this.atlas = cast atlas;
|
|
|
|
}
|
2022-03-08 03:13:53 -05:00
|
|
|
|
2021-02-21 13:08:30 -05:00
|
|
|
public function createItem(x = 0.0, y = 0.0, name, callback, fireInstantly = false)
|
|
|
|
{
|
|
|
|
var item = new AtlasMenuItem(x, y, name, atlas, callback);
|
|
|
|
item.fireInstantly = fireInstantly;
|
|
|
|
return addItem(name, item);
|
|
|
|
}
|
2022-03-08 03:13:53 -05:00
|
|
|
|
2021-02-21 13:08:30 -05:00
|
|
|
override function destroy()
|
|
|
|
{
|
|
|
|
super.destroy();
|
|
|
|
atlas = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-29 21:56:04 -04:00
|
|
|
/**
|
|
|
|
* A menu list item which uses single texture atlas.
|
|
|
|
*/
|
2021-02-21 13:08:30 -05:00
|
|
|
class AtlasMenuItem extends MenuItem
|
2022-03-08 03:13:53 -05:00
|
|
|
{
|
2021-02-21 13:08:30 -05:00
|
|
|
var atlas:FlxAtlasFrames;
|
2022-03-08 03:13:53 -05:00
|
|
|
|
2022-03-29 21:56:04 -04:00
|
|
|
public var centered:Bool = false;
|
|
|
|
|
|
|
|
public function new(x = 0.0, y = 0.0, name:String, atlas, callback)
|
2021-02-21 13:08:30 -05:00
|
|
|
{
|
|
|
|
this.atlas = atlas;
|
|
|
|
super(x, y, name, callback);
|
|
|
|
}
|
2022-03-08 03:13:53 -05:00
|
|
|
|
2021-02-21 13:08:30 -05:00
|
|
|
override function setData(name:String, ?callback:Void->Void)
|
|
|
|
{
|
|
|
|
frames = atlas;
|
|
|
|
animation.addByPrefix('idle', '$name idle', 24);
|
|
|
|
animation.addByPrefix('selected', '$name selected', 24);
|
2022-03-08 03:13:53 -05:00
|
|
|
|
2021-02-21 13:08:30 -05:00
|
|
|
super.setData(name, callback);
|
|
|
|
}
|
2022-03-08 03:13:53 -05:00
|
|
|
|
2022-03-29 21:56:04 -04:00
|
|
|
public function changeAnim(animName:String)
|
2021-02-21 13:08:30 -05:00
|
|
|
{
|
|
|
|
animation.play(animName);
|
|
|
|
updateHitbox();
|
2022-03-29 21:56:04 -04:00
|
|
|
|
|
|
|
if (centered)
|
|
|
|
{
|
|
|
|
// position by center
|
|
|
|
centerOrigin();
|
|
|
|
offset.copyFrom(origin);
|
|
|
|
}
|
2021-02-21 13:08:30 -05:00
|
|
|
}
|
2022-03-08 03:13:53 -05:00
|
|
|
|
2021-02-21 13:08:30 -05:00
|
|
|
override function idle()
|
|
|
|
{
|
|
|
|
changeAnim('idle');
|
|
|
|
}
|
2022-03-08 03:13:53 -05:00
|
|
|
|
2021-02-21 13:08:30 -05:00
|
|
|
override function select()
|
|
|
|
{
|
|
|
|
changeAnim('selected');
|
|
|
|
}
|
2022-03-08 03:13:53 -05:00
|
|
|
|
2021-02-21 13:08:30 -05:00
|
|
|
override function get_selected()
|
|
|
|
{
|
|
|
|
return animation.curAnim != null && animation.curAnim.name == "selected";
|
|
|
|
}
|
2022-03-08 03:13:53 -05:00
|
|
|
|
2021-02-21 13:08:30 -05:00
|
|
|
override function destroy()
|
|
|
|
{
|
|
|
|
super.destroy();
|
|
|
|
atlas = null;
|
|
|
|
}
|
2022-03-08 03:13:53 -05:00
|
|
|
}
|