Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Declare a table with the buttons that will be printed,
- --with it's own Text Colour and Background Colour and
- --unique x and y values.
- --Table Variables
- t = {
- {text = "Charging" , x = 1, y = 7, txtCol = colors.green, bgCol = colors.blue},
- {text = "Off" , x = 10, y = 7, txtCol = colors.red , bgCol = colors.blue},
- {text = "Activate" , x = 1, y = 11, txtCol = colors.green, bgCol = colors.blue},
- {text = "Deactivate" , x = 10, y = 11, txtCol = colors.red , bgCol = colors.blue}
- }
- --Monitor Variables
- mon = peripheral.wrap("top")
- function draw()
- mon.clear()
- mon.setBackgroundColor(colors.black)
- mon.setCursorPos(8,1)
- mon.write("TSCraft Server")
- mon.setCursorPos(6,2)
- mon.write("Wither Arena Conrtol")
- mon.setCursorPos(3,5)
- mon.write("MFFS Converter")
- mon.setCursorPos(3,9)
- mon.write("MFFS Projector")
- end
- --Functions
- function writeButtons(_table)
- for i, v in pairs(_table) do
- mon.setCursorPos(v.x, v.y)
- mon.setTextColor(v.txtCol)
- mon.setBackgroundColor(v.bgCol)
- mon.write(v.text)
- end
- end
- function isValidClick(_table, mx, my)
- for i, v in pairs(_table) do
- if mx >= v.x and mx <= (v.x + #v.text) and my == v.y then
- return true, v.text
- end
- end
- return false, nil
- end
- --Program
- draw()
- writeButtons(t)
- rs.setOutput("left",true)--Turn on Charging by default
- while true do
- _, but, x, y = os.pullEvent("monitor_touch")
- bClick, option = isValidClick(t, x, y)
- if bClick then
- -- Yes, it's a valid click. Now let's do something with the returned text 'option'
- if option == "Charging" then
- rs.setOutput("left",true)
- elseif option == "Off" then
- rs.setOutput("left",false)
- elseif option == "Activate" then
- rs.setOutput("bottom",true)
- elseif option == "Deactivate" then
- rs.setOutput("bottom",false)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement