Guest User

sadsadsegasegasead

a guest
Apr 15th, 2013
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.78 KB | None | 0 0
  1.  local ButtonAPI
  2. local buttons = {}
  3.  
  4.  
  5. function install( xMin, xMax, yMin, yMax, textColour, backgroundColour, text, func, buttonID )
  6.     if buttons[buttonID] then
  7.         error("ButtonID: Returned False of "..buttonID.."! ID, already exists!")
  8.     end
  9.     buttons[buttonID] = {}
  10.     buttons[buttonID].xMin = tonumber(xMin)
  11.     buttons[buttonID].xMax = tonumber(xMax)
  12.     buttons[buttonID].yMin = tonumber(yMin)
  13.     buttons[buttonID].yMax = tonumber(yMax)
  14.     buttons[buttonID].tCol = textColour
  15.     buttons[buttonID].bCol = backgroundColour
  16.     buttons[buttonID].text = text
  17.     buttons[buttonID].handler = func
  18.     buttons[buttonID].enabled = true
  19.     buttons[buttonID].visible = true
  20.     term.clear()
  21.     term.setCursorPos(1,1)
  22.     -- print("Installed!") -- just testing methods ( i know i could use for k,v in pairs....., but somehow that errored out.)
  23.     -- print(buttons[buttonID].xMin)
  24.     -- print(buttons[buttonID].xMax)
  25.     -- print(buttons[buttonID].yMin)
  26.     -- print(buttons[buttonID].yMax)
  27.     -- print(buttons[buttonID].tCol)
  28.     -- print(buttons[buttonID].bCol)
  29.     -- print(buttons[buttonID].text)
  30.     -- print(buttons[buttonID].handler)
  31. end
  32.  
  33. function enable( buttonID, bolean )
  34.     buttons[buttonID].enabled = bolean
  35. end
  36.  
  37. function visible( buttonID, bolean )
  38.     button[buttonID].visible = bolean
  39. end
  40.  
  41. function delete( buttonID )
  42.     buttons[buttonID] = nil
  43. end
  44.  
  45. function runFunction( buttonID )
  46.     buttons[buttonID].handler()
  47. end
  48.  
  49. function draw( buttonID )
  50.     local setPos = term.setCursorPos
  51.     setPos(buttons[buttonID][xMin], buttons[buttonID][yMin])
  52.     if buttons[buttonID][bCol] then
  53.         term.setBackgroundColor(colors.buttons[buttonID][bCol])
  54.     end
  55.     if buttons[buttonID][tCol] then
  56.         term.setTextColor(buttons[buttonID][tCol])
  57.     end
  58.     for y = buttons[buttonID][yMin], buttons[buttonID][yMax] do
  59.         for l = buttons[buttonID][xMin], buttons[buttonID][xMax] do
  60.             setPos(l,y)
  61.             write(" ")
  62.         end
  63.     end
  64. end
Advertisement
Add Comment
Please, Sign In to add comment