From 3c32a5f75eb404c73f50032d23d6450d76bdfb0b Mon Sep 17 00:00:00 2001 From: Insality Date: Wed, 23 Sep 2020 01:29:16 +0300 Subject: [PATCH] Add set_input_state for component to enable/disable input --- druid/component.lua | 16 ++++++++++++++++ druid/system/druid_instance.lua | 7 +++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/druid/component.lua b/druid/component.lua index 1dc359c..99fd222 100644 --- a/druid/component.lua +++ b/druid/component.lua @@ -150,6 +150,22 @@ function Component:get_name() 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 + + function Component:get_parent_component() local context = self:get_context() diff --git a/druid/system/druid_instance.lua b/druid/system/druid_instance.lua index 102cff9..d3b8452 100644 --- a/druid/system/druid_instance.lua +++ b/druid/system/druid_instance.lua @@ -100,7 +100,8 @@ local function process_input(action_id, action, components, is_input_consumed) for i = #components, 1, -1 do local component = components[i] -- 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 is_input_consumed = component:on_input(action_id, action) else @@ -113,7 +114,9 @@ local function process_input(action_id, action, components, is_input_consumed) for i = #components, 1, -1 do 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 is_input_consumed = component:on_input(action_id, action) else