Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Program by TheOriginalBIT
- -- CC Forums Profile: http://www.computercraft.info/forums2/index.php?/user/1217-theoriginalbit/
- local function niceError( msg )
- printError( msg )
- error()
- end
- local function findPeripheral( t )
- for _,side in pairs(rs.getSides()) do
- if peripheral.getType(side) == t then
- return side
- end
- end
- niceError( 'No '..t..' attached to the computer' )
- end
- local monitorSide = findPeripheral('monitor')
- local monitor = peripheral.wrap( monitorSide )
- if not monitor.isColor() then
- niceError( 'No advanced monitor attached to the computer' )
- end
- term.redirect(monitor)
- local sw, sh = term.getSize()
- --[[
- #################################
- EDIT THESE VARIABLES TO CUSTOMISE
- #################################
- ]]--
- local redstoneSide = 'back'
- local pulseLength = 1
- local topLine = 'Some Text'
- local topLineX = sw / 2 - #topLine / 2 + (#topLine % 2 == 0 and 1 or 0) -- centre of screen
- local topLineY = sh / 2 - 3
- local buttonLine = 'Teleport'
- local buttonW = #buttonLine + 2
- local buttonH = 3
- local buttonX = sw / 2 - buttonW / 2
- local buttonY = sh / 2 - 1
- local bottomLine = 'Some Text'
- local bottomLineX = sw / 2 - #topLine / 2 + (#topLine % 2 == 0 and 1 or 0) -- centre of screen
- local bottomLineY = sh / 2 + 3
- local backColor = colors.black
- local topLineTextColor = colors.white
- local bottomLineTextColor = colors.white
- local buttonBackColor = colors.lightBlue
- local buttonTextColor = colors.white
- -- END EDITABLE VARIABLES --
- local function drawGui()
- term.setBackgroundColor(backColor)
- term.setTextColor(topLineTextColor)
- term.setCursorPos(topLineX, topLineY)
- write(topLine)
- term.setTextColor(bottomLineTextColor)
- term.setCursorPos(bottomLineX, bottomLineY)
- write(bottomLine)
- term.setBackgroundColor(buttonBackColor)
- term.setTextColor(buttonTextColor)
- for i = 0, buttonH - 1 do
- term.setCursorPos(buttonX, buttonY + i)
- write( string.rep( ' ', buttonW) )
- end
- term.setCursorPos(math.ceil(buttonX + (buttonW / 2) - (#buttonLine / 2) - 1), math.ceil(buttonY + (buttonH / 2) - 1) )
- write(buttonLine)
- end
- local function processInput(mouseX, mouseY)
- if mouseX >= buttonX - 1 and mouseX <= buttonX + buttonW - 1 and mouseY >= buttonY and mouseY <= buttonY + buttonH then
- rs.setOutput(redstoneSide, true)
- os.startTimer(pulseLength)
- os.pullEvent('timer')
- rs.setOutput(redstoneSide, false)
- end
- end
- term.setBackgroundColor(backColor)
- term.setTextColor(textColor)
- term.clear()
- while true do
- drawGui()
- local e, s, x, y = os.pullEventRaw()
- if e == 'monitor_touch' and s == monitorSide then
- processInput(x, y)
- elseif e == 'terminate' then
- term.restore()
- error()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment