Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local gfx = require("gfx")
- local utils = require("utils")
- function createParent()
- return {isVisible = true, children = {}}
- end
- -- Buttons
- function setAllButtonsOff(parent)
- for i = 1, #(parent["children"]) do
- local current = parent["children"][i]
- if current["type"] == "button" then
- parent["children"][i]["selected"] = false
- end
- end
- end
- function toggleButton(parent, buttonID)
- local data = parent["children"][buttonID]["selected"]
- parent["children"][buttonID]["selected"] = not data
- end
- function addCentralXButton(parent, message, posY, callback)
- local x, y = utils.midpoint(Width, Height)
- local newX = utils.getXPosOfString(message, x)
- return addButton(parent, message, newX, posY, callback)
- end
- function addButton(parent, message, posX, posY, callback)
- local data = {}
- data["type"] = "button"
- data["selected"] = false
- data["message"] = message
- data["posX"] = posX
- data["posY"] = posY
- data["callback"] = callback
- local lengthOfChildren = #(parent["children"])
- parent["children"][lengthOfChildren + 1] = data
- return lengthOfChildren
- end
- function show(parent)
- for item = 1, #(parent["children"]) do
- local current = parent["children"][item]
- if current["type"] == "button" then
- local message, posX, posY = current["message"], current["posX"], current["posY"]
- local selected = current["selected"]
- if selected then
- gfx.addText("[ " .. message .. " ]", posX - 2, posY)
- else
- gfx.addText(message, posX, posY)
- end
- end
- end
- end
- return {
- createParent = createParent,
- show = show,
- setAllButtonsOff = setAllButtonsOff,
- toggleButton = toggleButton,
- addButton = addButton,
- addCentralXButton = addCentralXButton
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement