modules/menusystem: add a way to manage menusystem activity
This commit is contained in:
parent
802e1a78a3
commit
f37eaef79a
1 changed files with 60 additions and 35 deletions
|
@ -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,45 +144,52 @@ end
|
||||||
-- Update the menus of the menusystem
|
-- Update the menus of the menusystem
|
||||||
|
|
||||||
function MenuSystem:update(dt)
|
function MenuSystem:update(dt)
|
||||||
self:removeDestroyedMenus()
|
if (self.isActive) then
|
||||||
for k,v in pairs(self.menus) do
|
self:removeDestroyedMenus()
|
||||||
v:update(dt)
|
for k,v in pairs(self.menus) do
|
||||||
v:updateWidgets(dt)
|
v:update(dt)
|
||||||
end
|
v:updateWidgets(dt)
|
||||||
|
end
|
||||||
|
|
||||||
if self.menus[self.focusedMenu] ~= nil then
|
if self.menus[self.focusedMenu] ~= nil then
|
||||||
-- Only check buttons if the current focused menu is actually active
|
-- Only check buttons if the current focused menu is actually active
|
||||||
if self.menus[self.focusedMenu].isActive then
|
if self.menus[self.focusedMenu].isActive then
|
||||||
for k,v in pairs(self.keys) do
|
for k,v in pairs(self.keys) do
|
||||||
if self.keys[k].isPressed then
|
if self.keys[k].isPressed then
|
||||||
self.menus[self.focusedMenu]:keyreleased(k)
|
self.menus[self.focusedMenu]:keyreleased(k)
|
||||||
|
end
|
||||||
end
|
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)
|
||||||
for k,v in pairs(self.menus) do
|
if (self.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
|
for k,v in pairs(self.menus) do
|
||||||
v:mousemoved(x - v.x, y - v.y)
|
if v.isActive then
|
||||||
break;
|
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)
|
||||||
|
break;
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function MenuSystem:mousepressed( x, y, button, istouch )
|
function MenuSystem:mousepressed( x, y, button, istouch )
|
||||||
for k,v in pairs(self.menus) do
|
if (self.isActive) then
|
||||||
if v.isActive then
|
for k,v in pairs(self.menus) do
|
||||||
if (x > v.x) and (x < v.x + v.w) and (y > v.y) and (y < v.y + v.h) then
|
if v.isActive then
|
||||||
v:mousepressed(x - v.x, y - v.y, button, istouch )
|
if (x > v.x) and (x < v.x + v.w) and (y > v.y) and (y < v.y + v.h) then
|
||||||
break;
|
v:mousepressed(x - v.x, y - v.y, button, istouch )
|
||||||
|
break;
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -188,22 +211,24 @@ function MenuSystem:getDrawList()
|
||||||
return drawList
|
return drawList
|
||||||
end
|
end
|
||||||
|
|
||||||
function MenuSystem:draw(dt) -- On dessine les entitées
|
function MenuSystem:draw(dt)
|
||||||
self.drawList = self:getDrawList()
|
if (self.isActive) then
|
||||||
|
-- Draw all the menus
|
||||||
|
self.drawList = self:getDrawList()
|
||||||
|
|
||||||
for i,v in ipairs(self.drawList) do
|
for i,v in ipairs(self.drawList) do
|
||||||
local v2 = self.menus[v.name]
|
local v2 = self.menus[v.name]
|
||||||
if (v2.isVisible) then
|
if (v2.isVisible) then
|
||||||
v2:draw(dt)
|
v2:draw(dt)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if self.menus[self.focusedMenu] ~= nil then
|
||||||
|
if (self.menus[self.focusedMenu].isVisible) then
|
||||||
|
self.menus[self.focusedMenu]:drawCursor()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if self.menus[self.focusedMenu] ~= nil then
|
|
||||||
if (self.menus[self.focusedMenu].isVisible) then
|
|
||||||
self.menus[self.focusedMenu]:drawCursor()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return MenuSystem
|
return MenuSystem
|
||||||
|
|
Loading…
Reference in a new issue