Which LuaGuiElement is in front?

Place to get help with not working mods / modding interface.
Post Reply
Smart Inserter
Smart Inserter
Posts: 1297
Joined: Sun Oct 14, 2018 8:13 am

Which LuaGuiElement is in front?

Post by Pi-C »

My mod has 2 GUIs on player.gui.screen. When I turn them on, I will use LuaGuiElement.bring_to_front() to make sure they are visible. One of them ("Available characters") can become quite small, as you can see in this screenshot:
overlay-guis.png (2.79 MiB) Viewed 193 times
In this case the small GUI is on top, so it is visible. But if the bigger GUI gets the focus, the small one will be completely hidden. The button flow at the top left of the screen contains the buttons that toggle GUI visibility. Now, if the small GUI is hidden by something else, clicking the "Available characters" button will (apparently!) do nothing: The GUI already is visible, so using the button will make it invisible, and only on the next click will it be visible (and in the foreground) again.

Is there any way to find out whether a particular GUI element is hidden, or at least if it is on top? If so, I could check whether my GUI is visible but possibly hidden and bring it to the front instead of turning it off when the toggle button is used.
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

User avatar
Long Handed Inserter
Long Handed Inserter
Posts: 69
Joined: Wed Nov 17, 2021 11:26 pm

Re: Which LuaGuiElement is in front?

Post by yaim904 »

I would like to help you, but I don't think I understand what the problem is.

If what you want is to prevent the windows from overlapping, place it to one side of the main one

Code: Select all

script.on_event(defines.events.on_player_created, function(event)
    local player = game.get_player(event.player_index)
    local anchor = {gui=defines.relative_gui_type.controller_gui, position=defines.relative_gui_position.top}
    local frame = player.gui.relative.add{type="frame", anchor=anchor}
    frame.add{type="label", caption=player.name}

While you don't need the window, hide it with the "element.style.visible = false" property or destroy it.
Solo entiendo español, pero si tu también lo entiendes, escríbeme
Everything i write in English is translated by google.

Post Reply

Return to “Modding help”