modules/menusystem: add a way to manage menusystem activity

This commit is contained in:
Kazhnuz 2019-04-15 16:30:45 +02:00
parent 802e1a78a3
commit f37eaef79a

View file

@ -41,12 +41,28 @@ MenuSystem.Widget = require(cwd .. "widgets")
function MenuSystem:new()
self.menus = {}
self.focusedMenu = ""
self.isActive = true
end
function MenuSystem:reset()
self.menus = {}
end
-- ACTIVATION FUNCTIONS
-- Activate and deactivate the whole menusystem
function MenuSystem:activate()
self.isActive = true
end
function MenuSystem:deactivate()
self.isActive = false
end
function MenuSystem:getActiveState()
return self.isActive
end
-- MENUS FUNCTIONS
-- Controle the menus of the menusystem
@ -128,6 +144,7 @@ end
-- Update the menus of the menusystem
function MenuSystem:update(dt)
if (self.isActive) then
self:removeDestroyedMenus()
for k,v in pairs(self.menus) do
v:update(dt)
@ -144,13 +161,15 @@ function MenuSystem:update(dt)
end
end
end
end
end
-- MOUSE FUNCTIONS
-- Send mouse inputs to the menu
function MenuSystem:mousemoved(x, y, dx, dy)
if (self.isActive) then
for k,v in pairs(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
@ -159,9 +178,12 @@ function MenuSystem:mousemoved(x, y, dx, dy)
end
end
end
end
end
function MenuSystem:mousepressed( x, y, button, istouch )
if (self.isActive) then
for k,v in pairs(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
@ -170,6 +192,7 @@ function MenuSystem:mousepressed( x, y, button, istouch )
end
end
end
end
end
-- DRAW FUNCTIONS
@ -188,7 +211,9 @@ function MenuSystem:getDrawList()
return drawList
end
function MenuSystem:draw(dt) -- On dessine les entitées
function MenuSystem:draw(dt)
if (self.isActive) then
-- Draw all the menus
self.drawList = self:getDrawList()
for i,v in ipairs(self.drawList) do
@ -203,7 +228,7 @@ function MenuSystem:draw(dt) -- On dessine les entitées
self.menus[self.focusedMenu]:drawCursor()
end
end
end
end
return MenuSystem