Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --ButtonAPI by Freack100
- local x,y = term.getSize()
- local buttons = {}
- function draw()
- for buttonCount = 1, #buttons do
- if buttons[buttonCount]["visible"] then
- term.setCursorPos(buttons[buttonCount]["sX"],buttons[buttonCount]["sY"])
- term.setBackgroundColor(buttons[buttonCount]["bgcol"])
- term.setTextColor(buttons[buttonCount]["txtcol"])
- for i = buttons[buttonCount]["sY"], buttons[buttonCount]["eY"] do
- term.setCursorPos(buttons[buttonCount]["sX"], i)
- for u = buttons[buttonCount]["sX"], buttons[buttonCount]["eX"] do
- term.write(" ")
- end
- end
- term.setCursorPos(((buttons[buttonCount]["sX"]+buttons[buttonCount]["eX"])/2)-(string.len(buttons[buttonCount]["txt"])/2), (buttons[buttonCount]["sY"]+buttons[buttonCount]["eY"])/2)
- term.write(buttons[buttonCount]["txt"])
- end
- end
- end
- function create(sX,sY,eX,eY,bgcol,txtcol,txt,func)
- buttons[#buttons+1] = {["visible"] = true,["sX"]=sX,["sY"]=sY,["eX"]=eX,["eY"]=eY,["bgcol"]=bgcol,["txtcol"]=txtcol,["txt"]=txt,["func"]=func}
- return #buttons --This is the ID
- end
- function changeVisibility(ID)
- if not buttons[ID] then error("No button with this ID.",2) end
- buttons[ID]["visible"] = not buttons[ID]["visible"]
- end
- function deleteButton(ID)
- if not buttons[ID] then error("Buttons doesn't exists.",2) end
- buttons[ID] = nil
- end
- function getVisibility(ID)
- if not buttons[ID] then error("Button doesn't exists.",2) end
- return buttons[ID]["visible"]
- end
- function waitForEvents()
- while true do
- local evt,btn,pX,pY = os.pullEvent()
- if evt == "mouse_click" then
- for i = 1, #buttons do
- if buttons[i]["visible"] then
- if pX >= buttons[i]["sX"] and pX <= buttons[i]["eX"] and pY >= buttons[i]["sY"] and pY <= buttons[i]["eY"] then
- buttons[i]["func"]()
- return
- end
- end
- end
- end
- sleep(0)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement