core/menusystem: fuse MenuSystem and MenuController

This commit is contained in:
Kazhnuz 2019-02-10 11:58:39 +01:00
parent 6e7d75f09a
commit 3cbb7a1373

View file

@ -1,5 +1,4 @@
local MenuSystem = {}
local MenuController = Object:extend()
local MenuSystem = Object:extend()
local cwd = (...):gsub('%.init$', '') .. "."
@ -14,21 +13,21 @@ MenuSystem.Widget = require(cwd .. "widgets")
--local VirtualPad = require "modules.virtualpad"
function MenuController:new()
function MenuSystem:new()
self.menus = {}
self.virtualpad = game.input --VirtualPad(1)
end
function MenuController:reset()
function MenuSystem:reset()
self.menus = {}
self.virtualpad = game.input --VirtualPad(1)
end
function MenuController:addMenu(menu)
function MenuSystem:addMenu(menu)
table.insert(self.menus, menu)
end
function MenuController:update(dt)
function MenuSystem:update(dt)
self:clear()
for i,v in ipairs(self.menus) do
v.id = i
@ -44,7 +43,7 @@ function MenuController:update(dt)
end
end
function MenuController:clear()
function MenuSystem:clear()
-- On retire les entitées marquées comme supprimées
for i,v in ipairs(self.menus) do
if (v.destroyed == true) then
@ -53,17 +52,17 @@ function MenuController:clear()
end
end
function MenuController:updateList()
function MenuSystem:updateList()
for i,v in ipairs(self.menus) do
v.id = i
end
end
function MenuController:keyreleased(key, code)
function MenuSystem:keyreleased(key, code)
-- TODO:depreciated function
end
function MenuController:mousemoved(x, y, dx, dy)
function MenuSystem:mousemoved(x, y, dx, dy)
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:mousemoved(x - v.x, y - v.y)
@ -75,7 +74,7 @@ function MenuController:mousemoved(x, y, dx, dy)
end
end
function MenuController:mousepressed( x, y, button, istouch )
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 )
@ -87,13 +86,11 @@ function MenuController:mousepressed( x, y, button, istouch )
end
end
function MenuController:draw(dt) -- On dessine les entitées
function MenuSystem:draw(dt) -- On dessine les entitées
for i,v in ipairs(self.menus) do
v.id = i
v:draw(dt)
end
end
MenuSystem.Controller = MenuController
return MenuSystem