Elrol

Startup - Desktop

Mar 2nd, 2018 (edited)
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.15 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. local tArgs = {...}
  7. local config = "DS_Data/.conf"
  8. local images = "Documents/Images/"
  9. local w,h = term.getSize()
  10. local brunning = true
  11. local slc = 0
  12.  
  13. local _osVer = string.sub(kernal.getLine(config, 1), string.find(kernal.getLine(config, 1), ":")+2)
  14. local _tbcol = string.sub(kernal.getLine(config, 2), string.find(kernal.getLine(config, 2), ":")+2)
  15. local _tbtext = string.sub(kernal.getLine(config, 3), string.find(kernal.getLine(config, 3), ":")+2)
  16. local _bgcolor = tonumber(string.sub(kernal.getLine(config, 4), string.find(kernal.getLine(config, 4), ":")+2))
  17. local _bgimage = string.sub(kernal.getLine(config, 5), string.find(kernal.getLine(config, 5), ":")+2)
  18. local _mtext = tonumber(string.sub(kernal.getLine(config, 6), string.find(kernal.getLine(config, 6), ":") +2))
  19. local _mback = tonumber(string.sub(kernal.getLine(config, 7), string.find(kernal.getLine(config, 7), ":") +2))
  20. local _allowBegin = string.sub(kernal.getLine(config, 8), string.find(kernal.getLine(config, 8), ":") +2)
  21.  
  22.  
  23.  
  24.  
  25. --Tables
  26. local menu = {
  27.     [1] = {txt = ""; tcol = _mtext; bcol = _mback; x = 1; xx = 7; y = 1; cmd = function() slc = 1 end};
  28.     [2] = {txt = "            "; tcol = _mtext; bcol = _mback; x = 1; xx = 12; y = 2; cmd = function() shell.run("edit",config) end};
  29.     [3] = {txt = " Programs > "; tcol = _mtext; bcol = _mback; x = 1; xx = 12; y = 3; cmd = function() end};
  30.     [4] = {txt = " Settings > "; tcol = _mtext; bcol = _mback; x = 1; xx = 12; y = 4; cmd = function() end};
  31.     [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};
  32.     [6] = {txt = " Quit       "; tcol = _mtext; bcol = _mback; x = 1; xx = 12; y = 6; cmd = function() term.setBackgroundColor(colors.black) term.setCursorPos(1,1) term.clear() brunning = false end};
  33.     [7] = {txt = " Logoff     "; tcol = _mtext; bcol = _mback; x = 1; xx = 12; y = 7; cmd = function() end};
  34.     [8] = {txt = " Reboot     "; tcol = _mtext; bcol = _mback; x = 1; xx = 12; y = 8; cmd = function() os.reboot() end};
  35.     [9] = {txt = " Shutdown   "; tcol = _mtext; bcol = _mback; x = 1; xx = 12; y = 9; cmd = function() os.shutdown() end};
  36.     [10] = {txt = "            "; tcol = _mtext; bcol = _mback; x = 1; xx = 12; y = 10; cmd = function() error("test error")end};
  37. }
  38.  
  39. local security = {
  40.     [1] = {txt = ""; tcol = _mtext; bcol = _mback; x = 9; xx = 18; y = 1; cmd = function() slc = 2 end};
  41.     [2] = {txt = "             "; tcol = _mtext; bcol = _mback; x = 9; xx = 21; y = 2; cmd = function() end};
  42.     [3] = {txt = " Turrets On  "; tcol = _mtext; bcol = _mback; x = 9; xx = 21; y = 3; cmd = function() redstone.setBundledOutput("back", 0) end};
  43.     [4] = {txt = " Turrets Off "; tcol = _mtext; bcol = _mback; x = 9; xx = 21; y = 4; cmd = function() redstone.setBundledOutput("back", colors.combine(redstone.getBundledOutput("back"), colors.red)) end};
  44.     [5] = {txt = " Shields On  "; tcol = _mtext; bcol = _mback; x = 9; xx = 21; y = 5; cmd = function() redstone.setBundledOutput("back", colors.combine(redstone.getBundledOutput("back"), colors.green)) end};
  45.     [6] = {txt = " Shields Off "; tcol = _mtext; bcol = _mback; x = 9; xx = 21; y = 6; cmd = function() redstone.setBundledOutput("back", 0) end};
  46.     [7] = {txt = "             "; tcol = _mtext; bcol = _mback; x = 9; xx = 21; y = 7; cmd = function() end};
  47. }
  48. --Functions
  49. local function clear(bcol)
  50.     term.setBackgroundColor(bcol)
  51.     term.clear()
  52. end
  53.  
  54. local function tb_draw()
  55.     term.setCursorPos(1,1)
  56.     term.setBackgroundColor(colors.lightGray)
  57.     term.setTextColor(colors.black)
  58.     term.clearLine()
  59.     print("[Start] [Security]")
  60.     term.setCursorPos(math.floor(w)-#_osVer, 1)
  61.     print(_osVer)
  62. end
  63.  
  64. local function drawMenu()
  65.     for k,v in pairs(menu) do
  66.         term.setBackgroundColor(v.bcol)
  67.         term.setTextColor(v.tcol)
  68.         term.setCursorPos(v.x, v.y)
  69.         print(v.txt)
  70.     end
  71. end
  72.  
  73. local function drawSecurity()
  74.     for k, v in pairs(security) do
  75.         term.setBackgroundColor(v.bcol)
  76.         term.setTextColor(v.tcol)
  77.         term.setCursorPos(v.x, v.y)
  78.         print(v.txt)
  79.     end
  80. end
  81.  
  82. local function drawStatus()
  83.     local w,h = term.getSize()
  84.     local text = " T  S  "
  85.     term.setCursorPos(w-#text, h)
  86.     term.setBackgroundColor(colors.white)
  87.     write(text)
  88.     if redstone.testBundledInput("back", colors.red) then
  89.         paintutils.drawImage(paintutils.loadImage(images.."off.npg"), 46, 19)
  90.     else
  91.         paintutils.drawImage(paintutils.loadImage(images.."on.npg"), 46, 19)
  92.     end
  93.    
  94.     if redstone.testBundledInput("back", colors.green) then
  95.         paintutils.drawImage(paintutils.loadImage(images.."on.npg"), 49, 19)
  96.     else
  97.         paintutils.drawImage(paintutils.loadImage(images.."off.npg"), 49, 19)
  98.     end
  99.        
  100. end
  101.  
  102. local function drawScreen(bcol, bimage)
  103.     clear(bcol)
  104.     if bimage == "None" then bimage = images.."bg.npg" end
  105.     paintutils.drawImage(paintutils.loadImage(images.."bg.npg"), 1, 1)
  106.     tb_draw()
  107.     drawStatus()
  108. end
  109.  
  110. local function menuClick()
  111.     for k,v in pairs(menu) do
  112.         local e = {os.pullEvent()}
  113.         if e[1] == "mouse_click" then
  114.             if e[2] == 1 then
  115.                 if e[3] >= v.x and e[3] <= v.xx and e[4] > v.y -1 and e[4] < v.y +1 then
  116.                     v.cmd()
  117.                     slc = 0
  118.                     drawScreen(_bgcolor, _bgimage)
  119.                 end
  120.             elseif e[2] == 2 then
  121.                 slc = 0
  122.                 drawScreen(_bgcolor, _bgimage)
  123.             end
  124.         end
  125.     end return true
  126. end
  127.  
  128. local function securityClick()
  129.     for k,v in pairs(security) do
  130.         local e = {os.pullEvent()}
  131.         if e[1] == "mouse_click" then
  132.             if e[2] == 1 then
  133.                 if e[3] >= v.x and e[3] <= v.xx and e[4] > v.y -1 and e[4] < v.y +1 then
  134.                     v.cmd()
  135.                     slc = 0
  136.                     drawScreen(_bgcolor, _bgimage)
  137.                 end
  138.             elseif e[2] == 2 then
  139.                 slc = 0
  140.                 drawScreen(_bgcolor, _bgimage)
  141.             end
  142.         end
  143.     end return true
  144. end
  145.  
  146. local function getFile(url, path)
  147.     dowload = http.get(url)
  148.     kernal.fwrite(path, dowload.readAll())
  149. end
  150. --Main
  151. local function main()
  152.     drawScreen(_bgcolor, _bgimage)
  153.     while brunning do
  154.     local event, button, x, y = os.pullEvent("mouse_click")
  155.         if slc == 0 then
  156.             drawScreen(_bgcolor, _bgimage)
  157.             term.setCursorPos(1,5)
  158.             print(button, " X:",x, ", Y:", y)
  159.             if button == 1 then
  160.                 if x >= 1 and x <= 7 and y == 1 then
  161.                     slc = 1
  162.                     drawMenu()
  163.                 elseif x >= 9 and x <= 18 and y == 1 then
  164.                     slc = 2
  165.                     drawSecurity()
  166.                 end
  167.             end
  168.         elseif slc == 1 then
  169.             drawMenu()
  170.             menuClick()
  171.         elseif slc == 2 then
  172.             drawSecurity()
  173.             securityClick()
  174.         end
  175.     end
  176. end
  177.  
  178. ccatch.A_crash(main, "center", 1, 8)
Add Comment
Please, Sign In to add comment