Guest User

Untitled

a guest
Apr 14th, 2013
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.13 KB | None | 0 0
  1. -- Program by TheOriginalBIT
  2. -- CC Forums Profile: http://www.computercraft.info/forums2/index.php?/user/1217-theoriginalbit/
  3.  
  4. local rsOn = rs.getInput(redstoneSide)
  5.  
  6. local function niceError( msg )
  7.   error(msg, 0)
  8. end
  9.  
  10. local function findPeripheral( t )
  11.   for _,side in pairs(rs.getSides()) do
  12.     if peripheral.getType(side) == t then
  13.       return side
  14.     end
  15.   end
  16.  
  17.   niceError( 'No '..t..' attached to the computer' )
  18. end
  19.  
  20. local monitorSide = findPeripheral('monitor')
  21. local monitor = peripheral.wrap( monitorSide )
  22.  
  23. if not monitor.isColor() then
  24.   niceError( 'No advanced monitor attached to the computer' )
  25. end
  26.  
  27. term.redirect(monitor)
  28.  
  29. local sw, sh = term.getSize()
  30.  
  31. --[[
  32. #################################
  33.  
  34. EDIT THESE VARIABLES TO CUSTOMISE
  35.  
  36. #################################
  37. ]]--
  38.  
  39. local redstoneSide = 'back'
  40.  
  41. local buttonText = 'Your Text'
  42. local buttonW = #buttonText + 2
  43. local buttonH = 3
  44. local buttonX = sw / 2 - buttonW / 2 -- middle of screen
  45. local buttonY = sh / 2 - 1 -- middle of screen
  46.  
  47. local backColor = colors.black
  48. local buttonBackColor = colors.lightBlue
  49. local buttonTextColor = colors.white
  50.  
  51. -- I DO NOT SUGGEST EDITING VARIABLES OR FUNCTIONS BEYOND THIS POINT, IT MAY BREAK THE PROGRAM --
  52.  
  53. local function drawGui()
  54.   term.setBackgroundColor(rsOn and colors.red or buttonBackColor)
  55.   term.setTextColor(buttonTextColor)
  56.  
  57.   for i = 0, buttonH - 1 do
  58.     term.setCursorPos(buttonX, buttonY + i)
  59.     write( string.rep( ' ', buttonW) )
  60.   end
  61.  
  62.   term.setCursorPos(math.ceil(buttonX + (buttonW / 2) - (#buttonText / 2) - 1), math.ceil(buttonY + (buttonH / 2) - 1) )
  63.   write(buttonText)
  64. end
  65.  
  66. local function processInput(mouseX, mouseY)
  67.   if mouseX >= buttonX - 1 and mouseX <= buttonX + buttonW - 1 and mouseY >= buttonY and mouseY <= buttonY + buttonH then
  68.     rsOn = not rsOn
  69.     rs.setOutput(redstoneSide, rsOn)
  70.   end
  71. end
  72.  
  73. term.setBackgroundColor(backColor)
  74. term.clear()
  75. drawGui()
  76.  
  77. while true do
  78.   local e, s, x, y = os.pullEventRaw()
  79.   if e == 'monitor_touch' and s == monitorSide then
  80.     processInput(x, y)
  81.   elseif e == 'terminate' then
  82.     break
  83.   end
  84. end
  85.  
  86. term.restore()
Advertisement
Add Comment
Please, Sign In to add comment