lego11

GEM Chiosco LeNet

Jun 11th, 2020
234
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 5tq5WgFL /.settings")
  28. end
  29.  
  30. if not fs.exists("/programs/lenet") then
  31.   shell.run("pastebin get EQgHhsAA /programs/lenet")
  32.   shell.run("pastebin get LtqRbjn6 /programs/icons/lenet")
  33. end
  34.  
  35. if not fs.exists("/.settings") then
  36.   shell.run("pastebin get 5tq5WgFL /.settings")
  37. end
  38.  
  39. if not fs.exists("/settings") then
  40.   shell.run("pastebin get 1NphnkqB /settings")
  41. end
  42.  
  43. function loadDeskSettings()
  44.   file = fs.open("/.settings", "r")
  45.   settings = textutils.unserialize(file.readAll())
  46.   file.close()
  47.   pref["background"] = settings["background"]
  48. end
  49.  
  50.  
  51. function drawDesktop()
  52.   loadDeskSettings()
  53.   term.setBackgroundColor(settings["background"])
  54.   term.clear()
  55.   term.setCursorPos(1, 1)
  56.   term.setBackgroundColor(colors.white)
  57.   for i=1, pref["w"] do
  58.     term.write(" ")
  59.   end
  60.   term.setTextColor(colors.black)
  61.   term.setCursorPos((pref["w"]/2)-(#pref["pcname"]/2), 1)
  62.   term.write(pref["pcname"])
  63.   term.setCursorPos(1, 1)
  64.   term.setBackgroundColor(colors.lightGray)
  65.   term.write("Menu")
  66.   term.setCursorPos(2, 3)
  67.   term.setBackgroundColor(colors.white)
  68.   x, y = term.getCursorPos()
  69.   for i, k in pairs(fs.list("/programs")) do
  70.     if fs.isDir("/programs/"..k) ~= true then
  71.       if x >= 51 then
  72.         x = 2
  73.         y = y + 7
  74.       end
  75.       term.setCursorPos(x, y)
  76.       ico = paintutils.loadImage("/programs/icons/"..k)
  77.       paintutils.drawImage(ico, x, y)
  78.       term.setCursorPos(x, y+5)
  79.       term.setBackgroundColor(settings["background"])
  80.       term.write(string.sub(k, 1, 5))
  81.       for i=x, x+4 do
  82.         for b=y, y+4 do
  83.           icoreg[tostring(i).." "..tostring(b)] = "/programs/"..k
  84.         end
  85.       end
  86.       x = x + 6
  87.     end
  88.   end
  89. end
  90.  
  91. function drawMenu()
  92.   term.setCursorPos(1, 2)
  93.   term.setBackgroundColor(colors.lightGray)
  94.   term.setTextColor(colors.black)
  95.   term.setTextColor(colors.red)
  96.   term.write("Spegni      ")
  97.   term.setCursorPos(1, 3)
  98.   term.setTextColor(colors.yellow)
  99.   term.write("Riavvia     ")
  100.   term.setCursorPos(1, 4)
  101.   term.setTextColor(colors.black)
  102.   term.write("Impostazioni")
  103. end
  104.  
  105. function drawClock()
  106.   term.setBackgroundColor(colors.white)
  107.   term.setCursorPos(pref["w"]-#textutils.formatTime(os.time(), true), 1)
  108.   term.setTextColor(colors.black)
  109.   term.write(textutils.formatTime(os.time(), true))
  110. end
  111.  
  112. function getInput()
  113.   menu = false
  114.   while true do
  115.     if not menu then
  116.       drawDesktop()
  117.     end
  118.     drawClock()
  119.     timerclock = os.startTimer(1)
  120.     _, bt, x, y = os.pullEventRaw()
  121.     if _ == "timer" and bt == timerclock then
  122.       drawClock()
  123.     end
  124.     if _ == "terminate" then
  125.       if settings["terminable"] then
  126.         term.setBackgroundColor(colors.black)
  127.         term.clear()
  128.         term.setCursorPos(1, 1)
  129.         if settings["live"] then
  130.         for i, k in pairs(fs.list("/data")) do
  131.           fs.delete("/data/"..k)
  132.         end
  133.         end
  134.         return
  135.       end
  136.     end
  137.     if bt == 1 and _ == "mouse_click" and x >= 1 and x <= 4 and y == 1 then
  138.         if menu then
  139.           drawDesktop()
  140.           drawClock()
  141.           menu = false
  142.         else
  143.           drawDesktop()
  144.           drawMenu()
  145.           drawClock()
  146.           menu = true
  147.         end
  148.     elseif bt == 1 and _ == "mouse_click" and x >= 1 and x <= 12 and menu and y >= 2 and y <= 4 then
  149.       if y == 2 then
  150.         if settings["live"] then
  151.           for i, k in pairs(fs.list("/data")) do
  152.             fs.delete("/data/"..k)
  153.           end
  154.         end
  155.         os.shutdown()
  156.       elseif y == 3 then
  157.         if settings["live"] then
  158.           for i, k in pairs(fs.list("/data")) do
  159.             fs.delete("/data/"..k)
  160.           end
  161.         end
  162.         os.reboot()
  163.       elseif y == 4 then
  164.         menu = false
  165.         shell.run("/settings")
  166.         loadDeskSettings()
  167.         drawDesktop()
  168.       end
  169.     elseif _ == "mouse_click" then
  170.       if icoreg[tostring(x).." "..tostring(y)] ~= nil then
  171.         shell.run(icoreg[tostring(x).." "..tostring(y)])
  172.       end
  173.       menu = false
  174.     end
  175.   end
  176. end
  177.  
  178. getInput()
Add Comment
Please, Sign In to add comment