Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local buttons = {}
- local function clear()
- term.clear()
- term.setCursorPos(1,1)
- end
- function reset()
- buttons = {}
- end
- function add(text, startX, startY, endX, endY, tStartX, tStartY, bColor, bcColor, btColor, func)
- --local buttons[#buttons+1] = {}
- local sTemp = {}
- sTemp["text"] = text
- sTemp["startX"] = startX
- sTemp["startY"] = startY
- sTemp["endX"] = endX
- sTemp["endY"] = endY
- sTemp["tStartX"] = tStartX
- sTemp["tStartY"] = tStartY
- sTemp["bColor"] = bColor
- sTemp["bcColor"] = bcColor
- sTemp["btColor"] = btColor
- sTemp["func"] = func
- sTemp["isActive"] = false
- buttons[#buttons+1] = sTemp
- end
- function addFromTable(tbl)
- if type(tbl) == "table" then
- for i,v in ipairs(tbl) do
- add(unpack(v))
- end
- end
- end
- function draw()
- term.setBackgroundColor(colors.white)
- clear()
- for i=1, #buttons do
- v = buttons[i]
- if v["isActive"] == true then
- term.setBackgroundColor(v["bcColor"])
- else
- term.setBackgroundColor(v["bColor"])
- end
- term.setTextColor(v["btColor"])
- for yPos = v["startY"], v["endY"] do
- for xPos = v["startX"], v["endX"] do
- term.setCursorPos(xPos, yPos)
- write(" ")
- end
- end
- term.setCursorPos(v["tStartX"], v["tStartY"])
- write(v["text"])
- end
- end
- local function pulse(btn)
- term.setBackgroundColor(btn["bcColor"])
- for yPos = btn["startY"], btn["endY"] do
- for xPos = btn["startX"], btn["endX"] do
- term.setCursorPos(xPos,yPos)
- write(" ")
- end
- end
- term.setTextColor(btn["btColor"])
- term.setCursorPos(btn["tStartX"], btn["tStartY"])
- write(btn["text"])
- sleep(.1)
- term.setBackgroundColor(btn["bColor"])
- for yPos = btn["startY"], btn["endY"] do
- for xPos = btn["startX"], btn["endX"] do
- term.setCursorPos(xPos,yPos)
- write(" ")
- end
- end
- term.setTextColor(btn["btColor"])
- term.setCursorPos(btn["tStartX"], btn["tStartY"])
- write(btn["text"])
- sleep(.1)
- end
- function check(x,y)
- for i,v in ipairs(buttons) do
- if x >= v["startX"] and x <= v["endX"] and y >= v["startY"] and y <=v["endY"] then
- pulse(v)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- clear()
- v["func"]()
- end
- end
- end
Add Comment
Please, Sign In to add comment