mirror of
https://github.com/Insality/druid
synced 2025-06-27 10:27:48 +02:00
Add reinit data_list example, add debug mode for druid/components. Refactor scroll is_in_view. Use late remove while scroll update
This commit is contained in:
parent
4166fbe089
commit
db1e7ec502
@ -168,7 +168,6 @@ function Scroll.init(self, view_node, content_node)
|
||||
self._is_vertical_scroll = true
|
||||
self._grid_on_change = nil
|
||||
self._grid_on_change_callback = nil
|
||||
self._outside_offset_vector = vmath.vector3(0)
|
||||
|
||||
self:_update_size()
|
||||
end
|
||||
@ -190,8 +189,6 @@ end
|
||||
|
||||
|
||||
function Scroll.update(self, dt)
|
||||
self:_update_params()
|
||||
|
||||
if self.drag.is_drag then
|
||||
self:_update_hand_scroll(dt)
|
||||
else
|
||||
@ -402,8 +399,27 @@ end
|
||||
-- @tparam node node The node to check
|
||||
-- @treturn boolean True if node in visible scroll area
|
||||
function Scroll.is_node_in_view(self, node)
|
||||
local node_border = helper.get_border(node, gui.get_position(node))
|
||||
local view_border = helper.get_border(self.view_node, -(self.position - self._outside_offset_vector))
|
||||
local node_offset_for_view = gui.get_position(node)
|
||||
local parent = gui.get_parent(node)
|
||||
local is_parent_of_view = false
|
||||
while parent do
|
||||
if parent ~= self.view_node then
|
||||
local parent_pos = gui.get_position(parent)
|
||||
node_offset_for_view.x = node_offset_for_view.x + parent_pos.x
|
||||
node_offset_for_view.y = node_offset_for_view.y + parent_pos.y
|
||||
parent = gui.get_parent(parent)
|
||||
else
|
||||
is_parent_of_view = true
|
||||
parent = nil
|
||||
end
|
||||
end
|
||||
if not is_parent_of_view then
|
||||
error("The node to check is_node_in_view should be child if scroll view")
|
||||
return false
|
||||
end
|
||||
|
||||
local node_border = helper.get_border(node, node_offset_for_view)
|
||||
local view_border = helper.get_border(self.view_node)
|
||||
|
||||
-- Check is vertical outside (Left or Right):
|
||||
if node_border.z < view_border.x or node_border.x > view_border.z then
|
||||
@ -438,7 +454,10 @@ function Scroll.bind_grid(self, grid)
|
||||
|
||||
self._grid_on_change = grid.on_change_items
|
||||
self._grid_on_change_callback = self._grid_on_change:subscribe(function()
|
||||
self:set_size(grid:get_size(), grid:get_offset())
|
||||
local size = grid:get_size()
|
||||
local offset = grid:get_offset()
|
||||
self:set_size(size, offset)
|
||||
self:log_message("Change size from grid", { size = size, offset = offset })
|
||||
end)
|
||||
self:set_size(grid:get_size(), grid:get_offset())
|
||||
|
||||
@ -547,7 +566,6 @@ function Scroll._set_scroll_position(self, position)
|
||||
if self.position.x ~= position.x or self.position.y ~= position.y then
|
||||
self.position.x = position.x
|
||||
self.position.y = position.y
|
||||
self:_update_params()
|
||||
gui.set_position(self.content_node, position)
|
||||
|
||||
self.on_scroll:trigger(self:get_context(), self.position)
|
||||
@ -718,32 +736,6 @@ function Scroll._update_size(self)
|
||||
end
|
||||
|
||||
|
||||
function Scroll._update_params(self)
|
||||
local t = self.target_position
|
||||
local b = self.available_pos
|
||||
|
||||
self._outside_offset_vector.x = 0
|
||||
self._outside_offset_vector.y = 0
|
||||
|
||||
-- Right border (minimum x)
|
||||
if t.x < b.x then
|
||||
self._outside_offset_vector.x = t.x - b.x
|
||||
end
|
||||
-- Left border (maximum x)
|
||||
if t.x > b.z then
|
||||
self._outside_offset_vector.x = t.x - b.z
|
||||
end
|
||||
-- Top border (minimum y)
|
||||
if t.y < b.y then
|
||||
self._outside_offset_vector.y = t.y - b.y
|
||||
end
|
||||
-- Bot border (maximum y)
|
||||
if t.y > b.w then
|
||||
self._outside_offset_vector.y = t.y - b.w
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function Scroll._process_scroll_wheel(self, action_id, action)
|
||||
if not self._is_mouse_hover or self.style.WHEEL_SCROLL_SPEED == 0 then
|
||||
return false
|
||||
|
@ -190,7 +190,16 @@ end
|
||||
-- @tparam BaseComponent self @{BaseComponent}
|
||||
-- @treturn string The component name
|
||||
function BaseComponent.get_name(self)
|
||||
return self._component.name
|
||||
return self._component.name .. self:get_uid()
|
||||
end
|
||||
|
||||
|
||||
--- Return parent component name
|
||||
-- @tparam BaseComponent self @{BaseComponent}
|
||||
-- @treturn string|nil The parent component name if exist or bil
|
||||
function BaseComponent.get_parent_name(self)
|
||||
local parent = self:get_parent_component()
|
||||
return parent and parent:get_name()
|
||||
end
|
||||
|
||||
|
||||
@ -313,12 +322,33 @@ function BaseComponent.initialize(self, name, input_priority)
|
||||
name = name,
|
||||
input_priority = input_priority or const.PRIORITY_INPUT,
|
||||
default_input_priority = input_priority or const.PRIORITY_INPUT,
|
||||
is_debug = false,
|
||||
_is_input_priority_changed = true, -- Default true for sort once time after GUI init
|
||||
_uid = BaseComponent.get_uid()
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
--- Print log information if debug mode is enabled (protected)
|
||||
-- @tparam BaseComponent self @{BaseComponent}
|
||||
-- @tparam string message
|
||||
-- @tparam table context
|
||||
function BaseComponent.log_message(self, message, context)
|
||||
if not self._component.is_debug then
|
||||
return
|
||||
end
|
||||
print("[" .. self:get_name() .. "]:", message, helper.table_to_string(context))
|
||||
end
|
||||
|
||||
|
||||
--- Set debug logs for component enabled or disabled
|
||||
-- @tparam BaseComponent self @{BaseComponent}
|
||||
-- @tparam bool is_debug
|
||||
function BaseComponent.set_debug(self, is_debug)
|
||||
self._component.is_debug = is_debug
|
||||
end
|
||||
|
||||
|
||||
--- Return true, if input priority was changed
|
||||
-- @tparam BaseComponent self @{BaseComponent}
|
||||
-- @local
|
||||
|
@ -61,6 +61,8 @@ function DataList.init(self, scroll, grid, create_function)
|
||||
self.scroll.on_scroll:subscribe(self._check_elements, self)
|
||||
|
||||
self.on_scroll_progress_change = Event()
|
||||
|
||||
self:set_data()
|
||||
end
|
||||
|
||||
|
||||
@ -109,6 +111,8 @@ function DataList.add(self, data, index, shift_policy)
|
||||
self._data[index] = data
|
||||
self:_update_data_info()
|
||||
self:_check_elements()
|
||||
|
||||
self:log_message("Add element", { index = index })
|
||||
end
|
||||
|
||||
|
||||
@ -120,6 +124,8 @@ end
|
||||
function DataList.remove(self, index, shift_policy)
|
||||
table.remove(self._data, index)
|
||||
self:_refresh()
|
||||
|
||||
self:log_message("Remove element", { index = index })
|
||||
end
|
||||
|
||||
|
||||
@ -209,6 +215,8 @@ function DataList._add_at(self, index)
|
||||
node = node,
|
||||
component = instance
|
||||
}
|
||||
|
||||
self:log_message("Add element at", { index = index })
|
||||
end
|
||||
|
||||
|
||||
@ -226,6 +234,8 @@ function DataList._remove_at(self, index)
|
||||
self.druid:remove(self._data_visual[index].component)
|
||||
end
|
||||
self._data_visual[index] = nil
|
||||
|
||||
self:log_message("Remove element at", { index = index })
|
||||
end
|
||||
|
||||
|
||||
@ -270,6 +280,8 @@ function DataList._check_elements(self)
|
||||
progress = 0
|
||||
end
|
||||
|
||||
self:log_message("Check elements", { top_index = self.top_index, last_index = self.last_index, progress = progress })
|
||||
|
||||
if self.scroll_progress ~= progress then
|
||||
self.scroll_progress = progress
|
||||
self.on_scroll_progress_change:trigger(self:get_context(), progress)
|
||||
|
@ -222,6 +222,27 @@ function M.is_web()
|
||||
end
|
||||
|
||||
|
||||
--- Transform table to oneline string
|
||||
-- @tparam table t
|
||||
-- @treturn string
|
||||
function M.table_to_string(t)
|
||||
if not t then
|
||||
return const.EMPTY_STRING
|
||||
end
|
||||
|
||||
local result = "{"
|
||||
|
||||
for key, value in pairs(t) do
|
||||
if #result > 1 then
|
||||
result = result .. ","
|
||||
end
|
||||
result = result .. key .. ": " .. value
|
||||
end
|
||||
|
||||
return result .. "}"
|
||||
end
|
||||
|
||||
|
||||
--- Distance from node position to his borders
|
||||
-- @function helper.get_border
|
||||
-- @tparam node node The gui node to check
|
||||
|
@ -199,8 +199,9 @@ function DruidInstance.initialize(self, context, style)
|
||||
self._context = context
|
||||
self._style = style or settings.default_style
|
||||
self._deleted = false
|
||||
self._is_input_processing = false
|
||||
self._is_late_remove_enabled = false
|
||||
self._late_remove = {}
|
||||
self._is_debug = false
|
||||
self.url = msg.url()
|
||||
|
||||
self._input_blacklist = nil
|
||||
@ -238,6 +239,7 @@ function DruidInstance.new(self, component, ...)
|
||||
instance:init(...)
|
||||
end
|
||||
|
||||
self:log_message("Create component", { name = instance:get_name(), parent = instance:get_parent_name() })
|
||||
return instance
|
||||
end
|
||||
|
||||
@ -257,6 +259,8 @@ function DruidInstance.final(self)
|
||||
self._deleted = true
|
||||
|
||||
input_release(self)
|
||||
|
||||
self:log_message("Druid final")
|
||||
end
|
||||
|
||||
|
||||
@ -265,7 +269,7 @@ end
|
||||
-- @tparam DruidInstance self
|
||||
-- @tparam Component component Component instance
|
||||
function DruidInstance.remove(self, component)
|
||||
if self._is_input_processing then
|
||||
if self._is_late_remove_enabled then
|
||||
table.insert(self._late_remove, component)
|
||||
return
|
||||
end
|
||||
@ -301,6 +305,8 @@ function DruidInstance.remove(self, component)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
self:log_message("Remove", { name = component:get_name(), parent = component:get_parent_name() })
|
||||
end
|
||||
|
||||
|
||||
@ -319,10 +325,14 @@ function DruidInstance.update(self, dt)
|
||||
input_init(self)
|
||||
end
|
||||
|
||||
self._is_late_remove_enabled = true
|
||||
local components = self.components_interest[base_component.ON_UPDATE]
|
||||
for i = 1, #components do
|
||||
components[i]:update(dt)
|
||||
end
|
||||
self._is_late_remove_enabled = false
|
||||
|
||||
self:_clear_late_remove()
|
||||
end
|
||||
|
||||
|
||||
@ -332,21 +342,15 @@ end
|
||||
-- @tparam table action Action from on_input
|
||||
-- @treturn bool The boolean value is input was consumed
|
||||
function DruidInstance.on_input(self, action_id, action)
|
||||
self._is_input_processing = true
|
||||
self._is_late_remove_enabled = true
|
||||
|
||||
local components = self.components_interest[base_component.ON_INPUT]
|
||||
check_sort_input_stack(self, components)
|
||||
local is_input_consumed = process_input(self, action_id, action, components)
|
||||
|
||||
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
|
||||
self._is_late_remove_enabled = false
|
||||
|
||||
self:_clear_late_remove()
|
||||
return is_input_consumed
|
||||
end
|
||||
|
||||
@ -397,6 +401,8 @@ function DruidInstance.on_focus_lost(self)
|
||||
for i = 1, #components do
|
||||
components[i]:on_focus_lost()
|
||||
end
|
||||
|
||||
self:log_message("On focus lost")
|
||||
end
|
||||
|
||||
|
||||
@ -409,11 +415,13 @@ function DruidInstance.on_focus_gained(self)
|
||||
for i = 1, #components do
|
||||
components[i]:on_focus_gained()
|
||||
end
|
||||
|
||||
self:log_message("On focus gained")
|
||||
end
|
||||
|
||||
|
||||
--- Druid on language change.
|
||||
-- This one called by global gruid.on_language_change, but can be
|
||||
-- This one called by global druid.on_language_change, but can be
|
||||
-- call manualy to update all translations
|
||||
-- @tparam DruidInstance self
|
||||
-- @local
|
||||
@ -422,6 +430,8 @@ function DruidInstance.on_language_change(self)
|
||||
for i = 1, #components do
|
||||
components[i]:on_language_change()
|
||||
end
|
||||
|
||||
self:log_message("On language change")
|
||||
end
|
||||
|
||||
|
||||
@ -450,7 +460,7 @@ end
|
||||
--- Set blacklist components for input processing.
|
||||
-- If blacklist is not empty and component contains in this list,
|
||||
-- component will be not processed on input step
|
||||
-- @tparam DruidInstance self
|
||||
-- @tparam DruidInstance self @{DruidInstance}
|
||||
-- @tparam[opt=nil] table|Component blacklist_components The array of component to blacklist
|
||||
function DruidInstance.set_blacklist(self, blacklist_components)
|
||||
if blacklist_components and blacklist_components.isInstanceOf then
|
||||
@ -469,6 +479,40 @@ function DruidInstance.set_blacklist(self, blacklist_components)
|
||||
end
|
||||
|
||||
|
||||
--- Set debug mode for current Druid instance. It's enable debug log messages
|
||||
-- @tparam DruidInstance self @{DruidInstance}
|
||||
-- @tparam bool is_debug
|
||||
-- @treturn self @{DruidInstance}
|
||||
function DruidInstance.set_debug(self, is_debug)
|
||||
self._is_debug = is_debug
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
--- Log message, if is_debug mode is enabled
|
||||
-- @tparam DruidInstance self @{DruidInstance}
|
||||
-- @tparam string message
|
||||
-- @tparam[opt] table context
|
||||
function DruidInstance.log_message(self, message, context)
|
||||
if not self._is_debug then
|
||||
return
|
||||
end
|
||||
print("[Druid]:", message, helper.table_to_string(context))
|
||||
end
|
||||
|
||||
|
||||
--- Remove all components on late remove step
|
||||
-- @tparam DruidInstance self @{DruidInstance}
|
||||
-- @local
|
||||
function DruidInstance._clear_late_remove(self)
|
||||
if #self._late_remove > 0 then
|
||||
for i = 1, #self._late_remove do
|
||||
self:remove(self._late_remove[i])
|
||||
end
|
||||
self._late_remove = {}
|
||||
end
|
||||
end
|
||||
|
||||
--- Create button basic component
|
||||
-- @tparam DruidInstance self
|
||||
-- @tparam node node Gui node
|
||||
|
@ -1625,3 +1625,66 @@ embedded_instances {
|
||||
z: 1.0
|
||||
}
|
||||
}
|
||||
embedded_instances {
|
||||
id: "data_list_reinit_data"
|
||||
data: "components {\n"
|
||||
" id: \"screen_factory\"\n"
|
||||
" component: \"/monarch/screen_factory.script\"\n"
|
||||
" position {\n"
|
||||
" x: 0.0\n"
|
||||
" y: 0.0\n"
|
||||
" z: 0.0\n"
|
||||
" }\n"
|
||||
" rotation {\n"
|
||||
" x: 0.0\n"
|
||||
" y: 0.0\n"
|
||||
" z: 0.0\n"
|
||||
" w: 1.0\n"
|
||||
" }\n"
|
||||
" properties {\n"
|
||||
" id: \"screen_id\"\n"
|
||||
" value: \"data_list_reinit_data\"\n"
|
||||
" type: PROPERTY_TYPE_HASH\n"
|
||||
" }\n"
|
||||
" properties {\n"
|
||||
" id: \"popup\"\n"
|
||||
" value: \"true\"\n"
|
||||
" type: PROPERTY_TYPE_BOOLEAN\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
"embedded_components {\n"
|
||||
" id: \"collectionfactory\"\n"
|
||||
" type: \"collectionfactory\"\n"
|
||||
" data: \"prototype: \\\"/example/examples/data_list/reinit_data/reinit_data.collection\\\"\\n"
|
||||
"load_dynamically: false\\n"
|
||||
"\"\n"
|
||||
" position {\n"
|
||||
" x: 0.0\n"
|
||||
" y: 0.0\n"
|
||||
" z: 0.0\n"
|
||||
" }\n"
|
||||
" rotation {\n"
|
||||
" x: 0.0\n"
|
||||
" y: 0.0\n"
|
||||
" z: 0.0\n"
|
||||
" w: 1.0\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
""
|
||||
position {
|
||||
x: 0.0
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
}
|
||||
rotation {
|
||||
x: 0.0
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
scale3 {
|
||||
x: 1.0
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
}
|
||||
}
|
||||
|
@ -155,6 +155,7 @@ local function init_lobby(self)
|
||||
self.lobby_grid:add(get_button(self, "With dynamic grid", "data_list_dynamic_grid", "/data_list/dynamic_grid/dynamic_grid.gui_script"))
|
||||
self.lobby_grid:add(get_button_disabled(self, "Add/remove elements", "data_list_add_remove_nodes"))
|
||||
self.lobby_grid:add(get_button(self, "Navigate over elements", "data_list_navigate", "/data_list/navigate/navigate.gui_script"))
|
||||
self.lobby_grid:add(get_button(self, "Reinit data", "data_list_reinit_data", "/data_list/reinit_data/reinit_data.gui_script"))
|
||||
|
||||
self.lobby_grid:add(get_title(self, "Custom components"))
|
||||
self.lobby_grid:add(get_button(self, "Rich Input", "custom_rich_input", "/custom/rich_input/rich_input.gui_script"))
|
||||
|
@ -0,0 +1,37 @@
|
||||
name: "data_list_reinit"
|
||||
scale_along_z: 0
|
||||
embedded_instances {
|
||||
id: "go"
|
||||
data: "components {\n"
|
||||
" id: \"data_list_reinit\"\n"
|
||||
" component: \"/example/examples/data_list/reinit_data/reinit_data.gui\"\n"
|
||||
" position {\n"
|
||||
" x: 0.0\n"
|
||||
" y: 0.0\n"
|
||||
" z: 0.0\n"
|
||||
" }\n"
|
||||
" rotation {\n"
|
||||
" x: 0.0\n"
|
||||
" y: 0.0\n"
|
||||
" z: 0.0\n"
|
||||
" w: 1.0\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
""
|
||||
position {
|
||||
x: 0.0
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
}
|
||||
rotation {
|
||||
x: 0.0
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
scale3 {
|
||||
x: 1.0
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
}
|
||||
}
|
751
example/examples/data_list/reinit_data/reinit_data.gui
Normal file
751
example/examples/data_list/reinit_data/reinit_data.gui
Normal file
@ -0,0 +1,751 @@
|
||||
script: "/example/examples/data_list/reinit_data/reinit_data.gui_script"
|
||||
fonts {
|
||||
name: "game"
|
||||
font: "/example/assets/fonts/game.font"
|
||||
}
|
||||
textures {
|
||||
name: "kenney"
|
||||
texture: "/example/assets/images/kenney.atlas"
|
||||
}
|
||||
background_color {
|
||||
x: 0.0
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
w: 0.0
|
||||
}
|
||||
nodes {
|
||||
position {
|
||||
x: 300.0
|
||||
y: 415.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: 600.0
|
||||
y: 830.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: "root"
|
||||
xanchor: XANCHOR_NONE
|
||||
yanchor: YANCHOR_NONE
|
||||
pivot: PIVOT_CENTER
|
||||
adjust_mode: ADJUST_MODE_FIT
|
||||
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
|
||||
custom_type: 0
|
||||
}
|
||||
nodes {
|
||||
position {
|
||||
x: 0.0
|
||||
y: 370.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: 700.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_TEXT
|
||||
blend_mode: BLEND_MODE_ALPHA
|
||||
text: "Press button to set data or clear data"
|
||||
font: "game"
|
||||
id: "text_hint_horizontal"
|
||||
xanchor: XANCHOR_NONE
|
||||
yanchor: YANCHOR_NONE
|
||||
pivot: PIVOT_CENTER
|
||||
outline {
|
||||
x: 0.0
|
||||
y: 0.0
|
||||
z: 0.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: "root"
|
||||
layer: ""
|
||||
inherit_alpha: true
|
||||
alpha: 1.0
|
||||
outline_alpha: 1.0
|
||||
shadow_alpha: 0.0
|
||||
template_node_child: false
|
||||
text_leading: 1.0
|
||||
text_tracking: 0.0
|
||||
custom_type: 0
|
||||
}
|
||||
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: 300.0
|
||||
y: 400.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
color {
|
||||
x: 0.8
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
w: 1.0
|
||||
}
|
||||
type: TYPE_BOX
|
||||
blend_mode: BLEND_MODE_ALPHA
|
||||
texture: ""
|
||||
id: "data_list_view"
|
||||
xanchor: XANCHOR_NONE
|
||||
yanchor: YANCHOR_NONE
|
||||
pivot: PIVOT_N
|
||||
adjust_mode: ADJUST_MODE_FIT
|
||||
parent: "root"
|
||||
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
|
||||
custom_type: 0
|
||||
}
|
||||
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: 300.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: "data_list_content"
|
||||
xanchor: XANCHOR_NONE
|
||||
yanchor: YANCHOR_NONE
|
||||
pivot: PIVOT_N
|
||||
adjust_mode: ADJUST_MODE_FIT
|
||||
parent: "data_list_view"
|
||||
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
|
||||
custom_type: 0
|
||||
}
|
||||
nodes {
|
||||
position {
|
||||
x: -110.0
|
||||
y: 270.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_fill"
|
||||
parent: "root"
|
||||
layer: ""
|
||||
inherit_alpha: true
|
||||
alpha: 1.0
|
||||
template: "/example/templates/button.gui"
|
||||
template_node_child: false
|
||||
custom_type: 0
|
||||
}
|
||||
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: 90.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_fill/button"
|
||||
xanchor: XANCHOR_NONE
|
||||
yanchor: YANCHOR_NONE
|
||||
pivot: PIVOT_CENTER
|
||||
adjust_mode: ADJUST_MODE_FIT
|
||||
parent: "button_fill"
|
||||
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
|
||||
overridden_fields: 4
|
||||
template_node_child: true
|
||||
size_mode: SIZE_MODE_MANUAL
|
||||
custom_type: 0
|
||||
}
|
||||
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: 100.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: "Fill"
|
||||
font: "game"
|
||||
id: "button_fill/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_fill/button"
|
||||
layer: "text"
|
||||
inherit_alpha: true
|
||||
alpha: 1.0
|
||||
outline_alpha: 0.0
|
||||
shadow_alpha: 0.78
|
||||
overridden_fields: 4
|
||||
overridden_fields: 8
|
||||
overridden_fields: 36
|
||||
template_node_child: true
|
||||
text_leading: 0.8
|
||||
text_tracking: 0.0
|
||||
custom_type: 0
|
||||
}
|
||||
nodes {
|
||||
position {
|
||||
x: 110.0
|
||||
y: 270.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: "root"
|
||||
layer: ""
|
||||
inherit_alpha: true
|
||||
alpha: 1.0
|
||||
template: "/example/templates/button.gui"
|
||||
template_node_child: false
|
||||
custom_type: 0
|
||||
}
|
||||
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: 90.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
|
||||
overridden_fields: 4
|
||||
template_node_child: true
|
||||
size_mode: SIZE_MODE_MANUAL
|
||||
custom_type: 0
|
||||
}
|
||||
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: 100.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: "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: 4
|
||||
overridden_fields: 8
|
||||
overridden_fields: 36
|
||||
template_node_child: true
|
||||
text_leading: 0.8
|
||||
text_tracking: 0.0
|
||||
custom_type: 0
|
||||
}
|
||||
nodes {
|
||||
position {
|
||||
x: 385.0
|
||||
y: 139.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_prefab"
|
||||
parent: "root"
|
||||
layer: ""
|
||||
inherit_alpha: true
|
||||
alpha: 1.0
|
||||
template: "/example/templates/button.gui"
|
||||
template_node_child: false
|
||||
custom_type: 0
|
||||
}
|
||||
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: 140.0
|
||||
y: 140.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_prefab/button"
|
||||
xanchor: XANCHOR_NONE
|
||||
yanchor: YANCHOR_NONE
|
||||
pivot: PIVOT_CENTER
|
||||
adjust_mode: ADJUST_MODE_FIT
|
||||
parent: "button_prefab"
|
||||
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
|
||||
overridden_fields: 4
|
||||
template_node_child: true
|
||||
size_mode: SIZE_MODE_MANUAL
|
||||
custom_type: 0
|
||||
}
|
||||
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: 150.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: "Element"
|
||||
font: "game"
|
||||
id: "button_prefab/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: true
|
||||
parent: "button_prefab/button"
|
||||
layer: "text"
|
||||
inherit_alpha: true
|
||||
alpha: 1.0
|
||||
outline_alpha: 0.0
|
||||
shadow_alpha: 0.78
|
||||
overridden_fields: 4
|
||||
overridden_fields: 8
|
||||
overridden_fields: 18
|
||||
overridden_fields: 36
|
||||
template_node_child: true
|
||||
text_leading: 0.8
|
||||
text_tracking: 0.0
|
||||
custom_type: 0
|
||||
}
|
||||
layers {
|
||||
name: "image"
|
||||
}
|
||||
layers {
|
||||
name: "text"
|
||||
}
|
||||
material: "/builtins/materials/gui.material"
|
||||
adjust_reference: ADJUST_REFERENCE_PARENT
|
||||
max_nodes: 512
|
@ -0,0 +1,65 @@
|
||||
local druid = require("druid.druid")
|
||||
|
||||
|
||||
local function create_element(self, data)
|
||||
local nodes = gui.clone_tree(self.prefab)
|
||||
local root = nodes["button_prefab/button"]
|
||||
gui.set_text(nodes["button_prefab/text"], "Element " .. data)
|
||||
gui.set_enabled(root, true)
|
||||
|
||||
local button = self.druid:new_button(root, function()end)
|
||||
button:set_click_zone(self.scroll.view_node)
|
||||
return root, button
|
||||
end
|
||||
|
||||
|
||||
local function on_fill(self)
|
||||
self.data_list:set_data(self.data)
|
||||
end
|
||||
|
||||
|
||||
local function on_clear(self)
|
||||
self.data_list:set_data()
|
||||
end
|
||||
|
||||
|
||||
function init(self)
|
||||
self.druid = druid.new(self)
|
||||
|
||||
self.prefab = gui.get_node("button_prefab/button")
|
||||
gui.set_enabled(self.prefab, false)
|
||||
|
||||
self.scroll = self.druid:new_scroll("data_list_view", "data_list_content")
|
||||
self.scroll:set_horizontal_scroll(false)
|
||||
self.grid = self.druid:new_static_grid("data_list_content", self.prefab, 2)
|
||||
self.data_list = self.druid:new_data_list(self.scroll, self.grid, create_element)
|
||||
self.data_list:set_debug(true)
|
||||
|
||||
self.data = {}
|
||||
for i = 1, 30 do
|
||||
table.insert(self.data, i)
|
||||
end
|
||||
|
||||
self.druid:new_button("button_fill/button", on_fill)
|
||||
self.druid:new_button("button_clear/button", on_clear)
|
||||
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
|
Loading…
x
Reference in New Issue
Block a user