2019-02-10 11:58:39 +01:00
|
|
|
local MenuSystem = Object:extend()
|
2019-02-10 11:56:45 +01:00
|
|
|
|
|
|
|
local cwd = (...):gsub('%.init$', '') .. "."
|
|
|
|
|
2019-02-10 12:00:02 +01:00
|
|
|
MenuSystem.Parent = require(cwd .. "parent")
|
2019-02-10 11:56:45 +01:00
|
|
|
MenuSystem.ListBox = require(cwd .. "listbox")
|
|
|
|
MenuSystem.FlowBox = require(cwd .. "flowbox")
|
|
|
|
MenuSystem.Grid = require(cwd .. "grid")
|
|
|
|
MenuSystem.TextMenu = require(cwd .. "textmenu")
|
|
|
|
|
|
|
|
MenuSystem.Widget = require(cwd .. "widgets")
|
|
|
|
|
|
|
|
|
|
|
|
--local VirtualPad = require "modules.virtualpad"
|
|
|
|
|
2019-02-10 11:58:39 +01:00
|
|
|
function MenuSystem:new()
|
2019-02-10 11:56:45 +01:00
|
|
|
self.menus = {}
|
2019-02-12 18:31:32 +01:00
|
|
|
self.focusedMenu = ""
|
2019-02-10 11:56:45 +01:00
|
|
|
end
|
|
|
|
|
2019-02-10 11:58:39 +01:00
|
|
|
function MenuSystem:reset()
|
2019-02-10 11:56:45 +01:00
|
|
|
self.menus = {}
|
|
|
|
end
|
|
|
|
|
2019-02-11 19:22:13 +01:00
|
|
|
function MenuSystem:addMenu(name, menu)
|
|
|
|
self.menus[name] = menu
|
2019-02-10 11:56:45 +01:00
|
|
|
end
|
|
|
|
|
2019-02-10 11:58:39 +01:00
|
|
|
function MenuSystem:update(dt)
|
2019-02-10 14:44:04 +01:00
|
|
|
self:removeDestroyedMenus()
|
2019-02-12 18:31:32 +01:00
|
|
|
for k,v in pairs(self.menus) do
|
2019-02-10 11:56:45 +01:00
|
|
|
v:update(dt)
|
|
|
|
v:updateWidgets(dt)
|
2019-02-12 18:31:32 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
if self.menus[self.focusedMenu] ~= nil then
|
|
|
|
for k,v in pairs(self.keys) do
|
|
|
|
if self.keys[k].isPressed then
|
|
|
|
self.menus[self.focusedMenu]:keyreleased(k)
|
2019-02-10 11:56:45 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-02-12 18:31:32 +01:00
|
|
|
|
2019-02-10 11:56:45 +01:00
|
|
|
end
|
|
|
|
|
2019-02-10 14:44:04 +01:00
|
|
|
function MenuSystem:removeDestroyedMenus()
|
2019-02-10 11:56:45 +01:00
|
|
|
-- On retire les entitées marquées comme supprimées
|
2019-02-11 19:22:13 +01:00
|
|
|
for k,v in pairs(self.menus) do
|
2019-02-10 14:41:27 +01:00
|
|
|
if (v.isDestroyed == true) then
|
2019-02-11 19:22:13 +01:00
|
|
|
self.menus[k] = nil
|
2019-02-10 11:56:45 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-02-10 11:58:39 +01:00
|
|
|
function MenuSystem:keyreleased(key, code)
|
2019-02-10 11:56:45 +01:00
|
|
|
-- TODO:depreciated function
|
|
|
|
end
|
|
|
|
|
2019-02-10 11:58:39 +01:00
|
|
|
function MenuSystem:mousemoved(x, y, dx, dy)
|
2019-02-11 19:22:13 +01:00
|
|
|
for k,v in pairs(self.menus) do
|
2019-02-10 14:41:27 +01:00
|
|
|
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)
|
2019-02-10 11:56:45 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-02-10 11:58:39 +01:00
|
|
|
function MenuSystem:mousepressed( x, y, button, istouch )
|
2019-02-11 19:22:13 +01:00
|
|
|
for k,v in pairs(self.menus) do
|
2019-02-11 22:39:18 +01:00
|
|
|
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:mousepressed(x - v.x, y - v.y, button, istouch )
|
2019-02-10 11:56:45 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-02-10 11:58:39 +01:00
|
|
|
function MenuSystem:draw(dt) -- On dessine les entitées
|
2019-02-11 19:22:13 +01:00
|
|
|
for k,v in pairs(self.menus) do
|
2019-02-10 14:41:27 +01:00
|
|
|
if (v.isVisible) then
|
|
|
|
v:draw(dt)
|
|
|
|
end
|
2019-02-10 11:56:45 +01:00
|
|
|
end
|
2019-02-12 18:52:38 +01:00
|
|
|
|
|
|
|
if self.menus[self.focusedMenu] ~= nil then
|
|
|
|
self.menus[self.focusedMenu]:drawCursor()
|
|
|
|
end
|
|
|
|
|
2019-02-10 11:56:45 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
return MenuSystem
|