Gooey child nodes visual update (SOLVED)

In Gooey how can I also update visuals of the child nodes?

You can create a theme, like this: https://github.com/britzl/gooey-rpg

What do you want to do more specifically?

Just basic button with text. I’m trying to change the font color and outline also when pressed.

Ok, so this can be solved using a theme. Or you can use the refresh_fn callback when the state of the button has changed.

gooey.button(node_id, action_id, action, fn, refresh_fn)

Let’s say you have two buttons:

local function update_button(button)
	if button.pressed_now then
		gui.set_color(button.node, COLOR_LIGHTGREY)
	elseif button.released_now then
		gui.set_color(button.node, COLOR_WHITE)
	end
end

function on_input(self, action_id, action)
   gooey.button("foo", action_id, action, function(button)
      print("Pressed foo")
   end, update_button)
   
   gooey.button("bar", action_id, action, function(button)
      print("Pressed bar")
   end, update_button)
end

“foo” and “bar” are the ids of the button background nodes and they are referenced from the update_button() function to change the button color. As you can see there is no way to know what other nodes there are on the button, for instance the button text node or some additional decoration.

Assuming that the text on the node is named similar to the background you can create a helper function to work with the button and apply the extra styling you need:

local function mybutton(id, callback_fn)
   -- get the text node
   -- it has to be named as the button background node with "_text" as suffix
   local text_node = gui.get_node(id .. "_text")

   -- custom button update function
   local function update_button(button)
      if button.pressed_now then
         gui.set_color(button.node, COLOR_WHITE)
         gui.set_color(text_node, COLOR_BLACK)
      elseif button.released_now then
         gui.set_color(button.node, COLOR_LIGHTGREY)
         gui.set_color(text_node, COLOR_DARKGREY)
      end
   end

   -- run the actual gooey button function
   return gooey.button(id, action_id, action, callback_fn, update_button)
end


function on_input(self, action_id, action)
   -- call our custom gooey button function
   mybutton("foo", action_id, action, function(button)
      print("Pressed foo")
   end)
   
   mybutton("bar", action_id, action, function(button)
      print("Pressed bar")
   end)
end
1 Like

Thanks I got the button working now. I also added checks for box/text nodes so I don’t get any errors if they don’t exist in the pressed button. Is this ok?

	-- Check if pressed button has box/text node
	local has_text_node = pcall(gui.get_node, id .. "_text")
	local has_box_node = pcall(gui.get_node, id .. "_box")

Sure, looks good!

1 Like