Update set/reset input priority functions. Remove increase_input_priority function

This commit is contained in:
Insality
2021-04-01 20:59:47 +03:00
parent 44842f78dc
commit 14dccea799
6 changed files with 59 additions and 35 deletions

View File

@@ -92,6 +92,7 @@ local function sort_input_stack(self)
if a:get_input_priority() ~= b:get_input_priority() then
return a:get_input_priority() < b:get_input_priority()
end
return a:get_uid() < b:get_uid()
end)
end
@@ -111,7 +112,6 @@ local function create(self, instance_class)
if base_component.UI_INPUT[interest] then
input_init(self)
sort_input_stack(self)
end
end
@@ -119,6 +119,27 @@ local function create(self, instance_class)
end
local function check_sort_input_stack(self, components)
if not components or #components == 0 then
return
end
local is_need_sort_input_stack = false
for i = #components, 1, -1 do
local component = components[i]
if component:_is_input_priority_changed() then
is_need_sort_input_stack = true
end
component:_reset_input_priority_changed()
end
if is_need_sort_input_stack then
sort_input_stack(self)
end
end
local function process_input(action_id, action, components, is_input_consumed)
if #components == 0 then
return is_input_consumed
@@ -126,24 +147,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
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
if component.on_input_interrupt then
component:on_input_interrupt()
end
end
end
end
for i = #components, 1, -1 do
local component = components[i]
-- Process usual input priority next
local meta = component._meta
if meta.input_enabled and not meta.increased_input_priority then
if meta.input_enabled then
if not is_input_consumed then
is_input_consumed = component:on_input(action_id, action)
else
@@ -273,9 +278,9 @@ function DruidInstance.on_input(self, action_id, action)
self._is_input_processing = true
local is_input_consumed = false
is_input_consumed = process_input(action_id, action,
self.components[base_component.ON_INPUT], is_input_consumed)
local components = self.components[base_component.ON_INPUT]
check_sort_input_stack(self, components)
is_input_consumed = process_input(action_id, action, components, is_input_consumed)
self._is_input_processing = false