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 = {}
|
|
|
|
self.virtualpad = game.input --VirtualPad(1)
|
|
|
|
end
|
|
|
|
|
2019-02-10 11:58:39 +01:00
|
|
|
function MenuSystem:reset()
|
2019-02-10 11:56:45 +01:00
|
|
|
self.menus = {}
|
|
|
|
self.virtualpad = game.input --VirtualPad(1)
|
|
|
|
end
|
|
|
|
|
2019-02-10 11:58:39 +01:00
|
|
|
function MenuSystem:addMenu(menu)
|
2019-02-10 11:56:45 +01:00
|
|
|
table.insert(self.menus, menu)
|
|
|
|
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-10 11:56:45 +01:00
|
|
|
for i,v in ipairs(self.menus) do
|
|
|
|
v.id = i
|
|
|
|
v:update(dt)
|
|
|
|
v:updateWidgets(dt)
|
2019-02-10 14:41:27 +01:00
|
|
|
if v.haveFocus == true then
|
2019-02-10 11:56:45 +01:00
|
|
|
for k,w in pairs(self.virtualpad.keys) do
|
|
|
|
if self.virtualpad.keys[k].isPressed then
|
|
|
|
v:keyreleased(k)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
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
|
|
|
|
for i,v in ipairs(self.menus) do
|
2019-02-10 14:41:27 +01:00
|
|
|
if (v.isDestroyed == true) then
|
2019-02-10 11:56:45 +01:00
|
|
|
table.remove(self.menus, i)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-02-10 11:58:39 +01:00
|
|
|
function MenuSystem:updateList()
|
2019-02-10 11:56:45 +01:00
|
|
|
for i,v in ipairs(self.menus) do
|
|
|
|
v.id = i
|
|
|
|
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-10 11:56:45 +01:00
|
|
|
for i,v in ipairs(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)
|
|
|
|
for j,u in ipairs(self.menus) do
|
|
|
|
u.haveFocus = false
|
|
|
|
end
|
|
|
|
v.haveFocus = true
|
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-10 11:56:45 +01:00
|
|
|
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:mousepressed(x - v.x, y - v.y, button, istouch )
|
|
|
|
for j,u in ipairs(self.menus) do
|
|
|
|
u.focus = false
|
|
|
|
end
|
|
|
|
v.focus = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-02-10 11:58:39 +01:00
|
|
|
function MenuSystem:draw(dt) -- On dessine les entitées
|
2019-02-10 11:56:45 +01:00
|
|
|
for i,v in ipairs(self.menus) do
|
|
|
|
v.id = i
|
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
|
|
|
|
end
|
|
|
|
|
|
|
|
return MenuSystem
|