GUI Input Focus

Context:

  1. Game screen
  2. Game screen reaches complete state
  3. Game screen releases input focus and messages GUI to move node into frame and acquire input focus

Collection

  • GO contains the main game
  • GUI
    – Main GUI
    – Level Complete (Rendered but out of frame); box with 1 text child, 1 button child

Problems:

  1. Can click through the GUI node box and still play the game

Is there any easy way to prevent clicking through the GUI to play the game behind it? For example creating a box node that covers the screen? Locking input focus to the GUI complete screen and not allowing any other GO to try to acquire input focus until the lock has been released?

You can prevent input from propagating by consuming the input.

2 Likes

Read this before and just copied the code into my project only altering the node names. The GUI window still does not have 100% focus. The game behind steals the focus. There’s parts of my code that on certain events acquires input focus which I believe could be causing the problem?

Tomorrow I’ll update from 1.2.149, read through the documentation further about input stacks and then see if the problem is my spaghetti code. Any easy way to debug what the current input stack order is?

No there’s no way to debug the input stack. How many objects do you have that needs input focus?

function on_message(self, message_id, message, sender)
	-- receive message that gui is closed
	if message_id == hash("gui_open") then
		gui_open = true 
	-- receive message that gui is closed
	elseif message_id == hash("gui_close") then
		gui_close = false
	end
end

function on_input(self, action_id, action)
	if not gui_open then
		if action_id == hash("touch") and (action.pressed or action.released) then
			...
		end
	end
end

I managed to fix the problem by adding the above code to the main game script that just blocks input based on a boolean whenever the GUI is open. Probably not the most elegant solution but it seems to be working.