From b1cf66add0fa259da2e547f18d78c596a1fa3ce5 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 10 Feb 2019 14:41:27 +0100 Subject: [PATCH] core/menusystem: rework "system" flags for menu --- .../core/modules/menusystem/init.lua | 20 +++++++++++-------- .../core/modules/menusystem/parent.lua | 6 ++++-- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/sonic-boost.love/core/modules/menusystem/init.lua b/sonic-boost.love/core/modules/menusystem/init.lua index c729b4a..46c76fe 100644 --- a/sonic-boost.love/core/modules/menusystem/init.lua +++ b/sonic-boost.love/core/modules/menusystem/init.lua @@ -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 diff --git a/sonic-boost.love/core/modules/menusystem/parent.lua b/sonic-boost.love/core/modules/menusystem/parent.lua index 8cf64f5..46381a5 100644 --- a/sonic-boost.love/core/modules/menusystem/parent.lua +++ b/sonic-boost.love/core/modules/menusystem/parent.lua @@ -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