Hi,
I’m having an issue where two overlapping GUI boxes both return true on a gui.pick_node
. Is there a way that I can easily figure out which one is on top so I can ignore input on the other one?
~Charles
Hi,
I’m having an issue where two overlapping GUI boxes both return true on a gui.pick_node
. Is there a way that I can easily figure out which one is on top so I can ignore input on the other one?
~Charles
What does the situation look like?
You can set a value in a script as you enable / disable potentially overlapping elements to have a kind of layer system where you can tell which layers should be clickable or not.
Thanks, this helps. But it doesn’t seem to be absolute? The 4th child of any node in the hierarchy is registering as index 3, even if its parent is on top of or below some other nodes.
I think i’ll have to write some additional code to establish the true order.
In case anyone else has this issue, here is the solution I ended up going with:
function cmp_draw_order(a, b)
local a_lst = { }
local b_lst = { }
local nd = a
while nd ~= nil do
a_lst[#a_lst] = gui.get_index(nd)
nd = gui.get_parent(nd)
end
nd = b
while nd ~= nil do
b_lst[#b_lst] = gui.get_index(nd)
nd = gui.get_parent(nd)
end
for i = 0, #a_lst do
local aind = a_lst[#a_lst - i]
local bind = b_lst[#b_lst - i]
if aind ~= bind then
return not bind or (aind and aind > bind)
end
end
return false -- We should never get here.
end
Given two nodes A and B, it returns true if A is on top of B in visibility (just based on the hierarchy).
Wrote it in a few minutes and i’m new to Lua, so If anyone has better suggestions, please let me know!
Could you explain what you are actually doing in your game?
If it’s actual menus I’d still hard code the layers and make things active / inactive based on active layer in code only.
I have a scene with a lot of dynamically generated GUI and lots of moving elements. Sometimes buttons overlap each other partially and clicking on the overlapping area fires both. I’d like to maintain the ability to click on everything, so I don’t think having entire layers of active/inactive ui will help much.
I could add this layering, and check buttons in “layer order”, but in my particular case that isn’t really very different from using the above solution, because my on_input is looping over a list of buttons anyway. Its similarly efficient for me to perform an ordered insert based on the comparison function above, and then iterate over the list as normal. The layer information i’d be adding would basically be establishing the same order as the hierarchy information.