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() function MenuSystem:new()
self.menus = {} self.menus = {}
self.focusedMenu = "" self.focusedMenu = ""
self.isActive = true
end end
function MenuSystem:reset() function MenuSystem:reset()
self.menus = {} self.menus = {}
end 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 -- MENUS FUNCTIONS
-- Controle the menus of the menusystem -- Controle the menus of the menusystem
@ -128,6 +144,7 @@ end
-- Update the menus of the menusystem -- Update the menus of the menusystem
function MenuSystem:update(dt) function MenuSystem:update(dt)
if (self.isActive) then
self:removeDestroyedMenus() self:removeDestroyedMenus()
for k,v in pairs(self.menus) do for k,v in pairs(self.menus) do
v:update(dt) v:update(dt)
@ -144,13 +161,15 @@ function MenuSystem:update(dt)
end end
end end
end end
end
end end
-- MOUSE FUNCTIONS -- MOUSE FUNCTIONS
-- Send mouse inputs to the menu -- Send mouse inputs to the menu
function MenuSystem:mousemoved(x, y, dx, dy) function MenuSystem:mousemoved(x, y, dx, dy)
if (self.isActive) then
for k,v in pairs(self.menus) do for k,v in pairs(self.menus) do
if v.isActive then 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
@ -159,9 +178,12 @@ function MenuSystem:mousemoved(x, y, dx, dy)
end end
end end
end end
end
end end
function MenuSystem:mousepressed( x, y, button, istouch ) function MenuSystem:mousepressed( x, y, button, istouch )
if (self.isActive) then
for k,v in pairs(self.menus) do for k,v in pairs(self.menus) do
if v.isActive then 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
@ -171,6 +193,7 @@ function MenuSystem:mousepressed( x, y, button, istouch )
end end
end end
end end
end
-- DRAW FUNCTIONS -- DRAW FUNCTIONS
-- All functions to draw the menus of the menusystem -- All functions to draw the menus of the menusystem
@ -188,7 +211,9 @@ function MenuSystem:getDrawList()
return drawList return drawList
end 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() self.drawList = self:getDrawList()
for i,v in ipairs(self.drawList) do 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() self.menus[self.focusedMenu]:drawCursor()
end end
end end
end
end end
return MenuSystem return MenuSystem