Advertisement
Griffen8280

Wither Arena Control

Feb 22nd, 2013
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.92 KB | None | 0 0
  1. --Declare a table with the buttons that will be printed,
  2. --with it's own Text Colour and Background Colour and
  3. --unique x and y values.
  4.  
  5. --Table Variables
  6.  
  7. t = {
  8.     {text = "Charging"   , x = 1,  y = 7,  txtCol = colors.green, bgCol = colors.blue},
  9.     {text = "Off"        , x = 10, y = 7,  txtCol = colors.red  , bgCol = colors.blue},
  10.     {text = "Activate"   , x = 1,  y = 11, txtCol = colors.green, bgCol = colors.blue},
  11.     {text = "Deactivate" , x = 10, y = 11, txtCol = colors.red  , bgCol = colors.blue}
  12. }
  13.  
  14. --Monitor Variables
  15.  
  16. mon = peripheral.wrap("top")
  17.  
  18. function draw()
  19. mon.clear()
  20. mon.setBackgroundColor(colors.black)
  21. mon.setCursorPos(8,1)
  22. mon.write("TSCraft Server")
  23. mon.setCursorPos(6,2)
  24. mon.write("Wither Arena Conrtol")
  25. mon.setCursorPos(3,5)
  26. mon.write("MFFS Converter")
  27. mon.setCursorPos(3,9)
  28. mon.write("MFFS Projector")
  29. end
  30.  
  31. --Functions
  32.  
  33. function writeButtons(_table)
  34.     for i, v in pairs(_table) do
  35.         mon.setCursorPos(v.x, v.y)
  36.         mon.setTextColor(v.txtCol)
  37.         mon.setBackgroundColor(v.bgCol)
  38.         mon.write(v.text)
  39.     end
  40. end
  41.  
  42. function isValidClick(_table, mx, my)
  43.  
  44.     for i, v in pairs(_table) do
  45.         if mx >= v.x and mx <= (v.x + #v.text) and my == v.y then
  46.              return true, v.text
  47.         end
  48.     end
  49.     return false, nil
  50. end
  51.  
  52. --Program
  53.  
  54. draw()
  55. writeButtons(t)
  56. rs.setOutput("left",true)--Turn on Charging by default
  57.  
  58. while true do
  59.     _, but, x, y = os.pullEvent("monitor_touch")
  60.     bClick, option = isValidClick(t, x, y)
  61.     if bClick then
  62.     -- Yes, it's a valid click. Now let's do something with the returned text 'option'
  63.       if option == "Charging" then
  64.        rs.setOutput("left",true)
  65.       elseif option == "Off" then
  66.         rs.setOutput("left",false)
  67.       elseif option == "Activate" then
  68.        rs.setOutput("bottom",true)
  69.       elseif option == "Deactivate" then
  70.        rs.setOutput("bottom",false)
  71.       end
  72.    end
  73. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement