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

View file

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