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 rsOn = rs.getInput(redstoneSide)
- local function niceError( msg )
- error(msg, 0)
- 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 buttonText = 'Your Text'
- local buttonW = #buttonText + 2
- local buttonH = 3
- local buttonX = sw / 2 - buttonW / 2 -- middle of screen
- local buttonY = sh / 2 - 1 -- middle of screen
- local backColor = colors.black
- local buttonBackColor = colors.lightBlue
- local buttonTextColor = colors.white
- -- I DO NOT SUGGEST EDITING VARIABLES OR FUNCTIONS BEYOND THIS POINT, IT MAY BREAK THE PROGRAM --
- local function drawGui()
- term.setBackgroundColor(rsOn and colors.red or 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) - (#buttonText / 2) - 1), math.ceil(buttonY + (buttonH / 2) - 1) )
- write(buttonText)
- end
- local function processInput(mouseX, mouseY)
- if mouseX >= buttonX - 1 and mouseX <= buttonX + buttonW - 1 and mouseY >= buttonY and mouseY <= buttonY + buttonH then
- rsOn = not rsOn
- rs.setOutput(redstoneSide, rsOn)
- end
- end
- term.setBackgroundColor(backColor)
- term.clear()
- drawGui()
- while true do
- local e, s, x, y = os.pullEventRaw()
- if e == 'monitor_touch' and s == monitorSide then
- processInput(x, y)
- elseif e == 'terminate' then
- break
- end
- end
- term.restore()
Advertisement
Add Comment
Please, Sign In to add comment