LolzPB

gem

Jun 11th, 2020
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.19 KB | None | 0 0
  1. pref = {}
  2. w, h = term.getSize()
  3. pref["w"] = w
  4. pref["h"] = h
  5. icoreg = {}
  6.  
  7.  
  8. if os.getComputerLabel() == nil then
  9.   lab = math.random(100000)
  10.   os.setComputerLabel("GemPC-"..tostring(lab))
  11. end
  12.  
  13. pref["pcname"] = os.getComputerLabel()
  14.  
  15. local settings = {}
  16.  
  17. if not fs.exists("/programs") then
  18.   fs.makeDir("/programs")
  19.   fs.makeDir("/programs/icons")
  20. end
  21.  
  22. if not fs.exists("/data") then
  23.   fs.makeDir("/data")
  24. end
  25.  
  26. if not fs.exists("/.settings") then
  27.   shell.run("pastebin get tdLqAp7r /.settings")
  28. end
  29.  
  30. if not fs.exists("/.settings") then
  31.   shell.run("pastebin get 1NphnkqB /settings")
  32. end
  33.  
  34. function loadDeskSettings()
  35.   file = fs.open("/.settings", "r")
  36.   settings = textutils.unserialize(file.readAll())
  37.   file.close()
  38.   pref["background"] = settings["background"]
  39. end
  40.  
  41.  
  42. function drawDesktop()
  43.   loadDeskSettings()
  44.   term.setBackgroundColor(settings["background"])
  45.   term.clear()
  46.   term.setCursorPos(1, 1)
  47.   term.setBackgroundColor(colors.white)
  48.   for i=1, pref["w"] do
  49.     term.write(" ")
  50.   end
  51.   term.setTextColor(colors.black)
  52.   term.setCursorPos((pref["w"]/2)-(#pref["pcname"]/2), 1)
  53.   term.write(pref["pcname"])
  54.   term.setCursorPos(1, 1)
  55.   term.setBackgroundColor(colors.lightGray)
  56.   term.write("Menu")
  57.   term.setCursorPos(2, 3)
  58.   term.setBackgroundColor(colors.white)
  59.   x, y = term.getCursorPos()
  60.   for i, k in pairs(fs.list("/programs")) do
  61.     if fs.isDir("/programs/"..k) ~= true then
  62.       if x >= 51 then
  63.         x = 2
  64.         y = y + 7
  65.       end
  66.       term.setCursorPos(x, y)
  67.       ico = paintutils.loadImage("/programs/icons/"..k)
  68.       paintutils.drawImage(ico, x, y)
  69.       term.setCursorPos(x, y+5)
  70.       term.setBackgroundColor(settings["background"])
  71.       term.write(string.sub(k, 1, 5))
  72.       for i=x, x+4 do
  73.         for b=y, y+4 do
  74.           icoreg[tostring(i).." "..tostring(b)] = "/programs/"..k
  75.         end
  76.       end
  77.       x = x + 6
  78.     end
  79.   end
  80. end
  81.  
  82. function drawMenu()
  83.   term.setCursorPos(1, 2)
  84.   term.setBackgroundColor(colors.lightGray)
  85.   term.setTextColor(colors.black)
  86.   term.setTextColor(colors.red)
  87.   term.write("Spegni      ")
  88.   term.setCursorPos(1, 3)
  89.   term.setTextColor(colors.yellow)
  90.   term.write("Riavvia     ")
  91.   term.setCursorPos(1, 4)
  92.   term.setTextColor(colors.black)
  93.   term.write("Impostazioni")
  94. end
  95.  
  96. function drawClock()
  97.   term.setBackgroundColor(colors.white)
  98.   term.setCursorPos(pref["w"]-#textutils.formatTime(os.time(), true), 1)
  99.   term.setTextColor(colors.black)
  100.   term.write(textutils.formatTime(os.time(), true))
  101. end
  102.  
  103. function getInput()
  104.   menu = false
  105.   while true do
  106.     if not menu then
  107.       drawDesktop()
  108.     end
  109.     drawClock()
  110.     timerclock = os.startTimer(1)
  111.     _, bt, x, y = os.pullEventRaw()
  112.     if _ == "timer" and bt == timerclock then
  113.       drawClock()
  114.     end
  115.     if _ == "terminate" then
  116.       if settings["terminable"] then
  117.         term.setBackgroundColor(colors.black)
  118.         term.clear()
  119.         term.setCursorPos(1, 1)
  120.         for i, k in pairs(fs.list("/data")) do
  121.           fs.delete("/data/"..k)
  122.         end
  123.         return
  124.       end
  125.     end
  126.     if bt == 1 and _ == "mouse_click" and x >= 1 and x <= 4 and y == 1 then
  127.         if menu then
  128.           drawDesktop()
  129.           drawClock()
  130.           menu = false
  131.         else
  132.           drawDesktop()
  133.           drawMenu()
  134.           drawClock()
  135.           menu = true
  136.         end
  137.     elseif bt == 1 and _ == "mouse_click" and x >= 1 and x <= 12 and menu and y >= 2 and y <= 4 then
  138.       if y == 2 then
  139.         if settings["live"] then
  140.           for i, k in pairs(fs.list("/data")) do
  141.             fs.delete("/data/"..k)
  142.           end
  143.         end
  144.         os.shutdown()
  145.       elseif y == 3 then
  146.         if settings["live"] then
  147.           for i, k in pairs(fs.list("/data")) do
  148.             fs.delete("/data/"..k)
  149.           end
  150.         end
  151.         os.reboot()
  152.       elseif y == 4 then
  153.         menu = false
  154.         shell.run("/settings")
  155.         loadDeskSettings()
  156.         drawDesktop()
  157.       end
  158.     elseif _ == "mouse_click" then
  159.       if icoreg[tostring(x).." "..tostring(y)] ~= nil then
  160.         shell.run(icoreg[tostring(x).." "..tostring(y)])
  161.       end
  162.       menu = false
  163.     end
  164.   end
  165. end
  166.  
  167. getInput()
Add Comment
Please, Sign In to add comment