Stravides

MobController

Mar 15th, 2014
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.02 KB | None | 0 0
  1. --[[
  2. Mob Control Panel
  3. --]]
  4.  
  5. local mon = peripheral.wrap("top")
  6. mon.setTextScale(1)
  7. mon.setTextColor(colors.white)
  8. local button={}
  9. mon.setBackgroundColor(colors.black)
  10. rednet.open("bottom")
  11. wireside = "back"
  12. rs.setBundledOutput(wireside,0)
  13.  
  14. function setInvertTable(name, func, xmin, xmax, ymin, ymax)
  15.    button[name] = {}
  16.    button[name]["func"] = func
  17.    button[name]["active"] = true
  18.    button[name]["xmin"] = xmin
  19.    button[name]["ymin"] = ymin
  20.    button[name]["xmax"] = xmax
  21.    button[name]["ymax"] = ymax
  22. end
  23.          
  24. function setTable(name, func, xmin, xmax, ymin, ymax)
  25.    button[name] = {}
  26.    button[name]["func"] = func
  27.    button[name]["active"] = false
  28.    button[name]["xmin"] = xmin
  29.    button[name]["ymin"] = ymin
  30.    button[name]["xmax"] = xmax
  31.    button[name]["ymax"] = ymax
  32. end
  33.  
  34. --setwire
  35. function setwire (side, nColors, value)
  36.     current = redstone.getBundledOutput(side)
  37.         if onoff then
  38.                 rs.setBundledOutput(side, colors.subtract(current, nColors))
  39.         else
  40.                 rs.setBundledOutput(side, colors.combine(current, nColors))
  41.         end
  42.    
  43. end
  44.  
  45.  
  46. -- ====== WIRES ======
  47. function white()
  48.     setwire(wireside, colors.white, onoff)
  49. end
  50.  
  51. function orange()
  52.     setwire(wireside, colors.orange, onoff)
  53. end
  54. function magenta()
  55.     setwire(wireside, colors.magenta, onoff)
  56. end
  57. function lightblue()
  58.     setwire(wireside, colors.lightBlue, onoff)
  59. end
  60. function yellow()
  61.     setwire(wireside, colors.yellow, onoff)
  62. end
  63. function lime()
  64.     setwire(wireside, colors.lime, onoff)
  65. end
  66. function pink()
  67.     setwire(wireside, colors.pink, onoff)
  68. end
  69. function gray()
  70.     setwire(wireside, colors.gray, onoff)
  71. end
  72. function lightgray()
  73.     setwire(wireside, colors.lightGray, onoff)
  74. end
  75. function cyan()
  76.     setwire(wireside, colors.cyan, onoff)
  77. end
  78. function purple()
  79.     setwire(wireside, colors.purple, onoff)
  80. end
  81. function blue()
  82.     setwire(wireside, colors.blue, onoff)
  83. end
  84. function brown()
  85.     setwire(wireside, colors.brown, onoff)
  86. end
  87. function green()
  88.     setwire(wireside, colors.green, onoff)
  89. end
  90. function red()
  91.     setwire(wireside, colors.red, onoff)
  92. end
  93. function black()
  94.     setwire(wireside, colors.black, onoff)
  95. end
  96.  
  97. --[[ Button layout Map
  98.      A, B, C, D
  99.    
  100.      A       B
  101.      |       |
  102. C----+-------+----C
  103.      |       |
  104. D-----------------D
  105.      |       |
  106.      A       B
  107. --]]
  108.  
  109.  
  110. --Current layout requires a 5x3 advanced monitor setup
  111. function fillTable()
  112.     setInvertTable("Enderman", white, 5, 23, 3, 5)
  113.     setInvertTable("Enderman2", orange, 5, 23, 7, 9)
  114.     setInvertTable("WitherSkelly", magenta, 5, 23, 11, 13)
  115.     setInvertTable("Pigman", lightblue, 5, 23, 15, 17)
  116.  
  117. --[[ Not enough room with a 5x3 setup
  118.     setTable("Yellow", yellow, 5, 23, 19, 21)
  119.     setTable("Lime", lime, 5, 23, 23, 25)
  120.     setTable("Pink", pink, 5, 23, 27, 29)
  121.     setTable("Gray", gray, 5, 23, 31, 33)
  122. --]]
  123.     setTable("Lightgray", lightgray, 28, 46, 3, 5)
  124.     setTable("Cyan", cyan, 28, 46, 7, 9)
  125.     setTable("Refill Mob Essence", purple, 28, 46, 11, 13)
  126.     setTable("Toggle Floor", blue, 28, 46, 15, 17)
  127.  
  128. --[[Not enough room with a 5x3 setup
  129.     setTable("Brown", brown, 28, 46, 19, 21)
  130.     setTable("Green", green, 28, 46, 23, 25)
  131.     setTable("Red", red, 28, 46, 27, 29)
  132.     setTable("Black", black, 28, 46, 31, 33)
  133. --]]
  134. end    
  135.  
  136. function fill(text, color, bData)
  137.    mon.setBackgroundColor(color)
  138.    local yspot = math.floor((bData["ymin"] + bData["ymax"]) /2)
  139.    local xspot = math.floor((bData["xmax"] - bData["xmin"] - string.len(text)) /2) +1
  140.    for j = bData["ymin"], bData["ymax"] do
  141.       mon.setCursorPos(bData["xmin"], j)
  142.       if j == yspot then
  143.          for k = 0, bData["xmax"] - bData["xmin"] - string.len(text) +1 do
  144.             if k == xspot then
  145.                mon.write(text)
  146.             else
  147.                mon.write(" ")
  148.             end
  149.          end
  150.       else
  151.          for i = bData["xmin"], bData["xmax"] do
  152.             mon.write(" ")
  153.          end
  154.       end
  155.    end
  156.    mon.setBackgroundColor(colors.black)
  157. end
  158.      
  159. function screen()
  160.    local currColor
  161.    for name,data in pairs(button) do
  162.       local on = data["active"]
  163.       if on == true
  164.          then currColor = colors.lime
  165.               rednet.broadcast("ON")    
  166.          else currColor = colors.red
  167.               rednet.broadcast("OFF")
  168.       end
  169.       fill(name, currColor, data)
  170.        
  171.    end
  172. end
  173.      
  174. function checkxy(x, y)
  175.    for name, data in pairs(button) do
  176.       if y>=data["ymin"] and  y <= data["ymax"] then
  177.          if x>=data["xmin"] and x<= data["xmax"] then
  178. --          print(data["active"])
  179.             onoff = data["active"]
  180.             data["func"]()
  181.             data["active"] = not data["active"]
  182.             onoff = data["active"]
  183. --          print(data["active"])
  184.  --         print(name)
  185.          end
  186.       end
  187.    end
  188. end
  189.      
  190. function heading(text)
  191.    w, h = mon.getSize()
  192.    mon.setCursorPos((w-string.len(text))/2+1, 1)
  193.    mon.write(text)
  194. end
  195.      
  196. fillTable()
  197. while true do
  198.    mon.clear()
  199.    heading("Stravides Mob Farm Control Panel")
  200.    screen()
  201.    local e,side,x,y = os.pullEvent("monitor_touch")
  202.    print(x..":"..y)
  203.    checkxy(x,y)
  204.    sleep(.1)
  205. end
Advertisement
Add Comment
Please, Sign In to add comment