Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- buttons = {} --Button Array of Sorts
- function addButton(name,displaytext,func,coloron,coloroff,textcolor,xmin,xmax,ymin,ymax)
- buttons[name] = {}
- buttons[name]["displaytext"] = displaytext
- buttons[name]["func"] = func
- buttons[name]["xmin"] = xmin
- buttons[name]["xmax"] = xmax
- buttons[name]["ymin"] = ymin
- buttons[name]["ymax"] = ymax
- buttons[name]["coloron"] = coloron
- buttons[name]["coloroff"] = coloroff
- buttons[name]["textcolor"] = textcolor
- buttons[name]["active"] = false
- end
- function listButtons()
- for name,data in pairs(buttons) do
- name = tostring(name)
- print(name)
- end
- end
- function fillButton(text,bData,color)
- term.setBackgroundColor(color)
- local yspot = math.floor((bData["ymin"] + bData["ymax"])/2)
- local xspot = math.floor((bData["xmax"] - bData["xmin"] - string.len(text))/2)+1
- for j = bData["ymin"],bData["ymax"] do
- term.setCursorPos(bData["xmin"],j)
- if j == yspot then
- for k = 0, bData["xmax"] - bData["xmin"] - string.len(text) +1 do
- if k == xspot then
- term.setTextColor(bData["textcolor"])
- if bData["displaytext"] == yes then
- term.write(text)
- elseif bData["displaytext"] == no then
- term.write(" ")
- end
- else
- term.write(" ")
- end
- end
- else
- for i = bData["xmin"], bData["xmax"] do
- term.write(" ")
- end
- end
- end
- term.setBackgroundColor(colors.black)
- end
- function displayButton()
- local currColor
- for name,data in pairs(buttons) do
- local on = data["active"]
- if on == true then currColor = data["coloron"] else currColor = data["coloroff"] end
- fillButton(name,data,currColor)
- end
- end
- function xyCheck(x,y)
- for name,data in pairs(button) do
- if y>=data["ymin"] and y<=data["ymax"] then
- data["func"]()
- data["active"] = not data["active"]
- print(name)
- end
- end
- end
- function buttonLoop()
- displayButton()
- local e,side,x,y = os.pullEvent("monitor_touch")
- xyCheck(x,y)
- sleep(.1)
- end
- buttons.listButtons()
Advertisement
Add Comment
Please, Sign In to add comment