Merge branch 'develop'

This commit is contained in:
Insality 2020-07-19 13:11:15 +03:00
commit bce68d9c35
13 changed files with 993 additions and 13 deletions

View File

@ -99,5 +99,8 @@ Druid 0.5.0:
- **Fix #71:** Blocker: blocker now correct block mouse hover event - **Fix #71:** Blocker: blocker now correct block mouse hover event
- **Fix #72:** Fix `return nil` in some `on_input` functions - **Fix #72:** Fix `return nil` in some `on_input` functions
- **Fix #74:** Fix typo: strech -> stretch. Scroll function `set_extra_stretch_size` renamed - **Fix #74:** Fix typo: strech -> stretch. Scroll function `set_extra_stretch_size` renamed
- **Fix #76:** Add params for lang text localization component
- **Fix #79:** Fix druid:remove inside on_input callback
- **Fix #80:** Fix hover set_enable typo function call
- Add `component.tempalte.lua` as template for Druid custom component - Add `component.tempalte.lua` as template for Druid custom component

View File

@ -65,7 +65,7 @@ end
function M.on_input_interrupt(self) function M.on_input_interrupt(self)
M.set_hover(self, false) self:set_hover(false)
end end
@ -109,10 +109,10 @@ function M.set_enabled(self, state)
if not state then if not state then
if self._is_hovered then if self._is_hovered then
M.set_hover(false) self:set_hover(false)
end end
if self._is_mouse_hovered then if self._is_mouse_hovered then
M.set_mouse_hover(false) self:set_mouse_hover(false)
end end
end end
end end

View File

@ -26,6 +26,7 @@ local M = component.create("lang_text", { const.ON_LANGUAGE_CHANGE })
function M.init(self, node, locale_id, no_adjust) function M.init(self, node, locale_id, no_adjust)
self.druid = self:get_druid() self.druid = self:get_druid()
self.text = self.druid:new_text(node, locale_id, no_adjust) self.text = self.druid:new_text(node, locale_id, no_adjust)
self.last_locale_args = {}
self.on_change = Event() self.on_change = Event()
@ -37,7 +38,7 @@ end
function M.on_language_change(self) function M.on_language_change(self)
if self.last_locale then if self.last_locale then
M.translate(self) M.translate(self, self.last_locale, unpack(self.last_locale_args))
end end
end end
@ -55,9 +56,10 @@ end
--- Translate the text by locale_id --- Translate the text by locale_id
-- @function lang_text:translate -- @function lang_text:translate
-- @tparam string locale_id Locale id -- @tparam string locale_id Locale id
function M.translate(self, locale_id) function M.translate(self, locale_id, ...)
self.last_locale_args = {...}
self.last_locale = locale_id or self.last_locale self.last_locale = locale_id or self.last_locale
self.text:set_to(settings.get_text(self.last_locale)) self.text:set_to(settings.get_text(self.last_locale, ...))
end end

View File

@ -135,6 +135,8 @@ function Druid.initialize(self, context, style)
self._context = context self._context = context
self._style = style or settings.default_style self._style = style or settings.default_style
self._deleted = false self._deleted = false
self._is_input_processing = false
self._late_remove = {}
self.url = msg.url() self.url = msg.url()
self.components = {} self.components = {}
@ -182,10 +184,15 @@ end
-- @function druid:remove -- @function druid:remove
-- @tparam Component component Component instance -- @tparam Component component Component instance
function Druid.remove(self, component) function Druid.remove(self, component)
if self._is_input_processing then
table.insert(self._late_remove, component)
return
end
local all_components = self.components[const.ALL] local all_components = self.components[const.ALL]
-- Recursive remove all children of component -- Recursive remove all children of component
for i = 1, #all_components do for i = #all_components, 1, -1 do
local inst = all_components[i] local inst = all_components[i]
if inst:is_child_of(component) then if inst:is_child_of(component) then
self:remove(inst) self:remove(inst)
@ -197,7 +204,7 @@ function Druid.remove(self, component)
if component.on_remove then if component.on_remove then
component:on_remove() component:on_remove()
end end
table.remove(self, i) table.remove(all_components, i)
end end
end end
@ -230,6 +237,8 @@ end
-- @tparam hash action_id Action_id from on_input -- @tparam hash action_id Action_id from on_input
-- @tparam table action Action from on_input -- @tparam table action Action from on_input
function Druid.on_input(self, action_id, action) function Druid.on_input(self, action_id, action)
self._is_input_processing = true
local is_input_consumed = false local is_input_consumed = false
is_input_consumed = process_input(action_id, action, is_input_consumed = process_input(action_id, action,
@ -238,6 +247,15 @@ function Druid.on_input(self, action_id, action)
is_input_consumed = process_input(action_id, action, is_input_consumed = process_input(action_id, action,
self.components[const.ON_INPUT], is_input_consumed) self.components[const.ON_INPUT], is_input_consumed)
self._is_input_processing = false
if #self._late_remove > 0 then
for i = 1, #self._late_remove do
self:remove(self._late_remove[i])
end
self._late_remove = {}
end
return is_input_consumed return is_input_consumed
end end

View File

@ -6,7 +6,8 @@ local M = {}
M.default_style = nil M.default_style = nil
function M.get_text(name)
function M.get_text(name, ...)
return "[Druid]: locales not inited" return "[Druid]: locales not inited"
end end

View File

@ -0,0 +1,76 @@
--- @license MIT, Insality 2020
--- @source https://github.com/Insality/druid
local M = {}
local function ends_with(str, ending)
return ending == "" or str:sub(-#ending) == ending
end
function M.get_commands()
return {
{
label = "Print gui scheme",
locations = { "Outline" },
query = {
selection = {type = "outline", cardinality = "many"}
},
active = function(opts)
return true
end,
run = function(opts)
print("local SCHEME = {")
for i = 1, #opts.selection do
local file = opts.selection[i]
if editor.can_get(file, "id") then
local id = editor.get(file, "id")
print("\t" .. string.upper(id) .. " = \"" .. id .. "\",")
end
end
print("}")
print("")
end
},
{
label = "Assign layers",
locations = {"Edit"},
query = {
selection = {type = "resource", cardinality = "one"}
},
active = function(opts)
local path = editor.get(opts.selection, "path")
return ends_with(path, ".gui")
end,
run = function(opts)
local file = opts.selection
print("Run script for", editor.get(file, "path"))
return {
{
action = "shell",
command = {
"bash",
"./editor_scripts/setup_layers.sh",
"." .. editor.get(file, "path")
}
}
}
end
}
}
end
return M

View File

@ -0,0 +1,44 @@
# @license MIT, Insality 2020
# @source https://github.com/Insality/druid
import sys
import deftree
def main():
filename = sys.argv[1]
print("Auto setup layers for file", filename)
tree = deftree.parse(filename)
root = tree.get_root()
layers = []
for texture in root.iter_elements("textures"):
layers.append(texture.get_attribute("name").value)
for fonts in root.iter_elements("fonts"):
layers.append(fonts.get_attribute("name").value)
to_remove_layers = []
for layer in root.iter_elements("layers"):
to_remove_layers.append(layer)
for layer in to_remove_layers:
root.remove(layer)
for layer in layers:
new_layer = root.add_element("layers")
new_layer.add_attribute("name", layer)
for node in root.iter_elements("nodes"):
texture = node.get_attribute("texture")
font = node.get_attribute("font")
if texture:
layer = texture.value.split("/")[0]
node.set_attribute("layer", layer)
if font:
layer = font.value
node.set_attribute("layer", layer)
tree.write()
main()

8
editor_scripts/setup_layers.sh Executable file
View File

@ -0,0 +1,8 @@
#!/bin/bash
# @license MIT, Insality 2020
# @source https://github.com/Insality/druid
echo "Run bash for $1"
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
/usr/local/bin/python3.7 $DIR/setup_layers.py $@

View File

@ -9693,6 +9693,766 @@ nodes {
text_leading: 1.0 text_leading: 1.0
text_tracking: 0.0 text_tracking: 0.0
} }
nodes {
position {
x: 3600.0
y: 0.0
z: 0.0
w: 1.0
}
rotation {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
scale {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
size {
x: 1.0
y: 1.0
z: 0.0
w: 1.0
}
color {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
type: TYPE_BOX
blend_mode: BLEND_MODE_ALPHA
texture: "kenney/empty"
id: "grid_page"
xanchor: XANCHOR_NONE
yanchor: YANCHOR_NONE
pivot: PIVOT_CENTER
adjust_mode: ADJUST_MODE_STRETCH
parent: "C_Anchor"
layer: "image"
inherit_alpha: true
slice9 {
x: 0.0
y: 0.0
z: 0.0
w: 0.0
}
clipping_mode: CLIPPING_MODE_NONE
clipping_visible: true
clipping_inverted: false
alpha: 1.0
template_node_child: false
size_mode: SIZE_MODE_AUTO
}
nodes {
position {
x: 0.0
y: 200.0
z: 0.0
w: 1.0
}
rotation {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
scale {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
size {
x: 400.0
y: 400.0
z: 0.0
w: 1.0
}
color {
x: 0.8
y: 1.0
z: 0.8
w: 1.0
}
type: TYPE_BOX
blend_mode: BLEND_MODE_ALPHA
texture: ""
id: "grid_nodes"
xanchor: XANCHOR_NONE
yanchor: YANCHOR_NONE
pivot: PIVOT_N
adjust_mode: ADJUST_MODE_FIT
parent: "grid_page"
layer: ""
inherit_alpha: true
slice9 {
x: 0.0
y: 0.0
z: 0.0
w: 0.0
}
clipping_mode: CLIPPING_MODE_NONE
clipping_visible: true
clipping_inverted: false
alpha: 1.0
template_node_child: false
size_mode: SIZE_MODE_MANUAL
}
nodes {
position {
x: -150.0
y: 250.0
z: 0.0
w: 1.0
}
rotation {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
scale {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
size {
x: 200.0
y: 100.0
z: 0.0
w: 1.0
}
color {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
type: TYPE_TEMPLATE
id: "button_add"
parent: "grid_page"
layer: ""
inherit_alpha: true
alpha: 1.0
template: "/example/templates/button.gui"
template_node_child: false
}
nodes {
position {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
rotation {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
scale {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
size {
x: 130.0
y: 60.0
z: 0.0
w: 1.0
}
color {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
type: TYPE_BOX
blend_mode: BLEND_MODE_ALPHA
texture: "kenney/button_blue"
id: "button_add/button"
xanchor: XANCHOR_NONE
yanchor: YANCHOR_NONE
pivot: PIVOT_CENTER
adjust_mode: ADJUST_MODE_FIT
parent: "button_add"
layer: "image"
inherit_alpha: true
slice9 {
x: 15.0
y: 15.0
z: 15.0
w: 15.0
}
clipping_mode: CLIPPING_MODE_NONE
clipping_visible: true
clipping_inverted: false
alpha: 1.0
template_node_child: true
size_mode: SIZE_MODE_MANUAL
}
nodes {
position {
x: 0.0
y: 7.0
z: 0.0
w: 1.0
}
rotation {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
scale {
x: 0.7
y: 0.7
z: 1.0
w: 1.0
}
size {
x: 200.0
y: 100.0
z: 0.0
w: 1.0
}
color {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
type: TYPE_TEXT
blend_mode: BLEND_MODE_ALPHA
text: "Add"
font: "game"
id: "button_add/text"
xanchor: XANCHOR_NONE
yanchor: YANCHOR_NONE
pivot: PIVOT_CENTER
outline {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
shadow {
x: 0.101960786
y: 0.2
z: 0.6
w: 1.0
}
adjust_mode: ADJUST_MODE_FIT
line_break: false
parent: "button_add/button"
layer: "text"
inherit_alpha: true
alpha: 1.0
outline_alpha: 0.0
shadow_alpha: 0.78
overridden_fields: 8
template_node_child: true
text_leading: 1.0
text_tracking: 0.0
}
nodes {
position {
x: 0.0
y: 250.0
z: 0.0
w: 1.0
}
rotation {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
scale {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
size {
x: 200.0
y: 100.0
z: 0.0
w: 1.0
}
color {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
type: TYPE_TEMPLATE
id: "button_remove"
parent: "grid_page"
layer: ""
inherit_alpha: true
alpha: 1.0
template: "/example/templates/button.gui"
template_node_child: false
}
nodes {
position {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
rotation {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
scale {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
size {
x: 130.0
y: 60.0
z: 0.0
w: 1.0
}
color {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
type: TYPE_BOX
blend_mode: BLEND_MODE_ALPHA
texture: "kenney/button_blue"
id: "button_remove/button"
xanchor: XANCHOR_NONE
yanchor: YANCHOR_NONE
pivot: PIVOT_CENTER
adjust_mode: ADJUST_MODE_FIT
parent: "button_remove"
layer: "image"
inherit_alpha: true
slice9 {
x: 15.0
y: 15.0
z: 15.0
w: 15.0
}
clipping_mode: CLIPPING_MODE_NONE
clipping_visible: true
clipping_inverted: false
alpha: 1.0
template_node_child: true
size_mode: SIZE_MODE_MANUAL
}
nodes {
position {
x: 0.0
y: 7.0
z: 0.0
w: 1.0
}
rotation {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
scale {
x: 0.7
y: 0.7
z: 1.0
w: 1.0
}
size {
x: 200.0
y: 100.0
z: 0.0
w: 1.0
}
color {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
type: TYPE_TEXT
blend_mode: BLEND_MODE_ALPHA
text: "Remove"
font: "game"
id: "button_remove/text"
xanchor: XANCHOR_NONE
yanchor: YANCHOR_NONE
pivot: PIVOT_CENTER
outline {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
shadow {
x: 0.101960786
y: 0.2
z: 0.6
w: 1.0
}
adjust_mode: ADJUST_MODE_FIT
line_break: false
parent: "button_remove/button"
layer: "text"
inherit_alpha: true
alpha: 1.0
outline_alpha: 0.0
shadow_alpha: 0.78
overridden_fields: 8
template_node_child: true
text_leading: 1.0
text_tracking: 0.0
}
nodes {
position {
x: 150.0
y: 250.0
z: 0.0
w: 1.0
}
rotation {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
scale {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
size {
x: 200.0
y: 100.0
z: 0.0
w: 1.0
}
color {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
type: TYPE_TEMPLATE
id: "button_clear"
parent: "grid_page"
layer: ""
inherit_alpha: true
alpha: 1.0
template: "/example/templates/button.gui"
template_node_child: false
}
nodes {
position {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
rotation {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
scale {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
size {
x: 130.0
y: 60.0
z: 0.0
w: 1.0
}
color {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
type: TYPE_BOX
blend_mode: BLEND_MODE_ALPHA
texture: "kenney/button_blue"
id: "button_clear/button"
xanchor: XANCHOR_NONE
yanchor: YANCHOR_NONE
pivot: PIVOT_CENTER
adjust_mode: ADJUST_MODE_FIT
parent: "button_clear"
layer: "image"
inherit_alpha: true
slice9 {
x: 15.0
y: 15.0
z: 15.0
w: 15.0
}
clipping_mode: CLIPPING_MODE_NONE
clipping_visible: true
clipping_inverted: false
alpha: 1.0
template_node_child: true
size_mode: SIZE_MODE_MANUAL
}
nodes {
position {
x: 0.0
y: 7.0
z: 0.0
w: 1.0
}
rotation {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
scale {
x: 0.7
y: 0.7
z: 1.0
w: 1.0
}
size {
x: 200.0
y: 100.0
z: 0.0
w: 1.0
}
color {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
type: TYPE_TEXT
blend_mode: BLEND_MODE_ALPHA
text: "Clear"
font: "game"
id: "button_clear/text"
xanchor: XANCHOR_NONE
yanchor: YANCHOR_NONE
pivot: PIVOT_CENTER
outline {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
shadow {
x: 0.101960786
y: 0.2
z: 0.6
w: 1.0
}
adjust_mode: ADJUST_MODE_FIT
line_break: false
parent: "button_clear/button"
layer: "text"
inherit_alpha: true
alpha: 1.0
outline_alpha: 0.0
shadow_alpha: 0.78
overridden_fields: 8
template_node_child: true
text_leading: 1.0
text_tracking: 0.0
}
nodes {
position {
x: -160.0
y: 160.0
z: 0.0
w: 1.0
}
rotation {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
scale {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
size {
x: 80.0
y: 80.0
z: 0.0
w: 1.0
}
color {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
type: TYPE_BOX
blend_mode: BLEND_MODE_ALPHA
texture: "kenney/empty"
id: "grid_nodes_prefab"
xanchor: XANCHOR_NONE
yanchor: YANCHOR_NONE
pivot: PIVOT_CENTER
adjust_mode: ADJUST_MODE_FIT
parent: "grid_page"
layer: ""
inherit_alpha: true
slice9 {
x: 0.0
y: 0.0
z: 0.0
w: 0.0
}
clipping_mode: CLIPPING_MODE_NONE
clipping_visible: true
clipping_inverted: false
alpha: 1.0
template_node_child: false
size_mode: SIZE_MODE_MANUAL
}
nodes {
position {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
rotation {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
scale {
x: 1.5
y: 1.5
z: 1.0
w: 1.0
}
size {
x: 36.0
y: 36.0
z: 0.0
w: 1.0
}
color {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
type: TYPE_BOX
blend_mode: BLEND_MODE_ALPHA
texture: "kenney/slider_move"
id: "grid_nodes_dot"
xanchor: XANCHOR_NONE
yanchor: YANCHOR_NONE
pivot: PIVOT_CENTER
adjust_mode: ADJUST_MODE_FIT
parent: "grid_nodes_prefab"
layer: ""
inherit_alpha: true
slice9 {
x: 0.0
y: 0.0
z: 0.0
w: 0.0
}
clipping_mode: CLIPPING_MODE_NONE
clipping_visible: true
clipping_inverted: false
alpha: 1.0
template_node_child: false
size_mode: SIZE_MODE_AUTO
}
nodes {
position {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
rotation {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
scale {
x: 0.75
y: 0.75
z: 1.0
w: 1.0
}
size {
x: 50.0
y: 50.0
z: 0.0
w: 1.0
}
color {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
type: TYPE_TEXT
blend_mode: BLEND_MODE_ALPHA
text: "1"
font: "game"
id: "grid_nodes_text"
xanchor: XANCHOR_NONE
yanchor: YANCHOR_NONE
pivot: PIVOT_CENTER
outline {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
shadow {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
adjust_mode: ADJUST_MODE_FIT
line_break: false
parent: "grid_nodes_dot"
layer: ""
inherit_alpha: true
alpha: 1.0
outline_alpha: 0.0
shadow_alpha: 0.0
template_node_child: false
text_leading: 1.0
text_tracking: 0.0
}
nodes { nodes {
position { position {
x: 0.0 x: 0.0

View File

@ -9,6 +9,7 @@ local button_page = require("example.page.button_page")
local scroll_page = require("example.page.scroll_page") local scroll_page = require("example.page.scroll_page")
local slider_page = require("example.page.slider_page") local slider_page = require("example.page.slider_page")
local input_page = require("example.page.input_page") local input_page = require("example.page.input_page")
local grid_page = require("example.page.grid_page")
local pages = { local pages = {
"main_page", "main_page",
@ -17,6 +18,7 @@ local pages = {
"scroll_page", "scroll_page",
"slider_page", "slider_page",
"input_page", "input_page",
"grid_page",
} }
local function on_control_button(self, delta) local function on_control_button(self, delta)
@ -70,6 +72,7 @@ function init(self)
scroll_page.setup_page(self) scroll_page.setup_page(self)
slider_page.setup_page(self) slider_page.setup_page(self)
input_page.setup_page(self) input_page.setup_page(self)
grid_page.setup_page(self)
init_top_panel(self) init_top_panel(self)

View File

@ -7,8 +7,8 @@ local function setup_druid()
sound.play("kenney:/sound#" .. name) sound.play("kenney:/sound#" .. name)
end) end)
druid.set_text_function(function(lang_id) druid.set_text_function(function(lang_id, ...)
return lang.get_locale(lang_id) return lang.get_locale(lang_id, ...)
end) end)
druid.on_language_change() druid.on_language_change()

View File

@ -9,6 +9,7 @@ local en = {
scroll_page = "Scroll page", scroll_page = "Scroll page",
slider_page = "Slider page", slider_page = "Slider page",
input_page = "Input page", input_page = "Input page",
grid_page = "Grid page",
ui_section_button = "Button", ui_section_button = "Button",
ui_section_text = "Text", ui_section_text = "Text",
ui_section_timer = "Timer", ui_section_timer = "Timer",
@ -27,6 +28,7 @@ local ru = {
scroll_page = "Скролл", scroll_page = "Скролл",
slider_page = "Слайдеры", slider_page = "Слайдеры",
input_page = "Текст. ввод", input_page = "Текст. ввод",
grid_page = "Сетка",
ui_section_button = "Кнопка", ui_section_button = "Кнопка",
ui_section_text = "Текст", ui_section_text = "Текст",
ui_section_timer = "Таймер", ui_section_timer = "Таймер",
@ -42,8 +44,14 @@ local ru = {
local data = en local data = en
function M.get_locale(lang_id) function M.get_locale(lang_id, ...)
return data[lang_id] or lang_id local localized_text = data[lang_id] or lang_id
if #{...} > 0 then
localized_text = string.format(localized_text, ...)
end
return localized_text
end end

View File

@ -0,0 +1,57 @@
local M = {}
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 + 1
gui.set_text(cloned["grid_nodes_text"], index)
local button = self.druid:new_button(cloned["grid_nodes_prefab"], function()
print(index)
end)
table.insert(self.grid_node_buttons, button)
self.grid_nodes:add(cloned["grid_nodes_prefab"])
end
local function clear_nodes(self)
local nodes = self.grid_nodes.nodes
for i = 1, #nodes do
gui.delete_node(nodes[i])
end
for i = 1, #self.grid_node_buttons do
self.druid:remove(self.grid_node_buttons[i])
end
self.grid_node_buttons = {}
self.grid_nodes:clear()
end
local function remove_node(self)
-- Remove is not implemented yet
end
function M.setup_page(self)
self.grid_nodes = self.druid:new_grid("grid_nodes", "grid_nodes_prefab", 5)
self.grid_node_buttons = {}
gui.set_enabled(gui.get_node("grid_nodes_prefab"), false)
for i = 1, 15 do
add_node(self)
end
self.druid:new_button("button_add/button", add_node)
self.druid:new_button("button_clear/button", clear_nodes)
local remove_button = self.druid:new_button("button_remove/button", remove_node)
gui.set_enabled(remove_button.node, false)
end
return M