Advertisement
AquaJD

[AUT] Desktop

May 3rd, 2014
341
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 10.85 KB | None | 0 0
  1. --[[
  2.  
  3.     Autos
  4.     Official Desktop File
  5.  
  6. ]]--
  7.  
  8. os.pullEvent = os.pullEventRaw
  9.  
  10. -- Loading APIs
  11. os.loadAPI("System/.osfiles/resources/APIs/autos")
  12. os.loadAPI("System/.osfiles/resources/APIs/settings")
  13.  
  14. -- Current Menu | 0 = NONE | 1 = StartMenu |
  15. slc = 0
  16. -- Config path
  17. fs_config = "System/.osfiles/.cfg"
  18. -- Width, Height of Term
  19. w,h = term.getSize()
  20. -- Visibility of the icons
  21. ico_i1_visible = 1
  22. ico_i2_visible = 1
  23. -- Decides what icon should be dragged
  24. ico_selected = 1
  25. -- Senses mouse drag
  26. drag = 0
  27. dragTime = 0
  28. -- Senses the computers time
  29. time = os.startTimer(1)
  30. -- Shell start messages
  31. shellMessages = {
  32.     "Check the changelog as well",
  33.     "Also, check out the credits",
  34.     "Click Yellow to go to CraftOS"
  35. }
  36.  
  37. -- Config loading
  38. if fs.exists(fs_config) then
  39.     loadedCFG = settings.openSettingsFile(fs_config)
  40.     col_mainback = loadedCFG.getSectionedValue("Colors","col_mainback")
  41.     col_maintext = loadedCFG.getSectionedValue("Colors","col_maintext")
  42.     col_butnback = loadedCFG.getSectionedValue("Colors","col_butnback")
  43.     col_butntitl = loadedCFG.getSectionedValue("Colors","col_butntitl")
  44.     col_butntext = loadedCFG.getSectionedValue("Colors","col_butntext")
  45.     col_butnhilt = loadedCFG.getSectionedValue("Colors","col_butnhilt")
  46.     col_titlback = loadedCFG.getSectionedValue("Colors","col_titlback")
  47.     col_titltext = loadedCFG.getSectionedValue("Colors","col_titltext")
  48.     col_titlhilb = loadedCFG.getSectionedValue("Colors","col_titlhilb")
  49.     col_titlhilt = loadedCFG.getSectionedValue("Colors","col_titlhilt")
  50.     oss_ostype = loadedCFG.getSectionedValue("OSSettings","oss_ostype")
  51.     oss_usertype = loadedCFG.getSectionedValue("OSSettings","oss_usertype")
  52.     oss_version = loadedCFG.getSectionedValue("OSSettings","oss_version")
  53.     oss_showIcons = loadedCFG.getSectionedValue("OSSettings","oss_showIcons")
  54.     img_fileIcon1 = loadedCFG.getSectionedValue("Images","img_fileIcon1")
  55.     img_fileIcon2 = loadedCFG.getSectionedValue("Images","img_fileIcon2")
  56.     img_fileBack1 = loadedCFG.getSectionedValue("Images","img_fileBack1")
  57.     ico_i1_x = loadedCFG.getSectionedValue("Icons","ico_i1_x")
  58.     ico_i1_y = loadedCFG.getSectionedValue("Icons","ico_i1_y")
  59.     ico_i2_x = loadedCFG.getSectionedValue("Icons","ico_i2_x")
  60.     ico_i2_y = loadedCFG.getSectionedValue("Icons","ico_i2_y")
  61.     loadedCFG.save(fs_config)
  62.     col_mainback = tonumber(col_mainback)
  63.     col_maintext = tonumber(col_maintext)
  64.     col_butnback = tonumber(col_butnback)
  65.     col_butntitl = tonumber(col_butntitl)
  66.     col_butntext = tonumber(col_butntext)
  67.     col_titlback = tonumber(col_titlback)
  68.     col_titltext = tonumber(col_titltext)
  69.     oss_showIcons = tonumber(oss_showIcons)
  70.     ico_i1_x = tonumber(ico_i1_x)
  71.     ico_i1_y = tonumber(ico_i1_y)
  72.     ico_i2_x = tonumber(ico_i2_x)
  73.     ico_i2_y = tonumber(ico_i2_y)
  74.     ico_i1_visible = tonumber(ico_i1_visible)
  75.     ico_i2_visible = tonumber(ico_i2_visible)
  76. else
  77.     autos.clean(1,1)
  78.     autos.pError("CRITICAL","OS Error: INVALID CONFIG")
  79.     sleep(0.1)
  80.     autos.pError("TRUBLSHT","Searching for issue fix...")
  81.     sleep(1.5)
  82.     autos.pError("TRUBLSHT","Re-install Autos")
  83.     return
  84. end
  85.  
  86. -- Detects OS type
  87. if oss_ostype == "acp_normal" then
  88.     userType = "Adv.Computer"
  89.     osType = "Computer Control"
  90. else
  91.     autos.clean(1,1)
  92.     autos.pError("CRITICAL","OS Error: INVALID OS TYPE")
  93.     sleep(0.1)
  94.     autos.pError("TRUBLSHT","Searching for issue fix...")
  95.     sleep(1.5)
  96.     autos.pError("TRUBLSHT","Re-install Autos")
  97.     return
  98. end
  99.  
  100. -- Loading the icon images
  101. fileIcon1 = paintutils.loadImage(img_fileIcon1)
  102. fileIcon2 = paintutils.loadImage(img_fileIcon2)
  103.  
  104. -- The start menu
  105. function drawMenu_Start()
  106.     autos.bColor(col_titlback)
  107.     autos.tColor(col_titltext)
  108.     autos.setCursor(1,15)
  109.     print("               ")
  110.     autos.setCursor(1,16)
  111.     print("    CraftOS    ")
  112.     autos.setCursor(1,17)
  113.     print(" Control Panel ")
  114.     autos.setCursor(1,18)
  115.     print("               ")
  116. end
  117.  
  118. -- The title bar
  119. function draw_titleBar()
  120.     autos.setCursor(1,19)
  121.     autos.bColor(col_titlback)
  122.     term.clearLine()
  123.     autos.bColor(col_titlhilb)
  124.     autos.tColor(col_titlhilt)
  125.     autos.setCursor(1,19)
  126.     print(" START ")
  127.     autos.bColor(col_mainback)
  128.     term.scroll(-1)
  129. end
  130.  
  131. -- Draws the time
  132. function draw_time()
  133.     autos.tColor(col_titlhilt)
  134.     autos.bColor(col_titlback)
  135.     autos.setCursor(36,19)
  136.     print("Time: "..textutils.formatTime(os.time(),false))
  137.     autos.bColor(col_mainback)
  138.     term.scroll(-1)
  139. end
  140.  
  141. -- Draws the desktop
  142. function draw_desktop()
  143.     autos.bColor(col_mainback)
  144.     autos.clean(1,1)
  145.     -- Detects if it should draw the icons or not
  146.     if oss_showIcons == 1 then
  147.         if ico_i1_visible == 1 then
  148.             paintutils.drawImage(fileIcon1,ico_i1_x,ico_i1_y)
  149.             autos.setCursor(ico_i1_x+3,ico_i1_y)
  150.             autos.tColor(colors.white)
  151.             autos.bColor(colors.gray)
  152.             print("Lua")
  153.         end
  154.         if ico_i2_visible == 1 then
  155.             paintutils.drawImage(fileIcon2,ico_i2_x,ico_i2_y)
  156.             autos.setCursor(ico_i2_x+2,ico_i2_y)
  157.             autos.tColor(colors.white)
  158.             autos.bColor(colors.gray)
  159.             print("Ctrl")
  160.         end
  161.     end
  162.     draw_titleBar()
  163. end
  164.  
  165. -- Draws a message and does an action (exit or action)
  166. function launch_message(msg,action,exit)
  167.     autos.draw_Box(11,12,31,3,col_butnback,col_butntitl,"MESSAGE",false)
  168.     autos.bColor(colors.yellow)
  169.     autos.setCursor(40,12)
  170.     print(" ")
  171.     autos.bColor(colors.red)
  172.     autos.setCursor(41,12)
  173.     print(" ")
  174.     autos.bColor(col_butnback)
  175.     autos.tColor(col_butntext)
  176.     if #msg == 29 then
  177.         autos.setCursor(12,13)
  178.     elseif #msg == 27 then
  179.         autos.setCursor(13,13)
  180.     end
  181.     print(msg)
  182.     while true do
  183.         local event,button,X,Y = os.pullEventRaw()
  184.         if event == "mouse_click" then
  185.             -- Detects the red button being clicked
  186.             if X == 41 and Y == 12 and button == 1 then
  187.                 -- Launches the exit program (desktop or custom)
  188.                 if exit == "desktop" then
  189.                     launch_desktop()
  190.                     return
  191.                 else
  192.                     autos.bColor(colors.black)
  193.                     autos.clean(1,1)
  194.                     shell.run(exit)
  195.                     return
  196.                 end
  197.             -- Detects the yellow button being clicked
  198.             elseif X == 40 and Y == 12 and button == 1 then
  199.                 -- Launches the action program (desktop or custom)
  200.                 if action == "desktop" then
  201.                     launch_desktop()
  202.                     return
  203.                 else
  204.                     autos.bColor(colors.black)
  205.                     autos.clean(1,1)
  206.                     shell.run(action)
  207.                     return
  208.                 end
  209.             end
  210.         -- Computer time timer
  211.         elseif event == "timer" then
  212.             time = os.startTimer(1)
  213.             draw_time()
  214.         end
  215.     end
  216. end
  217.  
  218. -- The main function
  219. function launch_desktop()
  220.     draw_desktop()
  221.     while true do
  222.         local event,button,X,Y = os.pullEventRaw()
  223.         if event == "mouse_click" then
  224.             -- The current menu (none in this case)
  225.             if slc == 0 then
  226.                 -- The start menu being clicked
  227.                 if X>=1 and X<=7 and Y==19 and button==1 then
  228.                     drawMenu_Start()
  229.                     -- Sets the current menu to start menu
  230.                     slc = 1
  231.                 -- Icon 1's red button being clicked
  232.                 elseif X==ico_i1_x+1 and Y==ico_i1_y and button==1 then
  233.                     -- Makes Icon 1 invisible
  234.                     ico_i1_visible = 0
  235.                     draw_desktop()
  236.                 -- Icon 2's red button being clicked
  237.                 elseif X==ico_i2_x+1 and Y==ico_i2_y and button==1 then
  238.                     -- Makes Icon 2 invisible
  239.                     ico_i2_visible = 0
  240.                     draw_desktop()
  241.                 -- Icon 1's green button being clicked
  242.                 elseif X==ico_i1_x and Y==ico_i1_y and button==1 then
  243.                     -- Makes Icon 1 the selected icon (for dragging)
  244.                     ico_selected = 1
  245.                     draw_desktop()
  246.                 -- Icon 2's green button being clicked
  247.                 elseif X==ico_i2_x and Y==ico_i2_y and button==1 then
  248.                     -- Makes Icon 2 the selected icon (for dragging)
  249.                     ico_selected = 2
  250.                     draw_desktop()
  251.                 -- Icon 1 being run (Lua prompt)
  252.                 elseif X>=ico_i1_x and X<=ico_i1_x+5 and Y>=ico_i1_y+1 and Y<=ico_i1_y+5 and button==1 then
  253.                     -- Launches lua prompt message box (action and exit)
  254.                     launch_message("Press Yellow to start LUAJCMD","lua","desktop")
  255.                     draw_desktop()
  256.                 -- Icon 2 being run (control panel)
  257.                 elseif X>=ico_i2_x and X<=ico_i2_x+5 and Y>=ico_i2_y+1 and Y<=ico_i2_y+5 and button==1 then
  258.                     -- Launches control panel message box (action and exit)
  259.                     launch_message("That's not implemented yet...","desktop","desktop")
  260.                     draw_desktop()
  261.                 end
  262.             -- The current menu (start menu)
  263.             elseif slc == 1 then
  264.                 -- Control Panel selected
  265.                 if X>=1 and X<=15 and Y==17 and button==1 then
  266.                     -- Sets the menu back to none
  267.                     slc = 0
  268.                     autos.clean(1,1)
  269.                     draw_desktop()
  270.                     -- Launches control panel message box (action and exit)
  271.                     launch_message("That's not implemented yet...","desktop","desktop")
  272.                     draw_desktop()
  273.                 -- CraftOS launched
  274.                 elseif X>=1 and X<=15 and Y==16 and button==1 then
  275.                     -- Sets the menu back to none
  276.                     slc = 0
  277.                     autos.clean(1,1)
  278.                     draw_desktop()
  279.                     -- Launches the shell message box (action and exit)
  280.                     launch_message(shellMessages[math.random(1,#shellMessages)],"shell","desktop")
  281.                     return
  282.                 -- This debugs the menu and sets it back to none
  283.                 else
  284.                     slc = 0
  285.                     autos.clean(1,1)
  286.                     draw_desktop()
  287.                 end
  288.             end
  289.         -- The computer clock's timer
  290.         elseif event == "timer" then
  291.             -- Button is actually the timer's label
  292.             if button==time then
  293.                 time = os.startTimer(1)
  294.                 draw_time()
  295.             -- Again, button is the timer's label
  296.             elseif button==dragTime then
  297.                 -- Detects dragging
  298.                 drag = false
  299.             end
  300.         elseif event == "mouse_drag" then
  301.             -- Detects the current menu (none here)
  302.             if slc == 0 then
  303.                 -- The current icon selected (chooses which one to drag)
  304.                 if ico_selected == 1 then
  305.                     -- Says its dragging
  306.                     drag = 1
  307.                     dragTime = os.startTimer(1)
  308.                     -- Sets the new coords for the icon
  309.                     ico_i1_x = X
  310.                     ico_i1_y = Y
  311.                     loadedCFG = settings.openSettingsFile(fs_config)
  312.                     loadedCFG.setSectionedValue("Icons","ico_i1_x",X)
  313.                     loadedCFG.setSectionedValue("Icons","ico_i1_y",Y)
  314.                     loadedCFG.save(fs_config)
  315.                     draw_desktop()
  316.                     -- Does it all again until user stops dragging
  317.                     if drag == 1 then
  318.                         dragTime = os.startTimer(1)
  319.                         ico_i1_x = X
  320.                         ico_i1_y = Y
  321.                         loadedCFG = settings.openSettingsFile(fs_config)
  322.                         loadedCFG.setSectionedValue("Icons","ico_i1_x",X)
  323.                         loadedCFG.setSectionedValue("Icons","ico_i1_y",Y)
  324.                         loadedCFG.save(fs_config)
  325.                         draw_desktop()
  326.                     end
  327.                 -- Repeat of previous except for Icon 2
  328.                 elseif ico_selected == 2 then
  329.                     drag = 1
  330.                     dragTime = os.startTimer(1)
  331.                     ico_i2_x = X
  332.                     ico_i2_y = Y
  333.                     loadedCFG = settings.openSettingsFile(fs_config)
  334.                     loadedCFG.setSectionedValue("Icons","ico_i2_x",X)
  335.                     loadedCFG.setSectionedValue("Icons","ico_i2_y",Y)
  336.                     loadedCFG.save(fs_config)
  337.                     draw_desktop()
  338.                     if drag == 1 then
  339.                         dragTime = os.startTimer(1)
  340.                         ico_i2_x = X
  341.                         ico_i2_y = Y
  342.                         loadedCFG = settings.openSettingsFile(fs_config)
  343.                         loadedCFG.setSectionedValue("Icons","ico_i2_x",X)
  344.                         loadedCFG.setSectionedValue("Icons","ico_i2_y",Y)
  345.                         loadedCFG.save(fs_config)
  346.                         draw_desktop()
  347.                     end
  348.                 end
  349.             end
  350.         end
  351.     end
  352. end
  353.  
  354. -- The start of the program (FRESH AND CLEAN)
  355. autos.bColor(col_mainback)
  356. autos.clean(1,1)
  357. launch_desktop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement