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