core/menusystem: rework "system" flags for menu

This commit is contained in:
Kazhnuz 2019-02-10 14:41:27 +01:00
parent bf77a06741
commit b1cf66add0
2 changed files with 16 additions and 10 deletions

View File

@ -33,7 +33,7 @@ function MenuSystem:update(dt)
v.id = i
v:update(dt)
v:updateWidgets(dt)
if v.focus == true then
if v.haveFocus == true then
for k,w in pairs(self.virtualpad.keys) do
if self.virtualpad.keys[k].isPressed then
v:keyreleased(k)
@ -46,7 +46,7 @@ end
function MenuSystem:clear()
-- On retire les entitées marquées comme supprimées
for i,v in ipairs(self.menus) do
if (v.destroyed == true) then
if (v.isDestroyed == true) then
table.remove(self.menus, i)
end
end
@ -64,12 +64,14 @@ end
function MenuSystem:mousemoved(x, y, dx, dy)
for i,v in ipairs(self.menus) do
if (x > v.x) and (x < v.x + v.w) and (y > v.y) and (y < v.y + v.h) then
v:mousemoved(x - v.x, y - v.y)
for j,u in ipairs(self.menus) do
u.focus = false
if v.isActive then
if (x > v.x) and (x < v.x + v.w) and (y > v.y) and (y < v.y + v.h) then
v:mousemoved(x - v.x, y - v.y)
for j,u in ipairs(self.menus) do
u.haveFocus = false
end
v.haveFocus = true
end
v.focus = true
end
end
end
@ -89,7 +91,9 @@ end
function MenuSystem:draw(dt) -- On dessine les entitées
for i,v in ipairs(self.menus) do
v.id = i
v:draw(dt)
if (v.isVisible) then
v:draw(dt)
end
end
end

View File

@ -14,8 +14,10 @@ function Menu:new(x,y,w,h)
self.widget.h = 0
self.widget.w = 0
self.isdestroyed = false
self.focus = false
self.isDestroyed = false
self.haveFocus = false
self.isVisible = true
self.isActive = true
self.sound = {}
self.sound.asset = nil