Merge branch 'develop' into 43-infinity-scroll

# Conflicts:
#	druid/base/grid.lua
#	druid/const.lua
#	druid/system/druid_instance.lua
This commit is contained in:
Insality
2020-11-03 23:25:02 +03:00
101 changed files with 15213 additions and 8762 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -1,3 +1,4 @@
---@type druid
local druid = require("druid.druid")
local empty_style = require("druid.styles.empty.style")

View File

@@ -1,26 +1,49 @@
local M = {}
local function add_node(self)
local function simple_animate(node, pos)
gui.animate(node, "position", pos, gui.EASING_OUTSINE, 0.2)
end
local function remove_node(self, button, is_shift)
gui.delete_node(button.node)
self.druid:remove(button)
local index = self.grid_static_grid:get_index_by_node(button.node)
self.grid_static_grid:remove(index, is_shift)
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, index)
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)
local button = self.druid:new_button(cloned["grid_nodes_prefab"], function(_, params, button)
remove_node(self, button, true)
end)
button.on_long_click:subscribe(function()
remove_node(self, button)
end)
button:set_click_zone(self.grid_static_scroll.view_node)
table.insert(self.grid_node_buttons, button)
self.grid_nodes:add(cloned["grid_nodes_prefab"])
self.grid_static_grid:add(cloned["grid_nodes_prefab"], index)
end
local function clear_nodes(self)
local nodes = self.grid_nodes.nodes
for i = 1, #nodes do
gui.delete_node(nodes[i])
local nodes = self.grid_static_grid.nodes
for i, node in pairs(nodes) do
gui.delete_node(node)
end
for i = 1, #self.grid_node_buttons do
@@ -28,29 +51,125 @@ local function clear_nodes(self)
end
self.grid_node_buttons = {}
self.grid_nodes:clear()
self.grid_static_grid: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)
local function init_static_grid(self)
self.grid_node_buttons = {}
gui.set_enabled(gui.get_node("grid_nodes_prefab"), false)
for i = 1, 15 do
add_node(self)
add_node(self, i)
end
self.druid:new_button("button_add/button", add_node)
self.druid:new_button("button_clear/button", clear_nodes)
self.druid:new_button("button_add/button", function()
add_node(self)
end)
self.druid:new_button("button_clear/button", function()
clear_nodes(self)
end)
end
local remove_button = self.druid:new_button("button_remove/button", remove_node)
gui.set_enabled(remove_button.node, false)
local function remove_dynamic_node(self, button, is_shift_left)
gui.delete_node(button.node)
self.druid:remove(button)
local index = self.grid_dynamic_grid:get_index_by_node(button.node)
self.grid_dynamic_grid:remove(index, is_shift_left)
for i = 1, #self.dynamic_node_buttons do
if self.dynamic_node_buttons[i] == button then
table.remove(self.dynamic_node_buttons, i)
break
end
end
end
local function add_node_dynamic(self, index, is_shift_left)
local node = gui.clone(self.prefab_dynamic)
gui.set_enabled(node, true)
gui.set_size(node, vmath.vector3(250, math.random(60, 150), 0))
self.grid_dynamic_grid:add(node, index, is_shift_left)
local button = self.druid:new_button(node, function(_, params, button)
remove_dynamic_node(self, button)
end)
button.on_long_click:subscribe(function()
remove_dynamic_node(self, button, true)
end)
button:set_click_zone(self.grid_dynamic_scroll.view_node)
table.insert(self.dynamic_node_buttons, button)
end
local function add_node_dynamic_hor(self, index)
local node = gui.clone(self.prefab_hor_dynamic)
gui.set_enabled(node, true)
gui.set_size(node, vmath.vector3(80 + math.random(0, 80), 80, 0))
self.grid_dynamic_hor_grid:add(node, index)
end
local function init_dynamic_grid(self)
-- Vertical horizontal grid
self.dynamic_node_buttons = {}
self.prefab_dynamic = gui.get_node("grid_dynamic_prefab")
gui.set_enabled(self.prefab_dynamic, false)
for i = 1, 10 do
add_node_dynamic(self, i)
end
self.druid:new_button("button_add_start_dynamic/button", function()
local start_index = (self.grid_dynamic_grid.first_index or 2) - 1
add_node_dynamic(self, start_index)
end)
self.druid:new_button("button_add_end_dynamic/button", function()
add_node_dynamic(self)
end)
-- Horizontal dynamic grid
self.prefab_hor_dynamic = gui.get_node("grid_dynamic_hor_prefab")
gui.set_enabled(self.prefab_hor_dynamic, false)
for i = 1, 10 do
add_node_dynamic_hor(self, i)
end
self.druid:new_button("button_add_start_dynamic_hor/button", function()
add_node_dynamic_hor(self, 1)
end)
self.druid:new_button("button_add_end_dynamic_hor/button", function()
add_node_dynamic_hor(self)
end)
end
function M.setup_page(self)
self.grid_page_scroll = self.druid:new_scroll("grid_page", "grid_page_content")
self.grid_static_grid = self.druid:new_static_grid("grid_nodes", "grid_nodes_prefab", 5)
:set_position_function(simple_animate)
self.grid_static_scroll = self.druid:new_scroll("grid_nodes_view", "grid_nodes")
:set_horizontal_scroll(false)
:bind_grid(self.grid_static_grid)
self.grid_dynamic_grid = self.druid:new_dynamic_grid("grid_dynamic_nodes")
:set_position_function(simple_animate)
self.grid_dynamic_scroll = self.druid:new_scroll("grid_dynamic_view", "grid_dynamic_nodes")
:set_horizontal_scroll(false)
:bind_grid(self.grid_dynamic_grid)
self.grid_dynamic_hor_grid = self.druid:new_dynamic_grid("grid_dynamic_hor_nodes")
:set_position_function(simple_animate)
self.grid_dynamic_hor_scroll = self.druid:new_scroll("grid_dynamic_hor_view", "grid_dynamic_hor_nodes")
:set_vertical_scroll(false)
:bind_grid(self.grid_dynamic_hor_grid)
init_static_grid(self)
init_dynamic_grid(self)
end

View File

@@ -50,22 +50,6 @@ local function setup_progress(self)
end
local function setup_grid(self)
local grid = self.druid:new_grid("grid", "button_template/button", 3)
for i = 1, 12 do
local nodes = gui.clone_tree(gui.get_node("button_template/button"))
local root = nodes["button_template/button"]
self.druid:new_button(root, function(context, param)
grid:set_offset(vmath.vector3(param))
end, i)
self.druid:new_text(nodes["button_template/text"], "Grid"..i)
grid:add(root)
end
end
local function setup_slider(self)
local slider = self.druid:new_slider("slider_pin", vmath.vector3(95, 0, 0), function(_, value)
gui.set_text(gui.get_node("text_progress_slider"), math.ceil(value * 100) .. "%")
@@ -96,11 +80,6 @@ local function setup_timer(self)
end
local function setup_scroll(self)
self.druid:new_scroll("main_page", "scroll_content")
end
local function setup_back_handler(self)
self.druid:new_back_handler(empty_callback, "back button")
end
@@ -117,10 +96,8 @@ function M.setup_page(self)
setup_button(self)
setup_progress(self)
setup_grid(self)
setup_timer(self)
setup_checkbox(self)
setup_scroll(self)
setup_slider(self)
setup_back_handler(self)
setup_input(self)

View File

@@ -5,7 +5,7 @@ local function init_scroll_with_grid(self)
local prefab = gui.get_node("grid_prefab")
local grid_scroll = self.druid:new_scroll("scroll_with_grid_size", "grid_content")
local grid = self.druid:new_grid("grid_content", "grid_prefab", 20)
local grid = self.druid:new_static_grid("grid_content", "grid_prefab", 20)
for i = 1, 40 do
local clone_prefab = gui.clone_tree(prefab)

View File

@@ -27,7 +27,7 @@ local function setup_texts(self)
timer.delay(0.3, true, function()
anchoring:set_pivot(pivots[pivot_index])
pivot_index = pivot_index + 1
pivot_index = pivot_index + 1
if pivot_index > #pivots then
pivot_index = 1
end