Advertisement
quantumr8

MainControlPanel

Feb 27th, 2021 (edited)
829
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.34 KB | None | 0 0
  1. API = require("buttonAPI")
  2. local component = require("component")
  3. local computer = require("computer")
  4. local term = require("term")
  5. local event = require("event")
  6. local side = require("sides")
  7. local gpu = component.gpu
  8.  
  9.  
  10.  
  11.  
  12. local colors = { blue = 0x4286F4, purple = 0xB673d6, red = 0xC14141, green = 0xDA841,
  13. black = 0x000000, white = 0xFFFFFF, grey = 0x47494C, lightGrey = 0xBBBBBB}
  14.  
  15. -- set size of the screen for lvl 3
  16. gpu.setResolution(132,38)
  17. gpu.setBackground(colors.black)
  18. gpu.fill(1, 1, 132, 38, " ")
  19.  
  20.  
  21. -- Redstone IO addresses
  22.  
  23. local configAddress = {}
  24. configAddress["oreMiner"] = "63a338c9-443f-43f9-8c10-33d920d8c511"
  25. configAddress["oreMiner2"] = "2b11e636-b5b0-4835-8f98-364d49235498"
  26. configAddress["resourceMiner"] = "34322d7a-01fa-4097-b067-3db2b1c179e0"
  27. configAddress["botanicMiner"] = "b7742cd6-7620-474a-b2ba-da710f6c73dc"
  28. configAddress["stone"] = "d39fae60-e7b5-4c4f-8952-4dc45e36bf37"
  29. configAddress["sand"] = "228d6623-7996-4637-9019-cf8eb797946c"
  30. configAddress["glass"] = "30f09a8b-e09b-455f-937c-ba275905b91f"
  31. configAddress["TBD"] = ""
  32.  
  33.  
  34. -- defninitions
  35.  
  36. local sections = {}
  37. local rsToggle1 = component.proxy(configAddress["oreMiner"])
  38. local rsToggle2 = component.proxy(configAddress["oreMiner2"])
  39. local rsToggle3 = component.proxy(configAddress["resourceMiner"])
  40. local rsToggle4 = component.proxy(configAddress["botanicMiner"])
  41. local rsToggle5 = component.proxy(configAddress["stone"])
  42. local rsToggle6 = component.proxy(configAddress["sand"])
  43. local rsToggle7 = component.proxy(configAddress["glass"])
  44. local rsToggle8 = component.proxy(configAddress["TBD"])
  45.  
  46.  
  47. -- functions
  48.  
  49. function clearTxt()
  50.  
  51.   gpu.setBackground(colors.black)
  52.   gpu.fill(1, 1, 25, 1, " ")
  53.  
  54. end
  55.  
  56.  
  57. function setSections()
  58.  
  59.   sections["left"] = { x = 4, y = 3, width = 60, height= 12, title = "  MOB FARM(WIP)  "}
  60.   sections["right"] = { x = 70, y = 3, width = 60, height = 22, title = "  RESOURCES  "}
  61.   sections["bottom-left"] = { x = 4, y = 17, width = 60, height = 20, title = "  SECURITY  "}
  62.   sections["bottom-right"] = { x = 70, y = 27, width = 60, height = 10, title = "  OTHER  "}
  63.  
  64. end
  65.  
  66.  
  67. function setButtons()
  68.  
  69.   API.setTable("mob1", mobAllOn, 9, 5, 31, 8, "ALL ON", {on = colors.green, off = colors.blue})
  70.   API.setTable("mob2", mobAllOff, 9, 10, 31, 13, "ALL OFF", {on = colors.red, off = colors.blue})
  71.   API.setTable("mob3", mobNormal, 36, 5, 58, 8, "Normal Op", {on = colors.red, off = colors.green})
  72.   API.setTable("mob4", mobWither, 36, 10, 58, 13, "Wither", {on = colors.purple, off = colors.blue})
  73.  
  74.  
  75.   API.setTable("resource1", oreMiner, 75, 5, 96, 8, "Ore Miner", {on = colors.red, off = colors.green})
  76.   API.setTable("resource2", oreMiner2, 75, 10, 96, 13, "Ore Miner 2", {on = colors.red, off = colors.green})
  77.   API.setTable("resource3", resourceMiner, 75, 15, 96, 18, "Resource Miner", {on = colors.red, off = colors.green})
  78.   API.setTable("resource4", botanicMiner, 75, 20, 96, 23, "Botanic Miner", {on = colors.red, off = colors.green})
  79.  
  80.   API.setTable("resource5", stoneGen, 102, 5, 123, 8, "Stone Generator", {on = colors.red, off = colors.green})
  81.   API.setTable("resource6", sandGen, 102, 10, 123, 13, "Sand Generator", {on = colors.red, off = colors.green})
  82.   API.setTable("resource7", glassGen, 102, 15, 123, 18, "Glass Generator", {on = colors.red, off = colors.green})
  83.   API.setTable("resource8", TBD, 102, 20, 123, 23, "TBD", {on = colors.red, off = colors.green})
  84.  
  85.  
  86. end
  87.  
  88.  
  89. function printBorders(sectionName)
  90.  
  91.   local s = sections[sectionName]
  92.   -- set border
  93.   gpu.setBackground(colors.grey)
  94.   gpu.fill(s.x, s.y, s.width, 1, " ")
  95.   gpu.fill(s.x, s.y, 1, s.height, " ")
  96.   gpu.fill(s.x, s.y + s.height, s.width, 1, " ")
  97.   gpu.fill(s.x + s.width, s.y, 1, s.height + 1, " ")
  98.   -- set title
  99.   gpu.setBackground(colors.black)
  100.   gpu.set(s.x + 2, s.y, s.title)
  101.  
  102. end
  103.  
  104. function getMobStatus(name)
  105.  
  106.   --Code for getting status form mob control computer
  107.  
  108. end
  109.  
  110. function updateButtons()
  111.  
  112.   if ((getMobStatus("bay16") == true and API.getState("mob4") == false) or (getMobStatus("bay16") == false and API.getState("mob4") == true)) then
  113.  
  114.     API.toggleButton("mob4")
  115.  
  116.   end
  117.  
  118. end
  119.  
  120.  
  121. function mobAllOn()
  122.  
  123.   API.flash("mob1", 0.15)
  124.   --Send signal here
  125.  
  126. end
  127.  
  128.  
  129. function mobAllOff()
  130.  
  131.   API.flash("mob2", 0.15)
  132.   --Send signal here
  133.  
  134. end
  135.  
  136.  
  137. function mobNormal()
  138.  
  139.   API.toggleButton("mob3")
  140.   if API.getState("mob3") == true then
  141.  
  142.     --Send on signal
  143.  
  144.   else
  145.  
  146.     --Send off signal
  147.  
  148.   end
  149.  
  150. end
  151.  
  152.  
  153. function mobWither()
  154.  
  155.   API.toggleButton("mob4")
  156.   if API.getState("mob4") == true then
  157.  
  158.     --Send on signal
  159.  
  160.   else
  161.  
  162.     --Send off signal
  163.  
  164.   end
  165.  
  166. end
  167.  
  168.  
  169. function oreMiner()
  170.  
  171.   API.toggleButton("resource1")
  172.   if API.getState("resource1") == true then
  173.  
  174.     rsToggle1.setOutput(side.top, 0)
  175.  
  176.   else
  177.  
  178.     rsToggle1.setOutput(side.top, 15)
  179.  
  180.   end
  181.  
  182. end
  183.  
  184.  
  185. function oreMiner2()
  186.  
  187.   API.toggleButton("resource2")
  188.   if API.getState("resource2") == true then
  189.  
  190.     rsToggle2.setOutput(side.top, 0)
  191.  
  192.   else
  193.  
  194.     rsToggle2.setOutput(side.top, 15)
  195.  
  196.   end
  197.  
  198. end
  199.  
  200.  
  201. function resourceMiner()
  202.  
  203.   API.toggleButton("resource3")
  204.   if API.getState("resource3") == true then
  205.  
  206.     rsToggle3.setOutput(side.top, 0)
  207.  
  208.   else
  209.  
  210.     rsToggle3.setOutput(side.top, 15)
  211.  
  212.   end
  213.  
  214. end
  215.  
  216. function botanicMiner()
  217.  
  218.   API.toggleButton("resource4")
  219.   if API.getState("resource4") == true then
  220.  
  221.     rsToggle4.setOutput(side.top, 0)
  222.  
  223.   else
  224.  
  225.     rsToggle4.setOutput(side.top, 15)
  226.  
  227.   end
  228.  
  229. end
  230.  
  231.  
  232. function stoneGen()
  233.  
  234.   API.toggleButton("resource5")
  235.   if API.getState("resource5") == true then
  236.  
  237.     rsToggle5.setOutput(side.south, 15)
  238.  
  239.   else
  240.  
  241.     rsToggle5.setOutput(side.south, 0)
  242.  
  243.   end
  244.  
  245. end
  246.  
  247.  
  248. function sandGen()
  249.  
  250.   API.toggleButton("resource6")
  251.   if API.getState("resource6") == true then
  252.  
  253.     rsToggle6.setOutput(side.south, 15)
  254.  
  255.   else
  256.  
  257.     rsToggle6.setOutput(side.south, 0)
  258.  
  259.   end
  260.  
  261. end
  262.  
  263.  
  264. function glassGen()
  265.  
  266.   API.toggleButton("resource7")
  267.   if API.getState("resource7") == true then
  268.  
  269.     rsToggle7.setOutput(side.south, 15)
  270.  
  271.   else
  272.  
  273.     rsToggle7.setOutput(side.south, 0)
  274.  
  275.   end
  276.  
  277. end
  278.  
  279.  
  280. function TBD()
  281.  
  282.   API.toggleButton("resource8")
  283.   if API.getState("resource8") == true then
  284.  
  285.     rsToggle8.setOutput(side.top, 15)
  286.  
  287.   else
  288.  
  289.     rsToggle8.setOutput(side.top, 0)
  290.  
  291.   end
  292.  
  293. end
  294.  
  295.  
  296. function updateResources()
  297.  
  298.   if ((rsToggle1.getOutput(side.top) == 0 and API.getState("resource1") == false) or (rsToggle1.getOutput(side.top) == 15 and API.getState("resource1") == true)) then
  299.     API.toggleButton("resource1")
  300.   end
  301.  
  302.   if ((rsToggle2.getOutput(side.top) == 0 and API.getState("resource2") == false) or (rsToggle2.getOutput(side.top) == 15 and API.getState("resource2") == true)) then
  303.     API.toggleButton("resource2")
  304.   end
  305.  
  306.   if ((rsToggle3.getOutput(side.top) == 0 and API.getState("resource3") == false) or (rsToggle3.getOutput(side.top) == 15 and API.getState("resource3") == true)) then
  307.     API.toggleButton("resource3")
  308.   end
  309.  
  310.   if ((rsToggle4.getOutput(side.top) == 0 and API.getState("resource4") == false) or (rsToggle4.getOutput(side.top) == 15 and API.getState("resource4") == true)) then
  311.     API.toggleButton("resource4")
  312.   end
  313.  
  314.   if ((rsToggle5.getOutput(side.south) == 15 and API.getState("resource5") == false) or (rsToggle5.getOutput(side.south) == 0 and API.getState("resource5") == true)) then
  315.     API.toggleButton("resource5")
  316.   end
  317.  
  318.   if ((rsToggle6.getOutput(side.south) == 15 and API.getState("resource6") == false) or (rsToggle6.getOutput(side.south) == 0 and API.getState("resource6") == true)) then
  319.     API.toggleButton("resource6")
  320.   end
  321.  
  322.   if ((rsToggle7.getOutput(side.south) == 15 and API.getState("resource7") == false) or (rsToggle7.getOutput(side.south) == 0 and API.getState("resource7") == true)) then
  323.     API.toggleButton("resource7")
  324.   end
  325.  
  326. end
  327.  
  328.  
  329. function getClick()
  330.  
  331.   local _, _, x, y = event.pull(1,touch)
  332.   if x == nil or y == nil then
  333.  
  334.     local h, w = gpu.getResolution()
  335.     gpu.set(h, w, ".")
  336.     gpu.set(h, w, " ")
  337.  
  338.   else
  339.  
  340.     API.checkxy(_,_,x,y,_,_)
  341.  
  342.   end
  343.  
  344. end
  345.  
  346.  
  347. function startup()
  348.  
  349.   term.setCursorBlink(false)
  350.   setSections()
  351.   setButtons()
  352.   API.screen()
  353.   API.heading("Mob Spawner Control Panel")
  354.   for name, data in pairs(sections) do
  355.    
  356.     printBorders(name)
  357.    
  358.   end
  359.   updateResources()
  360.  
  361. end
  362.  
  363.  
  364. -- starting
  365.  
  366. startup()
  367.  
  368. while true do
  369.   getClick()
  370. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement