Elrol

Startup - Desktop v1.5

Mar 3rd, 2018 (edited)
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.27 KB | None | 0 0
  1. --Last Edit 8:27am
  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", colors.subtract(redstone.getBundledOutput("back"), colors.red)) 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.subtract(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", colors.combine(redstone.getBundledOutput("back"), colors.green)) 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.."off.npg"), 49, 19)
  96.     else
  97.         paintutils.drawImage(paintutils.loadImage(images.."on.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(button, x, y)
  111.     testClick(button, x, y)
  112.     for k,v in pairs(menu) do
  113.         if button == 1 then
  114.             if x >= v.x and x <= v.xx and y == 1 then
  115.                 v.cmd()
  116.                 slc = 0
  117.                 drawScreen(_bgcolor, _bgimage)
  118.             end
  119.         elseif button == 2 then
  120.             slc = 0
  121.             drawScreen(_bgcolor, _bgimage)
  122.         end
  123.     end return true
  124. end
  125.  
  126. local function securityClick(button, x, y)
  127.     testClick(button, x, y)
  128.     for k,v in pairs(security) do
  129.             if button == 1 then
  130.                 if x >= v.x and x <= v.xx and y == 1 then
  131.                     v.cmd()
  132.                     slc = 0
  133.                     drawScreen(_bgcolor, _bgimage)
  134.                 end
  135.             elseif button == 2 then
  136.                 slc = 0
  137.                 drawScreen(_bgcolor, _bgimage)
  138.             end
  139.     end return true
  140. end
  141.  
  142. local function getFile(url, path)
  143.     dowload = http.get(url)
  144.     kernal.fwrite(path, dowload.readAll())
  145. end
  146.  
  147. local function testClick(button, x, y)
  148.     term.setBackgroundColor(colors.yellow)
  149.     term.setCursorPos(1,5)
  150.     print(button, " X:",x, ", Y:", y)
  151. end
  152. --Main
  153. local function main()
  154.     drawScreen(_bgcolor, _bgimage)
  155.     while brunning do
  156.     local event, button, x, y = os.pullEvent("mouse_click")
  157.         if slc == 0 then
  158.             drawScreen(_bgcolor, _bgimage)
  159.             if button == 1 then
  160.                 if x >= 1 and x <= 7 and y == 1 then
  161.                     slc = 1
  162.                     drawMenu()
  163.                     testClick(button, x, y)
  164.                 elseif x >= 9 and x <= 18 and y == 1 then
  165.                     slc = 2
  166.                     drawSecurity()
  167.                     testClick(button, x, y)
  168.                 end
  169.             end
  170.         elseif slc == 1 then
  171.             drawMenu()
  172.             menuClick(button, x, y)
  173.         elseif slc == 2 then
  174.             drawSecurity()
  175.             securityClick(button, x, y)
  176.         end
  177.     end
  178. end
  179.  
  180. ccatch.A_crash(main, "center", 1, 8)
Add Comment
Please, Sign In to add comment