Evdev

dev_reactor

Jul 16th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --  BigReactor Control
  2. --  by jaranvil aka jared314
  3. --
  4. --  feel free to use and/or modify this code
  5. --
  6. -----------------------------------------------
  7. --Reactor Control - Version History
  8. --
  9. --  Version 2.4 - in development
  10. --      to-dos
  11. --          - Multible reactors
  12. --          - Ender IO support
  13. --      - dynamic monitor size
  14.  --     - adjustable text scales 0.5 or 1
  15.  --     - adjustable refresh rate
  16. --
  17. --  Version 2.3 - April 23/15
  18. --    - First update in awhile
  19. --    - lots of minor fixes and improvments
  20. --    - New loading and setup search with automated peripheral search
  21. --    - Changes to the update methods
  22.  
  23. -----------------------------------------------
  24.  
  25. local version = 3.0
  26. --is auto power enabled
  27. local auto_string = false
  28. --auto on value
  29. local on = 0
  30. --auto off value
  31. local off = 99
  32. --is auto control rods enabled
  33. local auto_rods = false
  34. --control rod auto value
  35. local auto_rf = 0
  36. local mainPower = false
  37.  
  38. --peripherals
  39. local reactor
  40. local reactors = {}
  41. local mon
  42.  
  43. --monitor size
  44. local monX
  45. local monY
  46.  
  47. local splitScreen = false
  48.  
  49. local settingsOffset = 14
  50.  
  51. local panel1Tool = 1
  52. local panel2Tool = 2
  53. local toolsTool = 1
  54. local currentInfoPage = 0
  55.  
  56. -- new settings
  57. -- need to be saved to config!
  58. local refresh = 1
  59. local energyStorageSetting = 1
  60.  
  61. -- button positions
  62. local powerX = 0
  63. local powerX2 = 0
  64. local optionsX = 0
  65. local optionsX2 = 0
  66. local infoX = 0
  67. local infoX2 = 0
  68. local bufferBtn = {}
  69. local enderBtn = {}
  70. local thermalBtn = {}
  71. local refreshUpBtn = {}
  72. local refreshDownBtn = {}
  73. local autoPowerBtn = {}
  74. local offDownBtn = {}
  75. local offUpBtn = {}
  76. local onDownBtn = {}
  77. local onUpBtn = {}
  78. local mainPowerBtn = {}
  79. local lastReactorBtn = {}
  80. local nextReactorBtn = {}
  81.  
  82.  
  83. term.clear()
  84. -------------------FORMATTING-------------------------------
  85. function clear()
  86.   mon.setBackgroundColor(colors.black)
  87.   mon.clear()
  88.   mon.setCursorPos(1,1)
  89. end
  90.  
  91. --display text on computer's terminal screen
  92. function draw_text_term(x, y, text, text_color, bg_color)
  93.   term.setTextColor(text_color)
  94.   term.setBackgroundColor(bg_color)
  95.   term.setCursorPos(x,y)
  96.   write(text)
  97. end
  98.  
  99. --display text text on monitor, "mon" peripheral
  100. function draw_text(x, y, text, text_color, bg_color)
  101.   mon.setBackgroundColor(bg_color)
  102.   mon.setTextColor(text_color)
  103.   mon.setCursorPos(x,y)
  104.   mon.write(text)
  105. end
  106.  
  107. --draw line on computer terminal
  108. function draw_line(x, y, length, color)
  109.     mon.setBackgroundColor(color)
  110.     mon.setCursorPos(x,y)
  111.     mon.write(string.rep(" ", length))
  112. end
  113.  
  114. --draw line on computer terminal
  115. function draw_line_term(x, y, length, color)
  116.     term.setBackgroundColor(color)
  117.     term.setCursorPos(x,y)
  118.     term.write(string.rep(" ", length))
  119. end
  120.  
  121. --create progress bar
  122. --draws two overlapping lines
  123. --background line of bg_color
  124. --main line of bar_color as a percentage of minVal/maxVal
  125. function progress_bar(x, y, length, minVal, maxVal, bar_color, bg_color, text)
  126.   draw_line(x, y, length, bg_color) --backgoround bar
  127.   local barSize = math.floor((minVal/maxVal) * length)
  128.   draw_line(x, y, barSize, bar_color) --progress so far
  129.  
  130.   txtIndent = indent(length, text)
  131.   if barSize >= txtIndent then
  132.     draw_text(x + txtIndent, y, text, colors.black, bar_color)
  133.   else
  134.     draw_text(x + txtIndent, y, text, colors.white, bg_color)
  135.   end
  136. end
  137.  
  138. --same as above but on the computer terminal
  139. function progress_bar_term(x, y, length, minVal, maxVal, bar_color, bg_color)
  140.   draw_line_term(x, y, length, bg_color) --backgoround bar
  141.   local barSize = math.floor((minVal/maxVal) * length)
  142.   draw_line_term(x, y, barSize, bar_color)  --progress so far
  143. end
  144.  
  145. --create button on monitor
  146. function button(x, y, length, text, txt_color, bg_color)
  147.   draw_line(x, y, length, bg_color)
  148.   draw_text((x+2), y, text, txt_color, bg_color)
  149. end
  150.  
  151. --header and footer bars on monitor
  152. function menu_bar()
  153.   draw_line(1, 1, monX, colors.blue)
  154.   draw_text(2, 1, "Power    Tools    Settings", colors.white, colors.blue)
  155.   draw_line(1, monY, monX, colors.blue)
  156.   draw_text((monX/2)-7, monY, "     Reactor Control", colors.white, colors.blue)
  157. end
  158.  
  159. function menu_bar_controller()
  160.   draw_line(1, 1, monX, colors.blue)
  161.   draw_text((monX/2)-9, 1, "Connected Reactors", colors.white, colors.blue)
  162.  
  163.   -- Main Menu buttons
  164.   local toolsY = monY-11
  165.   if splitScreen then
  166.     -- line between panels
  167.     draw_line(1, toolsY, monX/2-1, colors.blue)
  168.     draw_text(monX/2, toolsY, "|", colors.blue, colors.black)
  169.     draw_line(monX/2+1, toolsY, monX/2, colors.blue)
  170.    
  171.     col = monX/2
  172.     colCol = col/3
  173.     powerX = indent(colCol, "power")
  174.     infoX = colCol + indent(colCol, "info")
  175.     optionsX = colCol*2 + indent(colCol, "options")
  176.     powerX2 = col + indent(colCol, "power")
  177.     infoX2 = col + colCol + indent(colCol, "info")
  178.     optionsX2 = col + colCol*2 + indent(colCol, "options")
  179.    
  180.    
  181.  
  182.     -- Panel 1
  183.     if panel1Tool == 1 then
  184.  
  185.       draw_line(1, toolsY, colCol, colors.white)
  186.       draw_text(powerX,toolsY, "Power", colors.black, colors.white)
  187.     else
  188.       draw_text(powerX,toolsY, "Power", colors.white, colors.blue)
  189.     end
  190.     if panel1Tool == 2 then
  191.       draw_line(colCol, toolsY, colCol, colors.white)
  192.       draw_text(infoX,toolsY, "Info", colors.black, colors.white)
  193.     else
  194.       draw_text(infoX,toolsY, "Info", colors.white, colors.blue)
  195.     end
  196.     if panel1Tool == 3 then
  197.       draw_line(colCol*2, toolsY, colCol, colors.white)
  198.       draw_text(optionsX,toolsY, "Options", colors.black, colors.white)
  199.     else
  200.       draw_text(optionsX,toolsY, "Options", colors.white, colors.blue)
  201.     end
  202.    
  203.     -- Panel 2
  204.     if panel2Tool == 1 then
  205.       draw_line(colCol*3+1, toolsY, colCol-1, colors.white)
  206.       draw_text(powerX2,toolsY, "Power", colors.black, colors.white)
  207.     else
  208.       draw_text(powerX2,toolsY, "Power", colors.white, colors.blue)
  209.     end
  210.     if panel2Tool == 2 then
  211.       draw_line(colCol*4, toolsY, colCol, colors.white)
  212.       draw_text(infoX2,toolsY, "Info", colors.black, colors.white)
  213.     else
  214.       draw_text(infoX2,toolsY, "Info", colors.white, colors.blue)
  215.     end
  216.     if panel2Tool == 3 then
  217.       draw_line(colCol*5, toolsY, colCol, colors.white)
  218.       draw_text(optionsX2,toolsY, "Options", colors.black, colors.white)
  219.     else
  220.       draw_text(optionsX2,toolsY, "Options", colors.white, colors.blue)
  221.     end
  222.  
  223.   else
  224.     draw_line(1, toolsY, monX, colors.blue)
  225.     col = monX/3
  226.     powerX = indent(col, "power")
  227.     infoX = col + indent(col, "info")
  228.     optionsX = col*2 + indent(col, "options")
  229.     if panel1Tool == 1 then
  230.       draw_line(0, toolsY, col, colors.white)
  231.       draw_text(powerX,toolsY, "Power", colors.blue, colors.white)
  232.     else
  233.       draw_text(powerX,toolsY, "Power", colors.white, colors.blue)
  234.     end
  235.     if panel1Tool == 2 then
  236.       draw_line(col, toolsY, col, colors.white)
  237.       draw_text(infoX,toolsY, "Info", colors.blue, colors.white)
  238.     else
  239.       draw_text(infoX,toolsY, "Info", colors.white, colors.blue)
  240.     end
  241.     if panel1Tool == 3 then
  242.       draw_line(col*2, toolsY, col, colors.white)
  243.       draw_text(optionsX,toolsY, "Options", colors.blue, colors.white)
  244.     else
  245.       draw_text(optionsX,toolsY, "Options", colors.white, colors.blue)
  246.     end
  247.   end
  248.  
  249.  
  250. end
  251.  
  252. --dropdown menu for power options
  253. function power_menu()
  254.   draw_line(1, 2, 9, colors.gray)
  255.   draw_line(1, 3, 9, colors.gray)
  256.   draw_line(1, 4, 9, colors.gray)
  257.   if active then
  258.     draw_text(2, 2, "ON", colors.lightGray, colors.gray)
  259.     draw_text(2, 3, "OFF", colors.white, colors.gray)
  260.   else
  261.     draw_text(2, 2, "ON", colors.white, colors.gray)
  262.     draw_text(2, 3, "OFF", colors.lightGray, colors.gray)
  263.   end
  264.   draw_text(2, 4, "Auto", colors.white, colors.gray)
  265. end
  266.  
  267. --dropbox menu for tools
  268. function tools_menu()
  269.   draw_line(10, 2, 14, colors.gray)
  270.   draw_line(10, 3, 14, colors.gray)
  271.   draw_line(10, 4, 14, colors.gray)
  272.   draw_line(10, 5, 14, colors.gray)
  273.   draw_text(11, 2, "Control Rods", colors.white, colors.gray)
  274.   draw_text(11, 3, "Efficiency", colors.white, colors.gray)
  275.   draw_text(11, 4, "Fuel", colors.white, colors.gray)
  276.   draw_text(11, 5, "Waste", colors.white, colors.gray)
  277. end
  278.  
  279. --dropdown menu for settings
  280. function settings_menu()
  281.   draw_line(12, 2, 18, colors.gray)
  282.   draw_line(12, 3, 18, colors.gray)
  283.   draw_text(13, 2, "Check for Updates", colors.white, colors.gray)
  284.   draw_text(13, 3, "Reset peripherals", colors.white, colors.gray)
  285. end
  286.  
  287. --basic popup screen with title bar and exit button
  288. function popup_screen(y, title, height)
  289.   clear()
  290.   menu_bar()
  291.  
  292.   draw_line(4, y, 22, colors.blue)
  293.   draw_line(25, y, 1, colors.red)
  294.  
  295.   for counter = y+1, height+y do
  296.     draw_line(4, counter, 22, colors.white)
  297.   end
  298.  
  299.   draw_text(25, y, "X", colors.white, colors.red)
  300.   draw_text(5, y, title, colors.white, colors.blue)
  301. end
  302.  
  303.  
  304. ------------------------END FORMATTING--------------------------
  305.  
  306. -- Main Screen
  307. function controller()
  308.   -- resolution
  309.   mon.setTextScale(1)
  310.  
  311.   -- main loop
  312.   while true do
  313.     clear()
  314.     menu_bar_controller()
  315.     terminal_screen()
  316.     monX, monY = mon.getSize()
  317.     if monX > 50 then
  318.       splitScreen = true
  319.     else
  320.       splitScreen = false
  321.     end
  322.    
  323.     -- 6 header colums
  324.     col = monX/6
  325.     headerY = 3
  326.    
  327.     draw_text(indent(col, "reactor") , headerY, "Reactor", colors.white, colors.black)
  328.     draw_text(col+indent(col, "Power") , headerY, "Power", colors.white, colors.black)
  329.     draw_text((col*2)+indent(col, "rf/t"), headerY, "RF/t", colors.white, colors.black)
  330.     draw_text((col*3)+indent(col, "temp"), headerY, "Temp", colors.white, colors.black)
  331.     draw_text((col*4)+indent(col, "fuel"), headerY, "Fuel", colors.white, colors.black)
  332.     draw_text((col*5)+indent(col, "rods"), headerY, "Rods", colors.white, colors.black)
  333.  
  334.     for x=0, 5 do
  335.       draw_text(col*x, headerY, "|", colors.blue, colors.black)
  336.     end
  337.  
  338.     -- divide reactor list and menu
  339.     div = monY - 12
  340.     mon.setBackgroundColor(colors.black)
  341.     mon.setTextColor(colors.blue)
  342.     mon.setCursorPos(1,div)
  343.     mon.write(string.rep("=", monX))
  344.  
  345.     -- populate reactor list above div line
  346.     listReactors(div)
  347.    
  348.     -- draw whatever menus are selected
  349.     if splitScreen then
  350.       for i = div+1, monY-1 do
  351.         draw_text(monX/2, i, "|", colors.blue, colors.black)
  352.       end
  353.      
  354.       -- power select
  355.       if panel1Tool == 1 then
  356.         powerMenu(1, monX/2-1)
  357.       end
  358.       if panel2Tool == 1 then
  359.         powerMenu(monX/2+1, monX/2-1)
  360.       end
  361.      
  362.       -- info select
  363.       if panel1Tool == 2 then
  364.         infoMenu(1, monX/2-1)
  365.       end
  366.       if panel2Tool == 2 then
  367.         infoMenu(monX/2+1, monX/2-1)
  368.       end
  369.      
  370.       -- options select
  371.       if panel1Tool == 3 then
  372.         settingsMenu(1, monX/2-1)
  373.       end
  374.       if panel2Tool == 3 then
  375.         settingsMenu(monX/2+1, monX/2-1)
  376.       end
  377.      
  378.     else -- if not split screen
  379.    
  380.       if panel1Tool == 1 then
  381.         powerMenu(1, monX)
  382.       end
  383.       if panel1Tool == 2 then
  384.         infoMenu(1, monX)
  385.       end
  386.       if panel1Tool == 3 then
  387.         settingsMenu(1, monX)
  388.       end
  389.     end
  390.    
  391.     sleep(refresh)
  392.    
  393.   end
  394. end
  395.  
  396. function listReactors(div)
  397.  
  398.  
  399.  
  400.    -- list all reactors
  401.     local lineCounter = headerY + 2
  402.     for i=1, #reactors do
  403.       if lineCounter < div then
  404.      
  405.         if i == currentInfoPage then
  406.           bgcolor = colors.lightGray
  407.           draw_line(1, 2+(3*i), monX, colors.lightGray)
  408.           draw_line(1, 3+(3*i), monX, colors.lightGray)
  409.         else
  410.           bgcolor = colors.black
  411.         end
  412.    
  413.         -- line seperation reactors
  414.         mon.setBackgroundColor(colors.black)
  415.         mon.setTextColor(colors.blue)
  416.         mon.setCursorPos(1,lineCounter-1)
  417.         mon.write(string.rep("-", monX))
  418.        
  419.         -- add columns
  420.         for x=0, 5 do
  421.           draw_text(col*x, lineCounter, "|", colors.blue, bgcolor)
  422.           draw_text(col*x, lineCounter+1, "|", colors.blue, bgcolor)
  423.         end
  424.  
  425.         -- reactor number
  426.         draw_text(2, lineCounter, string.format("%i", i), colors.white, bgcolor)
  427.        
  428.         -- power
  429.         local active = reactors[i].getActive()
  430.         if active then
  431.           draw_text(col+1, lineCounter, "ONLINE", colors.lime, bgcolor)
  432.         else
  433.           draw_text(col+1, lineCounter, "OFFLINE", colors.red, bgcolor)
  434.         end
  435.        
  436.         -- output
  437.         rft = math.floor(reactors[i].getEnergyProducedLastTick())
  438.         string = rft.." "
  439.         draw_text((col*2)+1, lineCounter, string, colors.white, bgcolor)
  440.        
  441.         -- rod temp
  442.         maxHeat = 2000
  443.         heat = math.floor(reactors[i].getFuelTemperature())
  444.  
  445.         if heat < 500 then
  446.           draw_text((col*3)+1, lineCounter, "R "..heat, colors.lime, bgcolor)
  447.         else if heat < 1000 then
  448.           draw_text((col*3)+1, lineCounter, "R "..heat, colors.yellow, bgcolor)
  449.         else if heat < 1500 then  
  450.           draw_text((col*3)+1, lineCounter, "R "..heat, colors.orange, bgcolor)
  451.         else if heat < 2000 then
  452.           draw_text((col*3)+1, lineCounter, "R "..heat, colors.red, bgcolor)
  453.         else if heat >= 2000 then
  454.           draw_text((col*3)+1, lineCounter, "R "..heat, colors.red, bgcolor)
  455.         end
  456.         end
  457.         end
  458.         end
  459.         end
  460.        
  461.         -- casing temp
  462.         heat = math.floor(reactors[i].getCasingTemperature())
  463.  
  464.         if heat < 500 then
  465.           draw_text((col*3)+1, lineCounter+1, "C "..heat, colors.lime, bgcolor)
  466.         else if heat < 1000 then
  467.           draw_text((col*3)+1, lineCounter+1, "C "..heat, colors.yellow, bgcolor)
  468.         else if heat < 1500 then  
  469.           draw_text((col*3)+1, lineCounter+1, "C "..heat, colors.orange, bgcolor)
  470.         else if heat < 2000 then
  471.           draw_text((col*3)+1, lineCounter+1, "C "..heat, colors.red, bgcolor)
  472.         else if heat >= 2000 then
  473.           draw_text((col*3)+1, lineCounter+1, "C "..heat, colors.red, bgcolor)
  474.         end
  475.         end
  476.         end
  477.         end
  478.         end
  479.            
  480.         -- fuel level
  481.         local fuelMinVal = 0
  482.         local fuelMaxVal = 0
  483.         fuelMinVal = fuelMinVal + math.floor(reactors[i].getFuelAmount())
  484.         fuelMaxVal = fuelMaxVal + math.floor(reactors[i].getFuelAmountMax())
  485.  
  486.         percent = math.floor((fuelMinVal/fuelMaxVal)*100)
  487.         local string = percent.."%"
  488.  
  489.         if percent < 25 then
  490.         progress_bar(col*4+1, lineCounter, col-1, percent, 100, colors.red, colors.gray, string)
  491.         else if percent < 50 then
  492.         progress_bar(col*4+1, lineCounter, col-1, percent, 100, colors.orange, colors.gray, string)
  493.         else if percent < 75 then
  494.         progress_bar(col*4+1, lineCounter, col-1, percent, 100, colors.yellow, colors.gray, string)
  495.         else if percent <= 100 then
  496.         progress_bar(col*4+1, lineCounter, col-1, percent, 100, colors.lime, colors.gray, string)
  497.         end
  498.         end
  499.         end
  500.         end
  501.  
  502.         -- control rods
  503.         percent = reactors[i].getControlRodLevel(0)
  504.         progress_bar(col*5 + 1, lineCounter, col, percent, 100, colors.green, colors.gray, percent.."%")
  505.        
  506.         -- increase line counter for the next reactor
  507.         lineCounter = lineCounter + 3
  508.       end
  509.     end
  510. end
  511.  
  512. -- Draw the power screen
  513. function powerMenu(x, width)
  514.   y = monY - 10
  515.  
  516.   -- Main Power Satus Label
  517.   mainPowerBtn = {x+15, y+1}
  518.   draw_text(x+1, y+1, "Main Power:", colors.yellow, colors.black)
  519.   if mainPower then
  520.     draw_line(x+15, y+1, 8, colors.lime)
  521.     draw_text(x+15, y+1, " ONLINE", colors.black, colors.lime)
  522.   else
  523.     draw_line(x+15, y+1, 9, colors.red)
  524.     draw_text(x+15, y+1, " OFFLINE", colors.white, colors.red)
  525.   end
  526.  
  527.   -- total rf/t
  528.   draw_text(x+1, y+2, "Output:", colors.yellow, colors.black)
  529.   rft = 0
  530.   for i=1, #reactors do
  531.     rft = rft + math.floor(reactors[i].getEnergyProducedLastTick())
  532.   end
  533.   draw_text(x+15, y+2, rft.." RF/t", colors.white, colors.black)
  534.  
  535.   --storage
  536.   draw_text(x+1, y+4, "Energy Storage:", colors.yellow, colors.black)
  537.   energy_stored = 0
  538.   for i=1, #reactors do
  539.     energy_stored = energy_stored + reactors[i].getEnergyStored()
  540.     --energy_stored_percent = math.floor((energy_stored/(10000000*#reactors))*100)
  541.   end
  542.   if energyStorageSetting == 1 then
  543.     draw_text(x+1, y+5, "Reactor Buffers", colors.white, colors.black)
  544.   else if energyStorageSetting == 2 then
  545.     draw_text(x+1, y+5, "EnderIO Capacitors", colors.white, colors.black)
  546.   else if energyStorageSetting == 3 then
  547.     draw_text(x+1, y+5, "Thermal Expansion", colors.white, colors.black)
  548.   end
  549.   end
  550.   end
  551.  
  552.   barX = x+1
  553.   barLength = width-2
  554.  
  555.   minVal = energy_stored
  556.   maxVal = 10000000*#reactors
  557.   percent = math.floor((minVal/maxVal)*100)
  558.  
  559.   if percent < 25 then
  560.   progress_bar(barX, y+6, barLength, minVal, maxVal, colors.red, colors.gray, percent.."%")
  561.   else if percent < 50 then
  562.   progress_bar(barX, y+6, barLength, minVal, maxVal, colors.orange, colors.gray, percent.."%")
  563.   else if percent < 75 then
  564.   progress_bar(barX, y+6, barLength, minVal, maxVal, colors.yellow, colors.gray, percent.."%")
  565.   else if percent <= 100 then
  566.   progress_bar(barX, y+6, barLength, minVal, maxVal, colors.lime, colors.gray, percent.."%")
  567.   end
  568.   end
  569.   end
  570.   end
  571.  
  572.   -- auto power
  573.   draw_text(x+1, y+8, "Auto Power:", colors.yellow, colors.black)
  574.  
  575.   auto = auto_string == "true"
  576.       if auto then
  577.         draw_text(x+13, y+8, "active", colors.lime, colors.black)
  578.        -- if active then
  579.          -- draw_text(x+13, y+6, ":", colors.yellow, colors.black)
  580.          -- draw_text(13, 17, off.."% RF Stored", colors.white, colors.black)
  581.          -- if energy_stored_percent >= off then
  582.          --   reactor.setActive(false)
  583.          --   call_homepage()
  584.  
  585.         --else
  586. --          draw_text(2, 17, "Auto on:", colors.yellow, colors.black)
  587. --          draw_text(13, 17, on.."% RF Stored", colors.white, colors.black)
  588. --          if energy_stored_percent <= on then
  589. --            reactor.setActive(true)
  590. --            call_homepage()
  591. --          end
  592.  
  593.       else
  594.         draw_text(x+13, y+8, "Off", colors.white, colors.black)
  595.  
  596.       end
  597. end
  598.  
  599. function infoMenu(x, width)
  600.   y = monY - 10
  601.  
  602.   -- selection buttons
  603.   lastReactorBtn = {x+4, y+1}
  604.   nextReactorBtn = {x+(width-5), y+1}
  605.   draw_text(lastReactorBtn[1], lastReactorBtn[2], "<<", colors.white, colors.gray)
  606.   draw_text(nextReactorBtn[1], nextReactorBtn[2], ">>", colors.white, colors.gray)
  607.  
  608.   -- title
  609.   if currentInfoPage == 0 then
  610.     draw_text(x+indent(width, "All Reactors"), lastReactorBtn[2], "All Reactors", colors.yellow, colors.black)
  611.   else
  612.     draw_text(x+indent(width, "Reactor 1"), lastReactorBtn[2], "Reactor "..currentInfoPage, colors.yellow, colors.black)
  613.   end
  614.  
  615.   -- fuel tempature
  616.   maxHeat = 0
  617.   heat = 0
  618.   if currentInfoPage == 0 then
  619.     for a=1, #reactors do
  620.       heat = heat + math.floor(reactors[a].getFuelTemperature())
  621.     end
  622.     maxHeat = 2000*#reactors
  623.   else
  624.     heat = math.floor(reactors[currentInfoPage].getFuelTemperature())
  625.     maxHeat = 2000
  626.   end
  627.   percent = math.floor((heat/maxHeat)*100)
  628.  
  629.   draw_text(x+1, y+3, "Fuel Temp:", colors.yellow, colors.black)
  630.   draw_text(x+20, y+3, heat.."/"..maxHeat, colors.white, colors.black)
  631.   barX = x+1
  632.   barY = y+4
  633.   barLength = width - 2
  634.   if percent < 25 then
  635.   progress_bar(barX, barY, barLength, heat, maxHeat, colors.lime, colors.gray, " ")
  636.   else if percent < 50 then
  637.   progress_bar(barX, barY, barLength, heat, maxHeat, colors.yellow, colors.gray, " ")
  638.   else if percent < 75 then
  639.   progress_bar(barX, barY, barLength, heat, maxHeat, colors.orange, colors.gray, " ")
  640.   else
  641.   progress_bar(barX, barY, barLength, heat, maxHeat, colors.red, colors.gray, " ")
  642.   end
  643.   end
  644.   end
  645.  
  646.   -- casing tempature
  647.   maxHeat = 0
  648.   heat = 0
  649.   if currentInfoPage == 0 then
  650.     for a=1, #reactors do
  651.       heat = heat + math.floor(reactors[a].getCasingTemperature())
  652.     end
  653.     maxHeat = 2000*#reactors
  654.   else
  655.     heat = math.floor(reactors[currentInfoPage].getCasingTemperature())
  656.     maxHeat = 2000
  657.   end
  658.   percent = math.floor((heat/maxHeat)*100)
  659.  
  660.   draw_text(x+1, y+5, "Casing Temp:", colors.yellow, colors.black)
  661.   draw_text(x+20, y+5, heat.."/"..maxHeat, colors.white, colors.black)
  662.   barX = x+1
  663.   barY = y+6
  664.   barLength = width - 2
  665.   if percent < 25 then
  666.   progress_bar(barX, barY, barLength, heat, maxHeat, colors.lime, colors.gray, " ")
  667.   else if percent < 50 then
  668.   progress_bar(barX, barY, barLength, heat, maxHeat, colors.yellow, colors.gray, " ")
  669.   else if percent < 75 then
  670.   progress_bar(barX, barY, barLength, heat, maxHeat, colors.orange, colors.gray, " ")
  671.   else
  672.   progress_bar(barX, barY, barLength, heat, maxHeat, colors.red, colors.gray, " ")
  673.   end
  674.   end
  675.   end
  676.  
  677.   -- fuel and energy info
  678.   fuel_usage = 0
  679.   rft = 0
  680.   if currentInfoPage == 0 then
  681.     for i=1, #reactors do
  682.       fuel_usage = fuel_usage + reactors[i].getFuelConsumedLastTick()
  683.       rft = rft + math.floor(reactors[i].getEnergyProducedLastTick())
  684.     end
  685.     rfmb = rft / fuel_usage
  686.   else
  687.     fuel_usage = reactors[currentInfoPage].getFuelConsumedLastTick()
  688.     rft = math.floor(reactors[currentInfoPage].getEnergyProducedLastTick())
  689.     rfmb = rft / fuel_usage
  690.   end
  691.   draw_text(x+1, y+7, "Fuel Consumption: ", colors.yellow, colors.black)
  692.   draw_text(x+20, y+7, fuel_usage.." mB/t", colors.white, colors.black)
  693.   draw_text(x+1, y+8, "Energy per mB: ", colors.yellow, colors.black)
  694.   draw_text(x+20, y+8, rfmb.." RF/mB", colors.white, colors.black)
  695.   draw_text(x+1, y+9, "RF/tick:", colors.yellow, colors.black)
  696.   draw_text(x+20, y+9, rft.." RF/T", colors.white, colors.black)
  697. end
  698.  
  699. function settingsMenu(x, width)
  700.   y = monY-10
  701.  
  702.   -- Scroll Bar
  703.   for i=1, 8 do
  704.     draw_text(x + width-2, y+i, "||", colors.white, colors.black)
  705.   end
  706.   draw_text(x + width-2, y+1, "^^", colors.white, colors.black)
  707.   draw_text(x + width-2, y+9, "vv", colors.white, colors.black)
  708.  
  709.   drawSettings(x+1, y - 13 + settingsOffset, "Scroll through settings -->", colors.gray, colors.black)
  710.  
  711.   -- Auto Power Settings
  712.   auto = auto_string == "true"
  713.   drawSettings(x+1, y - 11 + settingsOffset, "Auto Power:", colors.yellow, colors.black)
  714.   drawSettings(x+2, y - 10 + settingsOffset, "Control power based on", colors.gray, colors.black)
  715.   drawSettings(x+2, y - 9 + settingsOffset, "total energy storage %", colors.gray, colors.black)
  716.  
  717.   offDownBtn = {x+25, y - 8 + settingsOffset}
  718.   offUpBtn = {x+18, y - 8 + settingsOffset}
  719.   onDownBtn = {x+25, y - 7 + settingsOffset}
  720.   onUpBtn = {x+18, y - 7 + settingsOffset}
  721.  
  722.   if auto then
  723.     autoPowerBtn = {x+(width/2-6), y - 6 + settingsOffset}
  724.     drawSettings(x+4, y - 8 + settingsOffset, "Power OFF at", colors.white, colors.black)
  725.     drawSettings(offUpBtn[1], offUpBtn[2], "<<", colors.white, colors.gray)
  726.     drawSettings(offDownBtn[1], offDownBtn[2], ">>", colors.white, colors.gray)
  727.     drawSettings(offUpBtn[1]+3, offUpBtn[2], off.."%", colors.white, colors.black)
  728.     drawSettings(x+4, y - 7 + settingsOffset, "Power ON at", colors.white, colors.black)
  729.     drawSettings(onUpBtn[1], onUpBtn[2], "<<", colors.white, colors.gray)
  730.     drawSettings(onDownBtn[1], onDownBtn[2], ">>", colors.white, colors.gray)
  731.     drawSettings(onUpBtn[1]+3, onUpBtn[2], on.."%", colors.white, colors.black)
  732.     drawSettingsLine(autoPowerBtn[1], autoPowerBtn[2], 10, colors.gray)
  733.     drawSettings(autoPowerBtn[1]+1, autoPowerBtn[2], "Turn Off", colors.white, colors.gray)
  734.   else
  735.  
  736.     -- reset above control button positions
  737.    
  738.     autoPowerBtn = {x+(width/2-5), y - 7 + settingsOffset}
  739.     drawSettingsLine(autoPowerBtn[1], autoPowerBtn[2], 9, colors.gray)
  740.     drawSettings(autoPowerBtn[1]+1, autoPowerBtn[2], "Turn On", colors.white, colors.gray)
  741.   end
  742.  
  743.   -- Auto Control Rod Settings
  744.   drawSettings(x+1, y - 4 + settingsOffset, "Limit Output:", colors.yellow, colors.black)
  745.   drawSettings(x+2, y - 3 + settingsOffset, "Adjust control rods to", colors.gray, colors.black)
  746.   drawSettings(x+2, y - 2 + settingsOffset, "mantain output of:", colors.gray, colors.black)
  747.   drawSettings(x+4, y - 1 + settingsOffset, " <<  <  3000 RF/t  >  >>", colors.white, colors.black)
  748.  
  749.  
  750.   drawSettings(x+1, y + 1 + settingsOffset, "Energy Storage:", colors.yellow, colors.black)
  751.  
  752.   -- Energy Storage Mod Setting
  753.   bufferBtn = {x+4, y+2+settingsOffset}
  754.   enderBtn = {x+4, y+3+settingsOffset}
  755.   thermalBtn = {x+4, y+4+settingsOffset}
  756.   drawSettings(bufferBtn[1], bufferBtn[2], "Reactor Buffers", colors.white, colors.black)
  757.   drawSettings(enderBtn[1], enderBtn[2], "EnderIO Capacitors", colors.white, colors.black)
  758.   drawSettings(thermalBtn[1], thermalBtn[2], "Thermal Expansion", colors.white, colors.black)
  759.   if energyStorageSetting == 1 then
  760.     drawSettingsLine(bufferBtn[1]-1, bufferBtn[2], 20, colors.gray)
  761.     drawSettings(bufferBtn[1], bufferBtn[2], "Reactor Buffers", colors.white, colors.gray)
  762.   else if energyStorageSetting == 2 then
  763.     drawSettingsLine(enderBtn[1]-1, enderBtn[2], 20, colors.gray)
  764.     drawSettings(enderBtn[1], enderBtn[2], "EnderIO Capacitors", colors.white, colors.gray)
  765.   else if energyStorageSetting == 3 then
  766.     drawSettingsLine(thermalBtn[1]-1, thermalBtn[2], 20, colors.gray)
  767.     drawSettings(thermalBtn[1], thermalBtn[2], "Thermal Expansion", colors.white, colors.gray)
  768.   end
  769.   end
  770.   end
  771.  
  772.   -- Screen refresh setting
  773.   refreshUpBtn = {x+10, y+7+settingsOffset}
  774.   refreshDownBtn = {x+10, y+9+settingsOffset}
  775.   drawSettings(x+1, y + 6 + settingsOffset, "Refresh Screen:", colors.yellow, colors.black)
  776.   drawSettings(x+4, y + 8 + settingsOffset, "every", colors.white, colors.black)
  777.   drawSettings(x+10, y + 8 + settingsOffset, string.format("%i", refresh), colors.white, colors.black)
  778.   drawSettings(x+12, y + 8 + settingsOffset, "seconds", colors.white, colors.black)
  779.   drawSettings(refreshUpBtn[1], refreshUpBtn[2], "^", colors.white, colors.gray)
  780.   drawSettings(refreshDownBtn[1], refreshDownBtn[2], "v", colors.white, colors.gray)
  781. end
  782.  
  783. -- limit content of settings menu to window size
  784. -- enables scrolling
  785. function drawSettings(x, y, text, fore, back)
  786.   if y > monY-10 then
  787.     draw_text(x, y, text, fore, back)
  788.   end
  789. end
  790. function drawSettingsLine(x, y, length, color)
  791.   if y > monY-10 then
  792.     mon.setBackgroundColor(color)
  793.     mon.setCursorPos(x,y)
  794.     mon.write(string.rep(" ", length))
  795.   end
  796. end
  797.  
  798. -- this method will be deleted
  799. function homepage()
  800.   while true do
  801.     clear()
  802.     menu_bar()
  803.     terminal_screen()
  804.     monX, monY = mon.getSize()
  805.  
  806.     energy_stored = reactor.getEnergyStored()
  807.    
  808.     --------POWER STAT--------------
  809.     draw_text(2, 3, "Power:", colors.yellow, colors.black)
  810.     active = reactor.getActive()
  811.     if active then
  812.       draw_text(10, 3, "ONLINE", colors.lime, colors.black)
  813.     else
  814.       draw_text(10, 3, "OFFLINE", colors.red, colors.black)
  815.     end
  816.  
  817.     -----------FUEL---------------------
  818.     draw_text(2, 5, "Fuel Level:", colors.yellow, colors.black)
  819.     local maxVal = reactor.getFuelAmountMax()
  820.     local minVal = reactor.getFuelAmount()
  821.     local percent = math.floor((minVal/maxVal)*100)
  822.     draw_text(15, 5, percent.."%", colors.white, colors.black)
  823.  
  824.     if percent < 25 then
  825.     progress_bar(2, 6, monX-2, minVal, maxVal, colors.red, colors.gray)
  826.     else if percent < 50 then
  827.     progress_bar(2, 6, monX-2, minVal, maxVal, colors.orange, colors.gray)
  828.     else if percent < 75 then
  829.     progress_bar(2, 6, monX-2, minVal, maxVal, colors.yellow, colors.gray)
  830.     else if percent <= 100 then
  831.     progress_bar(2, 6, monX-2, minVal, maxVal, colors.lime, colors.gray)
  832.     end
  833.     end
  834.     end
  835.     end
  836.  
  837.     -----------ROD HEAT---------------
  838.     draw_text(2, 8, "Fuel Temp:", colors.yellow, colors.black)
  839.     local maxVal = 2000
  840.     local minVal = math.floor(reactor.getFuelTemperature())
  841.  
  842.     if minVal < 500 then
  843.     progress_bar(2, 9, monX-2, minVal, maxVal, colors.lime, colors.gray)
  844.     else if minVal < 1000 then
  845.     progress_bar(2, 9, monX-2, minVal, maxVal, colors.yellow, colors.gray)
  846.     else if minVal < 1500 then  
  847.     progress_bar(2, 9, monX-2, minVal, maxVal, colors.orange, colors.gray)
  848.     else if minVal < 2000 then
  849.     progress_bar(2, 9, monX-2, minVal, maxVal, colors.red, colors.gray)
  850.     else if minVal >= 2000 then
  851.       progress_bar(2, 9, monX-2, 2000, maxVal, colors.red, colors.gray)
  852.     end
  853.     end
  854.     end
  855.     end
  856.     end
  857.  
  858.     draw_text(15, 8, math.floor(minVal).."/"..maxVal, colors.white, colors.black)
  859.  
  860.     -----------CASING HEAT---------------
  861.     draw_text(2, 11, "Casing Temp:", colors.yellow, colors.black)
  862.     local maxVal = 2000
  863.     local minVal = math.floor(reactor.getCasingTemperature())
  864.     if minVal < 500 then
  865.     progress_bar(2, 12, monX-2, minVal, maxVal, colors.lime, colors.gray)
  866.     else if minVal < 1000 then
  867.     progress_bar(2, 12, monX-2, minVal, maxVal, colors.yellow, colors.gray)
  868.     else if minVal < 1500 then  
  869.     progress_bar(2, 12, monX-2, minVal, maxVal, colors.orange, colors.gray)
  870.     else if minVal < 2000 then
  871.     progress_bar(2, 12, monX-2, minVal, maxVal, colors.red, colors.gray)
  872.     else if minVal >= 2000 then
  873.       progress_bar(2, 12, monX-2, 2000, maxVal, colors.red, colors.gray)
  874.     end
  875.     end
  876.     end
  877.     end
  878.     end
  879.     draw_text(15, 11, math.floor(minVal).."/"..maxVal, colors.white, colors.black)
  880.  
  881.     -------------OUTPUT-------------------
  882.     if reactor.isActivelyCooled() then
  883.  
  884.       draw_text(2, 14, "mB/tick:", colors.yellow, colors.black)
  885.       mbt = math.floor(reactor.getHotFluidProducedLastTick())
  886.       draw_text(13, 14, mbt.." mB/t", colors.white, colors.black)
  887.  
  888.     else
  889.  
  890.       draw_text(2, 14, "RF/tick:", colors.yellow, colors.black)
  891.       rft = math.floor(reactor.getEnergyProducedLastTick())
  892.       draw_text(13, 14, rft.." RF/T", colors.white, colors.black)
  893.  
  894.     end
  895.  
  896.     ------------STORAGE------------
  897.     if reactor.isActivelyCooled() then
  898.  
  899.       draw_text(2, 15, "mB Stored:", colors.yellow, colors.black)
  900.       fluid_stored = reactor.getHotFluidAmount()
  901.       fluid_max = reactor.getHotFluidAmountMax()
  902.       fluid_stored_percent = math.floor((fluid_stored/fluid_max)*100)
  903.       draw_text(13, 15, fluid_stored_percent.."% ("..fluid_stored.." mB)", colors.white, colors.black)
  904.  
  905.     else
  906.  
  907.       draw_text(2, 15, "RF Stored:", colors.yellow, colors.black)
  908.       energy_stored_percent = math.floor((energy_stored/10000000)*100)
  909.       draw_text(13, 15, energy_stored_percent.."% ("..energy_stored.." RF)", colors.white, colors.black)
  910.  
  911.  
  912.     end
  913.  
  914.     -------------AUTO CONTROL RODS-----------------------
  915.     auto_rods_bool = auto_rods == "true"
  916.     insertion_percent = reactor.getControlRodLevel(0)
  917.  
  918.     if reactor.isActivelyCooled() then
  919.       draw_text(2, 16, "Control Rods:", colors.yellow, colors.black)
  920.       draw_text(16, 16, insertion_percent.."%", colors.white, colors.black)
  921.     else
  922.  
  923.       if auto_rods_bool then
  924.         if active then
  925.           if rft > auto_rf+50 then
  926.             reactor.setAllControlRodLevels(insertion_percent+1)
  927.           else if rft < auto_rf-50 then
  928.             reactor.setAllControlRodLevels(insertion_percent-1)
  929.           end
  930.           end
  931.         end
  932.  
  933.         draw_text(2, 16, "Control Rods:", colors.yellow, colors.black)
  934.         draw_text(16, 16, insertion_percent.."%", colors.white, colors.black)
  935.         draw_text(21, 16, "(Auto)", colors.red, colors.black)
  936.      
  937.       else
  938.         draw_text(2, 16, "Control Rods:", colors.yellow, colors.black)
  939.         draw_text(16, 16, insertion_percent.."%", colors.white, colors.black)
  940.       end
  941.     end
  942.  
  943.  
  944.     -------------AUTO SHUTOFF--------------------------
  945.     if reactor.isActivelyCooled() then
  946.  
  947.       --i dont know what I should do here
  948.  
  949.  
  950.     else
  951.       auto = auto_string == "true"
  952.       if auto then
  953.         if active then
  954.           draw_text(2, 17, "Auto off:", colors.yellow, colors.black)
  955.           draw_text(13, 17, off.."% RF Stored", colors.white, colors.black)
  956.           if energy_stored_percent >= off then
  957.             reactor.setActive(false)
  958.             call_homepage()
  959.           end
  960.         else
  961.           draw_text(2, 17, "Auto on:", colors.yellow, colors.black)
  962.           draw_text(13, 17, on.."% RF Stored", colors.white, colors.black)
  963.           if energy_stored_percent <= on then
  964.             reactor.setActive(true)
  965.             call_homepage()
  966.           end
  967.         end
  968.       else
  969.         draw_text(2, 17, "Auto power:", colors.yellow, colors.black)
  970.         draw_text(14, 17, "disabled", colors.red, colors.black)
  971.       end
  972.     end
  973.  
  974.     sleep(0.5)
  975.   end
  976. end
  977.  
  978. --------------MENU SCREENS--------------
  979.  
  980. --auto power menu
  981. function auto_off()
  982.  
  983.   auto = auto_string == "true"
  984.   if auto then --auto power enabled
  985.  
  986.     popup_screen(3, "Auto Power", 11)
  987.     draw_text(5, 5, "Enabled", colors.lime, colors.white)
  988.     draw_text(15, 5, " disable ", colors.white, colors.black)
  989.    
  990.     draw_text(5, 7, "ON when storage =", colors.gray, colors.white)
  991.     draw_text(5, 8, " - ", colors.white, colors.black)
  992.     draw_text(13, 8, on.."% RF", colors.black, colors.white)
  993.     draw_text(22, 8, " + ", colors.white, colors.black)
  994.  
  995.     draw_text(5, 10, "OFF when storage =", colors.gray, colors.white)
  996.     draw_text(5, 11, " - ", colors.white, colors.black)
  997.     draw_text(13, 11, off.."% RF", colors.black, colors.white)
  998.     draw_text(22, 11, " + ", colors.white, colors.black)
  999.  
  1000.     draw_text(11, 13, " Save ", colors.white, colors.black)
  1001.  
  1002.     local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  1003.  
  1004.     --disable auto
  1005.     if yPos == 5 then
  1006.       if xPos >= 15 and xPos <= 21 then
  1007.         auto_string = "false"
  1008.         save_config()
  1009.         auto_off()
  1010.       else
  1011.         auto_off()
  1012.       end
  1013.     end
  1014.  
  1015.     --increase/decrease auto on %
  1016.     if yPos == 8 then
  1017.       if xPos >= 5 and xPos <= 8 then
  1018.         previous_on = on
  1019.         on = on-1
  1020.       end
  1021.       if xPos >= 22 and xPos <= 25 then
  1022.         previous_on = on
  1023.         on = on+1
  1024.       end
  1025.     end
  1026.  
  1027.     --increase/decrease auto off %
  1028.     if yPos == 11 then
  1029.       if xPos >= 5 and xPos <= 8 then
  1030.         previous_off = off
  1031.         off = off-1
  1032.       end
  1033.       if xPos >= 22 and xPos <= 25 then
  1034.         previous_off = off
  1035.         off = off+1
  1036.       end
  1037.     end
  1038.  
  1039.     if on < 0 then on = 0 end
  1040.     if off >99 then off = 99 end
  1041.  
  1042.     if on == off or on > off then
  1043.       on = previous_on
  1044.       off = previous_off
  1045.       popup_screen(5, "Error", 6)
  1046.       draw_text(5, 7, "Auto On value must be", colors.black, colors.white)
  1047.       draw_text(5, 8, "lower then auto off", colors.black, colors.white)
  1048.       draw_text(11, 10, "Okay", colors.white, colors.black)
  1049.       local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  1050.  
  1051.       auto_off()
  1052.     end
  1053.  
  1054.     --Okay button
  1055.     if yPos == 13 and xPos >= 11 and xPos <= 17 then
  1056.       save_config()
  1057.       call_homepage()
  1058.     end
  1059.  
  1060.     --Exit button
  1061.     if yPos == 3 and xPos == 25 then
  1062.       call_homepage()
  1063.     end
  1064.  
  1065.     auto_off()
  1066.   else
  1067.     popup_screen(3, "Auto Power", 5)
  1068.     draw_text(5, 5, "Disabled", colors.red, colors.white)
  1069.     draw_text(15, 5, " enable ", colors.white, colors.gray)
  1070.     draw_text(11, 7, "Okay", colors.white, colors.black)
  1071.  
  1072.     local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  1073.  
  1074.     --Okay button
  1075.     if yPos == 7 and xPos >= 11 and xPos <= 17 then
  1076.       call_homepage()
  1077.     end
  1078.  
  1079.     if yPos == 5 then
  1080.       if xPos >= 15 and xPos <= 21 then
  1081.         auto_string = "true"
  1082.         save_config()
  1083.         auto_off()
  1084.       else
  1085.         auto_off()
  1086.       end
  1087.     else
  1088.       auto_off()
  1089.     end
  1090.   end
  1091. end
  1092.  
  1093. --efficiency menu
  1094. function efficiency()
  1095.   popup_screen(3, "Efficiency", 12)
  1096.   fuel_usage = reactor.getFuelConsumedLastTick()
  1097.   rft = math.floor(reactor.getEnergyProducedLastTick())
  1098.  
  1099.   rfmb = rft / fuel_usage
  1100.  
  1101.   draw_text(5, 5, "Fuel Consumption: ", colors.lime, colors.white)
  1102.   draw_text(5, 6, fuel_usage.." mB/t", colors.black, colors.white)
  1103.   draw_text(5, 8, "Energy per mB: ", colors.lime, colors.white)
  1104.   draw_text(5, 9, rfmb.." RF/mB", colors.black, colors.white)
  1105.  
  1106.   draw_text(5, 11, "RF/tick:", colors.lime, colors.white)
  1107.   draw_text(5, 12, rft.." RF/T", colors.black, colors.white)
  1108.  
  1109.   draw_text(11, 14, " Okay ", colors.white, colors.black)
  1110.  
  1111.   local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  1112.  
  1113.   --Okay button
  1114.   if yPos == 14 and xPos >= 11 and xPos <= 17 then
  1115.     call_homepage()
  1116.   end
  1117.  
  1118.   --Exit button
  1119.   if yPos == 3 and xPos == 25 then
  1120.     call_homepage()
  1121.   end
  1122.  
  1123.   efficiency()
  1124. end
  1125.  
  1126.  
  1127. function fuel()
  1128.   popup_screen(3, "Fuel", 9)
  1129.  
  1130.   fuel_max = reactor.getFuelAmountMax()
  1131.   fuel_level = reactor.getFuelAmount()
  1132.   fuel_reactivity = math.floor(reactor.getFuelReactivity())
  1133.  
  1134.   draw_text(5, 5, "Fuel Level: ", colors.lime, colors.white)
  1135.   draw_text(5, 6, fuel_level.."/"..fuel_max, colors.black, colors.white)
  1136.  
  1137.   draw_text(5, 8, "Reactivity: ", colors.lime, colors.white)
  1138.   draw_text(5, 9, fuel_reactivity.."%", colors.black, colors.white)
  1139.  
  1140.   draw_text(11, 11, " Okay ", colors.white, colors.black)
  1141.  
  1142.   local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  1143.  
  1144.  
  1145.   --Okay button
  1146.   if yPos == 11 and xPos >= 11 and xPos <= 17 then
  1147.     call_homepage()
  1148.   end
  1149.  
  1150.   --Exit button
  1151.   if yPos == 3 and xPos == 25 then
  1152.     call_homepage()
  1153.   end
  1154.  
  1155.   fuel()
  1156. end
  1157.  
  1158. function waste()
  1159.   popup_screen(3, "Waste", 8)
  1160.  
  1161.   waste_amount = reactor.getWasteAmount()
  1162.   draw_text(5, 5, "Waste Amount: ", colors.lime, colors.white)
  1163.   draw_text(5, 6, waste_amount.." mB", colors.black, colors.white)
  1164.   draw_text(8, 8, " Eject Waste ", colors.white, colors.red)
  1165.   draw_text(11, 10, " Close ", colors.white, colors.black)
  1166.  
  1167.   local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  1168.  
  1169.   --eject button
  1170.   if yPos == 8 and xPos >= 8 and xPos <= 21 then
  1171.     reactor.doEjectWaste()
  1172.     popup_screen(5, "Waste Eject", 5)
  1173.     draw_text(5, 7, "Waste Ejeceted.", colors.black, colors.white)
  1174.     draw_text(11, 9, " Close ", colors.white, colors.black)
  1175.     local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  1176.     --Okay button
  1177.     if yPos == 7 and xPos >= 11 and xPos <= 17 then
  1178.       call_homepage()
  1179.     end
  1180.  
  1181.     --Exit button
  1182.     if yPos == 3 and xPos == 25 then
  1183.       call_homepage()
  1184.     end
  1185.   end
  1186.  
  1187.   --Okay button
  1188.   if yPos == 10 and xPos >= 11 and xPos <= 17 then
  1189.     call_homepage()
  1190.   end
  1191.  
  1192.   --Exit button
  1193.   if yPos == 3 and xPos == 25 then
  1194.     call_homepage()
  1195.   end
  1196.   waste()
  1197. end
  1198.  
  1199. function set_auto_rf()
  1200.   popup_screen(5, "Auto Adjust", 11)
  1201.     draw_text(5, 7, "Try to maintain:", colors.black, colors.white)
  1202.  
  1203.     draw_text(13, 9, " ^ ", colors.white, colors.gray)
  1204.     draw_text(10, 11, auto_rf.." RF/t", colors.black, colors.white)
  1205.     draw_text(13, 13, " v ", colors.white, colors.gray)
  1206.     draw_text(11, 15, " Okay ", colors.white, colors.gray)
  1207.  
  1208.     local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  1209.  
  1210.     --increase button
  1211.     if yPos == 9 then
  1212.       auto_rf = auto_rf + 100
  1213.       save_config()
  1214.       set_auto_rf()
  1215.     end
  1216.  
  1217.     --decrease button
  1218.     if yPos == 13 then
  1219.       auto_rf = auto_rf - 100
  1220.       if auto_rf < 0 then auto_rf = 0 end
  1221.       save_config()
  1222.       set_auto_rf()
  1223.     end
  1224.  
  1225.     if yPos == 15 then
  1226.       control_rods()
  1227.     end
  1228.  
  1229.     set_auto_rf()
  1230. end
  1231.  
  1232. function control_rods()
  1233.  
  1234.   if reactor.isActivelyCooled() then
  1235.  
  1236.     popup_screen(3, "Control Rods", 13)
  1237.     insertion_percent = reactor.getControlRodLevel(0)
  1238.  
  1239.     draw_text(5, 5, "Inserted: "..insertion_percent.."%", colors.black, colors.white)
  1240.     progress_bar(5, 7, 20, insertion_percent, 100, colors.yellow, colors.gray)
  1241.  
  1242.     draw_text(5, 9, " << ", colors.white, colors.black)
  1243.     draw_text(10, 9, " < ", colors.white, colors.black)
  1244.     draw_text(17, 9, " > ", colors.white, colors.black)
  1245.     draw_text(21, 9, " >> ", colors.white, colors.black)
  1246.  
  1247.     draw_text(5, 11, "Auto:", colors.black, colors.white)
  1248.     draw_text(5, 13, "unavilable for", colors.red, colors.white)
  1249.     draw_text(5, 14, "active cooling", colors.red, colors.white)
  1250.  
  1251.     draw_text(11, 16, " Close ", colors.white, colors.gray)
  1252.  
  1253.     local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  1254.  
  1255.     if yPos == 9 and xPos >= 5 and xPos <= 15 then
  1256.       reactor.setAllControlRodLevels(insertion_percent-10)
  1257.     end
  1258.  
  1259.     if yPos == 9 and xPos >= 10 and xPos <= 13 then
  1260.       reactor.setAllControlRodLevels(insertion_percent-1)
  1261.     end
  1262.  
  1263.     if yPos == 9 and xPos >= 17 and xPos <= 20 then
  1264.       reactor.setAllControlRodLevels(insertion_percent+1)
  1265.     end
  1266.  
  1267.     if yPos == 9 and xPos >= 21 and xPos <= 25 then
  1268.       reactor.setAllControlRodLevels(insertion_percent+10)
  1269.     end
  1270.  
  1271.     ------Close button-------
  1272.     if yPos == 16 and xPos >= 11 and xPos <= 17 then
  1273.       call_homepage()
  1274.     end
  1275.  
  1276.     ------Exit button------------
  1277.     if yPos == 5 and xPos == 25 then
  1278.       call_homepage()
  1279.     end
  1280.     control_rods()
  1281.  
  1282.   else
  1283.  
  1284.     popup_screen(3, "Control Rods", 13)
  1285.     insertion_percent = reactor.getControlRodLevel(0)
  1286.  
  1287.     draw_text(5, 5, "Inserted: "..insertion_percent.."%", colors.black, colors.white)
  1288.     progress_bar(5, 7, 20, insertion_percent, 100, colors.yellow, colors.gray)
  1289.  
  1290.     draw_text(5, 9, " << ", colors.white, colors.black)
  1291.     draw_text(10, 9, " < ", colors.white, colors.black)
  1292.     draw_text(17, 9, " > ", colors.white, colors.black)
  1293.     draw_text(21, 9, " >> ", colors.white, colors.black)
  1294.  
  1295.     draw_text(5, 11, "Auto:", colors.black, colors.white)
  1296.     draw_text(16, 11, " disable ", colors.white, colors.black)
  1297.  
  1298.     auto_rods_bool = auto_rods == "true"
  1299.     if auto_rods_bool then
  1300.      
  1301.       draw_text(5, 13, "RF/t: "..auto_rf, colors.black, colors.white)
  1302.       draw_text(18, 13, " set ", colors.white, colors.black)
  1303.     else
  1304.       draw_text(16, 11, " enable ", colors.white, colors.black)
  1305.       draw_text(5, 13, "disabled", colors.red, colors.white)
  1306.     end
  1307.  
  1308.     draw_text(11, 15, " Close ", colors.white, colors.gray)
  1309.  
  1310.     local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  1311.  
  1312.     -----manual adjust buttons------------
  1313.     if yPos == 9 and xPos >= 5 and xPos <= 15 then
  1314.       reactor.setAllControlRodLevels(insertion_percent-10)
  1315.     end
  1316.  
  1317.     if yPos == 9 and xPos >= 10 and xPos <= 13 then
  1318.       reactor.setAllControlRodLevels(insertion_percent-1)
  1319.     end
  1320.  
  1321.     if yPos == 9 and xPos >= 17 and xPos <= 20 then
  1322.       reactor.setAllControlRodLevels(insertion_percent+1)
  1323.     end
  1324.  
  1325.     if yPos == 9 and xPos >= 21 and xPos <= 25 then
  1326.       reactor.setAllControlRodLevels(insertion_percent+10)
  1327.     end
  1328.  
  1329.  
  1330.     ------auto buttons-----------------
  1331.     if yPos == 11 and xPos >= 16 then
  1332.       if auto_rods_bool then
  1333.         auto_rods = "false"
  1334.         save_config()
  1335.         control_rods()
  1336.       else
  1337.         auto_rods = "true"
  1338.         save_config()
  1339.         control_rods()
  1340.       end
  1341.     end
  1342.  
  1343.     if yPos == 13 and xPos >= 18 then
  1344.       set_auto_rf()
  1345.     end
  1346.  
  1347.     ------Close button-------
  1348.     if yPos == 15 and xPos >= 11 and xPos <= 17 then
  1349.       call_homepage()
  1350.     end
  1351.  
  1352.     ------Exit button------------
  1353.     if yPos == 5 and xPos == 25 then
  1354.       call_homepage()
  1355.     end
  1356.     control_rods()
  1357.  
  1358.   end
  1359. end
  1360.  
  1361. -----------------------Settings--------------------------------
  1362.  
  1363.  
  1364. function rf_mode()
  1365.   wait = read()
  1366. end
  1367.  
  1368. function steam_mode()
  1369.   wait = read()
  1370. end
  1371.  
  1372. function install_update(program, pastebin)
  1373.     clear()
  1374.     draw_line(4, 5, 22, colors.blue)
  1375.  
  1376.     for counter = 6, 10 do
  1377.       draw_line(4, counter, 22, colors.white)
  1378.     end
  1379.  
  1380.     draw_text(5, 5, "Updating...", colors.white, colors.blue)
  1381.     draw_text(5, 7, "Open computer", colors.black, colors.white)
  1382.     draw_text(5, 8, "terminal.", colors.black, colors.white)
  1383.  
  1384.     if fs.exists("install") then fs.delete("install") end
  1385.     shell.run("pastebin get p4zeq7Ma install")
  1386.     shell.run("install")
  1387. end
  1388.  
  1389. function update()
  1390.   popup_screen(5, "Updates", 4)
  1391.   draw_text(5, 7, "Connecting to", colors.black, colors.white)
  1392.   draw_text(5, 8, "pastebin...", colors.black, colors.white)
  1393.  
  1394.   sleep(0.5)
  1395.  
  1396.   shell.run("pastebin get MkF2QQjH current_version.txt")
  1397.   sr = fs.open("current_version.txt", "r")
  1398.   current_version = tonumber(sr.readLine())
  1399.   sr.close()
  1400.   fs.delete("current_version.txt")
  1401.   terminal_screen()
  1402.  
  1403.   if current_version > version then
  1404.  
  1405.     popup_screen(5, "Updates", 7)
  1406.     draw_text(5, 7, "Update Available!", colors.black, colors.white)
  1407.     draw_text(11, 9, " Install ", colors.white, colors.black)
  1408.     draw_text(11, 11, " Ignore ", colors.white, colors.black)
  1409.  
  1410.     local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  1411.  
  1412.     --Instatll button
  1413.     if yPos == 9 and xPos >= 11 and xPos <= 17 then
  1414.       install_update()
  1415.     end
  1416.  
  1417.     --Exit button
  1418.     if yPos == 5 and xPos == 25 then
  1419.       call_homepage()
  1420.     end
  1421.     call_homepage()
  1422.  
  1423.   else
  1424.     popup_screen(5, "Updates", 5)
  1425.     draw_text(5, 7, "You are up to date!", colors.black, colors.white)
  1426.     draw_text(11, 9, " Okay ", colors.white, colors.black)
  1427.  
  1428.     local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  1429.  
  1430.     --Okay button
  1431.     if yPos == 9 and xPos >= 11 and xPos <= 17 then
  1432.       call_homepage()
  1433.     end
  1434.  
  1435.     --Exit button
  1436.     if yPos == 5 and xPos == 25 then
  1437.       call_homepage()
  1438.     end
  1439.     call_homepage()
  1440.   end
  1441. end
  1442.  
  1443. function indent(width, string)
  1444. --((col/2)-(string:len()-1))
  1445.   length = string:len()
  1446.   if width >= length then
  1447.     num = (width/2) - (length/2)
  1448.     if num > 0 then
  1449.       return num
  1450.     else
  1451.       return 1
  1452.     end  
  1453.   else
  1454.     return 1  
  1455.   end
  1456. end
  1457.  
  1458. function reset_peripherals()
  1459.   clear()
  1460.   draw_line(4, 5, 22, colors.blue)
  1461.  
  1462.   for counter = 6, 10 do
  1463.     draw_line(4, counter, 22, colors.white)
  1464.   end
  1465.  
  1466.   draw_text(5, 5, "Reset Peripherals", colors.white, colors.blue)
  1467.   draw_text(5, 7, "Open computer", colors.black, colors.white)
  1468.   draw_text(5, 8, "terminal.", colors.black, colors.white)
  1469.   setup_wizard()
  1470.  
  1471. end
  1472.  
  1473. --stop running status screen if monitors was touched
  1474. function stop()
  1475.   while true do
  1476.     local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  1477.       x = xPos
  1478.       y = yPos
  1479.       stop_function = "monitor_touch"
  1480.     return
  1481.   end
  1482. end
  1483.  
  1484. function mon_touch_controller()
  1485.   -- panel menu buttons
  1486.   if y == monY-11 then
  1487.     if x >= powerX and  x <= powerX+5 then
  1488.       selectMenu(1, 1)
  1489.     else if x >= infoX and x <= infoX+5 then
  1490.       selectMenu(2, 1)
  1491.     else if x >= optionsX and x <= optionsX+8 then
  1492.       selectMenu(3, 1)
  1493.     else if x >= powerX2 and x <= powerX2+5 then
  1494.       selectMenu(1, 2)
  1495.     else if x >= infoX2 and x <= infoX2+5 then
  1496.       selectMenu(2, 2)
  1497.     else if x >= optionsX2 and x <= optionsX2+8 then
  1498.       selectMenu(3, 2)
  1499.     end
  1500.     end
  1501.     end
  1502.     end
  1503.     end
  1504.     end
  1505.   end
  1506.  
  1507.   if y == mainPowerBtn[2] then
  1508.     if x > mainPowerBtn[1] and x < mainPowerBtn[1]+6 then
  1509.       if mainPower then
  1510.         mainPower = false
  1511.         for i=1, #reactors do
  1512.           reactors[i].setActive(false)
  1513.         end
  1514.       else
  1515.         mainPower = true
  1516.         for i=1, #reactors do
  1517.           reactors[i].setActive(true)
  1518.         end
  1519.       end
  1520.     end
  1521.   end
  1522.  
  1523.   if y > monY-11 then
  1524.     mon_touch_settings(x, y)
  1525.   end
  1526.  
  1527.   call_controller()
  1528. end
  1529.  
  1530. function selectMenu(menu, panel)
  1531.   if panel == 1 then
  1532.     if panel1Tool == menu then
  1533.       panel1Tool = 0
  1534.     else
  1535.       panel1Tool = menu
  1536.     end
  1537.   else if panel == 2 then
  1538.     if panel2Tool == menu then
  1539.       panel2Tool = 0
  1540.     else
  1541.       panel2Tool = menu
  1542.     end
  1543.    
  1544.   end
  1545.   end
  1546.   call_controller()
  1547. end
  1548.  
  1549. function mon_touch_settings(x, y)
  1550.   -- settings scroll bar
  1551.   if splitScreen then
  1552.     if panel1Tool == 3 then
  1553.       if x == ((monX/2) - 2) or x == ((monX/2) - 1) then
  1554.         settingsOffset = settingsOffset + 1
  1555.       end
  1556.     end
  1557.     if panel2Tool == 3 then
  1558.       if x == (monX - 2) or x == (monX - 1) then
  1559.         if y > monY-10 and y < monY-5 then
  1560.           settingsOffset = settingsOffset + 1
  1561.         end
  1562.         if y > monY-5 and y < monY then
  1563.           settingsOffset = settingsOffset - 1
  1564.         end
  1565.       end
  1566.     end
  1567.   else
  1568.     if x == (monX - 1) or x == (monX ) then
  1569.       if y > monY-10 and y < monY-5 then
  1570.         settingsOffset = settingsOffset + 1
  1571.       end
  1572.       if y > monY-5 and y < monY then
  1573.         settingsOffset = settingsOffset - 1
  1574.       end
  1575.     end
  1576.   end
  1577.  
  1578.   -- energy storage settings
  1579.   if y == bufferBtn[2] then
  1580.     if x >= bufferBtn[1] and x < bufferBtn[1]+20 then
  1581.       energyStorageSetting = 1
  1582.     end
  1583.   end
  1584.   if y == enderBtn[2] then
  1585.     if x >= enderBtn[1] and x < enderBtn[1]+20 then
  1586.       energyStorageSetting = 2
  1587.     end
  1588.   end
  1589.   if y == thermalBtn[2] then
  1590.     if x >= thermalBtn[1] and x < thermalBtn[1]+20 then
  1591.       energyStorageSetting = 3
  1592.     end
  1593.   end
  1594.  
  1595.   -- refresh screen settings
  1596.   if y == refreshUpBtn[2] then
  1597.     if x > refreshUpBtn[1]-1 and x < refreshUpBtn[1]+1 then
  1598.       refresh = refresh + 1
  1599.     end
  1600.   end
  1601.   if y == refreshDownBtn[2] then
  1602.     if x > refreshDownBtn[1]-1 and x < refreshDownBtn[1]+1 then
  1603.       if refresh > 1 then
  1604.         refresh = refresh - 1
  1605.       end
  1606.     end
  1607.   end
  1608.  
  1609.   -- auto power toggle
  1610.   if y == autoPowerBtn[2] then
  1611.     if x > autoPowerBtn[1] and x < autoPowerBtn[1]+10 then
  1612.       auto = auto_string == "true"
  1613.       if auto then
  1614.         auto_string = "false"
  1615.       else
  1616.         auto_string = "true"
  1617.       end
  1618.     end
  1619.   end
  1620.  
  1621.   -- set auto power percents
  1622.   if y == offUpBtn[2] then
  1623.     if x > offUpBtn[1] and x < offUpBtn[1]+2 then
  1624.       if off < 100 then
  1625.         off = off + 1
  1626.       end
  1627.     end
  1628.   end
  1629.   if y == offDownBtn[2] then
  1630.     if x > offDownBtn[1] and x < offDownBtn[1]+2 then
  1631.       if off > on+1 then
  1632.         off = off - 1
  1633.       end
  1634.     end
  1635.   end
  1636.   if y == onUpBtn[2] then
  1637.     if x > onUpBtn[1] and x < onUpBtn[1]+2 then
  1638.       if on < off+1 then
  1639.         on = on + 1
  1640.       end
  1641.     end
  1642.   end
  1643.   if y == onDownBtn[2] then
  1644.     if x > onDownBtn[1] and x < onDownBtn[1]+2 then
  1645.       if on > 0 then
  1646.         on = on - 1
  1647.       end
  1648.     end
  1649.   end
  1650.  
  1651.   -- Select reactor for info page
  1652.   if y == lastReactorBtn[2] then
  1653.     if x > lastReactorBtn[1]-2 and x < lastReactorBtn[1]+3 then
  1654.       if currentInfoPage == 0 then
  1655.         currentInfoPage = #reactors
  1656.       else
  1657.         currentInfoPage = currentInfoPage - 1
  1658.       end
  1659.     end
  1660.   end
  1661.   if y == nextReactorBtn[2] then
  1662.     if x > nextReactorBtn[1]-2 and x < nextReactorBtn[1]+3 then
  1663.       if currentInfoPage == #reactors then
  1664.         currentInfoPage = 0
  1665.       else
  1666.         currentInfoPage = currentInfoPage + 1
  1667.       end
  1668.     end
  1669.   end
  1670.  
  1671.   save_config()
  1672.   call_controller()
  1673. end
  1674.  
  1675. function mon_touch()
  1676.   --when the monitor is touch on the homepage
  1677.   if y == 1 then
  1678.       if x < monX/3 then
  1679.         power_menu()
  1680.         local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  1681.         if xPos < 9 then
  1682.           if yPos == 2 then
  1683.             reactor.setActive(true)
  1684.             timer = 0 --reset anytime the reactor is turned on/off
  1685.             call_homepage()
  1686.           else if yPos == 3 then
  1687.             reactor.setActive(false)
  1688.             timer = 0 --reset anytime the reactor is turned on/off
  1689.             call_homepage()
  1690.           else if yPos == 4 then
  1691.             auto_off()
  1692.           else
  1693.             call_homepage()
  1694.           end
  1695.           end
  1696.           end
  1697.         else
  1698.           call_homepage()
  1699.         end
  1700.        
  1701.       else if x < 20 then
  1702.         tools_menu()
  1703.         local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  1704.         if xPos < 25 and xPos > 10 then
  1705.           if yPos == 2 then
  1706.             control_rods()
  1707.           else if yPos == 3 then
  1708.             efficiency()
  1709.           else if yPos == 4 then
  1710.             fuel()
  1711.           else if yPos == 5 then
  1712.             waste()
  1713.           else
  1714.             call_homepage()
  1715.           end
  1716.           end
  1717.           end
  1718.           end
  1719.         else
  1720.           call_homepage()
  1721.         end
  1722.       else if x < monX then
  1723.         settings_menu()
  1724.         local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  1725.         if xPos > 13 then
  1726.           if yPos == 2 then
  1727.             update()
  1728.           else if yPos == 3 then
  1729.             reset_peripherals()
  1730.           else
  1731.             call_homepage()
  1732.           end
  1733.           end
  1734.         else
  1735.           call_homepage()
  1736.         end
  1737.       end
  1738.       end
  1739.       end
  1740.     else
  1741.       call_homepage()
  1742.     end
  1743. end
  1744.  
  1745. function terminal_screen()
  1746.   term.clear()
  1747.   draw_line_term(1, 1, 55, colors.blue)
  1748.   draw_text_term(13, 1, "BigReactor Controls", colors.white, colors.blue)
  1749.   draw_line_term(1, 19, 55, colors.blue)
  1750.   draw_text_term(13, 19, "by jaranvil aka jared314", colors.white, colors.blue)
  1751.  
  1752.   draw_text_term(1, 3, "Current program:", colors.white, colors.black)
  1753.   draw_text_term(1, 4, "Reactor Control v"..version, colors.blue, colors.black)
  1754.  
  1755.   draw_text_term(1, 6, "Installer:", colors.white, colors.black)
  1756.   draw_text_term(1, 7, "pastebin.com/p4zeq7Ma", colors.blue, colors.black)
  1757.  
  1758.   draw_text_term(1, 9, "Please give me your feedback, suggestions,", colors.white, colors.black)
  1759.   draw_text_term(1, 10, "and errors!", colors.white, colors.black)
  1760.  
  1761.   draw_text_term(1, 11, "reddit.com/r/br_controls", colors.blue, colors.black)
  1762. end
  1763.  
  1764. --run both homepage() and stop() until one returns
  1765. function call_homepage()
  1766.   clear()
  1767.   parallel.waitForAny(homepage, stop)
  1768.  
  1769.   if stop_function == "terminal_screen" then
  1770.     stop_function = "nothing"
  1771.     setup_wizard()
  1772.   else if stop_function == "monitor_touch" then
  1773.     stop_function = "nothing"
  1774.     mon_touch()
  1775.   end
  1776.   end
  1777. end
  1778.  
  1779. function call_controller()
  1780.   clear()
  1781.   parallel.waitForAny(controller, stop)
  1782.  
  1783.   if stop_function == "terminal_screen" then
  1784.     stop_function = "nothing"
  1785.     setup_wizard()
  1786.   else if stop_function == "monitor_touch" then
  1787.     stop_function = "nothing"
  1788.     mon_touch_controller()
  1789.   end
  1790.   end
  1791. end
  1792.  
  1793. --write settings to config file
  1794. function save_config()
  1795.   sw = fs.open("config.txt", "w")  
  1796.     sw.writeLine(version)
  1797.     sw.writeLine(auto_string)
  1798.     sw.writeLine(on)
  1799.     sw.writeLine(off)
  1800.     sw.writeLine(auto_rods)
  1801.     sw.writeLine(auto_rf)
  1802.     sw.writeLine(refresh)
  1803.   sw.close()
  1804. end
  1805.  
  1806. --read settings from file
  1807. function load_config()
  1808.   sr = fs.open("config.txt", "r")
  1809.     version = tonumber(sr.readLine())
  1810.     auto_string = sr.readLine()
  1811.     on = tonumber(sr.readLine())
  1812.     off = tonumber(sr.readLine())
  1813.     auto_rods = sr.readLine()
  1814.     auto_rf = tonumber(sr.readLine())
  1815.     refresh = tonumber(sr.readLine())
  1816.   sr.close()
  1817. end
  1818.  
  1819. --test if the entered monitor and reactor can be wrapped
  1820.   function test_configs()
  1821.   term.clear()
  1822.  
  1823.   draw_line_term(1, 1, 55, colors.blue)
  1824.   draw_text_term(10, 1, "BigReactors Controls", colors.white, colors.blue)
  1825.  
  1826.   draw_line_term(1, 19, 55, colors.blue)
  1827.   draw_text_term(10, 19, "by jaranvil aka jared314", colors.white, colors.blue)
  1828.  
  1829.   draw_text_term(1, 3, "Searching for a peripherals...", colors.white, colors.black)
  1830.   sleep(1)
  1831.  
  1832.   reactorSearch()
  1833.   mon = monitorSearch()
  1834.  
  1835.  
  1836.   draw_text_term(2, 5, "Connecting to reactor...", colors.white, colors.black)
  1837.   sleep(0.5)
  1838.   if reactors[1] == null then
  1839.       draw_text_term(1, 8, "Error:", colors.red, colors.black)
  1840.       draw_text_term(1, 9, "Could not find any connected reactors", colors.red, colors.black)
  1841.       draw_text_term(1, 10, "Reactors must be connected with networking cable", colors.white, colors.black)
  1842.       draw_text_term(1, 11, "and modems or the computer is directly beside", colors.white, colors.black)
  1843.       draw_text_term(1, 12,"the reactors computer port.", colors.white, colors.black)
  1844.       draw_text_term(1, 14, "Press Enter to continue...", colors.gray, colors.black)
  1845.       wait = read()
  1846.       setup_wizard()
  1847.   else
  1848.       if #reactors == 1 then
  1849.         draw_text_term(27, 5, #reactors .. " reactor found", colors.lime, colors.black)
  1850.       else
  1851.         draw_text_term(27, 5, #reactors .. " reactors found", colors.lime, colors.black)
  1852.       end
  1853.       sleep(0.5)
  1854.   end
  1855.  
  1856.   draw_text_term(2, 6, "Connecting to monitor...", colors.white, colors.black)
  1857.   sleep(0.5)
  1858.   if mon == null then
  1859.       draw_text_term(1, 7, "Error:", colors.red, colors.black)
  1860.       draw_text_term(1, 8, "Could not connect to a monitor. Place a 3x3 advanced monitor", colors.red, colors.black)
  1861.       draw_text_term(1, 11, "Press Enter to continue...", colors.gray, colors.black)
  1862.       wait = read()
  1863.       setup_wizard()
  1864.   else
  1865.       monX, monY = mon.getSize()
  1866.       draw_text_term(27, 6, "success", colors.lime, colors.black)
  1867.       sleep(0.5)
  1868.   end
  1869.     draw_text_term(2, 7, "saving configuration...", colors.white, colors.black)  
  1870.  
  1871.     save_config()
  1872.  
  1873.     sleep(0.1)
  1874.     draw_text_term(1, 9, "Setup Complete!", colors.lime, colors.black)
  1875.     sleep(1)
  1876.  
  1877.     auto = auto_string == "true"
  1878.    
  1879.     if #reactors == 1 then
  1880.       reactor = reactors[1]
  1881.       call_homepage()
  1882.     else
  1883.       call_controller()
  1884.     end
  1885. end
  1886. ----------------SETUP-------------------------------
  1887.  
  1888. function setup_wizard()
  1889.  
  1890.   term.clear()
  1891.  
  1892.  
  1893.      draw_text_term(1, 1, "BigReactor Controls v"..version, colors.lime, colors.black)
  1894.      draw_text_term(1, 2, "Peripheral setup", colors.white, colors.black)
  1895.      draw_text_term(1, 4, "Step 1:", colors.lime, colors.black)
  1896.      draw_text_term(1, 5, "-Place 3x3 advanced monitors next to computer.", colors.white, colors.black)
  1897.      draw_text_term(1, 7, "Step 2:", colors.lime, colors.black)
  1898.      draw_text_term(1, 8, "-Place a wired modem on this computer and on the ", colors.white, colors.black)
  1899.      draw_text_term(1, 9, " computer port of the reactor.", colors.white, colors.black)
  1900.      draw_text_term(1, 10, "-connect modems with network cable.", colors.white, colors.black)
  1901.      draw_text_term(1, 11, "-right click modems to activate.", colors.white, colors.black)
  1902.      draw_text_term(1, 13, "Press Enter when ready...", colors.gray, colors.black)
  1903.    
  1904.      wait = read()
  1905.       test_configs()
  1906.  
  1907.    
  1908. end
  1909.  
  1910. function reactorSearch()
  1911.    local names = peripheral.getNames()
  1912.    local i, name
  1913.    local x=1
  1914. --   for i, name in pairs(names) do
  1915. --      if peripheral.getType(name) == "BigReactors-Reactor" then
  1916. --         reactors[x] = peripheral.wrap(name)
  1917. --           x = x + 1
  1918. --      end
  1919. --   end  
  1920.    
  1921.    for i=1,#names do
  1922.      if peripheral.getType(names[i]) == "BigReactors-Reactor" then
  1923.          reactors[x] = peripheral.wrap(names[i])
  1924.          x = x + 1
  1925.       end
  1926.    end
  1927. end
  1928.  
  1929. function monitorSearch()
  1930.    local names = peripheral.getNames()
  1931.    local i, name
  1932.    for i, name in pairs(names) do
  1933.       if peripheral.getType(name) == "monitor" then
  1934.         test = name
  1935.          return peripheral.wrap(name)
  1936.       else
  1937.          --return null
  1938.       end
  1939.    end
  1940. end
  1941.  
  1942. function start()
  1943.   --if configs exists, load values and test
  1944.   if fs.exists("config.txt") then
  1945.       load_config()
  1946.       test_configs()
  1947.   else
  1948.     setup_wizard()
  1949.   end
  1950. end
  1951.  
  1952. start()
Add Comment
Please, Sign In to add comment