I’ve been working on a new gui and I have several successful similar executions of the pick node function but this one for whatever reason isn’t working. When I click on the node (and I checked the click coordinates do hit the bounding box) it doesn’t return true. Not sure what I’m doing wrong. Here’s the code:
local inventories = require("assets.modules.inventory")
local slot
local inventory_panel
local desc_text
local desc_name
local desc_count
local menu
local slots
local x_button
function init(self)
slot = gui.get_node("slot_template")
inventory_panel = gui.get_node("slot_box")
desc_text = gui.get_node("description_text")
desc_name = gui.get_node("item_name_text")
desc_count = gui.get_node("item_count_text")
menu = gui.get_node("menu")
gui.set_enabled(menu, false)
gui.set_clipping_visible(menu, false)
slots = {}
x_button = gui.get_node("x_button")
end
function final(self)
-- Add finalization code here
-- Remove this function if not needed
end
function update(self, dt)
-- Add update code here
-- Remove this function if not needed
end
function on_message(self, message_id, message, sender)
if message_id == hash("show") then
msg.post(".", "acquire_input_focus")
gui.set_enabled(menu, true)
gui.set_clipping_visible(menu, true)
count = 0
inventory = message.object
pprint(inventories)
pprint(message)
pprint(inventories[message[object]])
for i, x in pairs(inventories[inventory]) do
slots[i] = {gui.clone_tree(slot), x}
pprint(slots[i][1])
gui.set_parent(slots[i][1].slot_template, inventory_panel, true)
local parent_pos = gui.get_position(inventory_panel)
local parent_size = gui.get_size(inventory_panel)
gui.set_position(slots[i][1].slot_template, vmath.vector3(-parent_size.x/2, parent_size.y/2, 0))
gui.set_scale(slots[i][1].slot_template, vmath.vector4(.1, .068, 0, 0))
print(gui.get_position(slots[i][1].slot_template))
gui.set_enabled(slots[i][1].slot_template, true)
local data = slots[i][2]:getStats()
print(data.name)
gui.set_text(slots[i][1].slot_label, data.name)
count = count + 1
end
end
end
function on_input(self, action_id, action)
if action_id == hash("mb1") and action.pressed then
if gui.pick_node(x_button, action.x, action.y) then
gui.set_enabled(menu, false)
gui.set_clipping_visible(menu, false)
else
for i, item in pairs(slots) do
print(i)
local slot_pos = gui.get_screen_position(item[1].slot_template)
print("location data:\nslot position: "..slot_pos.x..", "..slot_pos.y.."\naction.x: "..action.x.." action.y: "..action.y)
if gui.pick_node(item[1].slot_template, action.x, action.y) then
print("success")
end
end
end
end
end
function on_reload(self)
-- Add input-handling code here
-- Remove this function if not needed
end