sonic-bluestreak/sonic-boost.love/core/modules/menusystem/init.lua

100 lines
2.3 KiB
Lua

local MenuSystem = Object:extend()
local cwd = (...):gsub('%.init$', '') .. "."
MenuSystem.Parent = require(cwd .. "parent")
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"
function MenuSystem:new()
self.menus = {}
self.virtualpad = game.input --VirtualPad(1)
end
function MenuSystem:reset()
self.menus = {}
self.virtualpad = game.input --VirtualPad(1)
end
function MenuSystem:addMenu(menu)
table.insert(self.menus, menu)
end
function MenuSystem:update(dt)
self:removeDestroyedMenus()
for i,v in ipairs(self.menus) do
v.id = i
v:update(dt)
v:updateWidgets(dt)
if v.haveFocus == true then
for k,w in pairs(self.virtualpad.keys) do
if self.virtualpad.keys[k].isPressed then
v:keyreleased(k)
end
end
end
end
end
function MenuSystem:removeDestroyedMenus()
-- On retire les entitées marquées comme supprimées
for i,v in ipairs(self.menus) do
if (v.isDestroyed == true) then
table.remove(self.menus, i)
end
end
end
function MenuSystem:updateList()
for i,v in ipairs(self.menus) do
v.id = i
end
end
function MenuSystem:keyreleased(key, code)
-- TODO:depreciated function
end
function MenuSystem:mousemoved(x, y, dx, dy)
for i,v in ipairs(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
v:mousemoved(x - v.x, y - v.y)
for j,u in ipairs(self.menus) do
u.haveFocus = false
end
v.haveFocus = true
end
end
end
end
function MenuSystem:mousepressed( x, y, button, istouch )
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
function MenuSystem:draw(dt) -- On dessine les entitées
for i,v in ipairs(self.menus) do
v.id = i
if (v.isVisible) then
v:draw(dt)
end
end
end
return MenuSystem