Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local ButtonAPI
- local buttons = {}
- function install( xMin, xMax, yMin, yMax, textColour, backgroundColour, text, func, buttonID )
- if buttons[buttonID] then
- error("ButtonID: Returned False of "..buttonID.."! ID, already exists!")
- end
- buttons[buttonID] = {}
- buttons[buttonID].xMin = tonumber(xMin)
- buttons[buttonID].xMax = tonumber(xMax)
- buttons[buttonID].yMin = tonumber(yMin)
- buttons[buttonID].yMax = tonumber(yMax)
- buttons[buttonID].tCol = textColour
- buttons[buttonID].bCol = backgroundColour
- buttons[buttonID].text = text
- buttons[buttonID].handler = func
- buttons[buttonID].enabled = true
- buttons[buttonID].visible = true
- term.clear()
- term.setCursorPos(1,1)
- -- print("Installed!") -- just testing methods ( i know i could use for k,v in pairs....., but somehow that errored out.)
- -- print(buttons[buttonID].xMin)
- -- print(buttons[buttonID].xMax)
- -- print(buttons[buttonID].yMin)
- -- print(buttons[buttonID].yMax)
- -- print(buttons[buttonID].tCol)
- -- print(buttons[buttonID].bCol)
- -- print(buttons[buttonID].text)
- -- print(buttons[buttonID].handler)
- end
- function enable( buttonID, bolean )
- buttons[buttonID].enabled = bolean
- end
- function visible( buttonID, bolean )
- button[buttonID].visible = bolean
- end
- function delete( buttonID )
- buttons[buttonID] = nil
- end
- function runFunction( buttonID )
- buttons[buttonID].handler()
- end
- function draw( buttonID )
- local setPos = term.setCursorPos
- setPos(buttons[buttonID][xMin], buttons[buttonID][yMin])
- if buttons[buttonID][bCol] then
- term.setBackgroundColor(colors.buttons[buttonID][bCol])
- end
- if buttons[buttonID][tCol] then
- term.setTextColor(buttons[buttonID][tCol])
- end
- for y = buttons[buttonID][yMin], buttons[buttonID][yMax] do
- for l = buttons[buttonID][xMin], buttons[buttonID][xMax] do
- setPos(l,y)
- write(" ")
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment