more modular menu
This commit is contained in:
parent
d091f3a6bc
commit
7df0478890
6 changed files with 178 additions and 117 deletions
53
menu/state.lua
Normal file
53
menu/state.lua
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
-- Menu state class
|
||||
---@class MenuState
|
||||
---@field buttons Button[]
|
||||
---@field text Text[]
|
||||
MenuState = {
|
||||
buttons = {},
|
||||
text = {}
|
||||
}
|
||||
|
||||
-- Factory function
|
||||
---@param buttons Button[] | nil
|
||||
---@param text Text[] | nil
|
||||
---@return MenuState
|
||||
function MenuState:new( buttons, text )
|
||||
local state = {
|
||||
buttons = buttons or MenuState.buttons,
|
||||
text = text or MenuState.text
|
||||
}
|
||||
|
||||
setmetatable( state, { __index = self } )
|
||||
|
||||
return state
|
||||
end
|
||||
|
||||
-- Draw buttons
|
||||
function MenuState:draw()
|
||||
for _, button in ipairs(self.buttons) do
|
||||
button:draw()
|
||||
end
|
||||
for _, txt in ipairs(self.text) do
|
||||
txt:draw()
|
||||
end
|
||||
end
|
||||
|
||||
-- Update buttons
|
||||
---@param dt number
|
||||
---@param point Point
|
||||
---@param pressed boolean
|
||||
function MenuState:update( dt, point, pressed )
|
||||
for _, button in pairs(self.buttons) do
|
||||
button:update( dt, point, pressed )
|
||||
end
|
||||
end
|
||||
|
||||
---@enum MenuStateIndex
|
||||
MenuStateIndex = {
|
||||
start = 'start',
|
||||
pause = 'pause',
|
||||
levels = 'levels',
|
||||
hidden = 'hidden',
|
||||
completed = 'completed'
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue