From bfb417d0f5d666fcdd72306f19c6db844f01e346 Mon Sep 17 00:00:00 2001 From: Patrick Wrobel Date: Fri, 23 Jun 2023 00:53:01 -0400 Subject: [PATCH 1/2] Issue 104: Don't crash when clicking on combinator when the GUI is open --- cybersyn/scripts/gui.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cybersyn/scripts/gui.lua b/cybersyn/scripts/gui.lua index 6265a07..1dd1528 100644 --- a/cybersyn/scripts/gui.lua +++ b/cybersyn/scripts/gui.lua @@ -201,6 +201,9 @@ function gui_opened(comb, player) combinator_update(global, comb, true) local rootgui = player.gui.screen + if rootgui[COMBINATOR_NAME] then + rootgui[COMBINATOR_NAME].destroy() + end local selected_index, signal, switch_state, bits = get_comb_gui_settings(comb) local _, main_window = flib_gui.add(rootgui, { From 204ec6391bea4182bdfa2526f01e20a82d8ee315 Mon Sep 17 00:00:00 2001 From: Patrick Wrobel Date: Fri, 23 Jun 2023 02:07:16 -0400 Subject: [PATCH 2/2] Fix escape and E not closing the combinator GUI when the manager is enabled --- cybersyn/scripts/gui.lua | 3 --- cybersyn/scripts/gui/main.lua | 9 +++++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/cybersyn/scripts/gui.lua b/cybersyn/scripts/gui.lua index 1dd1528..6265a07 100644 --- a/cybersyn/scripts/gui.lua +++ b/cybersyn/scripts/gui.lua @@ -201,9 +201,6 @@ function gui_opened(comb, player) combinator_update(global, comb, true) local rootgui = player.gui.screen - if rootgui[COMBINATOR_NAME] then - rootgui[COMBINATOR_NAME].destroy() - end local selected_index, signal, switch_state, bits = get_comb_gui_settings(comb) local _, main_window = flib_gui.add(rootgui, { diff --git a/cybersyn/scripts/gui/main.lua b/cybersyn/scripts/gui/main.lua index 7628c42..d5030db 100644 --- a/cybersyn/scripts/gui/main.lua +++ b/cybersyn/scripts/gui/main.lua @@ -51,6 +51,15 @@ function manager_gui.on_lua_shortcut(e) if e.element then if e.element.name == "manager_window" then manager.wrapper(e, manager.handle.manager_toggle) + elseif e.element.name == COMBINATOR_NAME and e.name == defines.events.on_gui_closed then + -- With the manager enabled, this handler overwrites the combinator's + -- on_gui_close handler. Copy the logic to close the combinator's GUI here + -- as well. + local player = game.get_player(e.player_index) + if not player then return end + if player.gui.screen[COMBINATOR_NAME] then + player.gui.screen[COMBINATOR_NAME].destroy() + end end else manager.wrapper(e, manager.handle.manager_toggle)