GUI Get_node function

local druid = require("druid.druid")


function init(self)
	self.druid = druid.new(self)
	local prefab = gui.get_node("prefab")
	gui.set_enabled(prefab, false)

	
	local grid_w = self.druid:new_static_grid("grid_C_anchor", prefab, 5)


	local update_pos_func = function(node, pos) gui.animate(node, "position", pos, gui.EASING_OUTSINE, 0.2) end
	grid_w:set_position_function(update_pos_func)


	local grids = {
		grid_w
	}

	for i = 1, #grids do
		grids[i].style.IS_DYNAMIC_NODE_POSES = false
	end


	local animate_grides = function()
		for _, grid in ipairs(grids) do
			for i = 1, #grid.nodes do
				gui.delete_node(grid.nodes[i])
			end
			grid:clear()

			for i = 1, 10 do
				timer.delay(0, false, function()
					local node = gui.clone(prefab)
					gui.set_enabled(node, true)
					grid:add(node)
				end)
			end
		end
	end

	animate_grides()
	timer.delay(10, true, animate_grides)

end


function final(self)
	self.druid:final()
end


function update(self, dt)
	self.druid:update(dt)
end


function on_message(self, message_id, message, sender)
	self.druid:on_message(message_id, message, sender)
end


function on_input(self, action_id, action)
	return self.druid:on_input(action_id, action)
end


editor

image
build
where is 1

if you do gui.clone(prefab) it will copy only parent(prefab) node. You need to use gui.clone_tree(prefab) to copy whole prefab (including children)

for example my usage is following:

	for i, table in ipairs(rules.boosters) do
		boosters[i] = table.cost

		local node = gui.clone_tree(boost)
		grid_boost:add(node.boost)
		self.druid:new_button(node.boost, on_boost_presed, i)
		gui.set_enabled(node.boost, true)
		gui.play_flipbook(node.icon_boost, table.icon)

notice that gui.clone_tree returns table, not node itself.
for example to change text in cloned node you must do gui.set_text(node.text, "yourtext") to hide cloned node gui.set_visible(node.prefab, false)

4 Likes

Wouldn’t it be nice to write an easier function? @britzl

thanks @boruok

Easier how exactly? What do you suggest?

gui.clone(prefab) //including children

Not sure I understand. This is what gui.clone_tree() does isn’t it?

6 Likes

I tried but it doesn’t work. That’s why I opened this topic :slight_smile:

Why? Are you getting an error? Can you please share a minimal project or explain in more detail what you are trying to do?