core/menusystem: use name index instead of numeral index for menus
It makes more sense and avoid having to keep and update id of menus
This commit is contained in:
parent
464a1309c2
commit
5920fc18dd
6 changed files with 19 additions and 26 deletions
|
@ -3,8 +3,8 @@ local Menu = require(cwd .. "parent")
|
||||||
|
|
||||||
FlowBox = Menu:extend()
|
FlowBox = Menu:extend()
|
||||||
|
|
||||||
function FlowBox:new(controller, x,y,w,h,slots_hor,slots_vert)
|
function FlowBox:new(controller, name, x, y, w, h, slots_hor, slots_vert)
|
||||||
ListBox.super.new(self, controller, x, y, w, h)
|
ListBox.super.new(self, controller, name, x, y, w, h)
|
||||||
self.slots = slots_hor * slots_vert
|
self.slots = slots_hor * slots_vert
|
||||||
self.slots_hor = slots_hor
|
self.slots_hor = slots_hor
|
||||||
self.slots_vert = slots_vert
|
self.slots_vert = slots_vert
|
||||||
|
|
|
@ -4,8 +4,8 @@ local Menu = require(cwd .. "parent")
|
||||||
|
|
||||||
GridBox = Menu:extend()
|
GridBox = Menu:extend()
|
||||||
|
|
||||||
function GridBox:new(controller, x,y,w,h,slots_hor,slots_vert)
|
function GridBox:new(controller, name x, y, w, h, slots_hor, slots_vert)
|
||||||
ListBox.super.new(self, controller, x, y, w, h)
|
ListBox.super.new(self, controller, name, x, y, w, h)
|
||||||
self.slots = slots_hor * slots_vert
|
self.slots = slots_hor * slots_vert
|
||||||
self.slots_hor = slots_hor
|
self.slots_hor = slots_hor
|
||||||
self.slots_vert = slots_vert
|
self.slots_vert = slots_vert
|
||||||
|
|
|
@ -21,14 +21,13 @@ function MenuSystem:reset()
|
||||||
self.menus = {}
|
self.menus = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
function MenuSystem:addMenu(menu)
|
function MenuSystem:addMenu(name, menu)
|
||||||
table.insert(self.menus, menu)
|
self.menus[name] = menu
|
||||||
end
|
end
|
||||||
|
|
||||||
function MenuSystem:update(dt)
|
function MenuSystem:update(dt)
|
||||||
self:removeDestroyedMenus()
|
self:removeDestroyedMenus()
|
||||||
for i,v in ipairs(self.menus) do
|
for l,v in pairs(self.menus) do
|
||||||
v.id = i
|
|
||||||
v:update(dt)
|
v:update(dt)
|
||||||
v:updateWidgets(dt)
|
v:updateWidgets(dt)
|
||||||
if v.haveFocus == true then
|
if v.haveFocus == true then
|
||||||
|
@ -43,25 +42,19 @@ end
|
||||||
|
|
||||||
function MenuSystem:removeDestroyedMenus()
|
function MenuSystem:removeDestroyedMenus()
|
||||||
-- 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 k,v in pairs(self.menus) do
|
||||||
if (v.isDestroyed == true) then
|
if (v.isDestroyed == true) then
|
||||||
table.remove(self.menus, i)
|
self.menus[k] = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function MenuSystem:updateList()
|
|
||||||
for i,v in ipairs(self.menus) do
|
|
||||||
v.id = i
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function MenuSystem:keyreleased(key, code)
|
function MenuSystem:keyreleased(key, code)
|
||||||
-- TODO:depreciated function
|
-- TODO:depreciated function
|
||||||
end
|
end
|
||||||
|
|
||||||
function MenuSystem:mousemoved(x, y, dx, dy)
|
function MenuSystem:mousemoved(x, y, dx, dy)
|
||||||
for i,v in ipairs(self.menus) do
|
for k,v in pairs(self.menus) do
|
||||||
if v.isActive then
|
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
|
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 +68,7 @@ function MenuSystem:mousemoved(x, y, dx, dy)
|
||||||
end
|
end
|
||||||
|
|
||||||
function MenuSystem:mousepressed( x, y, button, istouch )
|
function MenuSystem:mousepressed( x, y, button, istouch )
|
||||||
for i,v in ipairs(self.menus) do
|
for k,v in pairs(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 )
|
||||||
for j,u in ipairs(self.menus) do
|
for j,u in ipairs(self.menus) do
|
||||||
|
@ -87,8 +80,7 @@ function MenuSystem:mousepressed( x, y, button, istouch )
|
||||||
end
|
end
|
||||||
|
|
||||||
function MenuSystem: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 k,v in pairs(self.menus) do
|
||||||
v.id = i
|
|
||||||
if (v.isVisible) then
|
if (v.isVisible) then
|
||||||
v:draw(dt)
|
v:draw(dt)
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,8 +3,8 @@ local Menu = require(cwd .. "parent")
|
||||||
|
|
||||||
ListBox = Menu:extend()
|
ListBox = Menu:extend()
|
||||||
|
|
||||||
function ListBox:new(controller, x,y,w,h,slots)
|
function ListBox:new(controller, name, x, y, w, h, slots)
|
||||||
ListBox.super.new(self, controller, x, y, w, h)
|
ListBox.super.new(self, controller, name, x, y, w, h)
|
||||||
self.slots = slots
|
self.slots = slots
|
||||||
self.begin = 1
|
self.begin = 1
|
||||||
self.h = slots * self.widget.h -- On fait en sorte que la hauteur
|
self.h = slots * self.widget.h -- On fait en sorte que la hauteur
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
local Menu = Object:extend()
|
local Menu = Object:extend()
|
||||||
|
|
||||||
function Menu:new(controller, x,y,w,h)
|
function Menu:new(controller, name, x, y, w, h)
|
||||||
self.controller = controller
|
self.controller = controller
|
||||||
|
self.name = name
|
||||||
|
|
||||||
self.x = x
|
self.x = x
|
||||||
self.y = y
|
self.y = y
|
||||||
|
@ -32,7 +33,7 @@ function Menu:new(controller, x,y,w,h)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Menu:register()
|
function Menu:register()
|
||||||
self.controller:addMenu(self)
|
self.controller:addMenu(self.name, self)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Menu:setCancelWidget(id)
|
function Menu:setCancelWidget(id)
|
||||||
|
|
|
@ -3,8 +3,8 @@ local Menu = require(cwd .. "parent")
|
||||||
|
|
||||||
local TextMenu = Menu:extend()
|
local TextMenu = Menu:extend()
|
||||||
|
|
||||||
function TextMenu:new(controller, x, y, font, slots)
|
function TextMenu:new(controller, name, x, y, font, slots)
|
||||||
TextMenu.super.new(self, controller, x, y, 0, 0)
|
TextMenu.super.new(self, controller, name, x, y, 0, 0)
|
||||||
self.ox = x
|
self.ox = x
|
||||||
self.oy = y
|
self.oy = y
|
||||||
self.font = font
|
self.font = font
|
||||||
|
|
Loading…
Reference in a new issue