jared314

reactor_control_2_2

Apr 23rd, 2015
835
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 28.83 KB | None | 0 0
  1. -----BigReactor Control
  2. -----by jaranvil aka jared314
  3.  
  4. -----feel free to use and/or mondify this code
  5. -----------------------------------------------
  6.  
  7. version = 2.2
  8. term.clear()
  9. -------------------FORMATTING-------------------------------
  10. function clear()
  11.     mon.setBackgroundColor(colors.black)
  12.     mon.clear()
  13.     mon.setCursorPos(1,1)
  14. end
  15.  
  16. function draw_text_term(x, y, text, text_color, bg_color)
  17.     term.setTextColor(text_color)
  18.     term.setBackgroundColor(bg_color)
  19.     term.setCursorPos(x,y)
  20.     write(text)
  21. end
  22.  
  23. function draw_text(x, y, text, text_color, bg_color)
  24.     mon.setBackgroundColor(bg_color)
  25.     mon.setTextColor(text_color)
  26.     mon.setCursorPos(x,y)
  27.     mon.write(text)
  28. end
  29.  
  30. function draw_line(x, y, length, color)
  31.         mon.setBackgroundColor(color)
  32.         mon.setCursorPos(x,y)
  33.         mon.write(string.rep(" ", length))
  34. end
  35.  
  36. function draw_line_term(x, y, length, color)
  37.         term.setBackgroundColor(color)
  38.         term.setCursorPos(x,y)
  39.         term.write(string.rep(" ", length))
  40. end
  41.  
  42. function progress_bar(x, y, length, minVal, maxVal, bar_color, bg_color)
  43.     draw_line(x, y, length, bg_color) --backgoround bar
  44.     local barSize = math.floor((minVal/maxVal) * length)
  45.     draw_line(x, y, barSize, bar_color) --progress so far
  46. end
  47.  
  48. function progress_bar_term(x, y, length, minVal, maxVal, bar_color, bg_color)
  49.     draw_line_term(x, y, length, bg_color) --backgoround bar
  50.     local barSize = math.floor((minVal/maxVal) * length)
  51.     draw_line_term(x, y, barSize, bar_color)    --progress so far
  52. end
  53.  
  54. function button(x, y, length, text, txt_color, bg_color)
  55.     draw_line(x, y, length, bg_color)
  56.     draw_text((x+2), y, text, txt_color, bg_color)
  57. end
  58.  
  59. function menu_bar()
  60.     draw_line(1, 1, monX, colors.blue)
  61.     draw_text(2, 1, "Power    Tools    Settings", colors.white, colors.blue)
  62.     draw_line(1, 19, monX, colors.blue)
  63.     draw_text(2, 19, "     Reactor Control", colors.white, colors.blue)
  64. end
  65.  
  66. function power_menu()
  67.     draw_line(1, 2, 9, colors.gray)
  68.     draw_line(1, 3, 9, colors.gray)
  69.     draw_line(1, 4, 9, colors.gray)
  70.     if active then
  71.         draw_text(2, 2, "ON", colors.lightGray, colors.gray)
  72.         draw_text(2, 3, "OFF", colors.white, colors.gray)
  73.     else
  74.         draw_text(2, 2, "ON", colors.white, colors.gray)
  75.         draw_text(2, 3, "OFF", colors.lightGray, colors.gray)
  76.     end
  77.     draw_text(2, 4, "Auto", colors.white, colors.gray)
  78. end
  79.  
  80. function tools_menu()
  81.     draw_line(10, 2, 14, colors.gray)
  82.     draw_line(10, 3, 14, colors.gray)
  83.     draw_line(10, 4, 14, colors.gray)
  84.     draw_line(10, 5, 14, colors.gray)
  85.     draw_text(11, 2, "Control Rods", colors.white, colors.gray)
  86.     draw_text(11, 3, "Efficiency", colors.white, colors.gray)
  87.     draw_text(11, 4, "Fuel", colors.white, colors.gray)
  88.     draw_text(11, 5, "Waste", colors.white, colors.gray)
  89.    
  90.    
  91. end
  92.  
  93. function settings_menu()
  94.     draw_line(12, 2, 18, colors.gray)
  95.     draw_line(12, 3, 18, colors.gray)
  96.     draw_text(13, 2, "Check for Updates", colors.white, colors.gray)
  97.     draw_text(13, 3, "Reset peripherals", colors.white, colors.gray)
  98. end
  99.  
  100. function popup_screen(y, title, height)
  101.     clear()
  102.     menu_bar()
  103.  
  104.     draw_line(4, y, 22, colors.blue)
  105.     draw_line(25, y, 1, colors.red)
  106.  
  107.     for counter = y+1, height+y do
  108.         draw_line(4, counter, 22, colors.white)
  109.     end
  110.  
  111.     draw_text(25, y, "X", colors.white, colors.red)
  112.     draw_text(5, y, title, colors.white, colors.blue)
  113. end
  114.  
  115. function save_config()
  116.     sw = fs.open("config.txt", "w")    
  117.         sw.writeLine(version)
  118.         sw.writeLine(side)
  119.         sw.writeLine(name)
  120.         sw.writeLine(auto_string)
  121.         sw.writeLine(on)
  122.         sw.writeLine(off)
  123.         sw.writeLine(auto_rods)
  124.         sw.writeLine(auto_rf)
  125.     sw.close()
  126. end
  127.  
  128. function load_config()
  129.     sr = fs.open("config.txt", "r")
  130.         version = tonumber(sr.readLine())
  131.         side = sr.readLine()
  132.         name = sr.readLine()
  133.         auto_string = sr.readLine()
  134.         on = tonumber(sr.readLine())
  135.         off = tonumber(sr.readLine())
  136.         auto_rods = sr.readLine()
  137.         auto_rf = tonumber(sr.readLine())
  138.     sr.close()
  139. end
  140.  
  141. --------------------------------------------------
  142.  
  143.  
  144.  
  145. function homepage()
  146.     while true do
  147.         clear()
  148.         menu_bar()
  149.         terminal_screen()
  150.  
  151.         energy_stored = reactor1.getEnergyStored()
  152.        
  153.  
  154.         --------POWER STAT--------------
  155.         draw_text(2, 3, "Power:", colors.yellow, colors.black)
  156.         active = reactor1.getActive()
  157.         if active then
  158.             draw_text(10, 3, "ONLINE", colors.lime, colors.black)
  159.         else
  160.             draw_text(10, 3, "OFFLINE", colors.red, colors.black)
  161.         end
  162.  
  163.  
  164.         -----------FUEL---------------------
  165.         draw_text(2, 5, "Fuel Level:", colors.yellow, colors.black)
  166.         local maxVal = reactor1.getFuelAmountMax()
  167.         local minVal = reactor1.getFuelAmount()
  168.         local percent = math.floor((minVal/maxVal)*100)
  169.         draw_text(15, 5, percent.."%", colors.white, colors.black)
  170.  
  171.         if percent < 25 then
  172.         progress_bar(2, 6, monX-2, minVal, maxVal, colors.red, colors.gray)
  173.         else if percent < 50 then
  174.         progress_bar(2, 6, monX-2, minVal, maxVal, colors.orange, colors.gray)
  175.         else if percent < 75 then  
  176.         progress_bar(2, 6, monX-2, minVal, maxVal, colors.yellow, colors.gray)
  177.         else if percent < 100 then
  178.         progress_bar(2, 6, monX-2, minVal, maxVal, colors.lime, colors.gray)
  179.         end
  180.         end
  181.         end
  182.         end
  183.  
  184.  
  185.         -----------ROD HEAT---------------
  186.         draw_text(2, 8, "Fuel Temp:", colors.yellow, colors.black)
  187.         local maxVal = 2000
  188.         local minVal = math.floor(reactor1.getFuelTemperature())
  189.  
  190.         if minVal < 500 then
  191.         progress_bar(2, 9, monX-2, minVal, maxVal, colors.lime, colors.gray)
  192.         else if minVal < 1000 then
  193.         progress_bar(2, 9, monX-2, minVal, maxVal, colors.yellow, colors.gray)
  194.         else if minVal < 1500 then 
  195.         progress_bar(2, 9, monX-2, minVal, maxVal, colors.orange, colors.gray)
  196.         else if minVal < 2000 then
  197.         progress_bar(2, 9, monX-2, minVal, maxVal, colors.red, colors.gray)
  198.         else if minVal >= 2000 then
  199.             progress_bar(2, 9, monX-2, 2000, maxVal, colors.red, colors.gray)
  200.         end
  201.         end
  202.         end
  203.         end
  204.         end
  205.  
  206.         draw_text(15, 8, math.floor(minVal).."/"..maxVal, colors.white, colors.black)
  207.  
  208.         -----------CASING HEAT---------------
  209.         draw_text(2, 11, "Casing Temp:", colors.yellow, colors.black)
  210.         local maxVal = 2000
  211.         local minVal = math.floor(reactor1.getCasingTemperature())
  212.         if minVal < 500 then
  213.         progress_bar(2, 12, monX-2, minVal, maxVal, colors.lime, colors.gray)
  214.         else if minVal < 1000 then
  215.         progress_bar(2, 12, monX-2, minVal, maxVal, colors.yellow, colors.gray)
  216.         else if minVal < 1500 then 
  217.         progress_bar(2, 12, monX-2, minVal, maxVal, colors.orange, colors.gray)
  218.         else if minVal < 2000 then
  219.         progress_bar(2, 12, monX-2, minVal, maxVal, colors.red, colors.gray)
  220.         else if minVal >= 2000 then
  221.             progress_bar(2, 12, monX-2, 2000, maxVal, colors.red, colors.gray)
  222.         end
  223.         end
  224.         end
  225.         end
  226.         end
  227.         draw_text(15, 11, math.floor(minVal).."/"..maxVal, colors.white, colors.black)
  228.  
  229.         -------------OUTPUT-------------------
  230.         if reactor1.isActivelyCooled() then
  231.  
  232.             draw_text(2, 14, "mB/tick:", colors.yellow, colors.black)
  233.             mbt = math.floor(reactor1.getHotFluidProducedLastTick())
  234.             draw_text(13, 14, mbt.." mB/t", colors.white, colors.black)
  235.  
  236.         else
  237.  
  238.             draw_text(2, 14, "RF/tick:", colors.yellow, colors.black)
  239.             rft = math.floor(reactor1.getEnergyProducedLastTick())
  240.             draw_text(13, 14, rft.." RF/T", colors.white, colors.black)
  241.  
  242.         end
  243.  
  244.         ------------STORAGE------------
  245.         if reactor1.isActivelyCooled() then
  246.  
  247.             draw_text(2, 15, "mB Stored:", colors.yellow, colors.black)
  248.             fluid_stored = reactor1.getHotFluidAmount()
  249.             fluid_max = reactor1.getHotFluidAmountMax()
  250.             fluid_stored_percent = math.floor((fluid_stored/fluid_max)*100)
  251.             draw_text(13, 15, fluid_stored_percent.."% ("..fluid_stored.." mB)", colors.white, colors.black)
  252.  
  253.         else
  254.  
  255.             draw_text(2, 15, "RF Stored:", colors.yellow, colors.black)
  256.             energy_stored_percent = math.floor((energy_stored/10000000)*100)
  257.             draw_text(13, 15, energy_stored_percent.."% ("..energy_stored.." RF)", colors.white, colors.black)
  258.  
  259.  
  260.         end
  261.  
  262.         -------------AUTO CONTROL RODS-----------------------
  263.         auto_rods_bool = auto_rods == "true"
  264.         insertion_percent = reactor1.getControlRodLevel(0)
  265.  
  266.         if reactor1.isActivelyCooled() then
  267.             draw_text(2, 16, "Control Rods:", colors.yellow, colors.black)
  268.             draw_text(16, 16, insertion_percent.."%", colors.white, colors.black)
  269.         else
  270.  
  271.             if auto_rods_bool then
  272.                 if active then
  273.                     if rft > auto_rf+50 then
  274.                         reactor1.setAllControlRodLevels(insertion_percent+1)
  275.                     else if rft < auto_rf-50 then
  276.                         reactor1.setAllControlRodLevels(insertion_percent-1)
  277.                     end
  278.                     end
  279.                 end
  280.  
  281.                 draw_text(2, 16, "Control Rods:", colors.yellow, colors.black)
  282.                 draw_text(16, 16, insertion_percent.."%", colors.white, colors.black)
  283.                 draw_text(21, 16, "(Auto)", colors.red, colors.black)
  284.            
  285.             else
  286.                 draw_text(2, 16, "Control Rods:", colors.yellow, colors.black)
  287.                 draw_text(16, 16, insertion_percent.."%", colors.white, colors.black)
  288.             end
  289.         end
  290.  
  291.  
  292.         -------------AUTO SHUTOFF--------------------------
  293.         if reactor1.isActivelyCooled() then
  294.  
  295.             --i dont know what I should do here
  296.  
  297.  
  298.         else
  299.             auto = auto_string == "true"
  300.             if auto then
  301.                 if active then
  302.                     draw_text(2, 17, "Auto off:", colors.yellow, colors.black)
  303.                     draw_text(13, 17, off.."% RF Stored", colors.white, colors.black)
  304.                     if energy_stored_percent >= off then
  305.                         reactor1.setActive(false)
  306.                         call_homepage()
  307.                     end
  308.                 else
  309.                     draw_text(2, 17, "Auto on:", colors.yellow, colors.black)
  310.                     draw_text(13, 17, on.."% RF Stored", colors.white, colors.black)
  311.                     if energy_stored_percent <= on then
  312.                         reactor1.setActive(true)
  313.                         call_homepage()
  314.                     end
  315.                 end
  316.             else
  317.                 draw_text(2, 17, "Auto power:", colors.yellow, colors.black)
  318.                 draw_text(14, 17, "disabled", colors.red, colors.black)
  319.             end
  320.         end
  321.  
  322.         sleep(0.5)
  323.     end
  324. end
  325.  
  326. --------------MENU SCREENS--------------
  327.  
  328. ---------------Power---------------
  329. function auto_off()
  330.  
  331.     auto = auto_string == "true"
  332.     if auto then --auto power enabled
  333.  
  334.         popup_screen(3, "Auto Power", 11)
  335.         draw_text(5, 5, "Enabled", colors.lime, colors.white)
  336.         draw_text(15, 5, " disable ", colors.white, colors.black)
  337.        
  338.         draw_text(5, 7, "ON when storage =", colors.gray, colors.white)
  339.         draw_text(5, 8, " - ", colors.white, colors.black)
  340.         draw_text(13, 8, on.."% RF", colors.black, colors.white)
  341.         draw_text(22, 8, " + ", colors.white, colors.black)
  342.  
  343.         draw_text(5, 10, "OFF when storage =", colors.gray, colors.white)
  344.         draw_text(5, 11, " - ", colors.white, colors.black)
  345.         draw_text(13, 11, off.."% RF", colors.black, colors.white)
  346.         draw_text(22, 11, " + ", colors.white, colors.black)
  347.  
  348.         draw_text(11, 13, " Save ", colors.white, colors.black)
  349.  
  350.         local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  351.  
  352.         --disable auto
  353.         if yPos == 5 then
  354.             if xPos >= 15 and xPos <= 21 then
  355.                 auto_string = "false"
  356.                 save_config()
  357.                 auto_off()
  358.             else
  359.                 auto_off()
  360.             end
  361.         end
  362.  
  363.         --increase/decrease auto on %
  364.         if yPos == 8 then
  365.             if xPos >= 5 and xPos <= 8 then
  366.                 previous_on = on
  367.                 on = on-1
  368.             end
  369.             if xPos >= 22 and xPos <= 25 then
  370.                 previous_on = on
  371.                 on = on+1
  372.             end
  373.         end
  374.  
  375.         --increase/decrease auto off %
  376.         if yPos == 11 then
  377.             if xPos >= 5 and xPos <= 8 then
  378.                 previous_off = off
  379.                 off = off-1
  380.             end
  381.             if xPos >= 22 and xPos <= 25 then
  382.                 previous_off = off
  383.                 off = off+1
  384.             end
  385.         end
  386.  
  387.         if on < 0 then on = 0 end
  388.         if off >99 then off = 99 end
  389.  
  390.         if on == off or on > off then
  391.             on = previous_on
  392.             off = previous_off
  393.             popup_screen(5, "Error", 6)
  394.             draw_text(5, 7, "Auto On value must be", colors.black, colors.white)
  395.             draw_text(5, 8, "lower then auto off", colors.black, colors.white)
  396.             draw_text(11, 10, "Okay", colors.white, colors.black)
  397.             local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  398.  
  399.             auto_off()
  400.         end
  401.  
  402.         --Okay button
  403.         if yPos == 13 and xPos >= 11 and xPos <= 17 then
  404.             save_config()
  405.             call_homepage()
  406.         end
  407.  
  408.         --Exit button
  409.         if yPos == 3 and xPos == 25 then
  410.             call_homepage()
  411.         end
  412.  
  413.         auto_off()
  414.     else
  415.         popup_screen(3, "Auto Power", 5)
  416.         draw_text(5, 5, "Disabled", colors.red, colors.white)
  417.         draw_text(15, 5, " enable ", colors.white, colors.gray)
  418.         draw_text(11, 7, "Okay", colors.white, colors.black)
  419.  
  420.         local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  421.  
  422.         --Okay button
  423.         if yPos == 7 and xPos >= 11 and xPos <= 17 then
  424.             call_homepage()
  425.         end
  426.  
  427.         if yPos == 5 then
  428.             if xPos >= 15 and xPos <= 21 then
  429.                 auto_string = "true"
  430.                 save_config()
  431.                 auto_off()
  432.             else
  433.                 auto_off()
  434.             end
  435.         else
  436.             auto_off()
  437.         end
  438.     end
  439. end
  440.  
  441. -------------------Tools----------------------
  442.  
  443. function efficiency()
  444.     popup_screen(3, "Efficiency", 12)
  445.     fuel_usage = reactor1.getFuelConsumedLastTick()
  446.     rft = math.floor(reactor1.getEnergyProducedLastTick())
  447.  
  448.     rfmb = rft / fuel_usage
  449.  
  450.     draw_text(5, 5, "Fuel Consumption: ", colors.lime, colors.white)
  451.     draw_text(5, 6, fuel_usage.." mB/t", colors.black, colors.white)
  452.     draw_text(5, 8, "Energy per mB: ", colors.lime, colors.white)
  453.     draw_text(5, 9, rfmb.." RF/mB", colors.black, colors.white)
  454.  
  455.     draw_text(5, 11, "RF/tick:", colors.lime, colors.white)
  456.     draw_text(5, 12, rft.." RF/T", colors.black, colors.white)
  457.  
  458.     draw_text(11, 14, " Okay ", colors.white, colors.black)
  459.  
  460.     local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  461.  
  462.     --Okay button
  463.     if yPos == 14 and xPos >= 11 and xPos <= 17 then
  464.         call_homepage()
  465.     end
  466.  
  467.     --Exit button
  468.     if yPos == 3 and xPos == 25 then
  469.         call_homepage()
  470.     end
  471.  
  472.     efficiency()
  473. end
  474.  
  475.  
  476. function fuel()
  477.     popup_screen(5, "Fuel", 9)
  478.  
  479.     fuel_max = reactor1.getFuelAmountMax()
  480.     fuel_level = reactor1.getFuelAmount()
  481.     fuel_reactivity = math.floor(reactor1.getFuelReactivity())
  482.  
  483.     draw_text(5, 7, "Fuel Level: ", colors.lime, colors.white)
  484.     draw_text(5, 8, fuel_level.."/"..fuel_max, colors.black, colors.white)
  485.  
  486.     draw_text(5, 10, "Reactivity: ", colors.lime, colors.white)
  487.     draw_text(5, 11, fuel_reactivity.."%", colors.black, colors.white)
  488.  
  489.     draw_text(11, 13, " Okay ", colors.white, colors.black)
  490.  
  491.     local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  492.  
  493.  
  494.     --Okay button
  495.     if yPos == 13 and xPos >= 11 and xPos <= 17 then
  496.         call_homepage()
  497.     end
  498.  
  499.     --Exit button
  500.     if yPos == 5 and xPos == 25 then
  501.         call_homepage()
  502.     end
  503.  
  504.     fuel()
  505. end
  506.  
  507. function waste()
  508.     popup_screen(5, "Waste", 8)
  509.  
  510.     waste_amount = reactor1.getWasteAmount()
  511.     draw_text(5, 7, "Waste Amount: ", colors.lime, colors.white)
  512.     draw_text(5, 8, waste_amount.." mB", colors.black, colors.white)
  513.     draw_text(8, 10, " Eject Waste ", colors.white, colors.red)
  514.     draw_text(11, 12, " Close ", colors.white, colors.black)
  515.  
  516.     local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  517.  
  518.     --eject button
  519.     if yPos == 10 and xPos >= 8 and xPos <= 21 then
  520.         reactor1.doEjectWaste()
  521.         popup_screen(5, "Waste Eject", 5)
  522.         draw_text(5, 7, "Waste Ejeceted.", colors.black, colors.white)
  523.         draw_text(11, 9, " Close ", colors.white, colors.black)
  524.         local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  525.         --Okay button
  526.         if yPos == 9 and xPos >= 11 and xPos <= 17 then
  527.             call_homepage()
  528.         end
  529.  
  530.         --Exit button
  531.         if yPos == 5 and xPos == 25 then
  532.             call_homepage()
  533.         end
  534.     end
  535.  
  536.     --Okay button
  537.     if yPos == 12 and xPos >= 11 and xPos <= 17 then
  538.         call_homepage()
  539.     end
  540.  
  541.     --Exit button
  542.     if yPos == 5 and xPos == 25 then
  543.         call_homepage()
  544.     end
  545.     waste()
  546. end
  547.  
  548. function set_auto_rf()
  549.     popup_screen(5, "Auto Adjust", 11)
  550.         draw_text(5, 7, "Try to maintain:", colors.black, colors.white)
  551.  
  552.         draw_text(13, 9, " ^ ", colors.white, colors.gray)
  553.         draw_text(10, 11, auto_rf.." RF/t", colors.black, colors.white)
  554.         draw_text(13, 13, " v ", colors.white, colors.gray)
  555.         draw_text(11, 15, " Okay ", colors.white, colors.gray)
  556.  
  557.         local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  558.  
  559.         --increase button
  560.         if yPos == 9 then
  561.             auto_rf = auto_rf + 100
  562.             save_config()
  563.             set_auto_rf()
  564.         end
  565.  
  566.         --decrease button
  567.         if yPos == 13 then
  568.             auto_rf = auto_rf - 100
  569.             if auto_rf < 0 then auto_rf = 0 end
  570.             save_config()
  571.             set_auto_rf()
  572.         end
  573.  
  574.         if yPos == 15 then
  575.             control_rods()
  576.         end
  577.  
  578.         set_auto_rf()
  579. end
  580.  
  581. function control_rods()
  582.  
  583.     if reactor1.isActivelyCooled() then
  584.  
  585.         popup_screen(3, "Control Rods", 13)
  586.         insertion_percent = reactor1.getControlRodLevel(0)
  587.  
  588.         draw_text(5, 5, "Inserted: "..insertion_percent.."%", colors.black, colors.white)
  589.         progress_bar(5, 7, 20, insertion_percent, 100, colors.yellow, colors.gray)
  590.  
  591.         draw_text(5, 9, " << ", colors.white, colors.black)
  592.         draw_text(10, 9, " < ", colors.white, colors.black)
  593.         draw_text(17, 9, " > ", colors.white, colors.black)
  594.         draw_text(21, 9, " >> ", colors.white, colors.black)
  595.  
  596.         draw_text(5, 11, "Auto:", colors.black, colors.white)
  597.         draw_text(5, 13, "unavilable for", colors.red, colors.white)
  598.         draw_text(5, 14, "active cooling", colors.red, colors.white)
  599.  
  600.         draw_text(11, 16, " Close ", colors.white, colors.gray)
  601.  
  602.         local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  603.  
  604.         if yPos == 9 and xPos >= 5 and xPos <= 15 then
  605.             reactor1.setAllControlRodLevels(insertion_percent-10)
  606.         end
  607.  
  608.         if yPos == 9 and xPos >= 10 and xPos <= 13 then
  609.             reactor1.setAllControlRodLevels(insertion_percent-1)
  610.         end
  611.  
  612.         if yPos == 9 and xPos >= 17 and xPos <= 20 then
  613.             reactor1.setAllControlRodLevels(insertion_percent+1)
  614.         end
  615.  
  616.         if yPos == 9 and xPos >= 21 and xPos <= 25 then
  617.             reactor1.setAllControlRodLevels(insertion_percent+10)
  618.         end
  619.  
  620.         ------Close button-------
  621.         if yPos == 16 and xPos >= 11 and xPos <= 17 then
  622.             call_homepage()
  623.         end
  624.  
  625.         ------Exit button------------
  626.         if yPos == 5 and xPos == 25 then
  627.             call_homepage()
  628.         end
  629.         control_rods()
  630.  
  631.     else
  632.  
  633.         popup_screen(3, "Control Rods", 13)
  634.         insertion_percent = reactor1.getControlRodLevel(0)
  635.  
  636.         draw_text(5, 5, "Inserted: "..insertion_percent.."%", colors.black, colors.white)
  637.         progress_bar(5, 7, 20, insertion_percent, 100, colors.yellow, colors.gray)
  638.  
  639.         draw_text(5, 9, " << ", colors.white, colors.black)
  640.         draw_text(10, 9, " < ", colors.white, colors.black)
  641.         draw_text(17, 9, " > ", colors.white, colors.black)
  642.         draw_text(21, 9, " >> ", colors.white, colors.black)
  643.  
  644.         draw_text(5, 11, "Auto:", colors.black, colors.white)
  645.         draw_text(16, 11, " disable ", colors.white, colors.black)
  646.  
  647.         auto_rods_bool = auto_rods == "true"
  648.         if auto_rods_bool then
  649.            
  650.             draw_text(5, 13, "RF/t: "..auto_rf, colors.black, colors.white)
  651.             draw_text(18, 13, " set ", colors.white, colors.black)
  652.         else
  653.             draw_text(16, 11, " enable ", colors.white, colors.black)
  654.             draw_text(5, 13, "disabled", colors.red, colors.white)
  655.         end
  656.  
  657.         draw_text(11, 15, " Close ", colors.white, colors.gray)
  658.  
  659.         local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  660.  
  661.         -----manual adjust buttons------------
  662.         if yPos == 9 and xPos >= 5 and xPos <= 15 then
  663.             reactor1.setAllControlRodLevels(insertion_percent-10)
  664.         end
  665.  
  666.         if yPos == 9 and xPos >= 10 and xPos <= 13 then
  667.             reactor1.setAllControlRodLevels(insertion_percent-1)
  668.         end
  669.  
  670.         if yPos == 9 and xPos >= 17 and xPos <= 20 then
  671.             reactor1.setAllControlRodLevels(insertion_percent+1)
  672.         end
  673.  
  674.         if yPos == 9 and xPos >= 21 and xPos <= 25 then
  675.             reactor1.setAllControlRodLevels(insertion_percent+10)
  676.         end
  677.  
  678.  
  679.         ------auto buttons-----------------
  680.         if yPos == 11 and xPos >= 16 then
  681.             if auto_rods_bool then
  682.                 auto_rods = "false"
  683.                 save_config()
  684.                 control_rods()
  685.             else
  686.                 auto_rods = "true"
  687.                 save_config()
  688.                 control_rods()
  689.             end
  690.         end
  691.  
  692.         if yPos == 13 and xPos >= 18 then
  693.             set_auto_rf()
  694.         end
  695.  
  696.         ------Close button-------
  697.         if yPos == 15 and xPos >= 11 and xPos <= 17 then
  698.             call_homepage()
  699.         end
  700.  
  701.         ------Exit button------------
  702.         if yPos == 5 and xPos == 25 then
  703.             call_homepage()
  704.         end
  705.         control_rods()
  706.  
  707.     end
  708. end
  709.  
  710. -----------------------Settings--------------------------------
  711.  
  712.  
  713. function rf_mode()
  714.     wait = read()
  715. end
  716.  
  717. function steam_mode()
  718.     wait = read()
  719. end
  720.  
  721. function install_update(program, pastebin)
  722.         clear()
  723.         draw_line(4, 5, 22, colors.blue)
  724.  
  725.         for counter = 6, 10 do
  726.             draw_line(4, counter, 22, colors.white)
  727.         end
  728.  
  729.         draw_text(5, 5, "Updating...", colors.white, colors.blue)
  730.         draw_text(5, 7, "Open computer", colors.black, colors.white)
  731.         draw_text(5, 8, "terminal.", colors.black, colors.white)
  732.  
  733.         if fs.exists("install") then fs.delete("install") end
  734.         shell.run("pastebin get p4zeq7Ma install")
  735.         shell.run("install")
  736. end
  737.  
  738. function update()
  739.     popup_screen(5, "Updates", 4)
  740.     draw_text(5, 7, "Connecting to", colors.black, colors.white)
  741.     draw_text(5, 8, "pastebin...", colors.black, colors.white)
  742.  
  743.     sleep(0.5)
  744.    
  745.     shell.run("pastebin get MkF2QQjH current_version.txt")
  746.     sr = fs.open("current_version.txt", "r")
  747.     current_version = tonumber(sr.readLine())
  748.     sr.close()
  749.     fs.delete("current_version.txt")
  750.     terminal_screen()
  751.  
  752.     if current_version > version then
  753.  
  754.         popup_screen(5, "Updates", 7)
  755.         draw_text(5, 7, "Update Available!", colors.black, colors.white)
  756.         draw_text(11, 9, " Intall ", colors.white, colors.black)
  757.         draw_text(11, 11, " Ignore ", colors.white, colors.black)
  758.  
  759.         local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  760.  
  761.         --Instatll button
  762.         if yPos == 9 and xPos >= 11 and xPos <= 17 then
  763.             install_update()
  764.         end
  765.  
  766.         --Exit button
  767.         if yPos == 5 and xPos == 25 then
  768.             call_homepage()
  769.         end
  770.         call_homepage()
  771.  
  772.     else
  773.         popup_screen(5, "Updates", 5)
  774.         draw_text(5, 7, "You are up to date!", colors.black, colors.white)
  775.         draw_text(11, 9, " Okay ", colors.white, colors.black)
  776.  
  777.         local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  778.  
  779.         --Okay button
  780.         if yPos == 9 and xPos >= 11 and xPos <= 17 then
  781.             call_homepage()
  782.         end
  783.  
  784.         --Exit button
  785.         if yPos == 5 and xPos == 25 then
  786.             call_homepage()
  787.         end
  788.         call_homepage()
  789.     end
  790.  
  791.    
  792.  
  793. end
  794.  
  795. function reset_peripherals()
  796.     clear()
  797.     draw_line(4, 5, 22, colors.blue)
  798.  
  799.     for counter = 6, 10 do
  800.         draw_line(4, counter, 22, colors.white)
  801.     end
  802.  
  803.     draw_text(5, 5, "Reset Peripherals", colors.white, colors.blue)
  804.     draw_text(5, 7, "Open computer", colors.black, colors.white)
  805.     draw_text(5, 8, "terminal.", colors.black, colors.white)
  806.     setup_wizard()
  807.  
  808. end
  809.  
  810. --stop running status screen if monitors was touched
  811. function stop()
  812.     while true do
  813.         local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  814.             x = xPos
  815.             y = yPos
  816.             stop_function = "monitor_touch"
  817.         return
  818.     end
  819. end
  820.  
  821. function mon_touch()
  822.     --when the monitor is touch on the homepage
  823.     if y == 1 then
  824.             if x < monX/3 then
  825.                 power_menu()
  826.                 local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  827.                 if xPos < 9 then
  828.                     if yPos == 2 then
  829.                         reactor1.setActive(true)
  830.                         timer = 0 --reset anytime the reactor is turned on/off
  831.                         call_homepage()
  832.                     else if yPos == 3 then
  833.                         reactor1.setActive(false)
  834.                         timer = 0 --reset anytime the reactor is turned on/off
  835.                         call_homepage()
  836.                     else if yPos == 4 then
  837.                         auto_off()
  838.                     else
  839.                         call_homepage()
  840.                     end
  841.                     end
  842.                     end
  843.                 else
  844.                     call_homepage()
  845.                 end
  846.                
  847.             else if x < 20 then
  848.                 tools_menu()
  849.                 local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  850.                 if xPos < 25 and xPos > 10 then
  851.                     if yPos == 2 then
  852.                         control_rods()
  853.                     else if yPos == 3 then
  854.                         efficiency()
  855.                     else if yPos == 4 then
  856.                         fuel()
  857.                     else if yPos == 5 then
  858.                         waste()
  859.                     else
  860.                         call_homepage()
  861.                     end
  862.                     end
  863.                     end
  864.                     end
  865.                 else
  866.                     call_homepage()
  867.                 end
  868.             else if x < monX then
  869.                 settings_menu()
  870.                 local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  871.                 if xPos > 13 then
  872.                     if yPos == 2 then
  873.                         update()
  874.                     else if yPos == 3 then
  875.                         reset_peripherals()
  876.                     else
  877.                         call_homepage()
  878.                     end
  879.                     end
  880.                 else
  881.                     call_homepage()
  882.                 end
  883.             end
  884.             end
  885.             end
  886.         else
  887.             call_homepage()
  888.         end
  889. end
  890.  
  891. function terminal_screen()
  892.     term.clear()
  893.     draw_line_term(1, 1, 55, colors.blue)
  894.     draw_text_term(13, 1, "BigReactor Controls", colors.white, colors.blue)
  895.     draw_line_term(1, 19, 55, colors.blue)
  896.     draw_text_term(13, 19, "by jaranvil aka jared314", colors.white, colors.blue)
  897.  
  898.     draw_text_term(1, 3, "Current program:", colors.white, colors.black)
  899.     draw_text_term(1, 4, "Reactor Control v"..version, colors.blue, colors.black)
  900.    
  901.     draw_text_term(1, 6, "Installer:", colors.white, colors.black)
  902.     draw_text_term(1, 7, "pastebin.com/p4zeq7Ma", colors.blue, colors.black)
  903.  
  904.     draw_text_term(1, 9, "Please give me your feedback, suggestions,", colors.white, colors.black)
  905.     draw_text_term(1, 10, "and errors!", colors.white, colors.black)
  906.  
  907.     draw_text_term(1, 11, "reddit.com/r/br_controls", colors.blue, colors.black)
  908. end
  909.  
  910. --run both homepage() and stop() until one returns
  911. function call_homepage()
  912.     clear()
  913.     parallel.waitForAny(homepage, stop)
  914.  
  915.     if stop_function == "terminal_screen" then
  916.         stop_function = "nothing"
  917.         setup_wizard()
  918.     else if stop_function == "monitor_touch" then
  919.         stop_function = "nothing"
  920.         mon_touch()
  921.     end
  922.     end
  923. end
  924.  
  925. --try to wrap peripherals
  926. --catch any errors
  927.     function test_reactor_connection()
  928.         reactor1 = peripheral.wrap(name)  --wrap reactor
  929.         c = reactor1.getConnected()
  930.         if unexpected_condition then error() end  
  931.     end
  932.  
  933.     function test_monitor_connection()
  934.         mon = peripheral.wrap(side) --wrap mon
  935.         monX, monY = mon.getSize() --get mon size ()
  936.         if unexpected_condition then error() end  
  937.     end
  938.  
  939. --test if the entered monitor and reactor can be wrapped
  940.     function test_configs()
  941.  
  942.         term.clear()
  943.         draw_line_term(1, 1, 55, colors.blue)
  944.         draw_text_term(10, 1, "BigReactor Controls v"..version, colors.white, colors.blue)
  945.         draw_line_term(1, 19, 55, colors.blue)
  946.         draw_text_term(10, 19, "by jaranvil aka jared314", colors.white, colors.blue)
  947.  
  948.         draw_text_term(1, 3, "Wrapping peripherals...", colors.blue, colors.black)
  949.         draw_text_term(2, 5, "wrap montior...", colors.white, colors.black)
  950.         sleep(0.1)
  951.         if pcall(test_monitor_connection) then
  952.             draw_text_term(18, 5, "success", colors.lime, colors.black)
  953.         else
  954.             draw_text_term(1, 4, "Error:", colors.red, colors.black)
  955.             draw_text_term(1, 8, "Could not connect to monitor on "..side.." side", colors.red, colors.black)
  956.             draw_text_term(1, 9, "Valid sides are 'left', 'right', 'top', 'bottom' and 'back'", colors.white, colors.black)
  957.             draw_text_term(1, 11, "Press Enter to continue...", colors.gray, colors.black)
  958.             wait = read()
  959.             setup_wizard()
  960.         end
  961.         sleep(0.1)
  962.         draw_text_term(2, 6, "wrap reactor...", colors.white, colors.black)
  963.         sleep(0.1)
  964.         if pcall(test_reactor_connection) then
  965.             draw_text_term(18, 6, "success", colors.lime, colors.black)
  966.         else
  967.             draw_text_term(1, 8, "Error:", colors.red, colors.black)
  968.             draw_text_term(1, 9, "Could not connect to "..name, colors.red, colors.black)
  969.             draw_text_term(1, 10, "Reactor must be connected with networking cable and wired modem", colors.white, colors.black)
  970.             draw_text_term(1, 12, "Press Enter to continue...", colors.gray, colors.black)
  971.             wait = read()
  972.             setup_wizard()
  973.         end
  974.         sleep(0.1)
  975.         draw_text_term(2, 8, "saving settings to file...", colors.white, colors.black) 
  976.  
  977.         save_config()
  978.  
  979.         sleep(0.1)
  980.         draw_text_term(1, 10, "Setup Complete!", colors.lime, colors.black)
  981.         sleep(1)
  982.  
  983.         auto = auto_string == "true"
  984.         call_homepage()
  985.  
  986. end
  987. ----------------SETUP-------------------------------
  988.  
  989. function setup_wizard()
  990.     term.clear()
  991.     draw_text_term(1, 1, "BigReactor Controls v"..version, colors.lime, colors.black)
  992.     draw_text_term(1, 2, "Peripheral setup wizard", colors.white, colors.black)
  993.     draw_text_term(1, 4, "Step 1:", colors.lime, colors.black)
  994.     draw_text_term(1, 5, "-Place 3x3 advanced monitors next to computer.", colors.white, colors.black)
  995.     draw_text_term(1, 7, "Step 2:", colors.lime, colors.black)
  996.     draw_text_term(1, 8, "-Place a wired modem on this computer and on the ", colors.white, colors.black)
  997.     draw_text_term(1, 9, " computer port of the reactor.", colors.white, colors.black)
  998.     draw_text_term(1, 10, "-connect modems with network cable.", colors.white, colors.black)
  999.     draw_text_term(1, 11, "-right click modems to activate.", colors.white, colors.black)
  1000.     draw_text_term(1, 13, "Press Enter when ready...", colors.gray, colors.black)
  1001.    
  1002.     wait = read()
  1003.    
  1004.     term.clear()
  1005.     draw_text_term(1, 1, "Peripheral Setup", colors.lime, colors.black)
  1006.     draw_text_term(1, 3, "What side is your monitor on?", colors.yellow, colors.black)
  1007.  
  1008.     term.setTextColor(colors.white)
  1009.     term.setCursorPos(1,4)
  1010.     side = read()
  1011.  
  1012.     term.clear()
  1013.     draw_text_term(1, 1, "Peripheral Setup", colors.lime, colors.black)
  1014.     draw_text_term(1, 3, "What is the reactor's name?", colors.yellow, colors.black)
  1015.     draw_text_term(1, 4, "type 'default' for  'BigReactors-Reactor_0'", colors.gray, colors.black)
  1016.  
  1017.     term.setTextColor(colors.white)
  1018.     term.setCursorPos(1,5)
  1019.     name = read()
  1020.  
  1021.     if name == "default" then name = "BigReactors-Reactor_0" end
  1022.     auto_string = false
  1023.     on = 0
  1024.     off = 99
  1025.     auto_rods = false
  1026.     auto_rf = 0
  1027.  
  1028.     test_configs()
  1029. end
  1030.  
  1031. function start()
  1032.     --if configs exists, load values and test
  1033.     if fs.exists("config.txt") then
  1034.             load_config()
  1035.  
  1036.             test_configs()
  1037.     else
  1038.         setup_wizard()
  1039.     end
  1040. end
  1041.  
  1042. start()
Add Comment
Please, Sign In to add comment