Elrol

Startup - Desktop v1.6

Mar 6th, 2018 (edited)
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 12.01 KB | None | 0 0
  1. --Last Edit 7:48pm
  2. --Variables
  3. os.loadAPI("DS_Data/kernal")
  4. os.loadAPI("DS_Data/ccatch")
  5.  
  6. tArgs = {...}
  7. config = "DS_Data/.conf"
  8. images = "Documents/Images/"
  9. w,h = term.getSize()
  10. brunning = true
  11. slc = "0"
  12. subSlc = 0
  13.  
  14. _osVer = string.sub(kernal.getLine(config, 1), string.find(kernal.getLine(config, 1), ":")+2)
  15. _tbcol = string.sub(kernal.getLine(config, 2), string.find(kernal.getLine(config, 2), ":")+2)
  16. _tbtext = string.sub(kernal.getLine(config, 3), string.find(kernal.getLine(config, 3), ":")+2)
  17. _bgcolor = tonumber(string.sub(kernal.getLine(config, 4), string.find(kernal.getLine(config, 4), ":")+2))
  18. _bgimage = string.sub(kernal.getLine(config, 5), string.find(kernal.getLine(config, 5), ":")+2)
  19. _mtext = tonumber(string.sub(kernal.getLine(config, 6), string.find(kernal.getLine(config, 6), ":") +2))
  20. _mback = tonumber(string.sub(kernal.getLine(config, 7), string.find(kernal.getLine(config, 7), ":") +2))
  21. _allowBegin = string.sub(kernal.getLine(config, 8), string.find(kernal.getLine(config, 8), ":") +2)
  22.  
  23. reactor = "BigReactors-Reactor_0"
  24.  
  25.  
  26.  
  27. --Tables
  28. mainMenu = {
  29.     [1] = {txt = ""; tcol = _mtext; bcol = _mback; x = 1; xx = 7; y = 1; cmd = function() slc = "0" end};
  30.     [2] = {txt = "            "; tcol = _mtext; bcol = _mback; x = 1; xx = 12; y = 2; cmd = function() end};
  31.     [3] = {txt = " Programs > "; tcol = _mtext; bcol = _mback; x = 1; xx = 12; y = 3; cmd = function() end};
  32.     [4] = {txt = " Settings > "; tcol = _mtext; bcol = _mback; x = 1; xx = 12; y = 4; cmd = function() shell.run("edit",config) end};
  33.     [5] = {txt = " Lua Prompt "; tcol = _mtext; bcol = _mback; x = 1; xx = 12; y = 5; cmd = function() shell.run("lua") term.setBackgroundColor(colors.black) term.setTextColor(1) end};
  34.     [6] = {txt = " Quit       "; tcol = _mtext; bcol = _mback; x = 1; xx = 12; y = 6; cmd = function() brunning = false term.setBackgroundColor(colors.black) term.setCursorPos(1,1) term.clear() end};
  35.     [7] = {txt = " Logoff     "; tcol = _mtext; bcol = _mback; x = 1; xx = 12; y = 7; cmd = function() end};
  36.     [8] = {txt = " Reboot     "; tcol = _mtext; bcol = _mback; x = 1; xx = 12; y = 8; cmd = function() os.reboot() end};
  37.     [9] = {txt = " Shutdown   "; tcol = _mtext; bcol = _mback; x = 1; xx = 12; y = 9; cmd = function() os.shutdown() end};
  38.     [10] = {txt = "            "; tcol = _mtext; bcol = _mback; x = 1; xx = 12; y = 10; cmd = function() error("test error")end};
  39. }
  40.  
  41. securityMenu = {
  42.     [1] = {txt = ""; tcol = _mtext; bcol = _mback; x = 9; xx = 18; y = 1; cmd = function() slc = "0" end};
  43.     [2] = {txt = "             "; tcol = _mtext; bcol = _mback; x = 9; xx = 21; y = 2; cmd = function() end};
  44.     [3] = {txt = " Turrets On  "; tcol = _mtext; bcol = _mback; x = 9; xx = 21; y = 3; cmd = function() term.setCursorPos(1,5) term.setTextColor(colors.lightGray) term.setBackgroundColor(colors.gray) print("Turrets On") redstone.setBundledOutput("back", colors.subtract(redstone.getBundledOutput("back"), colors.red)) end};
  45.     [4] = {txt = " Turrets Off "; tcol = _mtext; bcol = _mback; x = 9; xx = 21; y = 4; cmd = function() term.setCursorPos(1,5) term.setTextColor(colors.lightGray) term.setBackgroundColor(colors.gray) print("Turrets Off") redstone.setBundledOutput("back", colors.combine(redstone.getBundledOutput("back"), colors.red)) end};
  46.     [5] = {txt = " Shields On  "; tcol = _mtext; bcol = _mback; x = 9; xx = 21; y = 5; cmd = function() term.setCursorPos(1,5) term.setTextColor(colors.lightGray) term.setBackgroundColor(colors.gray) print("Shields On") redstone.setBundledOutput("back", colors.subtract(redstone.getBundledOutput("back"), colors.green)) end};
  47.     [6] = {txt = " Shields Off "; tcol = _mtext; bcol = _mback; x = 9; xx = 21; y = 6; cmd = function() term.setCursorPos(1,5) term.setTextColor(colors.lightGray) term.setBackgroundColor(colors.gray) print("Shields Off") redstone.setBundledOutput("back", colors.combine(redstone.getBundledOutput("back"), colors.green)) end};
  48.     [7] = {txt = "             "; tcol = _mtext; bcol = _mback; x = 9; xx = 21; y = 7; cmd = function() end};
  49. }
  50.  
  51. powerMenu = {
  52.     [1] = {txt = ""; tcol = _mtext; bcol = _mback; x = 20; xx = 27; y = 1; cmd = function() slc = "0" end};
  53.     [2] = {txt = "            "; tcol = _mtext; bcol = _mback; x = 20; xx = 31; y = 2; cmd = function() end};
  54.     [3] = {txt = " Reactor >  "; tcol = _mtext; bcol = _mback; x = 20; xx = 31; y = 3; cmd = function() slc = "3.1" end};
  55.     [4] = {txt = " Turbines > "; tcol = _mtext; bcol = _mback; x = 20; xx = 31; y = 4; cmd = function() slc = "3.2" end};
  56.     [5] = {txt = "            "; tcol = _mtext; bcol = _mback; x = 20; xx = 31; y = 5; cmd = function() end};
  57. }
  58.  
  59. reactorMenu = {
  60.     [1] = {txt = " On  "; tcol = _mtext; bcol = _mback; x = 32; xx = 36; y = 3; cmd = function() peripheral.wrap(reactor).setActive(true) end};
  61.     [2] = {txt = " Off "; tcol = _mtext; bcol = _mback; x = 32; xx = 36; y = 4; cmd = function() peripheral.wrap(reactor).setActive(false) end};
  62. }
  63.  
  64. turbinesMenu = {
  65.     [1] = {txt = " Turbine 1 > "; tcol = _mtext; bcol = _mback; x = 32; xx = 44; y = 4; cmd = function() slc = "3.2.1" end};
  66.     [2] = {txt = " Turbine 2 > "; tcol = _mtext; bcol = _mback; x = 32; xx = 44; y = 5; cmd = function() slc = "3.2.2" end};
  67.     [3] = {txt = " Turbine 3 > "; tcol = _mtext; bcol = _mback; x = 32; xx = 44; y = 6; cmd = function() slc = "3.2.3" end};
  68.     [4] = {txt = " Turbine 4 > "; tcol = _mtext; bcol = _mback; x = 32; xx = 44; y = 7; cmd = function() slc = "3.2.4" end};
  69. }
  70.  
  71. turbineMenu = {
  72.     [1] = {txt = " Activate        "; tcol = _mtext; bcol = _mback; x = 45; xx = 52; y = 3 + subSlc; cmd = function() peripheral.wrap("BigReactors-Turbine_"..subSlc).setActive(true) end};
  73.     [2] = {txt = " Deactivate      "; tcol = _mtext; bcol = _mback; x = 45; xx = 52; y = 4 + subSlc; cmd = function() peripheral.wrap("BigReactors-Turbine_"..subSlc).setActive(false) end};
  74.     [3] = {txt = " Engage Coils    "; tcol = _mtext; bcol = _mback; x = 45; xx = 52; y = 5 + subSlc; cmd = function() peripheral.wrap("BigReactors-Turbine_"..subSlc).setInductorEngaged(true) end};
  75.     [4] = {txt = " Disengage Coils "; tcol = _mtext; bcol = _mback; x = 45; xx = 52; y = 6 + subSlc; cmd = function() peripheral.wrap("BigReactors-Turbine_"..subSlc).setInductorEngaged(false) end};
  76. }
  77.  
  78. --Functions
  79. function clear(bcol)
  80.     term.setBackgroundColor(bcol)
  81.     term.clear()
  82. end
  83.  
  84. function draw_line(mon, x, y, length, color)
  85.         mon.setBackgroundColor(color)
  86.         mon.setCursorPos(x,y)
  87.         mon.write(string.rep(" ", length))
  88. end
  89.  
  90. function drawStatus()
  91.     local w,h = term.getSize()
  92.     local text = " T  S  "
  93.     term.setCursorPos(w-#text, h)
  94.     term.setBackgroundColor(colors.white)
  95.     write(text)
  96.     if redstone.testBundledInput("back", colors.red) then
  97.         paintutils.drawImage(paintutils.loadImage(images.."off.npg"), 46, 19)
  98.     else
  99.         paintutils.drawImage(paintutils.loadImage(images.."on.npg"), 46, 19)
  100.     end
  101.    
  102.     if redstone.testBundledInput("back", colors.green) then
  103.         paintutils.drawImage(paintutils.loadImage(images.."off.npg"), 49, 19)
  104.     else
  105.         paintutils.drawImage(paintutils.loadImage(images.."on.npg"), 49, 19)
  106.     end
  107.        
  108. end
  109.  
  110. function tb_draw()
  111.     term.setCursorPos(1,1)
  112.     term.setBackgroundColor(colors.lightGray)
  113.     term.setTextColor(colors.black)
  114.     term.clearLine()
  115.     print("[Start] [Security] [Power]")
  116.     term.setCursorPos(math.floor(w)-#_osVer, 1)
  117.     print(_osVer)
  118.     --sleep(0.1)
  119.     drawStatus()
  120. end
  121.  
  122. function drawMenu(menuVar)
  123.     for k,v in pairs(menuVar) do
  124.         term.setBackgroundColor(v.bcol)
  125.         term.setTextColor(v.tcol)
  126.         term.setCursorPos(v.x, v.y)
  127.         print(v.txt)
  128.     end
  129. end
  130.  
  131. function drawScreen(bcol, bimage)
  132.     clear(bcol)
  133.     if bimage == "None" then bimage = images.."bg.npg" end
  134.     paintutils.drawImage(paintutils.loadImage(images.."bg.npg"), 1, 1)
  135.     tb_draw()
  136. end
  137.  
  138. function menuClick(menuVar, button, x, y)
  139.     for k,v in pairs(menuVar) do
  140.         if button == 1 then
  141.             if x >= v.x and x <= v.xx and y == v.y then  
  142.                 v.cmd()
  143.                 drawScreen(_bgcolor, _bgimage)
  144.             end
  145.         elseif button == 2 then
  146.             slc = "0"
  147.             drawScreen(_bgcolor, _bgimage)
  148.         end
  149.     end return true
  150. end
  151.  
  152. function getFile(url, path)
  153.     dowload = http.get(url)
  154.     kernal.fwrite(path, dowload.readAll())
  155. end
  156.  
  157. function drawTurbine(turbine, monitor, id)
  158.     local w,h = monitor.getSize()
  159.     local y = 1 + (id * 6)
  160.     local x = 25
  161.     monitor.setTextScale(0.5)
  162.     for z = 0, 5 do
  163.         draw_line(monitor, 1, y+z, x+2, colors.lightGray)
  164.         if z > 0 and z < 5 then
  165.             draw_line(monitor, 2, y+z, x, colors.gray)
  166.         end
  167.     end
  168.     --Rotor speed
  169.     speed = math.floor(turbine.getRotorSpeed())
  170.     rswidth = math.floor((100*(speed/2000))/4)
  171.     draw_line(monitor, 2, y+1, rswidth, colors.lime)
  172.    
  173.     --Steam level
  174.     steam = math.floor(turbine.getInputAmount())
  175.     slwidth = math.floor((100*(steam/4000))/4)
  176.     draw_line(monitor, 2, y+2, slwidth, colors.white)
  177.    
  178.     --Water level
  179.     water = math.floor(turbine.getOutputAmount())
  180.     wlwidth = math.floor((100*(water/4000))/4)
  181.     draw_line(monitor, 2, y+3, wlwidth, colors.blue)
  182.    
  183.     --Rf storage
  184.     power = math.floor(turbine.getEnergyStored())
  185.     pwidth = math.floor((100*(power/1000000))/4)
  186.     draw_line(monitor, 2, y+4, pwidth, colors.red)
  187.    
  188.     --Text
  189.     monitor.setBackgroundColor(colors.black)
  190.     monitor.setTextColor(colors.yellow)
  191.     monitor.setCursorPos(30, y)
  192.     monitor.write("Turbine "..id..": "..turbine.getEnergyProducedLastTick().." RF/T")
  193.     monitor.setCursorPos(30, y+1)
  194.     monitor.write("Rotor Speed: "..speed)
  195.     monitor.setCursorPos(30, y+2)
  196.     monitor.write("Steam Level: "..steam)
  197.     monitor.setCursorPos(30, y+3)
  198.     monitor.write("Water Level: "..water)
  199.     monitor.setCursorPos(30, y+4)
  200.     monitor.write("Power Stored: "..power.." RF")
  201. end
  202.  
  203. function drawTurbines()
  204.     monitor = peripheral.wrap("monitor_0")
  205.     monitor.setBackgroundColor(colors.black)
  206.     monitor.clear()
  207.     monitor.setTextScale(0.5)
  208.     for i = 0, 3 do
  209.         turbine = peripheral.wrap("BigReactors-Turbine_"..i)
  210.         drawTurbine(turbine, monitor, i)
  211.     end
  212.    
  213. end
  214.  
  215.  
  216. --Main
  217. function drawMonitors()
  218.     while true do
  219.         drawScreen(_bgcolor, _bgimage)
  220.         drawTurbines()
  221.         sleep(0.5)
  222.     end
  223. end
  224.  
  225. function terminalClick()
  226.     local event, button, x, y = os.pullEvent("mouse_click")
  227.         drawScreen(_bgcolor, _bgimage)
  228.         if slc == "0" then
  229.             drawScreen(_bgcolor, _bgimage)
  230.             if button == 1 then
  231.                 if x >= 1 and x <= 7 and y == 1 then
  232.                     slc = "1"
  233.                     drawMenu(mainMenu)
  234.                 elseif x >= 9 and x <= 18 and y == 1 then
  235.                     slc = "2"
  236.                     drawMenu(securityMenu)
  237.                 elseif x >= 20 and x <= 26 and y == 1 then
  238.                     slc = "3"
  239.                     drawMenu(powerMenu)
  240.                 end
  241.             end
  242.         elseif slc == "1" then
  243.             drawMenu(mainMenu)
  244.             menuClick(mainMenu, button, x, y)
  245.         elseif slc == "2" then
  246.             drawMenu(securityMenu)
  247.             menuClick(securityMenu, button, x, y)
  248.         elseif slc == "3" then
  249.             drawMenu(powerMenu)
  250.             menuClick(powerMenu, button, x, y)
  251.         elseif slc == "3.1" then
  252.             drawMenu(powerMenu)
  253.             drawMenu(reactorMenu)
  254.             menuClick(reactorMenu, button, x, y)
  255.         elseif slc == "3.2" then
  256.             drawMenu(powerMenu)
  257.             drawMenu(turbinesMenu)
  258.             menuClick(turbinesMenu, button, x, y)
  259.         elseif string.find(slc, "3.2.")then
  260.             subSlc = tonumber(string.sub(slc, 5))
  261.             print(subSlc)
  262.             drawMenu(powerMenu)
  263.             drawMenu(turbinesMenu)
  264.             drawMenu(turbineMenu)
  265.             menuClick(turbineMenu)
  266.         end
  267.         start()
  268. end
  269.  
  270. function start()
  271.     clear()
  272.     parallel.waitForAny(drawMonitors, terminalClick)
  273.    
  274. end
  275.  
  276. ccatch.A_crash(start, "center", 1, 8)
Add Comment
Please, Sign In to add comment