#108 Move component interests const from const.lua to component.lua

This commit is contained in:
Insality
2020-11-07 17:28:07 +03:00
parent 86c7170053
commit da085238cc
21 changed files with 86 additions and 77 deletions

View File

@@ -28,11 +28,11 @@
-- @see Drag
-- @see Hover
local const = require("druid.const")
local helper = require("druid.helper")
local druid_input = require("druid.helper.druid_input")
local settings = require("druid.system.settings")
local class = require("druid.system.middleclass")
local settings = require("druid.system.settings")
local base_component = require("druid.component")
local druid_input = require("druid.helper.druid_input")
local back_handler = require("druid.base.back_handler")
local blocker = require("druid.base.blocker")
@@ -87,14 +87,14 @@ local function create(self, instance_class)
local instance = instance_class()
instance:setup_component(self, self._context, self._style)
table.insert(self.components[const.ALL], instance)
table.insert(self.components[base_component.ALL], instance)
local register_to = instance:__get_interests()
for i = 1, #register_to do
local interest = register_to[i]
table.insert(self.components[interest], instance)
if const.UI_INPUT[interest] then
if base_component.UI_INPUT[interest] then
input_init(self)
end
end
@@ -155,8 +155,8 @@ function DruidInstance.initialize(self, context, style)
self.url = msg.url()
self.components = {}
for i = 1, #const.ALL_INTERESTS do
self.components[const.ALL_INTERESTS[i]] = {}
for i = 1, #base_component.ALL_INTERESTS do
self.components[base_component.ALL_INTERESTS[i]] = {}
end
end
@@ -180,7 +180,7 @@ end
-- on all druid components
-- @tparam DruidInstance self
function DruidInstance.final(self)
local components = self.components[const.ALL]
local components = self.components[base_component.ALL]
for i = #components, 1, -1 do
if components[i].on_remove then
@@ -215,7 +215,7 @@ function DruidInstance.remove(self, component)
end
component._meta.children = {}
local all_components = self.components[const.ALL]
local all_components = self.components[base_component.ALL]
for i = #all_components, 1, -1 do
if all_components[i] == component then
if component.on_remove then
@@ -242,7 +242,7 @@ end
-- @tparam DruidInstance self
-- @tparam number dt Delta time
function DruidInstance.update(self, dt)
local components = self.components[const.ON_UPDATE]
local components = self.components[base_component.ON_UPDATE]
for i = 1, #components do
components[i]:update(dt)
end
@@ -259,10 +259,10 @@ function DruidInstance.on_input(self, action_id, action)
local is_input_consumed = false
is_input_consumed = process_input(action_id, action,
self.components[const.ON_INPUT_HIGH], is_input_consumed)
self.components[base_component.ON_INPUT_HIGH], is_input_consumed)
is_input_consumed = process_input(action_id, action,
self.components[const.ON_INPUT], is_input_consumed)
self.components[base_component.ON_INPUT], is_input_consumed)
self._is_input_processing = false
@@ -283,7 +283,7 @@ end
-- @tparam table message Message from on_message
-- @tparam hash sender Sender from on_message
function DruidInstance.on_message(self, message_id, message, sender)
local specific_ui_message = const.SPECIFIC_UI_MESSAGES[message_id]
local specific_ui_message = base_component.SPECIFIC_UI_MESSAGES[message_id]
if specific_ui_message then
local components = self.components[message_id]
@@ -294,7 +294,7 @@ function DruidInstance.on_message(self, message_id, message, sender)
end
end
else
local components = self.components[const.ON_MESSAGE]
local components = self.components[base_component.ON_MESSAGE]
for i = 1, #components do
components[i]:on_message(message_id, message, sender)
end
@@ -306,7 +306,7 @@ end
-- This one called by on_window_callback by global window listener
-- @tparam DruidInstance self
function DruidInstance.on_focus_lost(self)
local components = self.components[const.ON_FOCUS_LOST]
local components = self.components[base_component.ON_FOCUS_LOST]
for i = 1, #components do
components[i]:on_focus_lost()
end
@@ -317,7 +317,7 @@ end
-- This one called by on_window_callback by global window listener
-- @tparam DruidInstance self
function DruidInstance.on_focus_gained(self)
local components = self.components[const.ON_FOCUS_GAINED]
local components = self.components[base_component.ON_FOCUS_GAINED]
for i = 1, #components do
components[i]:on_focus_gained()
end
@@ -328,7 +328,7 @@ end
-- Called on update gui layout
-- @tparam DruidInstance self
function DruidInstance.on_layout_change(self)
local components = self.components[const.ON_LAYOUT_CHANGE]
local components = self.components[base_component.ON_LAYOUT_CHANGE]
for i = 1, #components do
components[i]:on_layout_change()
end
@@ -340,7 +340,7 @@ end
-- call manualy to update all translations
-- @function druid.on_language_change
function DruidInstance.on_language_change(self)
local components = self.components[const.ON_LANGUAGE_CHANGE]
local components = self.components[base_component.ON_LANGUAGE_CHANGE]
for i = 1, #components do
components[i]:on_language_change()
end