diff --git a/UserInterface/RPGInterface/assets/xml/state_default.xml b/UserInterface/RPGInterface/assets/xml/state_default.xml index 37c489a97..1e3ff1edd 100644 --- a/UserInterface/RPGInterface/assets/xml/state_default.xml +++ b/UserInterface/RPGInterface/assets/xml/state_default.xml @@ -52,10 +52,10 @@ - + - + diff --git a/UserInterface/RPGInterface/source/Popup_Default.hx b/UserInterface/RPGInterface/source/Popup_Default.hx new file mode 100644 index 000000000..9db312969 --- /dev/null +++ b/UserInterface/RPGInterface/source/Popup_Default.hx @@ -0,0 +1,43 @@ +import flixel.addons.ui.FlxUI; +import flixel.addons.ui.interfaces.IFlxUIState; +import flixel.addons.ui.FlxUITypedButton; +import flixel.addons.ui.interfaces.IFlxUIWidget; +import flixel.addons.ui.FlxUIPopup; + +class Popup_Default extends FlxUIPopup +{ + override function getEvent(id:String, sender:IFlxUIWidget, data:Dynamic, ?eventParams:Array) + { + if (eventParams == null) + { + if (params != null) + { + eventParams = []; + } + } + if (params != null) + { + eventParams = eventParams.concat(params); + } + + switch (id) + { + case FlxUITypedButton.CLICK_EVENT: + if (eventParams != null) + { + var buttonAmount:Int = Std.int(eventParams[0]); // 0 is Yes, 1 is No and 2 is Cancel + if ((_parentState is IFlxUIState)) + { + // This fixes a bug where the event was being sent to this popup rather than the state that created it + castParent().getEvent(FlxUIPopup.CLICK_EVENT, this, buttonAmount, eventParams); + } + else + { + // This is a generic fallback in case something goes wrong + FlxUI.event(FlxUIPopup.CLICK_EVENT, this, buttonAmount, eventParams); + } + close(); + } + } + } +} \ No newline at end of file diff --git a/UserInterface/RPGInterface/source/State_DefaultTest.hx b/UserInterface/RPGInterface/source/State_DefaultTest.hx index 7ef6e5972..5aba419b1 100644 --- a/UserInterface/RPGInterface/source/State_DefaultTest.hx +++ b/UserInterface/RPGInterface/source/State_DefaultTest.hx @@ -29,7 +29,7 @@ class State_DefaultTest extends FlxUIState { case "back": FlxG.switchState(new State_Title()); case "popup": - var popup:FlxUIPopup = new FlxUIPopup(); // create the popup + var popup:FlxUIPopup = new Popup_Default(); // create the popup popup.quickSetup // set it up (Main.tongue.get("$POPUP_DEMO_2_TITLE", "ui"), // title text Main.tongue.get("$POPUP_DEMO_2_BODY", "ui"), // body text @@ -54,4 +54,4 @@ class State_DefaultTest extends FlxUIState } } } -} +} \ No newline at end of file