[0.16.x] Setting LuaControl::opened with LuaGuiElement

Place to get help with not working mods / modding interface.
User avatar
Therax
Filter Inserter
Filter Inserter
Posts: 471
Joined: Sun May 21, 2017 6:28 pm
Contact:

[0.16.x] Setting LuaControl::opened with LuaGuiElement

Post by Therax »

From the 0.16.0 changelog:
Added support for setting a LuaGuiElement as the opened GUI for a player causing it to close with the normal close-GUI methods.
How exactly is this intended to work?

AFAICT the only way to get a new LuaGuiElement is to add it to an existing root container in a LuaGui. Setting opened to this LuaGuiElement works, but when pressing E or Esc to close the GUI, opened is reset to nil, but the LuaGuiElement is still displayed onscreen because it's still part of the LuaGui's root container. I haven't found a way to detach it from a LuaGui, since children is read-only and clear() and destroy() remove the LuaGuiElement even if it's the current target of opened.

My test code:

Code: Select all

local function show_gui(player)
    local frame = player.gui.center.add{
        type = "frame",
        name = "my-config",
        direction = "vertical",
    }
    frame.add{
        type = "label",
        name = "title",
        caption = "My Config",
    }
    player.opened = frame
end
Miniloader — UPS-friendly 1x1 loaders
Bulk Rail Loaders — Rapid train loading and unloading
Beltlayer & Pipelayer — Route items and fluids freely underground
Bilka
Factorio Staff
Factorio Staff
Posts: 3470
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: [0.16.x] Setting LuaControl::opened with LuaGuiElement

Post by Bilka »

You have to subscribe to the on_gui_closed event to then close your gui yourself. Code example for a mod I'm maintaining: https://github.com/Bilka2/Quill/commit/ ... 499bd7f22d
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.
User avatar
Therax
Filter Inserter
Filter Inserter
Posts: 471
Joined: Sun May 21, 2017 6:28 pm
Contact:

Re: [0.16.x] Setting LuaControl::opened with LuaGuiElement

Post by Therax »

Aha, interesting, if somewhat counterintuitive. It never occurred to me that the on_gui_closed event would be fired when an action hadn't been already completed by the engine to, you know, close a GUI. I guess setting opened to nil counts? In any case, thanks for the help!
Miniloader — UPS-friendly 1x1 loaders
Bulk Rail Loaders — Rapid train loading and unloading
Beltlayer & Pipelayer — Route items and fluids freely underground
Post Reply

Return to “Modding help”