1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2025-03-22 01:49:21 +00:00

alphabet menu items + separate ngPrompt

This commit is contained in:
George FunBook 2021-02-21 12:08:30 -06:00
parent 3936f739b2
commit aef55f90c6
8 changed files with 330 additions and 130 deletions

View file

@ -71,24 +71,24 @@
<library name="week6" preload="false" /> <library name="week6" preload="false" />
</section> </section>
<assets path="assets/songs" library="songs" exclude="*.ogg" if="web"/> <assets path="assets/songs" library="songs" exclude="*.fla|*.ogg" if="web"/>
<assets path="assets/songs" library="songs" exclude="*.mp3" unless="web"/> <assets path="assets/songs" library="songs" exclude="*.fla|*.mp3" unless="web"/>
<assets path="assets/shared" library="shared" exclude="*.ogg" if="web"/> <assets path="assets/shared" library="shared" exclude="*.fla|*.ogg" if="web"/>
<assets path="assets/shared" library="shared" exclude="*.mp3" unless="web"/> <assets path="assets/shared" library="shared" exclude="*.fla|*.mp3" unless="web"/>
<assets path="assets/tutorial" library="tutorial" exclude="*.ogg" if="web"/> <assets path="assets/tutorial" library="tutorial" exclude="*.fla|*.ogg" if="web"/>
<assets path="assets/tutorial" library="tutorial" exclude="*.mp3" unless="web"/> <assets path="assets/tutorial" library="tutorial" exclude="*.fla|*.mp3" unless="web"/>
<assets path="assets/week1" library="week1" exclude="*.ogg" if="web"/> <assets path="assets/week1" library="week1" exclude="*.fla|*.ogg" if="web"/>
<assets path="assets/week1" library="week1" exclude="*.mp3" unless="web"/> <assets path="assets/week1" library="week1" exclude="*.fla|*.mp3" unless="web"/>
<assets path="assets/week2" library="week2" exclude="*.ogg" if="web"/> <assets path="assets/week2" library="week2" exclude="*.fla|*.ogg" if="web"/>
<assets path="assets/week2" library="week2" exclude="*.mp3" unless="web"/> <assets path="assets/week2" library="week2" exclude="*.fla|*.mp3" unless="web"/>
<assets path="assets/week3" library="week3" exclude="*.ogg" if="web"/> <assets path="assets/week3" library="week3" exclude="*.fla|*.ogg" if="web"/>
<assets path="assets/week3" library="week3" exclude="*.mp3" unless="web"/> <assets path="assets/week3" library="week3" exclude="*.fla|*.mp3" unless="web"/>
<assets path="assets/week4" library="week4" exclude="*.ogg" if="web"/> <assets path="assets/week4" library="week4" exclude="*.fla|*.ogg" if="web"/>
<assets path="assets/week4" library="week4" exclude="*.mp3" unless="web"/> <assets path="assets/week4" library="week4" exclude="*.fla|*.mp3" unless="web"/>
<assets path="assets/week5" library="week5" exclude="*.ogg" if="web"/> <assets path="assets/week5" library="week5" exclude="*.fla|*.ogg" if="web"/>
<assets path="assets/week5" library="week5" exclude="*.mp3" unless="web"/> <assets path="assets/week5" library="week5" exclude="*.fla|*.mp3" unless="web"/>
<assets path="assets/week6" library="week6" exclude="*.ogg" if="web"/> <assets path="assets/week6" library="week6" exclude="*.fla|*.ogg" if="web"/>
<assets path="assets/week6" library="week6" exclude="*.mp3" unless="web"/> <assets path="assets/week6" library="week6" exclude="*.fla|*.mp3" unless="web"/>
<assets path='example_mods' rename='mods' embed='false'/> <assets path='example_mods' rename='mods' embed='false'/>
<assets path='art/readme.txt' rename='do NOT readme.txt' /> <assets path='art/readme.txt' rename='do NOT readme.txt' />
@ -171,7 +171,7 @@
<section if="newgrounds"> <section if="newgrounds">
<!-- Enables Ng.core.verbose --> <!-- Enables Ng.core.verbose -->
<haxedef name="NG_VERBOSE" /> <!-- <haxedef name="NG_VERBOSE" /> -->
<!-- Enables a NG debug session, so medals don't permently unlock --> <!-- Enables a NG debug session, so medals don't permently unlock -->
<!-- <haxedef name="NG_DEBUG" /> --> <!-- <haxedef name="NG_DEBUG" /> -->

View file

@ -40,7 +40,7 @@ class Alphabet extends FlxSpriteGroup
var isBold:Bool = false; var isBold:Bool = false;
public function new(x:Float, y:Float, text:String = "", ?bold:Bool = false, typed:Bool = false) public function new(x:Float = 0.0, y:Float = 0.0, text:String = "", ?bold:Bool = false, typed:Bool = false)
{ {
super(x, y); super(x, y);

View file

@ -21,7 +21,8 @@ import lime.app.Application;
import io.newgrounds.NG; import io.newgrounds.NG;
#end #end
import ui.MenuItemList; import ui.MenuList;
import ui.AtlasMenuList;
import ui.Prompt; import ui.Prompt;
import ui.NgPrompt; import ui.NgPrompt;
@ -29,7 +30,7 @@ using StringTools;
class MainMenuState extends MusicBeatState class MainMenuState extends MusicBeatState
{ {
var menuItems:MainMenuItemList; var menuItems:MainMenuList;
var magenta:FlxSprite; var magenta:FlxSprite;
var camFollow:FlxObject; var camFollow:FlxObject;
@ -70,7 +71,7 @@ class MainMenuState extends MusicBeatState
add(magenta); add(magenta);
// magenta.scrollFactor.set(); // magenta.scrollFactor.set();
menuItems = new MainMenuItemList('FNF_main_menu_assets'); menuItems = new MainMenuList();
add(menuItems); add(menuItems);
menuItems.onChange.add(onMenuItemChange); menuItems.onChange.add(onMenuItemChange);
menuItems.onAcceptPress.add(function(_) menuItems.onAcceptPress.add(function(_)
@ -88,6 +89,7 @@ class MainMenuState extends MusicBeatState
#if CAN_OPEN_LINKS #if CAN_OPEN_LINKS
menuItems.createItem('donate', selectDonate, hasPopupBlocker); menuItems.createItem('donate', selectDonate, hasPopupBlocker);
#end #end
// menuItems.createItem('options', function () startExitState(new OptionsMenu()));
#if newgrounds #if newgrounds
if (NGio.isLoggedIn) if (NGio.isLoggedIn)
menuItems.createItem("logout", selectLogout); menuItems.createItem("logout", selectLogout);
@ -123,10 +125,10 @@ class MainMenuState extends MusicBeatState
menuItems.enabled = true; menuItems.enabled = true;
#if newgrounds // #if newgrounds
if (NGio.savedSessionFailed) // if (NGio.savedSessionFailed)
showSavedSessionFailed(); // showSavedSessionFailed();
#end // #end
} }
function onMenuItemChange(selected:MenuItem) function onMenuItemChange(selected:MenuItem)
@ -146,23 +148,46 @@ class MainMenuState extends MusicBeatState
#if newgrounds #if newgrounds
function selectLogin() function selectLogin()
{ {
openPrompt(NgPrompt.showLogin(), openNgPrompt(NgPrompt.showLogin());
function onPromptClose() menuItems.resetItem("login", "logout", selectLogout)
);
} }
function selectLogout() function selectLogout()
{ {
openPrompt(NgPrompt.showLogout(), openNgPrompt(NgPrompt.showLogout());
function onPromptClose() menuItems.resetItem("logout", "login", selectLogin)
);
} }
function showSavedSessionFailed() function showSavedSessionFailed()
{ {
openPrompt(NgPrompt.showSavedSessionFailed(), openNgPrompt(NgPrompt.showSavedSessionFailed());
function onPromptClose() menuItems.resetItem("login", "logout", selectLogout) }
);
/**
* Calls openPrompt and redraws the login/logout button
* @param prompt
* @param onClose
*/
public function openNgPrompt(prompt:Prompt, ?onClose:Void->Void)
{
var onPromptClose = checkLoginStatus;
if (onClose != null)
{
onPromptClose = function ()
{
checkLoginStatus();
onClose();
}
}
openPrompt(prompt, onPromptClose);
}
function checkLoginStatus()
{
var prevLoggedIn = menuItems.has("logout");
if (prevLoggedIn && !NGio.isLoggedIn)
menuItems.resetItem("login", "logout", selectLogout);
else if (!prevLoggedIn && NGio.isLoggedIn)
menuItems.resetItem("logout", "login", selectLogin);
} }
#end #end
@ -211,26 +236,22 @@ class MainMenuState extends MusicBeatState
} }
} }
private class MainMenuItemList extends MenuTypedItemList<MainMenuItem> private class MainMenuList extends MenuTypedList<MainMenuItem>
{ {
public var atlas:FlxAtlasFrames; public var atlas:FlxAtlasFrames;
public function new (atlas) public function new ()
{ {
atlas = Paths.getSparrowAtlas('main_menu');
super(Vertical); super(Vertical);
if (Std.is(atlas, String))
this.atlas = Paths.getSparrowAtlas(cast atlas);
else
this.atlas = cast atlas;
} }
public function createItem(x = 0.0, y = 0.0, name:String, callback, fireInstantly = false) public function createItem(x = 0.0, y = 0.0, name:String, callback, fireInstantly = false)
{ {
var i = length;
var item = new MainMenuItem(x, y, name, atlas, callback); var item = new MainMenuItem(x, y, name, atlas, callback);
item.fireInstantly = fireInstantly; item.fireInstantly = fireInstantly;
item.ID = i; item.ID = length;
return addItem(name, item); return addItem(name, item);
} }
@ -241,7 +262,7 @@ private class MainMenuItemList extends MenuTypedItemList<MainMenuItem>
atlas = null; atlas = null;
} }
} }
private class MainMenuItem extends MenuItem private class MainMenuItem extends AtlasMenuItem
{ {
public function new(x = 0.0, y = 0.0, name, atlas, callback) public function new(x = 0.0, y = 0.0, name, atlas, callback)
{ {

View file

@ -0,0 +1,53 @@
package ui;
import ui.MenuList;
class AlphabetMenuList extends MenuTypedList<AlphabetMenuItem>
{
public function new (navControls:NavControls = Vertical)
{
super(navControls);
}
public function createItem(x = 0.0, y = 0.0, name:String, bold = true, callback, fireInstantly = false)
{
var item = new AlphabetMenuItem(x, y, name, bold, callback);
item.fireInstantly = fireInstantly;
return addItem(name, item);
}
}
class AlphabetMenuItem extends AlphabetTypedMenuItem<Alphabet>
{
public function new (x = 0.0, y = 0.0, name:String, bold = true, callback)
{
super(x, y, new Alphabet(x, y, name, bold), name, callback);
}
}
class AlphabetTypedMenuItem<T:Alphabet> extends MenuTypedItem<T>
{
public function new (x = 0.0, y = 0.0, label:T, name:String, callback)
{
super(x, y, label, name, callback);
}
override function setItem(name:String, ?callback:() -> Void)
{
if (label != null)
{
label.text = name;
width = label.width;
height = label.height;
}
super.setItem(name, callback);
}
override function set_label(value:T):T
{
super.set_label(value);
setItem(name, callback);
return value;
}
}

View file

@ -0,0 +1,81 @@
package ui;
import ui.MenuList;
import flixel.graphics.frames.FlxAtlasFrames;
typedef AtlasAsset = flixel.util.typeLimit.OneOfTwo<String, FlxAtlasFrames>;
class AtlasMenuList extends MenuTypedList<AtlasMenuItem>
{
public var atlas:FlxAtlasFrames;
public function new (atlas, navControls:NavControls = Vertical)
{
super(navControls);
if (Std.is(atlas, String))
this.atlas = Paths.getSparrowAtlas(cast atlas);
else
this.atlas = cast atlas;
}
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);
}
override function destroy()
{
super.destroy();
atlas = null;
}
}
class AtlasMenuItem extends MenuItem
{
var atlas:FlxAtlasFrames;
public function new (x = 0.0, y = 0.0, name:String, atlas:FlxAtlasFrames, callback)
{
this.atlas = atlas;
super(x, y, name, callback);
}
override function setData(name:String, ?callback:Void->Void)
{
frames = atlas;
animation.addByPrefix('idle', '$name idle', 24);
animation.addByPrefix('selected', '$name selected', 24);
super.setData(name, callback);
}
function changeAnim(animName:String)
{
animation.play(animName);
updateHitbox();
}
override function idle()
{
changeAnim('idle');
}
override function select()
{
changeAnim('selected');
}
override function get_selected()
{
return animation.curAnim != null && animation.curAnim.name == "selected";
}
override function destroy()
{
super.destroy();
atlas = null;
}
}

View file

@ -1,46 +1,13 @@
package ui; package ui;
import flixel.util.typeLimit.OneOfTwo;
import flixel.math.FlxPoint; import flixel.math.FlxPoint;
import flixel.FlxG; import flixel.FlxG;
import flixel.FlxSprite;
import flixel.effects.FlxFlicker; import flixel.effects.FlxFlicker;
import flixel.graphics.frames.FlxAtlasFrames;
import flixel.group.FlxGroup; import flixel.group.FlxGroup;
import flixel.tweens.FlxEase;
import flixel.tweens.FlxTween;
import flixel.util.FlxSignal; import flixel.util.FlxSignal;
typedef AtlasAsset = OneOfTwo<String, FlxAtlasFrames>; class MenuTypedList<T:MenuItem> extends FlxTypedGroup<T>
class MenuItemList extends MenuTypedItemList<MenuItem>
{
public var atlas:FlxAtlasFrames;
public function new (atlas, navControls:NavControls = Vertical)
{
super(navControls);
if (Std.is(atlas, String))
this.atlas = Paths.getSparrowAtlas(cast atlas);
else
this.atlas = cast atlas;
}
public function createItem(x = 0.0, y = 0.0, name, callback, fireInstantly = false)
{
var item = new MenuItem(x, y, name, atlas, callback);
item.fireInstantly = fireInstantly;
return addItem(name, item);
}
override function destroy()
{
super.destroy();
atlas = null;
}
}
class MenuTypedItemList<T:MenuItem> extends FlxTypedGroup<T>
{ {
public var selectedIndex(default, null) = 0; public var selectedIndex(default, null) = 0;
/** Called when a new item is highlighted */ /** Called when a new item is highlighted */
@ -165,6 +132,11 @@ class MenuTypedItemList<T:MenuItem> extends FlxTypedGroup<T>
onChange.dispatch(selected); onChange.dispatch(selected);
} }
public function has(name:String)
{
return byName.exists(name);
}
public function getItem(name:String) public function getItem(name:String)
{ {
return byName[name]; return byName[name];
@ -177,51 +149,140 @@ class MenuTypedItemList<T:MenuItem> extends FlxTypedGroup<T>
} }
} }
class MenuItem extends flixel.FlxSprite class MenuItem extends FlxSprite
{ {
public var callback:Void->Void; public var callback:Void->Void;
public var name:String;
/** /**
* Set to true for things like opening URLs otherwise, it may it get blocked. * Set to true for things like opening URLs otherwise, it may it get blocked.
*/ */
public var fireInstantly = false; public var fireInstantly = false;
public var selected(get, never):Bool;
function get_selected() return alpha == 1.0;
public function new (x = 0.0, y = 0.0, name, tex, callback) public function new (x = 0.0, y = 0.0, name:String, callback)
{ {
super(x, y); super(x, y);
frames = tex;
setItem(name, callback);
antialiasing = true; antialiasing = true;
setData(name, callback);
idle();
} }
public function setItem(name:String, ?callback:Void->Void) function setData(name:String, ?callback:Void->Void)
{ {
this.name = name;
if (callback != null) if (callback != null)
this.callback = callback; this.callback = callback;
var selected = animation.curAnim != null && animation.curAnim.name == "selected";
animation.addByPrefix('idle', '$name basic', 24);
animation.addByPrefix('selected', '$name white', 24);
idle();
if (selected)
select();
} }
function changeAnim(anim:String) /**
* Calls setData and resets/redraws the state of the item
* @param name
* @param callback
*/
public function setItem(name:String, ?callback:Void->Void)
{ {
animation.play(anim); setData(name, callback);
updateHitbox();
if (selected)
select();
else
idle();
} }
public function idle() public function idle()
{ {
changeAnim('idle'); alpha = 0.6;
} }
public function select() public function select()
{ {
changeAnim('selected'); alpha = 1.0;
}
}
class MenuTypedItem<T:FlxSprite> extends MenuItem
{
public var label(default, set):T;
public function new (x = 0.0, y = 0.0, label:T, name:String, callback)
{
super(x, y, name, callback);
// set label after super otherwise setters fuck up
this.label = label;
}
/**
* Use this when you only want to show the label
*/
function setEmptyBackground()
{
var oldWidth = width;
var oldHeight = height;
makeGraphic(1, 1, 0x0);
width = oldWidth;
height = oldHeight;
}
function set_label(value:T)
{
if (value != null)
{
value.x = x;
value.y = y;
value.alpha = alpha;
}
return this.label = value;
}
override function update(elapsed:Float)
{
super.update(elapsed);
if (label != null)
label.update(elapsed);
}
override function draw()
{
super.draw();
if (label != null)
{
label.cameras = cameras;
label.scrollFactor.copyFrom(scrollFactor);
label.draw();
}
}
override function set_alpha(value:Float):Float
{
super.set_alpha(value);
if (label != null)
label.alpha = alpha;
return alpha;
}
override function set_x(value:Float):Float
{
super.set_x(value);
if (label != null)
label.x = x;
return x;
}
override function set_y(Value:Float):Float
{
super.set_y(Value);
if (label != null)
label.y = y;
return y;
} }
} }

View file

@ -7,7 +7,7 @@ class NgPrompt extends Prompt
{ {
public function new (text:String, style:ButtonStyle = Yes_No) public function new (text:String, style:ButtonStyle = Yes_No)
{ {
super("prompt-ng_login", text, style); super(text, style);
} }
static public function showLogin() static public function showLogin()

View file

@ -1,5 +1,8 @@
package ui; package ui;
import ui.MenuList;
import flixel.FlxG;
import flixel.FlxSprite; import flixel.FlxSprite;
import flixel.graphics.frames.FlxAtlasFrames; import flixel.graphics.frames.FlxAtlasFrames;
import flixel.text.FlxText; import flixel.text.FlxText;
@ -11,33 +14,19 @@ class Prompt extends flixel.FlxSubState
public var onYes:Void->Void; public var onYes:Void->Void;
public var onNo:Void->Void; public var onNo:Void->Void;
public var buttons:MenuItemList; public var buttons:AlphabetMenuList;
public var field:FlxText; public var field:Alphabet;
public var back:FlxSprite;
var style:ButtonStyle; var style:ButtonStyle;
public function new (atlas, text:String, style:ButtonStyle = Ok) public function new (text:String, style:ButtonStyle = Ok)
{ {
this.style = style; this.style = style;
super(); super(0xA0000000);
var texture:FlxAtlasFrames; buttons = new AlphabetMenuList(Horizontal);
if (Std.is(atlas, String))
texture = Paths.getSparrowAtlas(cast atlas);
else
texture = cast atlas;
back = new FlxSprite(); field = new Alphabet(text, true);
back.frames = texture;
back.animation.addByPrefix("idle", "back");
back.scrollFactor.set(0, 0);
buttons = new MenuItemList(texture, Horizontal);
field = new FlxText();
field.setFormat(Paths.font("vcr.ttf"), 64, FlxColor.BLACK, CENTER);
field.text = text;
field.scrollFactor.set(0, 0); field.scrollFactor.set(0, 0);
} }
@ -45,12 +34,7 @@ class Prompt extends flixel.FlxSubState
{ {
super.create(); super.create();
back.animation.play("idle"); field.y = MARGIN;
back.updateHitbox();
back.screenCenter(XY);
add(back);
field.y = back.y + MARGIN;
field.screenCenter(X); field.screenCenter(X);
add(field); add(field);
@ -90,16 +74,16 @@ class Prompt extends flixel.FlxSubState
// pass anonymous functions rather than the current callbacks, in case they change later // pass anonymous functions rather than the current callbacks, in case they change later
var yesButton = buttons.createItem(yes, function() onYes()); var yesButton = buttons.createItem(yes, function() onYes());
yesButton.screenCenter(X); yesButton.screenCenter(X);
yesButton.y = back.y + back.height - yesButton.height - MARGIN; yesButton.y = FlxG.height - yesButton.height - MARGIN;
yesButton.scrollFactor.set(0, 0); yesButton.scrollFactor.set(0, 0);
if (no != null) if (no != null)
{ {
// place right // place right
yesButton.x = back.x + back.width - yesButton.width - MARGIN; yesButton.x = FlxG.width - yesButton.width - MARGIN;
var noButton = buttons.createItem(no, function() onNo()); var noButton = buttons.createItem(no, function() onNo());
noButton.x = back.x + MARGIN; noButton.x = MARGIN;
noButton.y = back.y + back.height - noButton.height - MARGIN; noButton.y = FlxG.height - noButton.height - MARGIN;
noButton.scrollFactor.set(0, 0); noButton.scrollFactor.set(0, 0);
} }
} }