From 0523212ad40de70931ad75ec8c08da6611776b2e Mon Sep 17 00:00:00 2001 From: UncertainProd <83609901+UncertainProd@users.noreply.github.com> Date: Tue, 28 Nov 2023 05:14:52 +0530 Subject: [PATCH 1/3] Fixed popup not closing on clicking the buttons (Fix for https://github.com/HaxeFlixel/flixel-demos/issues/267) --- .../RPGInterface/source/State_DefaultTest.hx | 47 ++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/UserInterface/RPGInterface/source/State_DefaultTest.hx b/UserInterface/RPGInterface/source/State_DefaultTest.hx index 7ef6e5972..a7b7ab02c 100644 --- a/UserInterface/RPGInterface/source/State_DefaultTest.hx +++ b/UserInterface/RPGInterface/source/State_DefaultTest.hx @@ -1,3 +1,7 @@ +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; import flixel.FlxG; import flixel.addons.ui.FlxUIState; @@ -29,7 +33,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 PopupFix(); // 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 @@ -55,3 +59,44 @@ class State_DefaultTest extends FlxUIState } } } + +/** + * An extension to `FlxUIPopup` that fixes a bug in `getEvent` where the event was not being broadcast correctly to the parent widget + */ +class PopupFix 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 From e9798e8a73d00bbe0499c760398afc776fbc76f2 Mon Sep 17 00:00:00 2001 From: UncertainProd <83609901+UncertainProd@users.noreply.github.com> Date: Tue, 28 Nov 2023 05:15:12 +0530 Subject: [PATCH 2/3] Fixed invalid xml file --- UserInterface/RPGInterface/assets/xml/state_default.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 @@ - + - + From f4018f517ebff9123e6297146be83cdcd1f057bf Mon Sep 17 00:00:00 2001 From: UncertainProd <83609901+UncertainProd@users.noreply.github.com> Date: Tue, 28 Nov 2023 22:37:19 +0530 Subject: [PATCH 3/3] Code re-organization --- .../RPGInterface/source/Popup_Default.hx | 43 +++++++++++++++++ .../RPGInterface/source/State_DefaultTest.hx | 47 +------------------ 2 files changed, 44 insertions(+), 46 deletions(-) create mode 100644 UserInterface/RPGInterface/source/Popup_Default.hx 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 a7b7ab02c..5aba419b1 100644 --- a/UserInterface/RPGInterface/source/State_DefaultTest.hx +++ b/UserInterface/RPGInterface/source/State_DefaultTest.hx @@ -1,7 +1,3 @@ -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; import flixel.FlxG; import flixel.addons.ui.FlxUIState; @@ -33,7 +29,7 @@ class State_DefaultTest extends FlxUIState { case "back": FlxG.switchState(new State_Title()); case "popup": - var popup:FlxUIPopup = new PopupFix(); // 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 @@ -58,45 +54,4 @@ class State_DefaultTest extends FlxUIState } } } -} - -/** - * An extension to `FlxUIPopup` that fixes a bug in `getEvent` where the event was not being broadcast correctly to the parent widget - */ -class PopupFix 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