tomtrein

desktop

Jul 23rd, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ---- By: Goodle
  2.  
  3. -- Variables
  4.  
  5. width, height = term.getSize()
  6.  
  7. CnWidth = width / 2
  8. CnHeight = height / 2
  9.  
  10. time = os.time()
  11. formattedTime = textutils.formatTime( time, false)
  12.  
  13. isMenu = false
  14. isDesktop = false
  15. isStartup = false
  16.          
  17. -- Functions
  18.  
  19. function time()
  20.   return textutils.formatTime(os.time(), true)
  21. end
  22.  
  23. startup = function()
  24.   isStartup = true
  25.   term.clear()
  26.   term.setCursorPos(CnWidth-5,height-1)
  27.   term.setTextColour( colours.blue )
  28.   term.write("WaffgoOS by")
  29.   term.setCursorPos(CnWidth-20,height)
  30.   term.write("Goodle Software - In cooperation with CPGGC")
  31.   term.setCursorPos(CnWidth-3,CnHeight-1)
  32.   term.setTextColour( colours.lightBlue )
  33.   term.write("Loading")
  34.   term.setCursorPos(CnWidth-6,CnHeight)
  35.   term.write(";")
  36.   term.setCursorPos(CnWidth+6,CnHeight)
  37.   term.write(";")
  38.   term.setBackgroundColour( colours.black )
  39.   term.setCursorPos(CnWidth,CnHeight+1)
  40.   term.write('0%')
  41.   sleep(1)
  42.   paintutils.drawLine(CnWidth-5,CnHeight, CnWidth,CnHeight, colours.green )
  43.   term.setBackgroundColour( colours.black )
  44.   term.setCursorPos(CnWidth-1,CnHeight+1)
  45.   term.write("50%")
  46.   sleep(0.5)
  47.   paintutils.drawLine(CnWidth,CnHeight, CnWidth+4,CnHeight, colours.green )
  48.   term.setBackgroundColour( colours.black )
  49.   term.setCursorPos(CnWidth-1,CnHeight+1)
  50.   term.clearLine()
  51.   term.write("78%")
  52.   sleep(0.3)
  53.   term.setCursorPos(CnWidth-1,CnHeight+1)
  54.   term.clearLine()
  55.   term.write("80%")
  56.   sleep(0.5)
  57.   paintutils.drawLine(CnWidth+4,CnHeight, CnWidth+5,CnHeight, colours.green )
  58.   term.setBackgroundColour( colours.black )
  59.   term.setCursorPos(CnWidth-1,CnHeight+1)
  60.   term.clearLine()
  61.   term.write("100%")
  62.   term.setCursorPos(CnWidth-3,CnHeight-1)
  63.   term.clearLine()
  64.   term.setBackgroundColour( colours.black )
  65.   term.write("Welcome!")
  66.   sleep(3)
  67.   isStartup = false
  68.   desktop()
  69. end
  70.  
  71.  
  72. desktop = function()
  73.  
  74.   isDesktop = true
  75.   term.clear()
  76.   pixelsDown = 1
  77.   pixelsDownLimit = height
  78.   -- Desktop drawing
  79.  
  80.   while pixelsDown ~= height
  81.     do paintutils.drawLine(1,pixelsDown, width,pixelsDown, colours.white )
  82.     pixelsDown = pixelsDown + 1
  83.     end
  84.   paintutils.drawLine(1,height, width,height, colours.blue )
  85.   term.setCursorPos(1,height)
  86.   term.setTextColour( colours.white )
  87.   term.setBackgroundColour( colours.lime )
  88.   term.write(' @ menu ')
  89.  
  90.   -- Clock Drawing
  91.  
  92.   term.setCursorPos(width-6,height)
  93.   term.setTextColour( colours.white )
  94.   term.setBackgroundColour( colours.blue )
  95.   local mon = window.create(term.current(),width-6,height,width,height)
  96.   local ok, err = pcall( function()
  97.   parallel.waitForAny(
  98.         function()
  99.           while true do
  100.                 mon.clear()
  101.                 mon.setCursorPos(2,3)
  102.                 mon.write(time())
  103.                 sleep(1)
  104.           end
  105.         end,
  106.         function()
  107.           os.run( {}, "desktop" )
  108.         end
  109.         )
  110.   end )
  111.  
  112.   while isDesktop == true do
  113.     term.setBackgroundColour( colours.white )
  114.     term.setCursorPos(0,0)
  115.     term.setCursorBlink(false)
  116.     local event, click, x, y = os.pullEvent("mouse_click")
  117.     if x == 2 then
  118.       if y == height then
  119.       break
  120.       end
  121.     end
  122.   end
  123. end
  124.  
  125. drawWindow = function()
  126.   term.clear()
  127. end
  128.  
  129.  
  130. drawMenu = function()
  131.   isMenu = true
  132.   local menuPD = 2 -- Menu pixels down
  133.   local menuPDL = height-1 -- Menu pixels down limit
  134.   local menuPUL = height-10 -- Menu pixels up limit
  135.   -- Menu pixels right limit is = 15
  136.   while menuPD < menuPDL do
  137.     paintutils.drawLine(1, menuPUL, 15, menuPUL, 400 )
  138.     menuPUL = menuPUL + 1
  139.     menuPD = menuPD + 1
  140.   end -- Dimensions of menu: w-15 from left, h-9 from height - 1
  141.   term.setCursorPos(1,height)
  142.   term.setTextColour( colours.white )
  143.   term.setBackgroundColour( colours.green )
  144.   term.write(" @ menu ")
  145.  
  146.   paintutils.drawLine(9,height, 15,height, colours.blue )
  147.   term.setCursorPos(2,height-1)
  148.   term.setBackgroundColour( 400 )
  149.   term.setTextColour( colours.yellow )
  150.   term.write("@ Exit") -- Logoff button
  151.   term.setCursorPos(2,height-2)
  152.   term.setTextColour( colours.red )
  153.   term.write("@ Shutdown") -- Shutdown button
  154.   term.setCursorPos(2,height-3)
  155.   term.setTextColour( colours.green )
  156.   term.write("@ TMNET") -- Shutdown button
  157.  
  158.   term.setBackgroundColour( colours.white )
  159.   while isMenu == true do
  160.     local event, click2, x, y = os.pullEvent("mouse_click")
  161.     if x == 2 and y == height then
  162.         isMenu = false
  163.         desktop()
  164.         break
  165.     end
  166.     if x == 2 then
  167.       if y == height-1 then
  168.         isMenu = false
  169.         isStartup = false
  170.         isDesktop = false
  171.         exit()
  172.       end
  173.    end
  174.    if x == 2 then
  175.      if y == height-2 then
  176.         os.shutdown()
  177.       end
  178.    end
  179.    if x == 2 then
  180.      if y == height-3 then
  181.         shell.run("web")
  182.         isMenu = false
  183.         desktop()
  184.         break
  185.       end
  186.    end
  187.   end  
  188. end
  189.  
  190. exit = function()
  191.   term.clear()
  192.   term.setBackgroundColour(colours.black)
  193.   term.setTextColour(colours.white)
  194.   term.setCursorPos(1,1)
  195.   term.clear()
  196. end
  197. -- Program execution
  198.  
  199. desktop()
  200.  
  201. drawMenu()
  202.  
  203. while isDesktop == true do
  204.   drawMenu()  
  205. end
Add Comment
Please, Sign In to add comment