2021-02-18 14:58:16 -05:00
|
|
|
package ui;
|
|
|
|
|
2021-02-23 19:55:24 -05:00
|
|
|
import ui.AtlasText;
|
2021-02-21 13:08:30 -05:00
|
|
|
import ui.MenuList;
|
|
|
|
|
|
|
|
import flixel.FlxG;
|
2021-02-18 14:58:16 -05:00
|
|
|
import flixel.FlxSprite;
|
|
|
|
import flixel.graphics.frames.FlxAtlasFrames;
|
|
|
|
import flixel.text.FlxText;
|
|
|
|
import flixel.util.FlxColor;
|
|
|
|
|
|
|
|
class Prompt extends flixel.FlxSubState
|
|
|
|
{
|
|
|
|
inline static var MARGIN = 100;
|
|
|
|
|
|
|
|
public var onYes:Void->Void;
|
|
|
|
public var onNo:Void->Void;
|
2021-02-23 19:55:24 -05:00
|
|
|
public var buttons:TextMenuList;
|
|
|
|
public var field:AtlasText;
|
2021-02-18 14:58:16 -05:00
|
|
|
|
|
|
|
var style:ButtonStyle;
|
|
|
|
|
2021-02-21 13:08:30 -05:00
|
|
|
public function new (text:String, style:ButtonStyle = Ok)
|
2021-02-18 14:58:16 -05:00
|
|
|
{
|
|
|
|
this.style = style;
|
2021-02-21 13:08:30 -05:00
|
|
|
super(0xA0000000);
|
2021-02-18 14:58:16 -05:00
|
|
|
|
2021-02-23 19:55:24 -05:00
|
|
|
buttons = new TextMenuList(Horizontal);
|
2021-02-18 14:58:16 -05:00
|
|
|
|
2021-02-23 19:55:24 -05:00
|
|
|
field = new BoldText(text);
|
2021-02-18 14:58:16 -05:00
|
|
|
field.scrollFactor.set(0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
override function create()
|
|
|
|
{
|
|
|
|
super.create();
|
|
|
|
|
2021-02-21 13:08:30 -05:00
|
|
|
field.y = MARGIN;
|
2021-02-18 14:58:16 -05:00
|
|
|
field.screenCenter(X);
|
|
|
|
add(field);
|
|
|
|
|
|
|
|
createButtons();
|
|
|
|
add(buttons);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setButtons(style:ButtonStyle)
|
|
|
|
{
|
|
|
|
if (this.style != style)
|
|
|
|
{
|
|
|
|
this.style = style;
|
|
|
|
createButtons();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function createButtons()
|
|
|
|
{
|
|
|
|
// destroy previous buttons
|
|
|
|
while(buttons.members.length > 0)
|
|
|
|
{
|
|
|
|
buttons.remove(buttons.members[0], true).destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(style)
|
|
|
|
{
|
|
|
|
case Yes_No : createButtonsHelper("yes", "no");
|
|
|
|
case Ok : createButtonsHelper("ok");
|
|
|
|
case Custom(yes, no): createButtonsHelper(yes, no);
|
|
|
|
case None : buttons.exists = false;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function createButtonsHelper(yes:String, ?no:String)
|
|
|
|
{
|
|
|
|
buttons.exists = true;
|
|
|
|
// pass anonymous functions rather than the current callbacks, in case they change later
|
|
|
|
var yesButton = buttons.createItem(yes, function() onYes());
|
|
|
|
yesButton.screenCenter(X);
|
2021-02-21 13:08:30 -05:00
|
|
|
yesButton.y = FlxG.height - yesButton.height - MARGIN;
|
2021-02-18 14:58:16 -05:00
|
|
|
yesButton.scrollFactor.set(0, 0);
|
|
|
|
if (no != null)
|
|
|
|
{
|
|
|
|
// place right
|
2021-02-21 13:08:30 -05:00
|
|
|
yesButton.x = FlxG.width - yesButton.width - MARGIN;
|
2021-02-18 14:58:16 -05:00
|
|
|
|
|
|
|
var noButton = buttons.createItem(no, function() onNo());
|
2021-02-21 13:08:30 -05:00
|
|
|
noButton.x = MARGIN;
|
|
|
|
noButton.y = FlxG.height - noButton.height - MARGIN;
|
2021-02-18 14:58:16 -05:00
|
|
|
noButton.scrollFactor.set(0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setText(text:String)
|
|
|
|
{
|
|
|
|
field.text = text;
|
|
|
|
field.screenCenter(X);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
enum ButtonStyle
|
|
|
|
{
|
|
|
|
Ok;
|
|
|
|
Yes_No;
|
|
|
|
Custom(yes:String, no:Null<String>);//Todo: more than 2
|
|
|
|
None;
|
|
|
|
}
|