Guest User

Untitled

a guest
Mar 21st, 2013
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.74 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 function niceError( msg )
  5.   printError( msg )
  6.   error()
  7. end
  8.  
  9. local function findPeripheral( t )
  10.   for _,side in pairs(rs.getSides()) do
  11.     if peripheral.getType(side) == t then
  12.       return side
  13.     end
  14.   end
  15.  
  16.   niceError( 'No '..t..' attached to the computer' )
  17. end
  18.  
  19. local monitorSide = findPeripheral('monitor')
  20. local monitor = peripheral.wrap( monitorSide )
  21.  
  22. if not monitor.isColor() then
  23.   niceError( 'No advanced monitor attached to the computer' )
  24. end
  25.  
  26. term.redirect(monitor)
  27.  
  28. local sw, sh = term.getSize()
  29.  
  30. --[[
  31. #################################
  32.  
  33. EDIT THESE VARIABLES TO CUSTOMISE
  34.  
  35. #################################
  36. ]]--
  37.  
  38. local redstoneSide = 'back'
  39. local pulseLength = 1
  40.  
  41. local topLine = 'Some Text'
  42. local topLineX = sw / 2 - #topLine / 2 + (#topLine % 2 == 0 and 1 or 0) -- centre of screen
  43. local topLineY = sh / 2 - 3
  44.  
  45. local buttonLine = 'Teleport'
  46. local buttonW = #buttonLine + 2
  47. local buttonH = 3
  48. local buttonX = sw / 2 - buttonW / 2
  49. local buttonY = sh / 2 - 1
  50.  
  51. local bottomLine = 'Some Text'
  52. local bottomLineX = sw / 2 - #topLine / 2 + (#topLine % 2 == 0 and 1 or 0) -- centre of screen
  53. local bottomLineY = sh / 2 + 3
  54.  
  55. local backColor = colors.black
  56. local topLineTextColor = colors.white
  57. local bottomLineTextColor = colors.white
  58. local buttonBackColor = colors.lightBlue
  59. local buttonTextColor = colors.white
  60.  
  61. -- END EDITABLE VARIABLES --
  62.  
  63. local function drawGui()
  64.   term.setBackgroundColor(backColor)
  65.   term.setTextColor(topLineTextColor)
  66.  
  67.   term.setCursorPos(topLineX, topLineY)
  68.   write(topLine)
  69.  
  70.   term.setTextColor(bottomLineTextColor)
  71.  
  72.   term.setCursorPos(bottomLineX, bottomLineY)
  73.   write(bottomLine)
  74.  
  75.   term.setBackgroundColor(buttonBackColor)
  76.   term.setTextColor(buttonTextColor)
  77.  
  78.   for i = 0, buttonH - 1 do
  79.     term.setCursorPos(buttonX, buttonY + i)
  80.     write( string.rep( ' ', buttonW) )
  81.   end
  82.  
  83.   term.setCursorPos(math.ceil(buttonX + (buttonW / 2) - (#buttonLine / 2) - 1), math.ceil(buttonY + (buttonH / 2) - 1) )
  84.   write(buttonLine)
  85. end
  86.  
  87. local function processInput(mouseX, mouseY)
  88.   if mouseX >= buttonX - 1 and mouseX <= buttonX + buttonW - 1 and mouseY >= buttonY and mouseY <= buttonY + buttonH then
  89.     rs.setOutput(redstoneSide, true)
  90.     os.startTimer(pulseLength)
  91.     os.pullEvent('timer')
  92.     rs.setOutput(redstoneSide, false)
  93.   end
  94. end
  95.  
  96. term.setBackgroundColor(backColor)
  97. term.setTextColor(textColor)
  98. term.clear()
  99.  
  100. while true do
  101.   drawGui()
  102.   local e, s, x, y = os.pullEventRaw()
  103.   if e == 'monitor_touch' and s == monitorSide then
  104.     processInput(x, y)
  105.   elseif e == 'terminate' then
  106.     term.restore()
  107.     error()
  108.   end
  109. end
Advertisement
Add Comment
Please, Sign In to add comment