Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Coded by HPWebcamAble--
- --[[
- NOTE: This is used for displaying buttons
- in the computer terminal, not on a monitor
- ]]
- function clear(cbt)
- term.clear()
- term.setCursorPos(1,1)
- if cbt then
- buttons = {}
- end
- end
- function draw(name,x,y,onColor,offColor,inacColor,borderX,borderY,func)
- buttons[name] = {}
- buttons[name]["xpos"] = x
- buttons[name]["ypos"] = y
- buttons[name]["onColor"] = onColor
- buttons[name]["offColor"] = offColor
- buttons[name]["inacColor"] = inacColor
- buttons[name]["borderX"] = borderX
- buttons[name]["borderY"] = borderY
- buttons[name]["state"] = 1
- buttons[name]["func"] = func
- drawButtons()
- end
- function toggleButton(name)
- if buttons[name]["state"] == 1 then
- buttons[name]["state"] = 2
- elseif buttons[name]["state"] == 2 then
- buttons[name]["state"] = 1
- end
- drawButtons()
- end
- function setState(name,state)
- buttons[name]["state"] = state
- drawButtons()
- end
- function flashButton(name,time)
- buttons[name]["state"] = not buttons[name]["state"]
- drawButtons()
- sleep(time)
- buttons[name]["state"] = not buttons[name]["state"]
- drawButtons()
- end
- function drawButtons()
- for name,data in pairs(buttons) do
- local xpos = buttons[name]["xpos"]
- local ypos = buttons[name]["ypos"]
- local xborder = buttons[name]["borderX"]
- local yborder = buttons[name]["borderY"]
- term.setCursorPos(xpos,ypos)
- if buttons[name]["state"] == 1 then
- term.setBackgroundColor(buttons[name]["onColor"])
- elseif buttons[name]["state"] == 2 then
- term.setBackgroundColor(buttons[name]["offColor"])
- elseif buttons[name]["state"] == 3 then
- term.setBackgroundColor(buttons[name]["inacColor"])
- end
- term.write(name)
- term.setCursorPos(xpos-xborder,ypos-yborder)
- tempx,tempy = term.getCursorPos()
- tempx2 = tempx
- for i = 1, yborder do
- tempx = tempx2
- for j = 1, buttons[name]["borderX"]*2+string.len(name) do
- term.setCursorPos(tempx,tempy)
- term.write(" ")
- tempx = tempx+1
- end
- tempy = tempy+1
- end
- term.setCursorPos(buttons[name]["xpos"]-xborder,buttons[name]["ypos"])
- for i = 1, xborder do
- term.write(" ")
- end
- term.setCursorPos(buttons[name]["xpos"]+string.len(name),buttons[name]["ypos"])
- for i = 1, xborder do
- term.write(" ")
- end
- tempx = buttons[name]["xpos"]-xborder
- tempy = buttons[name]["ypos"]+1
- for i = 1, buttons[name]["borderY"] do
- tempx = tempx2
- for j = 1, xborder*2+string.len(name) do
- term.setCursorPos(tempx,tempy)
- term.write(" ")
- tempx = tempx+1
- end
- tempy = tempy+1
- end
- end
- term.setBackgroundColor(colors.black)
- end
- function checkCords(tx,ty)
- for name,data in pairs(buttons) do
- tempx = buttons[name]["xpos"]
- tempy = buttons[name]["ypos"]
- xborder = buttons[name]["borderX"]
- yborder = buttons[name]["borderY"]
- minx = tempx-xborder
- miny = tempy-yborder
- maxx = tempx+string.len(name)+xborder
- maxy = tempy+yborder
- if tx >= minx and tx <= maxx and ty >= miny and ty <= maxy then
- if buttons[name]["func"] ~= nil then
- buttons[name]["func"]()
- else
- return name
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement