Advertisement
MJRLegends

Fusion Reactor Management Program Mekanism 9

May 26th, 2016
574
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.96 KB | None | 0 0
  1. ----------- Made BY MJRLegends (Please dont claim as your own code) -----------
  2. version = "1.0.4"
  3.  
  4. mouseWidth = 0
  5. mouseHeight = 0
  6.  
  7. setting = false
  8.  
  9. function draw_line(x, y, length, color)
  10.     monitor.setBackgroundColor(color)
  11.     monitor.setCursorPos(x,y)
  12.     monitor.write(string.rep(" ", length))
  13. end
  14.  
  15. function progress_bar(x, y, length, minVal, maxVal, bar_color, bg_color)
  16.     draw_line(x, y, length, bg_color) --backgoround bar
  17.     local barSize = math.floor((minVal/maxVal) * length)
  18.     draw_line(x, y, barSize, bar_color)     --progress so far
  19. end
  20.  
  21. function draw_text(x, y, text, text_color, bg_color)
  22.     monitor.setBackgroundColor(bg_color)
  23.     monitor.setTextColor(text_color)
  24.     monitor.setCursorPos(x,y)
  25.     monitor.write(text)
  26. end
  27.  
  28. function initPeripherals()
  29.     local perList = peripheral.getNames()
  30.     for i=1,#perList,1 do
  31.         if peripheral.getType(perList[i]) == "monitor" then
  32.             monitor = peripheral.wrap(perList[i])
  33.             term.setCursorPos(1,3)
  34.             term.write("Monitor Found!")
  35.         end
  36.         if peripheral.getType(perList[i]) == "mekanism_machine" then
  37.             reactor = peripheral.wrap(perList[i])
  38.             term.setCursorPos(1,4)
  39.             term.write("Fusion Reactor Found!")
  40.         end
  41.         if peripheral.getType(perList[i]) == "Reactor Logic Adapter" then
  42.             reactor = peripheral.wrap(perList[i])
  43.             term.setCursorPos(1,4)
  44.             term.write("Fusion Reactor Found!")
  45.         end
  46.     end
  47. end
  48.  
  49. function drawTitle()
  50.     monitor.setTextColour((colours.blue))
  51.     monitor.setCursorPos(1,1)
  52.     monitor.write("MJRLegends Fusion Reactor Management")
  53.     monitor.setTextColour((colours.white))
  54.    
  55.     displayW,displayH=monitor.getSize()
  56.     monitor.setTextColour((colours.blue))
  57.     monitor.setCursorPos(0,2)
  58.     monitor.write(string.rep("-", displayW))
  59. end
  60.  
  61. function drawConsoleHeader()
  62.     term.setBackgroundColor(colors.black)
  63.     term.setTextColor(colors.blue)
  64.     term.setCursorPos(1,1)
  65.     term.write("MJRLegends Fusion Reactor Management")
  66.     term.setCursorPos(1,2)
  67.     term.write("Version: " .. version)
  68. end
  69.  
  70. function drawControlScreen()
  71.     drawConsoleHeader()
  72.     monitor.setTextScale(1)
  73.     monitor.clear()
  74.     active = reactor.isIgnited()
  75.    
  76.     -----------Title---------------------
  77.     drawTitle()
  78.     -----------Reactor Enable/Disable---------------------
  79.     monitor.setCursorPos(1,3)
  80.     monitor.write("Reactor: ")
  81.     if active then
  82.         monitor.setBackgroundColour((colours.blue))
  83.     else
  84.         monitor.setBackgroundColour((colours.grey))
  85.     end
  86.     monitor.setCursorPos(20,3)
  87.     monitor.write(" ON  ")
  88.    
  89.     if active then
  90.         monitor.setBackgroundColour((colours.grey))
  91.     else
  92.         monitor.setBackgroundColour((colours.blue))
  93.     end
  94.     monitor.setCursorPos(25,3)
  95.     monitor.write(" OFF ")
  96.     monitor.setBackgroundColour((colours.black))
  97.  
  98.     -----------Section Lines---------------------
  99.     displayW,displayH=monitor.getSize()
  100.    
  101.     monitor.setTextColour((colours.blue))
  102.     monitor.setCursorPos(0,4)
  103.     monitor.write(string.rep("-", displayW))
  104.     monitor.setTextColour((colours.white))
  105.    
  106.     monitor.setTextColour((colours.blue))
  107.     monitor.setCursorPos(0,displayH - 2)
  108.     monitor.write(string.rep("-", displayW))
  109.     monitor.setTextColour((colours.white))
  110.    
  111.     monitor.setTextColour((colours.blue))
  112.     monitor.setCursorPos(0,displayH - 0)
  113.     monitor.write(string.rep("-", displayW))
  114.     monitor.setTextColour((colours.white))
  115.    
  116.     -----------Bottom Bar Buttons---------------------
  117.     if setting then
  118.         monitor.setBackgroundColour((colours.grey))
  119.     else
  120.         monitor.setBackgroundColour((colours.blue))
  121.     end
  122.     monitor.setCursorPos(displayW - 10,displayH - 1)
  123.     monitor.write(" Settings ")
  124.     monitor.setBackgroundColour((colours.black))
  125. end
  126.  
  127. function drawDisplayScreen()
  128.     displayW,displayH=monitor.getSize()
  129.     monitor.setTextScale(1)
  130.    
  131.     -----------Casing Heat---------------------
  132.     draw_text(2, 5, "Casing Heat: ", colors.yellow, colors.black)
  133.     local maxVal = 5000000000
  134.     local minVal = math.floor(tonumber(reactor.getCaseHeat()))
  135.     draw_text(19, 5, minVal.." C", colors.white, colors.black)
  136.    
  137.     if minVal < 100000 then
  138.     progress_bar(2, 6, displayW-2, minVal, maxVal, colors.lightBlue, colors.gray)
  139.     elseif minVal < math.floor((1000000000 / 2)/2) then
  140.     progress_bar(2, 6, displayW-2, minVal, maxVal, colors.lime, colors.gray)
  141.     elseif minVal < math.floor(1000000000 / 2) then
  142.     progress_bar(2, 6, displayW-2, minVal, maxVal, colors.yellow, colors.gray)
  143.     elseif minVal >= math.floor(1000000000 / 2) then
  144.     progress_bar(2, 6, displayW-2, minVal, maxVal, colors.red, colors.gray)
  145.     end
  146.     monitor.setBackgroundColour((colours.black))
  147.    
  148.     -----------Plasma Heat---------------------
  149.     draw_text(2, 8, "Plasma Heat: ", colors.yellow, colors.black)
  150.     local maxVal = 7350000000
  151.     local minVal = math.floor(tonumber(reactor.getPlasmaHeat()))
  152.     draw_text(19, 8, minVal.." C", colors.white, colors.black)
  153.    
  154.     if minVal < 100000 then
  155.     progress_bar(2, 9, displayW-2, minVal, maxVal, colors.lightBlue, colors.gray)
  156.     elseif minVal < math.floor((1000000000 / 2)/2) then
  157.     progress_bar(2, 9, displayW-2, minVal, maxVal, colors.lime, colors.gray)
  158.     elseif minVal < math.floor(1000000000 / 2) then
  159.     progress_bar(2, 9, displayW-2, minVal, maxVal, colors.yellow, colors.gray)
  160.     elseif minVal >= math.floor(1000000000 / 2) then
  161.     progress_bar(2, 9, displayW-2, minVal, maxVal, colors.red, colors.gray)
  162.     end
  163.     monitor.setBackgroundColour((colours.black))
  164.    
  165.     -----------Ignition Heat---------------------
  166.     draw_text(2, 11, "Ignition Heat: ", colors.yellow, colors.black)
  167.     local maxVal = 100000000
  168.     local minVal = math.floor(tonumber(reactor.getIgnitionTemp()))
  169.     draw_text(19, 11, minVal.." C", colors.white, colors.black)
  170.    
  171.     if minVal < 100000 then
  172.     progress_bar(2, 12, displayW-2, minVal, maxVal, colors.lightBlue, colors.gray)
  173.     elseif minVal < math.floor((100000000 / 2)/2) then
  174.     progress_bar(2, 12, displayW-2, minVal, maxVal, colors.lime, colors.gray)
  175.     elseif minVal < math.floor(100000000 / 2) then
  176.     progress_bar(2, 12, displayW-2, minVal, maxVal, colors.yellow, colors.gray)
  177.     elseif minVal >= math.floor(100000000 / 2) then
  178.     progress_bar(2, 12, displayW-2, minVal, maxVal, colors.red, colors.gray)
  179.     end
  180.     monitor.setBackgroundColour((colours.black))
  181.    
  182.     -----------Energy---------------------
  183.     draw_text(2, 14, "Power: ", colors.yellow, colors.black)
  184.     local maxVal = reactor.getMaxEnergy()
  185.     local minVal = math.floor(tonumber(reactor.getEnergy()))
  186.     draw_text(19, 14, math.floor(minVal / 2.5).." RF", colors.white, colors.black)
  187.    
  188.     progress_bar(2, 15, displayW-2, minVal, maxVal, colors.lightGray, colors.gray)
  189.     monitor.setBackgroundColour((colours.black))
  190.    
  191.     -----------Fuel---------------------
  192.     draw_text(2, 17, "Fuel: ", colors.yellow, colors.black)
  193.     local maxVal = reactor.getMaxEnergy()
  194.     local minVal = tonumber(reactor.getFuel())
  195.     draw_text(19, 17, minVal.." mb", colors.white, colors.black)
  196.    
  197.     progress_bar(2, 18, displayW-2, minVal, maxVal, colors.pink, colors.gray)
  198.     monitor.setBackgroundColour((colours.black))
  199.    
  200.     -----------Injection Rate---------------------
  201.     draw_text(2, 20, "Injection Rate: ", colors.yellow, colors.black)
  202.     draw_text(24, 20, reactor.getInjectionRate(), colors.white, colors.black)
  203.    
  204.     -----------Has Fuel---------------------
  205.     --draw_text(2, 18, "Fuel: ", colors.yellow, colors.black)
  206.     --draw_text(24, 18, reactor.hasFuel(), colors.white, colors.black)
  207.    
  208.     -----------Engery Producing---------------------
  209.     --draw_text(2, 19, "Engery Producing J/T: ", colors.yellow, colors.black)
  210.     --draw_text(24, 19, math.floor(tonumber(reactor.getProducing())) .. " J/T", colors.white, colors.black)
  211.     draw_text(2, 21, "Engery Producing RF/T: ", colors.yellow, colors.black)
  212.     draw_text(24, 21, math.floor(tonumber(reactor.getProducing()) / 2.5) .. " RF/T", colors.white, colors.black)
  213.    
  214.     -----------Can Ignite---------------------
  215.     --draw_text(2, 21, "Can Ignite: ", colors.yellow, colors.black)
  216.     --draw_text(24, 21, reactor.canIgnite(), colors.white, colors.black)
  217.    
  218. end
  219.  
  220. function drawSettingScreen()
  221.     displayW,displayH=monitor.getSize()
  222.    
  223.     -------------Title-------------------
  224.     draw_text(16, 6, "Settings", colors.blue, colors.black)
  225.    
  226.     monitor.setTextColour((colours.blue))
  227.     monitor.setCursorPos(0,7)
  228.     monitor.write(string.rep("-", displayW))
  229.     monitor.setTextColour((colours.white))
  230. end
  231.  
  232. function checkClickPosition()
  233.     displayW,displayH=monitor.getSize()
  234.     --if mouseWidth > 20 and mouseWidth < 24 and mouseHeight == 3 then
  235.     --    reactor.setActive(true)
  236.     --elseif mouseWidth > 24 and mouseWidth < 28 and mouseHeight == 3 then
  237.      --   reactor.setActive(false)
  238.     if mouseWidth > (displayW - 10) and mouseWidth < displayW and mouseHeight == (displayH - 1) then
  239.         if setting then
  240.             setting = false
  241.         else
  242.             setting = true
  243.         end
  244.     end
  245.     sleep(0.5)
  246. end
  247.  
  248.  
  249. function mainMenu()
  250.     initPeripherals()
  251.     drawConsoleHeader()
  252.     if reactor == nil then
  253.         term.setCursorPos(1,4)
  254.         term.setTextColor(colors.red)
  255.         term.write("No Fusion Reactor Found!")
  256.     elseif  monitor == nil then
  257.         term.setCursorPos(1,4)
  258.         term.setTextColor(colors.red)
  259.         term.write("No Monitor Found!")
  260.     else
  261.         while true do
  262.             displayW,displayH=monitor.getSize()
  263.             if displayH == 26 and displayW == 39 then
  264.                 if tonumber(reactor.getCaseHeat()) == nil then
  265.                     drawTitle()
  266.                     draw_text(2, 3, "Fusion Reactor currently not formed!", colors.red, colors.black)
  267.                 else
  268.                     drawControlScreen()
  269.                     if setting == true then
  270.                         drawSettingScreen()
  271.                     else
  272.                         drawDisplayScreen()
  273.                     end
  274.                 end
  275.             else
  276.                 print("This program is built for a 4x4 monitor only!")
  277.                 return
  278.             end
  279.             sleep(1.0)
  280.         end
  281.     end
  282. end
  283.  
  284. function events()
  285.     while true do
  286.         event,p1,p2,p3 = os.pullEvent()
  287.         if event=="monitor_touch" then
  288.             mouseWidth = p2 -- sets mouseWidth
  289.             mouseHeight = p3 -- and mouseHeight
  290.             checkClickPosition() -- this runs our function
  291.         end
  292.     end
  293. end
  294.  
  295. parallel.waitForAny(mainMenu,events)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement