alphabet menu items + separate ngPrompt

This commit is contained in:
George FunBook 2021-02-21 12:08:30 -06:00
parent 64917acad7
commit 4fc4ca2206
16 changed files with 420 additions and 143 deletions

View File

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

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 365 KiB

View File

@ -0,0 +1,77 @@
<?xml version="1.0" encoding="utf-8"?>
<TextureAtlas imagePath="main_menu.png">
<!-- Created with Adobe Animate version 19.2.1.408 -->
<!-- http://www.adobe.com/products/animate.html -->
<SubTexture name="donate idle0000" x="2" y="2" width="444" height="117"/>
<SubTexture name="donate idle0001" x="2" y="2" width="444" height="117"/>
<SubTexture name="donate idle0002" x="2" y="2" width="444" height="117"/>
<SubTexture name="donate idle0003" x="448" y="2" width="444" height="117"/>
<SubTexture name="donate idle0004" x="448" y="2" width="444" height="117"/>
<SubTexture name="donate idle0005" x="448" y="2" width="444" height="117"/>
<SubTexture name="donate idle0006" x="894" y="2" width="444" height="117"/>
<SubTexture name="donate idle0007" x="894" y="2" width="444" height="117"/>
<SubTexture name="donate idle0008" x="894" y="2" width="444" height="117"/>
<SubTexture name="donate selected0000" x="1340" y="2" width="590" height="157" frameX="0" frameY="-2" frameWidth="590" frameHeight="159"/>
<SubTexture name="donate selected0001" x="2" y="161" width="587" height="154" frameX="-1" frameY="-5" frameWidth="590" frameHeight="159"/>
<SubTexture name="donate selected0002" x="591" y="161" width="585" height="155" frameX="-3" frameY="0" frameWidth="590" frameHeight="159"/>
<SubTexture name="freeplay idle0000" x="1178" y="161" width="484" height="122"/>
<SubTexture name="freeplay idle0001" x="1178" y="161" width="484" height="122"/>
<SubTexture name="freeplay idle0002" x="1178" y="161" width="484" height="122"/>
<SubTexture name="freeplay idle0003" x="2" y="318" width="484" height="122"/>
<SubTexture name="freeplay idle0004" x="2" y="318" width="484" height="122"/>
<SubTexture name="freeplay idle0005" x="2" y="318" width="484" height="122"/>
<SubTexture name="freeplay idle0006" x="488" y="318" width="484" height="122"/>
<SubTexture name="freeplay idle0007" x="488" y="318" width="484" height="122"/>
<SubTexture name="freeplay idle0008" x="488" y="318" width="484" height="122"/>
<SubTexture name="freeplay selected0000" x="974" y="318" width="627" height="169" frameX="0" frameY="0" frameWidth="635" frameHeight="174"/>
<SubTexture name="freeplay selected0001" x="2" y="489" width="632" height="170" frameX="-3" frameY="-1" frameWidth="635" frameHeight="174"/>
<SubTexture name="freeplay selected0002" x="636" y="489" width="629" height="173" frameX="-4" frameY="-1" frameWidth="635" frameHeight="174"/>
<SubTexture name="login idle0000" x="1267" y="489" width="359" height="109"/>
<SubTexture name="login idle0001" x="1267" y="489" width="359" height="109"/>
<SubTexture name="login idle0002" x="1267" y="489" width="359" height="109"/>
<SubTexture name="login idle0003" x="1628" y="489" width="359" height="109"/>
<SubTexture name="login idle0004" x="1628" y="489" width="359" height="109"/>
<SubTexture name="login idle0005" x="1628" y="489" width="359" height="109"/>
<SubTexture name="login idle0006" x="2" y="664" width="358" height="109" frameX="0" frameY="0" frameWidth="359" frameHeight="109"/>
<SubTexture name="login idle0007" x="2" y="664" width="358" height="109" frameX="0" frameY="0" frameWidth="359" frameHeight="109"/>
<SubTexture name="login idle0008" x="2" y="664" width="358" height="109" frameX="0" frameY="0" frameWidth="359" frameHeight="109"/>
<SubTexture name="login selected0000" x="362" y="664" width="449" height="137"/>
<SubTexture name="login selected0001" x="813" y="664" width="449" height="137"/>
<SubTexture name="login selected0002" x="1264" y="664" width="448" height="137" frameX="0" frameY="0" frameWidth="449" frameHeight="137"/>
<SubTexture name="logout idle0000" x="2" y="803" width="428" height="110"/>
<SubTexture name="logout idle0001" x="2" y="803" width="428" height="110"/>
<SubTexture name="logout idle0002" x="2" y="803" width="428" height="110"/>
<SubTexture name="logout idle0003" x="432" y="803" width="428" height="110"/>
<SubTexture name="logout idle0004" x="432" y="803" width="428" height="110"/>
<SubTexture name="logout idle0005" x="432" y="803" width="428" height="110"/>
<SubTexture name="logout idle0006" x="862" y="803" width="428" height="110"/>
<SubTexture name="logout idle0007" x="862" y="803" width="428" height="110"/>
<SubTexture name="logout idle0008" x="862" y="803" width="428" height="110"/>
<SubTexture name="logout selected0000" x="1292" y="803" width="537" height="138" frameX="0" frameY="0" frameWidth="538" frameHeight="138"/>
<SubTexture name="logout selected0001" x="2" y="943" width="538" height="138"/>
<SubTexture name="logout selected0002" x="542" y="943" width="536" height="138" frameX="-1" frameY="0" frameWidth="538" frameHeight="138"/>
<SubTexture name="options idle0000" x="1080" y="943" width="487" height="112"/>
<SubTexture name="options idle0001" x="1080" y="943" width="487" height="112"/>
<SubTexture name="options idle0002" x="1080" y="943" width="487" height="112"/>
<SubTexture name="options idle0003" x="2" y="1083" width="487" height="112"/>
<SubTexture name="options idle0004" x="2" y="1083" width="487" height="112"/>
<SubTexture name="options idle0005" x="2" y="1083" width="487" height="112"/>
<SubTexture name="options idle0006" x="491" y="1083" width="487" height="112"/>
<SubTexture name="options idle0007" x="491" y="1083" width="487" height="112"/>
<SubTexture name="options idle0008" x="491" y="1083" width="487" height="112"/>
<SubTexture name="options selected0000" x="980" y="1083" width="607" height="155" frameX="-1" frameY="-1" frameWidth="609" frameHeight="163"/>
<SubTexture name="options selected0001" x="2" y="1240" width="606" height="158" frameX="-3" frameY="-1" frameWidth="609" frameHeight="163"/>
<SubTexture name="options selected0002" x="610" y="1240" width="609" height="163"/>
<SubTexture name="story mode idle0000" x="1221" y="1240" width="615" height="122"/>
<SubTexture name="story mode idle0001" x="1221" y="1240" width="615" height="122"/>
<SubTexture name="story mode idle0002" x="1221" y="1240" width="615" height="122"/>
<SubTexture name="story mode idle0003" x="2" y="1405" width="615" height="122"/>
<SubTexture name="story mode idle0004" x="2" y="1405" width="615" height="122"/>
<SubTexture name="story mode idle0005" x="2" y="1405" width="615" height="122"/>
<SubTexture name="story mode idle0006" x="619" y="1405" width="615" height="122"/>
<SubTexture name="story mode idle0007" x="619" y="1405" width="615" height="122"/>
<SubTexture name="story mode idle0008" x="619" y="1405" width="615" height="122"/>
<SubTexture name="story mode selected0000" x="1236" y="1405" width="796" height="173" frameX="0" frameY="-3" frameWidth="796" frameHeight="181"/>
<SubTexture name="story mode selected0001" x="2" y="1580" width="794" height="174" frameX="-2" frameY="-2" frameWidth="796" frameHeight="181"/>
<SubTexture name="story mode selected0002" x="798" y="1580" width="794" height="181" frameX="0" frameY="0" frameWidth="796" frameHeight="181"/>
</TextureAtlas>

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 78 KiB

After

Width:  |  Height:  |  Size: 78 KiB

View File

@ -2,17 +2,17 @@
<TextureAtlas imagePath="prompt-ng_login.png">
<!-- Created with Adobe Animate version 19.2.1.408 -->
<!-- http://www.adobe.com/products/animate.html -->
<SubTexture name="back0000" x="0" y="0" width="1157" height="645"/>
<SubTexture name="no basic0000" x="1159" y="0" width="210" height="197"/>
<SubTexture name="no white0000" x="1371" y="0" width="210" height="197" frameX="-1" frameY="-14" frameWidth="212" frameHeight="215"/>
<SubTexture name="no white0001" x="1583" y="0" width="212" height="194" frameX="0" frameY="-10" frameWidth="212" frameHeight="215"/>
<SubTexture name="no white0002" x="1797" y="0" width="210" height="215" frameX="0" frameY="0" frameWidth="212" frameHeight="215"/>
<SubTexture name="ok basic0000" x="0" y="647" width="231" height="167"/>
<SubTexture name="ok white0000" x="233" y="647" width="231" height="167" frameX="0" frameY="-9" frameWidth="238" frameHeight="181"/>
<SubTexture name="ok white0001" x="466" y="647" width="206" height="165" frameX="-21" frameY="-9" frameWidth="238" frameHeight="181"/>
<SubTexture name="ok white0002" x="674" y="647" width="220" height="181" frameX="-18" frameY="0" frameWidth="238" frameHeight="181"/>
<SubTexture name="yes basic0000" x="896" y="647" width="303" height="205"/>
<SubTexture name="yes white0000" x="1201" y="647" width="303" height="205" frameX="-13" frameY="-19" frameWidth="340" frameHeight="230"/>
<SubTexture name="yes white0001" x="1506" y="647" width="330" height="230" frameX="-8" frameY="0" frameWidth="340" frameHeight="230"/>
<SubTexture name="yes white0002" x="0" y="879" width="340" height="214" frameX="0" frameY="-12" frameWidth="340" frameHeight="230"/>
<SubTexture name="back0000" x="2" y="2" width="1157" height="645"/>
<SubTexture name="no idle0000" x="1161" y="2" width="210" height="197"/>
<SubTexture name="no selected0000" x="1373" y="2" width="210" height="197" frameX="-1" frameY="-14" frameWidth="212" frameHeight="215"/>
<SubTexture name="no selected0001" x="1585" y="2" width="212" height="194" frameX="0" frameY="-10" frameWidth="212" frameHeight="215"/>
<SubTexture name="no selected0002" x="1799" y="2" width="210" height="215" frameX="0" frameY="0" frameWidth="212" frameHeight="215"/>
<SubTexture name="ok idle0000" x="2" y="649" width="231" height="167"/>
<SubTexture name="ok selected0000" x="235" y="649" width="231" height="167" frameX="0" frameY="-9" frameWidth="238" frameHeight="181"/>
<SubTexture name="ok selected0001" x="468" y="649" width="206" height="165" frameX="-21" frameY="-9" frameWidth="238" frameHeight="181"/>
<SubTexture name="ok selected0002" x="676" y="649" width="220" height="181" frameX="-18" frameY="0" frameWidth="238" frameHeight="181"/>
<SubTexture name="yes idle0000" x="898" y="649" width="303" height="205"/>
<SubTexture name="yes selected0000" x="1203" y="649" width="303" height="205" frameX="-13" frameY="-19" frameWidth="340" frameHeight="230"/>
<SubTexture name="yes selected0001" x="1508" y="649" width="330" height="230" frameX="-8" frameY="0" frameWidth="340" frameHeight="230"/>
<SubTexture name="yes selected0002" x="2" y="881" width="340" height="214" frameX="0" frameY="-12" frameWidth="340" frameHeight="230"/>
</TextureAtlas>

View File

@ -40,7 +40,7 @@ class Alphabet extends FlxSpriteGroup
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);

View File

@ -21,7 +21,8 @@ import lime.app.Application;
import io.newgrounds.NG;
#end
import ui.MenuItemList;
import ui.MenuList;
import ui.AtlasMenuList;
import ui.Prompt;
import ui.NgPrompt;
@ -29,7 +30,7 @@ using StringTools;
class MainMenuState extends MusicBeatState
{
var menuItems:MainMenuItemList;
var menuItems:MainMenuList;
var magenta:FlxSprite;
var camFollow:FlxObject;
@ -70,7 +71,7 @@ class MainMenuState extends MusicBeatState
add(magenta);
// magenta.scrollFactor.set();
menuItems = new MainMenuItemList('FNF_main_menu_assets');
menuItems = new MainMenuList();
add(menuItems);
menuItems.onChange.add(onMenuItemChange);
menuItems.onAcceptPress.add(function(_)
@ -88,6 +89,7 @@ class MainMenuState extends MusicBeatState
#if CAN_OPEN_LINKS
menuItems.createItem('donate', selectDonate, hasPopupBlocker);
#end
// menuItems.createItem('options', function () startExitState(new OptionsMenu()));
#if newgrounds
if (NGio.isLoggedIn)
menuItems.createItem("logout", selectLogout);
@ -123,10 +125,10 @@ class MainMenuState extends MusicBeatState
menuItems.enabled = true;
#if newgrounds
if (NGio.savedSessionFailed)
showSavedSessionFailed();
#end
// #if newgrounds
// if (NGio.savedSessionFailed)
// showSavedSessionFailed();
// #end
}
function onMenuItemChange(selected:MenuItem)
@ -146,23 +148,46 @@ class MainMenuState extends MusicBeatState
#if newgrounds
function selectLogin()
{
openPrompt(NgPrompt.showLogin(),
function onPromptClose() menuItems.resetItem("login", "logout", selectLogout)
);
openNgPrompt(NgPrompt.showLogin());
}
function selectLogout()
{
openPrompt(NgPrompt.showLogout(),
function onPromptClose() menuItems.resetItem("logout", "login", selectLogin)
);
openNgPrompt(NgPrompt.showLogout());
}
function showSavedSessionFailed()
{
openPrompt(NgPrompt.showSavedSessionFailed(),
function onPromptClose() menuItems.resetItem("login", "logout", selectLogout)
);
openNgPrompt(NgPrompt.showSavedSessionFailed());
}
/**
* 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
@ -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 function new (atlas)
public function new ()
{
atlas = Paths.getSparrowAtlas('main_menu');
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)
{
var i = length;
var item = new MainMenuItem(x, y, name, atlas, callback);
item.fireInstantly = fireInstantly;
item.ID = i;
item.ID = length;
return addItem(name, item);
}
@ -241,7 +262,7 @@ private class MainMenuItemList extends MenuTypedItemList<MainMenuItem>
atlas = null;
}
}
private class MainMenuItem extends MenuItem
private class MainMenuItem extends AtlasMenuItem
{
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;
import flixel.util.typeLimit.OneOfTwo;
import flixel.math.FlxPoint;
import flixel.FlxG;
import flixel.FlxSprite;
import flixel.effects.FlxFlicker;
import flixel.graphics.frames.FlxAtlasFrames;
import flixel.group.FlxGroup;
import flixel.tweens.FlxEase;
import flixel.tweens.FlxTween;
import flixel.util.FlxSignal;
typedef AtlasAsset = OneOfTwo<String, FlxAtlasFrames>;
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>
class MenuTypedList<T:MenuItem> extends FlxTypedGroup<T>
{
public var selectedIndex(default, null) = 0;
/** Called when a new item is highlighted */
@ -165,6 +132,11 @@ class MenuTypedItemList<T:MenuItem> extends FlxTypedGroup<T>
onChange.dispatch(selected);
}
public function has(name:String)
{
return byName.exists(name);
}
public function getItem(name:String)
{
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 name:String;
/**
* Set to true for things like opening URLs otherwise, it may it get blocked.
*/
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);
frames = tex;
setItem(name, callback);
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)
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);
updateHitbox();
setData(name, callback);
if (selected)
select();
else
idle();
}
public function idle()
{
changeAnim('idle');
alpha = 0.6;
}
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)
{
super("prompt-ng_login", text, style);
super(text, style);
}
static public function showLogin()

View File

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