mirror of
https://github.com/Insality/druid
synced 2025-06-27 10:27:48 +02:00
#53 Add init all interests arrays, fix final on empty druid instance
This commit is contained in:
parent
0cc848b53f
commit
94e882577b
@ -162,9 +162,11 @@ end
|
||||
-- by `Component.static.create`
|
||||
-- @function component:initialize
|
||||
-- @tparam string name Component name
|
||||
-- @tparam table interest List of component's interest
|
||||
-- @tparam[opt={}] table interest List of component's interest
|
||||
-- @local
|
||||
function Component.initialize(self, name, interest)
|
||||
interest = interest or {}
|
||||
|
||||
self._component = {
|
||||
name = name,
|
||||
interest = interest
|
||||
@ -176,7 +178,7 @@ end
|
||||
-- druid component.
|
||||
-- @function Component.create
|
||||
-- @tparam string name Component name
|
||||
-- @tparam table interest List of component's interest
|
||||
-- @tparam[opt={}] table interest List of component's interest
|
||||
function Component.static.create(name, interest)
|
||||
-- Yea, inheritance here
|
||||
local new_class = class(name, Component)
|
||||
|
@ -37,6 +37,19 @@ M.ON_LAYOUT_CHANGE = hash("on_layout_change")
|
||||
M.ON_LANGUAGE_CHANGE = hash("on_language_change")
|
||||
|
||||
|
||||
M.ALL_INTERESTS = {
|
||||
M.ALL,
|
||||
M.ON_INPUT,
|
||||
M.ON_UPDATE,
|
||||
M.ON_MESSAGE,
|
||||
M.ON_FOCUS_LOST,
|
||||
M.ON_INPUT_HIGH,
|
||||
M.ON_FOCUS_GAINED,
|
||||
M.ON_LAYOUT_CHANGE,
|
||||
M.ON_LANGUAGE_CHANGE,
|
||||
}
|
||||
|
||||
|
||||
M.PIVOTS = {
|
||||
[gui.PIVOT_CENTER] = vmath.vector3(0),
|
||||
[gui.PIVOT_N] = vmath.vector3(0, 0.5, 0),
|
||||
|
@ -63,30 +63,24 @@ local function create(self, instance_class)
|
||||
local instance = instance_class()
|
||||
instance:setup_component(self._context, self._style)
|
||||
|
||||
self.components[const.ALL] = self.components[const.ALL] or {}
|
||||
table.insert(self.components[const.ALL], instance)
|
||||
|
||||
local register_to = instance:get_interests()
|
||||
if register_to then
|
||||
for i = 1, #register_to do
|
||||
local interest = register_to[i]
|
||||
if not self.components[interest] then
|
||||
self.components[interest] = {}
|
||||
end
|
||||
table.insert(self.components[interest], instance)
|
||||
|
||||
if const.UI_INPUT[interest] then
|
||||
input_init(self)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return instance
|
||||
end
|
||||
|
||||
|
||||
local function process_input(action_id, action, components, is_input_consumed)
|
||||
if not components then
|
||||
if #components == 0 then
|
||||
return is_input_consumed
|
||||
end
|
||||
|
||||
@ -130,7 +124,11 @@ function Druid.initialize(self, context, style)
|
||||
self._style = style or settings.default_style
|
||||
self._deleted = false
|
||||
self.url = msg.url()
|
||||
|
||||
self.components = {}
|
||||
for i = 1, #const.ALL_INTERESTS do
|
||||
self.components[const.ALL_INTERESTS[i]] = {}
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@ -182,7 +180,6 @@ function Druid.remove(self, component)
|
||||
end
|
||||
|
||||
local interests = component:get_interests()
|
||||
if interests then
|
||||
for i = 1, #interests do
|
||||
local interest = interests[i]
|
||||
local components = self.components[interest]
|
||||
@ -193,7 +190,6 @@ function Druid.remove(self, component)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--- Druid update function
|
||||
@ -201,12 +197,10 @@ end
|
||||
-- @tparam number dt Delta time
|
||||
function Druid.update(self, dt)
|
||||
local components = self.components[const.ON_UPDATE]
|
||||
if components then
|
||||
for i = 1, #components do
|
||||
components[i]:update(dt)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--- Druid on_input function
|
||||
@ -233,6 +227,7 @@ end
|
||||
-- @tparam hash sender Sender from on_message
|
||||
function Druid.on_message(self, message_id, message, sender)
|
||||
local specific_ui_message = const.SPECIFIC_UI_MESSAGES[message_id]
|
||||
|
||||
if specific_ui_message then
|
||||
local components = self.components[message_id]
|
||||
if components then
|
||||
@ -243,13 +238,11 @@ function Druid.on_message(self, message_id, message, sender)
|
||||
end
|
||||
else
|
||||
local components = self.components[const.ON_MESSAGE]
|
||||
if components then
|
||||
for i = 1, #components do
|
||||
components[i]:on_message(message_id, message, sender)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--- Druid on focus lost interest function.
|
||||
@ -257,12 +250,10 @@ end
|
||||
-- @function druid:on_focus_lost
|
||||
function Druid.on_focus_lost(self)
|
||||
local components = self.components[const.ON_FOCUS_LOST]
|
||||
if components then
|
||||
for i = 1, #components do
|
||||
components[i]:on_focus_lost()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--- Druid on focus gained interest function.
|
||||
@ -270,12 +261,10 @@ end
|
||||
-- @function druid:on_focus_gained
|
||||
function Druid.on_focus_gained(self)
|
||||
local components = self.components[const.ON_FOCUS_GAINED]
|
||||
if components then
|
||||
for i = 1, #components do
|
||||
components[i]:on_focus_gained()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--- Druid on layout change function.
|
||||
@ -283,12 +272,10 @@ end
|
||||
-- @function druid:on_layout_change
|
||||
function Druid.on_layout_change(self)
|
||||
local components = self.components[const.ON_LAYOUT_CHANGE]
|
||||
if components then
|
||||
for i = 1, #components do
|
||||
components[i]:on_layout_change()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--- Druid on language change.
|
||||
@ -297,12 +284,10 @@ end
|
||||
-- @function druid.on_language_change
|
||||
function Druid.on_language_change(self)
|
||||
local components = self.components[const.ON_LANGUAGE_CHANGE]
|
||||
if components then
|
||||
for i = 1, #components do
|
||||
components[i]:on_language_change()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--- Create button basic component
|
||||
|
Loading…
x
Reference in New Issue
Block a user