Advertisement
Xylem_Gaming

Reactor Ver2

Mar 31st, 2016
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.76 KB | None | 0 0
  1. --[[
  2. This is the variables for the reactor function
  3. ]]
  4.  
  5. mon = peripheral.wrap("top")
  6. --if mon ~= nil then
  7.   local term = mon
  8. --end
  9.  
  10. max = 10000000
  11.  
  12. reactor1 = peripheral.wrap("BigReactors-Reactor_3")
  13. reactor2 = peripheral.wrap("")
  14. reactor3 = peripheral.wrap("")
  15. reactor4 = peripheral.wrap("")
  16.  
  17. --[[
  18. Variables for the main program, please do not touch
  19. ]]
  20. allToggle = true
  21. option = true
  22. x,y = term.getSize()
  23. running = true
  24. index = 1
  25.  
  26. default = {
  27. background = "black",
  28. textC = "white"
  29. }
  30.  
  31. button = {
  32. button1 = {text = "Back",bx = 1, by = y},
  33. button2 = {text = "Overview", bx = math.floor((x/2)-(string.len("Overview")/2)), by = y},
  34. button3 = {text = "Next",bx = x-string.len("Next")+1, by = y},
  35. button4 = {text = "Single",bx = math.floor((x/2)-(string.len("Single")/2)), by = y}
  36. }
  37. buttonSize = table.getn(button)
  38. local function drawButton(state1,state2,state3,state4,colour)
  39.   if colour == nil then colour = "red" end
  40.   term.setBackgroundColour(colours[colour])
  41.   if state1 then
  42.     term.setCursorPos(button.button1.bx,button.button1.by)
  43.     term.write(button.button1.text)
  44.   end
  45.   if state2 then
  46.     term.setCursorPos(button.button2.bx,button.button2.by)
  47.     term.write(button.button2.text)
  48.   end
  49.   if state3 then
  50.     term.setCursorPos(button.button3.bx,button.button3.by)
  51.     term.write(button.button3.text)
  52.   end
  53.   if state4 then
  54.     term.setCursorPos(button.button4.bx,button.button4.by)
  55.     term.write(button.button4.text)
  56.   end
  57.   term.setBackgroundColour(colours[default.background])
  58. end
  59.  
  60. local function flashButton(b)
  61.   if b == 1 then drawButton(true,false,false,false,"green") end
  62.   if b == 2 then drawButton(false,true,false,false,"green") end
  63.   if b == 3 then drawButton(false,false,true,false,"green") end
  64.   if b == 4 then drawButton(false,false,false,true,"green") end
  65.   sleep(0.25)
  66.   drawButton(true,true,true)
  67. end
  68.  
  69. local function clearScreen()
  70.   for i = 1,y-1 do
  71.     term.setCursorPos(1,i)
  72.     term.clearLine()
  73.   end
  74. end
  75.  
  76. term.clear()
  77.  
  78. local function printBar(x,y,val,per)
  79.   term.setCursorPos(x,y)
  80.   term.setBackgroundColour(colours[default.background])
  81.   term.clearLine()
  82.   term.setBackgroundColour(colours.red)
  83.   for i = 1,25 do
  84.     term.write(" ")
  85.   end
  86.   term.setCursorPos(x,y)
  87.   term.setBackgroundColour(colours.green)
  88.   for i = 1,val do
  89.     term.write(" ")
  90.   end
  91.   term.setBackgroundColour(colours[default.background])
  92.   term.setCursorPos(x+26,y)
  93.   term.write(per.."%")  
  94. end
  95.  
  96.  
  97. act2 = false
  98. act3 = false
  99. act4 = false
  100.  
  101. function printReactor()
  102.   while running do
  103.     act1 = reactor1.getActive()
  104.     cur1 = reactor1.getEnergyStored()
  105.     pert1 = math.floor((cur1/max)*100)
  106.     per1 = math.floor(pert1/4)
  107.     cur2 = 0
  108.     pert2 = math.floor((cur2/max)*100)
  109.     per2 = math.floor(pert2/4)
  110.     cur3 = 0
  111.     pert3 = math.floor((cur3/max)*100)
  112.     per3 = math.floor(pert3/4)
  113.     cur4 = 0
  114.     pert4 = math.floor((cur4/max)*100)
  115.     per4 = math.floor(pert4/4)
  116.     rft1 = reactor1.getEnergyProducedLastTick()
  117.     rft2 = 0
  118.     rft3 = 0
  119.     rft4 = 0
  120.     if option then
  121.       clearScreen()
  122.       term.setTextColour(colours.yellow)
  123.       term.setCursorPos(1,1)
  124.       term.write("OVERVIEW MODE")
  125.       term.setTextColour(colours[default.textC])
  126.       term.setCursorPos(1,3)
  127.  
  128.       term.setTextColour(colours.orange)
  129.       term.write("Reactor 1: ")
  130.       term.setTextColour(colours[default.textC])
  131.       term.write(rft1.." RF/t")
  132.       if act1 then
  133.         term.setTextColour(colours.green)
  134.         term.setCursorPos(1,4)
  135.         term.write("Online")
  136.       else
  137.         term.setTextColour(colours.red)
  138.         term.setCursorPos(1,4)
  139.         term.write("Offline")
  140.       end
  141.       term.setTextColour(colours[default.textC])
  142.       printBar(1,5,per1,pert1)
  143.       term.setCursorPos(1,6)
  144.  
  145.       term.setTextColour(colours.orange)
  146.       term.write("Reactor 2: ")
  147.       term.setTextColour(colours[default.textC])
  148.       term.write(rft2.." RF/t")
  149.       if act2 then
  150.         term.setTextColour(colours.green)
  151.         term.setCursorPos(1,7)
  152.         term.write("Online")
  153.       else
  154.         term.setTextColour(colours.red)
  155.         term.setCursorPos(1,7)
  156.         term.write("Offline")
  157.       end
  158.       term.setTextColour(colours[default.textC])
  159.       printBar(1,8,per2,pert2)
  160.       term.setCursorPos(1,9)
  161.  
  162.       term.setTextColour(colours.orange)
  163.       term.write("Reactor 3: ")
  164.       term.setTextColour(colours[default.textC])
  165.       term.write(rft3.." RF/t")
  166.       if act3 then
  167.         term.setTextColour(colours.green)
  168.         term.setCursorPos(1,10)
  169.         term.write("Online")
  170.       else
  171.         term.setTextColour(colours.red)
  172.         term.setCursorPos(1,10)
  173.         term.write("Offline")
  174.       end
  175.       term.setTextColour(colours[default.textC])
  176.       printBar(1,11,per3,pert3)
  177.       term.setCursorPos(1,12)
  178.  
  179.       term.setTextColour(colours.orange)
  180.       term.write("Reactor 4: ")
  181.       term.setTextColour(colours[default.textC])
  182.       term.write(rft4.." RF/t")
  183.       if act4 then
  184.         term.setTextColour(colours.green)
  185.         term.setCursorPos(1,13)
  186.         term.write("Online")
  187.       else
  188.         term.setTextColour(colours.red)
  189.         term.setCursorPos(1,13)
  190.         term.write("Offline")
  191.       end
  192.       term.setTextColour(colours[default.textC])
  193.       printBar(1,14,per4,pert4)
  194.      
  195.       term.setCursorPos(1,16)
  196.       if allToggle then
  197.         term.setBackgroundColour(colours.red)
  198.       else
  199.         term.setBackgroundColour(colours.green)
  200.       end
  201.       term.write("Toggle All")
  202.       term.setBackgroundColour(colours[default.background])
  203.     else
  204.       --SINGLE MODE
  205.       clearScreen()
  206.       term.setCursorPos(1,1)
  207.       term.setBackgroundColour(colours[default.background])
  208.       term.setTextColour(colours.yellow)
  209.       term.write("Reactor: "..index)
  210.       term.setBackgroundColour(colours[colour])
  211.       term.setTextColour(colours[default.textC])
  212.       term.setBackgroundColour(colours[default.background])
  213.       if index == 1 then
  214.         --cur1 = reactor1.getEnergyStored()
  215.         term.setCursorPos(1,3)
  216.         term.write("RF Stored: "..cur1.."/"..max)
  217.         printBar(1,4,per1,pert1)
  218.         term.setCursorPos(1,6)
  219.         term.write("Core Temperature: ")
  220.         term.setCursorPos(1,8)
  221.         term.write("Waste Produced (MB/t): ")
  222.         term.setCursorPos(1,10)
  223.         term.write("Fuel Rod Insertion: ")
  224.       elseif index == 2 then
  225.         term.setCursorPos(1,3)
  226.         term.write("RF Stored: "..cur2.."/"..max)
  227.         printBar(1,3,per2,pert2)
  228.       elseif index == 3 then
  229.         term.setCursorPos(1,3)
  230.         term.write("RF Stored: "..cur3.."/"..max)
  231.         printBar(1,3,per3,pert3)
  232.       elseif index == 4 then
  233.         term.setCursorPos(1,3)
  234.         term.write("RF Stored: "..cur4.."/"..max)
  235.         printBar(1,3,per4,pert4)
  236.       end
  237.     end
  238.     sleep(1)
  239.   end
  240. end
  241.  
  242. function gui()
  243.   while running do
  244.     if option then
  245.       drawButton(false,false,false,true)
  246.     else
  247.       if index == 1 then
  248.        drawButton(false,true,true,false)
  249.       elseif index == 4 then
  250.         drawButton(true,true,false,false)
  251.       else
  252.         drawButton(true,true,true,false)
  253.       end
  254.     end
  255.     event, param1, param2, param3 = os.pullEvent()
  256.     if event == "mouse_click" then
  257.       if param2 >= button.button1.bx and param2 <= (button.button1.bx + #button.button1.text) and param3 == button.button1.by and index ~= 1 and option == false then
  258.         flashButton(1)
  259.         index = index - 1
  260.         clearScreen()
  261.       elseif param2 >= button.button2.bx and param2 <= (button.button2.bx + #button.button2.text) and param3 == button.button2.by and option == false then
  262.         flashButton(2)
  263.         option = true
  264.       elseif param2 >= button.button3.bx and param2 <= (button.button3.bx + #button.button3.text) and param3 == button.button3.by and index ~= 4 and option == false then
  265.         flashButton(3)
  266.         index = index + 1
  267.         clearScreen()
  268.       elseif param2 >= button.button4.bx and param2 <= (button.button4.bx + #button.button4.text) and param3 == button.button4.by and option == true then
  269.         flashButton(4)
  270.         option = false
  271.       elseif param2 >= 1 and param2 <= 1+string.len("Toggle All") and param3 == 16 then
  272.         if allToggle then
  273.           allToggle = false
  274.           act1 = true
  275.           act2 = true
  276.           act3 = true
  277.           act4 = true
  278.         else
  279.           allToggle = true
  280.           act1 = false
  281.           act2 = false
  282.           act3 = false
  283.           act4 = false
  284.         end
  285.       end
  286.     elseif event == "key" then
  287.         if param1 == keys.y then
  288.           running = false
  289.           term.setBackgroundColour(colours[default.background])
  290.           term.clear()
  291.           term.setCursorPos(1,1)
  292.         end
  293.     end
  294.   term.setCursorPos(1,y)
  295.   term.clearLine()
  296.   end
  297. end
  298.  
  299. parallel.waitForAny(gui,printReactor)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement