lego11

GEM (pulito)

Jun 11th, 2020
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.         if settings["live"] then
  121.         for i, k in pairs(fs.list("/data")) do
  122.           fs.delete("/data/"..k)
  123.         end
  124.         end
  125.         return
  126.       end
  127.     end
  128.     if bt == 1 and _ == "mouse_click" and x >= 1 and x <= 4 and y == 1 then
  129.         if menu then
  130.           drawDesktop()
  131.           drawClock()
  132.           menu = false
  133.         else
  134.           drawDesktop()
  135.           drawMenu()
  136.           drawClock()
  137.           menu = true
  138.         end
  139.     elseif bt == 1 and _ == "mouse_click" and x >= 1 and x <= 12 and menu and y >= 2 and y <= 4 then
  140.       if y == 2 then
  141.         if settings["live"] then
  142.           for i, k in pairs(fs.list("/data")) do
  143.             fs.delete("/data/"..k)
  144.           end
  145.         end
  146.         os.shutdown()
  147.       elseif y == 3 then
  148.         if settings["live"] then
  149.           for i, k in pairs(fs.list("/data")) do
  150.             fs.delete("/data/"..k)
  151.           end
  152.         end
  153.         os.reboot()
  154.       elseif y == 4 then
  155.         menu = false
  156.         shell.run("/settings")
  157.         loadDeskSettings()
  158.         drawDesktop()
  159.       end
  160.     elseif _ == "mouse_click" then
  161.       if icoreg[tostring(x).." "..tostring(y)] ~= nil then
  162.         shell.run(icoreg[tostring(x).." "..tostring(y)])
  163.       end
  164.       menu = false
  165.     end
  166.   end
  167. end
  168.  
  169. getInput()
Add Comment
Please, Sign In to add comment