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

147 lines
2.9 KiB
Lua
Raw Normal View History

local Menu = Object:extend()
function Menu:new(x,y,w,h)
self.x = x
self.y = y
self.w = w
self.h = h
self.widget = {}
self.widget.list = {}
self.widget.selected = 0
self.widget.selectedPrevious = 0
self.widget.cancel = 0
self.destroyed = false
self.focus = false
self.cancel = 0
self.sound = {}
self.sound.asset = nil
self.sound.active = false
self.canvas = {}
self.canvas.texture = nil
self.canvas.needRedraw = true
end
function Menu:setCancelWidget(id)
self.widget.cancel = #self.widget.list
end
function Menu:cancelAction()
if (self.widget.cancel ~= 0) then
self.widget.list[self.widget.cancel]:action()
end
end
function Menu:update(dt)
-- Cette fonction ne contient rien par défaut
end
function Menu:empty()
self.widget.list = {}
self.widget.cancel = 0
end
function Menu:resize(x,y,w,h)
self.x = x
self.y = y
self.w = w
self.h = h
end
function Menu:destroy()
self.destroyed = true
end
function Menu:draw()
if self.canvas.needRedraw == true then
CScreen:cease()
self:drawCanvas()
self.canvas.needRedraw = false
CScreen:apply()
end
love.graphics.draw(self.canvas.texture, self.x, self.y)
end
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)
if #self.widget.list == 0 then
self.widget.selected = 1
end
table.insert(self.widget.list, newwidget)
end
function Menu:updateWidgets(dt)
self:clearWidgets()
for i,v in ipairs(self.widget.list) do
v.id = i
v:update(dt)
end
end
function Menu:clearWidgets() -- On retire les widgets marquées comme supprimées
for i,v in ipairs(self.widget.list) do
if (v.destroyed == true) then
table.remove(self.widget.list, i)
end
end
end
function Menu:setCursor(cursorid)
self.widget.selected = cursorid --math.max(1, math.min(cursorid, #self.widget.list))
end
function Menu:moveCursor(new_selected)
self:playSelectSound()
if new_selected < 1 then
self.widget.selected = #self.widget.list + new_selected
else
if new_selected > #self.widget.list then
self.widget.selected = new_selected - #self.widget.list
else
self.widget.selected = new_selected
end
end
self.canvas.needRedraw = true
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