Merge branch 'develop' into feature/77-grid-update

# Conflicts:
#	docs_md/changelog.md
#	druid/component.lua
This commit is contained in:
Insality 2020-09-23 23:15:37 +03:00
commit 4e476d7e67
3 changed files with 130 additions and 70 deletions

View File

@ -107,6 +107,8 @@ Druid 0.5.0:
- This grid can not have spaces between elements. You will get the error, if spawn element far away from other elements - This grid can not have spaces between elements. You will get the error, if spawn element far away from other elements
- The grid can spawn elements only in row or in collumn - The grid can spawn elements only in row or in collumn
- **#37** Add _on_layout_change_ support. Druid will keep and restore GUI component data between changing game layout. Override function _on_layout_change_ in your custom components to do stuff you need. - **#37** Add _on_layout_change_ support. Druid will keep and restore GUI component data between changing game layout. Override function _on_layout_change_ in your custom components to do stuff you need.
- **#85** Move several components from `base` folder to `extended`. In future, to use them, you have to register them manually. This is need for decrease build size by excluding unused components
- Add _scroll:set_vertical_scroll_ and _scroll:set_horizontal_scroll_ for disable scroll sides
- **Fix #61:** Button component: fix button animation node creation - **Fix #61:** Button component: fix button animation node creation
- **Fix #64:** Hover component: wrong mouse_hover default state - **Fix #64:** Hover component: wrong mouse_hover default state
- **Fix #71:** Blocker: blocker now correct block mouse hover event - **Fix #71:** Blocker: blocker now correct block mouse hover event
@ -115,8 +117,7 @@ Druid 0.5.0:
- **Fix #76:** Add params for lang text localization component - **Fix #76:** Add params for lang text localization component
- **Fix #79:** Fix druid:remove inside on_input callback - **Fix #79:** Fix druid:remove inside on_input callback
- **Fix #80:** Fix hover set_enable typo function call - **Fix #80:** Fix hover set_enable typo function call
- _druid:create_ deprecated. Use _druid:new_ instead (for custom components) - **Fix #88:** Add _component:set_input_enabled_ function to enable/disable input for druid component
- Add _scroll:set_vertical_scroll_ and _scroll:set_horizontal_scroll_ for disable scroll sides - Add `component.tempalte.lua` as template for Druid custom component
- **#85** Move several components from `base` folder to `extended`. In future, to use them, you have to register them manually. This is need for decrease build size by excluding unused components >>>>>>> develop
- Add `component.template.lua` as template for Druid custom component

View File

@ -14,7 +14,7 @@ local Component = class("druid.component")
-- their style changing and store all style params -- their style changing and store all style params
-- @function component:set_style -- @function component:set_style
-- @tparam table style Druid style module -- @tparam table style Druid style module
function Component.set_style(self, druid_style) function Component:set_style(druid_style)
self._meta.style = druid_style or const.EMPTY_TABLE self._meta.style = druid_style or const.EMPTY_TABLE
local component_style = self._meta.style[self._component.name] or const.EMPTY_TABLE local component_style = self._meta.style[self._component.name] or const.EMPTY_TABLE
@ -24,34 +24,18 @@ function Component.set_style(self, druid_style)
end end
--- Get current component template name
-- @function component:get_template
-- @treturn string Component template name
function Component.get_template(self)
return self._meta.template
end
--- Set current component template name --- Set current component template name
-- @function component:set_template -- @function component:set_template
-- @tparam string template Component template name -- @tparam string template Component template name
function Component.set_template(self, template) function Component:set_template(template)
self._meta.template = template self._meta.template = template
end end
--- Get current component nodes
-- @function component:get_component_nodes
-- @treturn table Component nodes table
function Component.get_component_nodes(self)
return self._meta.nodes
end
--- Set current component nodes --- Set current component nodes
-- @function component:set_nodes -- @function component:set_nodes
-- @tparam table nodes Component nodes table -- @tparam table nodes Component nodes table
function Component.set_nodes(self, nodes) function Component:set_nodes(nodes)
self._meta.nodes = nodes self._meta.nodes = nodes
end end
@ -59,37 +43,21 @@ end
--- Get current component context --- Get current component context
-- @function component:get_context -- @function component:get_context
-- @treturn table Component context -- @treturn table Component context
function Component.get_context(self, context) function Component:get_context(context)
return self._meta.context return self._meta.context
end end
--- Set current component context
-- @function component:set_context
-- @tparam table context Druid context. Usually it is self of script
function Component.set_context(self, context)
self._meta.context = context
end
--- Get current component interests
-- @function component:get_interests
-- @treturn table List of component interests
function Component.get_interests(self)
return self._component.interest
end
--- Increase input priority in current input stack --- Increase input priority in current input stack
-- @function component:increase_input_priority -- @function component:increase_input_priority
function Component.increase_input_priority(self) function Component:increase_input_priority()
self._meta.increased_input_priority = true self._meta.increased_input_priority = true
end end
--- Reset input priority in current input stack --- Reset input priority in current input stack
-- @function component:reset_input_priority -- @function component:reset_input_priority
function Component.reset_input_priority(self) function Component:reset_input_priority()
self._meta.increased_input_priority = false self._meta.increased_input_priority = false
end end
@ -101,9 +69,9 @@ end
-- @function component:get_node -- @function component:get_node
-- @tparam string|node node_or_name Node name or node itself -- @tparam string|node node_or_name Node name or node itself
-- @treturn node Gui node -- @treturn node Gui node
function Component.get_node(self, node_or_name) function Component:get_node(node_or_name)
local template_name = self:get_template() or const.EMPTY_STRING local template_name = self:__get_template() or const.EMPTY_STRING
local nodes = self:get_component_nodes() local nodes = self:__get_nodes()
if template_name ~= const.EMPTY_STRING then if template_name ~= const.EMPTY_STRING then
template_name = template_name .. "/" template_name = template_name .. "/"
@ -128,47 +96,76 @@ end
-- Use it to create component inside of other components. -- Use it to create component inside of other components.
-- @function component:get_druid -- @function component:get_druid
-- @treturn Druid Druid instance with component context -- @treturn Druid Druid instance with component context
function Component.get_druid(self) function Component:get_druid()
local context = { _context = self } local context = { _context = self }
return setmetatable(context, { __index = self._meta.druid }) return setmetatable(context, { __index = self._meta.druid })
end end
--- Return true, if current component is child of another component
-- @function component:is_child_of
-- @treturn bool True, if current component is child of another
function Component.is_child_of(self, component)
return self:get_context() == component
end
--- Return component name --- Return component name
-- @function component:get_name -- @function component:get_name
-- @treturn string The component name -- @treturn string The component name
function Component.get_name(self) function Component:get_name()
return self._component.name return self._component.name
end end
--- Set component input state. By default it enabled
-- You can disable any input of component by this function
-- @function component:set_input_enabled
-- @tparam bool state The component input state
-- @treturn Component Component itself
function Component:set_input_enabled(state)
self._meta.input_enabled = state
for index = 1, #self._meta.children do
self._meta.children[index]:set_input_enabled(state)
end
return self
end
--- Return the parent for current component
-- @function component:get_parent_component
-- @treturn Component|nil The druid component instance or nil
function Component:get_parent_component()
local context = self:get_context()
if context.isInstanceOf and context:isInstanceOf(Component) then
return context
end
return nil
end
--- Setup component context and his style table --- Setup component context and his style table
-- @function component:setup_component -- @function component:setup_component
-- @tparam druid_instance table The parent druid instance -- @tparam druid_instance table The parent druid instance
-- @tparam context table Druid context. Usually it is self of script -- @tparam context table Druid context. Usually it is self of script
-- @tparam style table Druid style module -- @tparam style table Druid style module
-- @treturn Component Component itself -- @treturn component Component itself
function Component.setup_component(self, druid_instance, context, style) function Component:setup_component(druid_instance, context, style)
self._meta = { self._meta = {
template = nil, template = nil,
context = nil, context = nil,
nodes = nil, nodes = nil,
style = nil, style = nil,
druid = druid_instance, druid = druid_instance,
increased_input_priority = false increased_input_priority = false,
input_enabled = true,
children = {}
} }
self:set_context(context) self:__set_context(context)
self:set_style(style) self:set_style(style)
local parent = self:get_parent_component()
if parent then
parent:__add_children(self)
end
return self return self
end end
@ -179,7 +176,7 @@ end
-- @tparam string name Component name -- @tparam string name Component name
-- @tparam[opt={}] table interest List of component's interest -- @tparam[opt={}] table interest List of component's interest
-- @local -- @local
function Component.initialize(self, name, interest) function Component:initialize(name, interest)
interest = interest or {} interest = interest or {}
self._component = { self._component = {
@ -189,6 +186,63 @@ function Component.initialize(self, name, interest)
end end
function Component:__tostring()
return self._component.name
end
--- Set current component context
-- @function component:__set_context
-- @tparam table context Druid context. Usually it is self of script
function Component:__set_context(context)
self._meta.context = context
end
--- Get current component interests
-- @function component:__get_interests
-- @treturn table List of component interests
function Component:__get_interests()
return self._component.interest
end
--- Get current component template name
-- @function component:__get_template
-- @treturn string Component template name
function Component:__get_template()
return self._meta.template
end
--- Get current component nodes
-- @function component:__get_nodes
-- @treturn table Component nodes table
function Component:__get_nodes()
return self._meta.nodes
end
--- Add child to component children list
-- @function component:__add_children
-- @tparam component children The druid component instance
function Component:__add_children(children)
table.insert(self._meta.children, children)
end
--- Remove child from component children list
-- @function component:__remove_children
-- @tparam component children The druid component instance
function Component:__remove_children(children)
for i = #self._meta.children, 1, -1 do
if self._meta.children[i] == children then
table.remove(self._meta.children, i)
end
end
end
--- Create new component. It will inheritance from basic --- Create new component. It will inheritance from basic
-- druid component. -- druid component.
-- @function Component.create -- @function Component.create

View File

@ -80,7 +80,7 @@ local function create(self, instance_class)
table.insert(self.components[const.ALL], instance) table.insert(self.components[const.ALL], instance)
local register_to = instance:get_interests() local register_to = instance:__get_interests()
for i = 1, #register_to do for i = 1, #register_to do
local interest = register_to[i] local interest = register_to[i]
table.insert(self.components[interest], instance) table.insert(self.components[interest], instance)
@ -102,7 +102,8 @@ local function process_input(action_id, action, components, is_input_consumed)
for i = #components, 1, -1 do for i = #components, 1, -1 do
local component = components[i] local component = components[i]
-- Process increased input priority first -- Process increased input priority first
if component._meta.increased_input_priority then local meta = component._meta
if meta.input_enabled and meta.increased_input_priority then
if not is_input_consumed then if not is_input_consumed then
is_input_consumed = component:on_input(action_id, action) is_input_consumed = component:on_input(action_id, action)
else else
@ -115,7 +116,9 @@ local function process_input(action_id, action, components, is_input_consumed)
for i = #components, 1, -1 do for i = #components, 1, -1 do
local component = components[i] local component = components[i]
if not component._meta.increased_input_priority then -- Process usual input priority next
local meta = component._meta
if meta.input_enabled and not meta.increased_input_priority then
if not is_input_consumed then if not is_input_consumed then
is_input_consumed = component:on_input(action_id, action) is_input_consumed = component:on_input(action_id, action)
else else
@ -192,16 +195,18 @@ function Druid.remove(self, component)
return return
end end
local all_components = self.components[const.ALL]
-- Recursive remove all children of component -- Recursive remove all children of component
for i = #all_components, 1, -1 do local children = component._meta.children
local inst = all_components[i] for i = 1, #children do
if inst:is_child_of(component) then self:remove(children[i])
self:remove(inst) local parent = children[i]:get_parent_component()
if parent then
parent:__remove_children(children[i])
end end
end end
component._meta.children = {}
local all_components = self.components[const.ALL]
for i = #all_components, 1, -1 do for i = #all_components, 1, -1 do
if all_components[i] == component then if all_components[i] == component then
if component.on_remove then if component.on_remove then
@ -211,7 +216,7 @@ function Druid.remove(self, component)
end end
end end
local interests = component:get_interests() local interests = component:__get_interests()
for i = 1, #interests do for i = 1, #interests do
local interest = interests[i] local interest = interests[i]
local components = self.components[interest] local components = self.components[interest]