feat: add depth sorting

This commit is contained in:
Kazhnuz 2021-08-22 12:39:44 +02:00
parent c586fb733d
commit c658f68e14
2 changed files with 13 additions and 1 deletions

View file

@ -20,7 +20,7 @@ end
function GuiElement:register() function GuiElement:register()
local gui = self:getGui() local gui = self:getGui()
gui:addElement(self.name, self) self.creationId = gui:addElement(self.name, self)
end end
function GuiElement:destroy() function GuiElement:destroy()

View file

@ -3,10 +3,13 @@ local ElementList = Object:extend()
function ElementList:initElements() function ElementList:initElements()
self.elements = {} self.elements = {}
self.focusedElem = nil self.focusedElem = nil
self.nbrElement = 0
end end
function ElementList:addElement(name, element) function ElementList:addElement(name, element)
self.nbrElement = self.nbrElement + 1
self.elements[name] = element self.elements[name] = element
return self.nbrElement
end end
function ElementList:deleteElement(name) function ElementList:deleteElement(name)
@ -22,6 +25,15 @@ function ElementList:getVisibleElement(topLayer)
end end
end end
end end
table.sort(visibleList, function (a, b)
if (a.depth == b.depth) then
return (a.creationId < b.creationId)
else
return (a.depth > b.depth)
end
end)
return visibleList return visibleList
end end