modules/menus:add a basic depth system to the menus

Fix #2
This commit is contained in:
Kazhnuz 2019-03-22 18:02:33 +01:00
parent 9519130613
commit 936cdc57f3
3 changed files with 32 additions and 3 deletions

View file

@ -90,6 +90,13 @@ function TestScene:new()
MenuType(self.menusystem, "text_menu5", x, y, w, h, 8)
MenuType(self.menusystem, "text_menu6", x, y, w, h, 8)
self.menusystem.menus["text_menu1"]:setDepth(-1)
self.menusystem.menus["text_menu2"]:setDepth(-1)
self.menusystem.menus["text_menu3"]:setDepth(-1)
self.menusystem.menus["text_menu4"]:setDepth(-1)
self.menusystem.menus["text_menu5"]:setDepth(-1)
self.menusystem.menus["text_menu6"]:setDepth(-1)
self:addTextWidget("text_menu1", 4)
self:addTextWidget("text_menu2", 10)
self:addTextWidget("text_menu3", 5)

View file

@ -106,10 +106,26 @@ function MenuSystem:mousepressed( x, y, button, istouch )
end
end
function MenuSystem:draw(dt) -- On dessine les entitées
function MenuSystem:getDrawList()
local drawList = {}
for k,v in pairs(self.menus) do
if (v.isVisible) then
v:draw(dt)
local drawObject = {}
drawObject.name = k
drawObject.depth = v.depth
table.insert(drawList, drawObject)
end
table.sort(drawList, function(a,b) return a.depth > b.depth end)
return drawList
end
function MenuSystem:draw(dt) -- On dessine les entitées
self.drawList = self:getDrawList()
for i,v in ipairs(self.drawList) do
local v2 = self.menus[v.name]
if (v2.isVisible) then
v2:draw(dt)
end
end

View file

@ -21,6 +21,8 @@ function Menu:new(menusystem, name, x, y, w, h)
self.isActive = true
self.isLocked = false
self.depth = 0
self.sound = {}
self.sound.asset = nil
self.sound.active = false
@ -28,6 +30,10 @@ function Menu:new(menusystem, name, x, y, w, h)
self:register()
end
function Menu:setDepth(depth)
self.depth = depth or 0
end
function Menu:setVisibility(visibility)
if self.isLocked == false then
self.isVisible = visibility