mirror of
https://github.com/Insality/druid.git
synced 2025-09-27 10:02:18 +02:00
Add node shift at add/remove for static grid
This commit is contained in:
@@ -10392,8 +10392,8 @@ nodes {
|
||||
}
|
||||
nodes {
|
||||
position {
|
||||
x: 0.0
|
||||
y: 0.0
|
||||
x: 1.0
|
||||
y: 2.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
@@ -10423,7 +10423,7 @@ nodes {
|
||||
}
|
||||
type: TYPE_TEXT
|
||||
blend_mode: BLEND_MODE_ALPHA
|
||||
text: "1"
|
||||
text: "X"
|
||||
font: "game"
|
||||
id: "grid_nodes_text"
|
||||
xanchor: XANCHOR_NONE
|
||||
|
@@ -1,23 +1,28 @@
|
||||
local M = {}
|
||||
|
||||
|
||||
local function remove_node(self, button)
|
||||
gui.delete_node(button.node)
|
||||
|
||||
self.druid:remove(button)
|
||||
local index = self.grid_nodes:get_index_by_node(button.node)
|
||||
self.grid_nodes:remove(index, true)
|
||||
for i = 1, #self.grid_node_buttons do
|
||||
if self.grid_node_buttons[i] == button then
|
||||
table.remove(self.grid_node_buttons, i)
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local function add_node(self)
|
||||
local prefab = gui.get_node("grid_nodes_prefab")
|
||||
local cloned = gui.clone_tree(prefab)
|
||||
gui.set_enabled(cloned["grid_nodes_prefab"], true)
|
||||
local index = #self.grid_nodes.nodes + 1
|
||||
gui.set_text(cloned["grid_nodes_text"], index)
|
||||
|
||||
local button = self.druid:new_button(cloned["grid_nodes_prefab"], function(_, params, button)
|
||||
gui.delete_node(button.node)
|
||||
self.druid:remove(button)
|
||||
self.grid_nodes:remove(index)
|
||||
for i = 1, #self.grid_node_buttons do
|
||||
if self.grid_node_buttons[i] == button then
|
||||
table.remove(self.grid_node_buttons, i)
|
||||
break
|
||||
end
|
||||
end
|
||||
remove_node(self, button)
|
||||
end)
|
||||
table.insert(self.grid_node_buttons, button)
|
||||
|
||||
@@ -40,11 +45,6 @@ local function clear_nodes(self)
|
||||
end
|
||||
|
||||
|
||||
local function remove_node(self)
|
||||
-- Remove is not implemented yet
|
||||
end
|
||||
|
||||
|
||||
function M.setup_page(self)
|
||||
self.grid_nodes = self.druid:new_static_grid("grid_nodes", "grid_nodes_prefab", 5)
|
||||
self.grid_nodes:set_position_function(function(node, pos)
|
||||
|
Reference in New Issue
Block a user