2019-02-10 11:56:45 +01:00
|
|
|
local Menu = Object:extend()
|
|
|
|
|
2019-02-11 19:53:34 +01:00
|
|
|
function Menu:new(menusystem, name, x, y, w, h)
|
|
|
|
self.menusystem = menusystem
|
2019-02-11 19:22:13 +01:00
|
|
|
self.name = name
|
2019-02-10 21:14:31 +01:00
|
|
|
|
2019-02-10 11:56:45 +01:00
|
|
|
self.x = x
|
|
|
|
self.y = y
|
|
|
|
self.w = w
|
|
|
|
self.h = h
|
2019-02-10 12:10:46 +01:00
|
|
|
|
|
|
|
self.widget = {}
|
|
|
|
self.widget.list = {}
|
|
|
|
self.widget.selected = 0
|
|
|
|
self.widget.selectedPrevious = 0
|
|
|
|
self.widget.cancel = 0
|
2019-02-11 19:44:23 +01:00
|
|
|
self:updateWidgetSize()
|
2019-02-10 11:56:45 +01:00
|
|
|
|
2019-02-10 14:41:27 +01:00
|
|
|
self.isDestroyed = false
|
|
|
|
self.isVisible = true
|
|
|
|
self.isActive = true
|
2019-02-10 11:56:45 +01:00
|
|
|
|
|
|
|
self.sound = {}
|
|
|
|
self.sound.asset = nil
|
|
|
|
self.sound.active = false
|
|
|
|
|
2019-02-10 21:14:31 +01:00
|
|
|
self:register()
|
|
|
|
end
|
|
|
|
|
2019-02-12 18:31:32 +01:00
|
|
|
function Menu:getFocus()
|
|
|
|
self.menusystem.focusedMenu = self.name
|
|
|
|
end
|
|
|
|
|
|
|
|
function Menu:haveFocus()
|
|
|
|
return (self.menusystem.focusedMenu == self.name)
|
|
|
|
end
|
|
|
|
|
2019-02-10 21:14:31 +01:00
|
|
|
function Menu:register()
|
2019-02-11 19:53:34 +01:00
|
|
|
self.menusystem:addMenu(self.name, self)
|
2019-02-10 11:56:45 +01:00
|
|
|
end
|
|
|
|
|
2019-02-10 12:10:46 +01:00
|
|
|
function Menu:setCancelWidget(id)
|
|
|
|
self.widget.cancel = #self.widget.list
|
2019-02-10 11:56:45 +01:00
|
|
|
end
|
|
|
|
|
2019-02-10 21:05:31 +01:00
|
|
|
function Menu:updateWidgetSize()
|
|
|
|
self.widget.h = 0
|
|
|
|
self.widget.w = 0
|
|
|
|
end
|
|
|
|
|
2019-02-10 14:34:04 +01:00
|
|
|
function Menu:getWidgetSize(id)
|
2019-02-12 18:48:51 +01:00
|
|
|
return self.widget.w, self.widget.h
|
2019-02-10 14:34:04 +01:00
|
|
|
end
|
|
|
|
|
2019-02-10 11:56:45 +01:00
|
|
|
function Menu:cancelAction()
|
2019-02-10 12:10:46 +01:00
|
|
|
if (self.widget.cancel ~= 0) then
|
|
|
|
self.widget.list[self.widget.cancel]:action()
|
2019-02-10 11:56:45 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function Menu:update(dt)
|
|
|
|
-- Cette fonction ne contient rien par défaut
|
|
|
|
end
|
|
|
|
|
2019-02-10 14:44:04 +01:00
|
|
|
function Menu:clear()
|
2019-02-10 12:10:46 +01:00
|
|
|
self.widget.list = {}
|
|
|
|
self.widget.cancel = 0
|
2019-02-10 11:56:45 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
function Menu:resize(x,y,w,h)
|
|
|
|
self.x = x
|
|
|
|
self.y = y
|
|
|
|
self.w = w
|
|
|
|
self.h = h
|
2019-02-10 21:05:31 +01:00
|
|
|
|
|
|
|
self:updateWidgetSize()
|
2019-02-10 11:56:45 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
function Menu:destroy()
|
|
|
|
self.destroyed = true
|
|
|
|
end
|
|
|
|
|
|
|
|
function Menu:draw()
|
2019-02-11 22:37:20 +01:00
|
|
|
-- nothing here
|
2019-02-10 11:56:45 +01:00
|
|
|
end
|
|
|
|
|
2019-02-12 18:52:38 +01:00
|
|
|
function Menu:drawCursor()
|
|
|
|
-- nothing here
|
|
|
|
end
|
|
|
|
|
2019-02-10 11:56:45 +01:00
|
|
|
function Menu:drawCanvas()
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
function Menu:keyreleased(key)
|
|
|
|
-- Cette fonction ne contient rien par défaut
|
|
|
|
end
|
|
|
|
|
|
|
|
function Menu:mousemoved(x, y)
|
|
|
|
-- Cette fonction ne contient rien par défaut
|
|
|
|
end
|
|
|
|
|
|
|
|
function Menu:mousepressed( x, y, button, istouch )
|
|
|
|
-- Cette fonction ne contient rien par défaut
|
|
|
|
end
|
|
|
|
|
|
|
|
function Menu:addWidget(newwidget)
|
2019-02-10 12:10:46 +01:00
|
|
|
if #self.widget.list == 0 then
|
|
|
|
self.widget.selected = 1
|
2019-02-10 11:56:45 +01:00
|
|
|
end
|
2019-02-10 12:10:46 +01:00
|
|
|
table.insert(self.widget.list, newwidget)
|
2019-02-10 11:56:45 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
function Menu:updateWidgets(dt)
|
2019-02-10 14:44:04 +01:00
|
|
|
self:removeDestroyedWidgets()
|
2019-02-10 12:10:46 +01:00
|
|
|
for i,v in ipairs(self.widget.list) do
|
2019-02-10 11:56:45 +01:00
|
|
|
v.id = i
|
|
|
|
v:update(dt)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-02-10 14:44:04 +01:00
|
|
|
function Menu:removeDestroyedWidgets() -- On retire les widgets marquées comme supprimées
|
2019-02-10 12:10:46 +01:00
|
|
|
for i,v in ipairs(self.widget.list) do
|
2019-02-10 11:56:45 +01:00
|
|
|
if (v.destroyed == true) then
|
2019-02-10 12:10:46 +01:00
|
|
|
table.remove(self.widget.list, i)
|
2019-02-10 11:56:45 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function Menu:setCursor(cursorid)
|
2019-02-10 12:10:46 +01:00
|
|
|
self.widget.selected = cursorid --math.max(1, math.min(cursorid, #self.widget.list))
|
2019-02-10 11:56:45 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
function Menu:moveCursor(new_selected)
|
|
|
|
self:playSelectSound()
|
|
|
|
if new_selected < 1 then
|
2019-02-10 12:10:46 +01:00
|
|
|
self.widget.selected = #self.widget.list + new_selected
|
2019-02-10 11:56:45 +01:00
|
|
|
else
|
2019-02-10 12:10:46 +01:00
|
|
|
if new_selected > #self.widget.list then
|
|
|
|
self.widget.selected = new_selected - #self.widget.list
|
2019-02-10 11:56:45 +01:00
|
|
|
else
|
2019-02-10 12:10:46 +01:00
|
|
|
self.widget.selected = new_selected
|
2019-02-10 11:56:45 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function Menu:setSound(soundasset)
|
|
|
|
self.sound.active = true
|
|
|
|
self.sound.asset = soundasset
|
|
|
|
end
|
|
|
|
|
|
|
|
function Menu:playSelectSound()
|
|
|
|
if self.sound.active == true then
|
|
|
|
self.sound.asset:setVolume(game.options.data.audio.sfx / 100)
|
|
|
|
love.audio.play( self.sound.asset )
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function Menu:resetView()
|
|
|
|
-- ne sert à rien ici, c'est juste pour éviter des crash
|
|
|
|
end
|
|
|
|
|
|
|
|
function Menu:moveView()
|
|
|
|
-- ne sert à rien ici, c'est juste pour éviter des crash
|
|
|
|
end
|
|
|
|
|
|
|
|
return Menu
|