Marlingaming

CC Tweaked CCSPS 20 - (Removed) TaskBar

Feb 21st, 2022 (edited)
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.74 KB | None | 0 0
  1. local w, h = term.getSize()
  2. local Items = {}
  3. local DeskItems = {}
  4. local OpenedTask = "n"
  5. local Tabs = {}
  6. local ActiveTab = 0
  7. local FullScreen = false
  8. local Desktop = "desktop"
  9.  
  10. local function Clear()
  11. term.clear()
  12. term.setCursorPos(1,1)
  13. end
  14.  
  15. function GetItems()
  16. local file = fs.open("os/SystemFiles/TaskbarShortcuts","r")
  17. local Name
  18. local Path
  19. local Image
  20. repeat
  21.     Name = file.readLine()
  22.     Path = file.readLine()
  23.     Image = file.readLine()
  24.     if Name ~= nil then Items[#Items + 1] = {Name,Path,Image} end
  25. until Name == nil
  26. file.close()
  27. GetDesktop()
  28. end
  29.  
  30. function GetDesktop()
  31. local file = fs.open("os/SystemFiles/DesktopShortcuts","r")
  32. local Name
  33. local Path
  34. local Image
  35. repeat
  36.     Name = file.readLine()
  37.     Path = file.readLine()
  38.     Image = file.readLine()
  39.     if Name ~= nil then DeskItems[#DeskItems + 1] = {Name,Path,Image} end
  40. until Name == nil
  41. file.close()
  42. end
  43.  
  44. function CreateTab(Program)
  45. Tabs[#Tabs + 1] = {window.create(term.current(),1,2,w, h - 1),Program}
  46. ActiveTab = #Tabs
  47. end
  48.  
  49. function DrawTabbar()
  50. term.redirect(Tabs[ActiveTab][1])
  51. paintutils.drawBox(1,1,w,1,colors.gray)
  52. term.setCursorPos(1,1)
  53. term.write(Tabs[ActiveTab][2])
  54. paintutils.drawBox(w,1,w,1,colors.red)
  55. end
  56.  
  57. function DrawTaskbar()
  58. local Prev = term.redirect(term.native())
  59. paintutils.drawBox(6,h,w-8,h,colors.lightGray)
  60. paintutils.drawBox(1,h,5,h,colors.gray)
  61. paintutils.drawBox(w - 7, h, w, h, colors.lightBlue)
  62. term.setCursorPos(w - 7, h)
  63. term.write(textutils.formatTime(os.time("local")))
  64. DrawItems(Prev)
  65. end
  66.  
  67. function DrawItems(Prev)
  68. local x = 7
  69. for i = 1, #Items do
  70.     if Items[i][3] == "n" then
  71.         paintutils.drawBox(x, h - 3, x + 3, h - 1, colors.white)
  72.     else
  73.         local Image = paintutils.loadImage(Items[i][3])
  74.         paintutils.drawImage(Image,x,h - 3)
  75.     end
  76.     term.setBackgroundColor(colors.lightGray)
  77.     term.setCursorPos(x,h)
  78.     term.write(Items[i][1])
  79.     x = x + 4
  80. end
  81. term.redirect(Prev)
  82. end
  83.  
  84. function Popup()
  85. local Prev = term.redirect(term.native())
  86. paintutils.drawFilledBox(1, h - 10, 7, h - 1, colors.lightGray)
  87. local n = 0
  88. while true do
  89.      local a, b, c, d = os.pullEvent("mouse_click")
  90.      if c > 7 or d < h - 10 or d == h then n = 50 end
  91.      if n > 0 then break end
  92. end
  93. term.redirect(Prev)
  94. end
  95.  
  96. function TabBar()
  97. local Prev = term.redirect(term.native())
  98. DrawTabbar()
  99. term.redirect(Prev)
  100. local n = 0
  101. while true do
  102.     local a, b, c, d = os.pullEvent("mouse_click")
  103.     if d == 1 and c == w then n = 1 end
  104.     if n > 0 then break end
  105. end
  106. end
  107.  
  108. function Run()
  109. end
  110.  
  111. function RunTask()
  112. term.redirect(Tabs[ActiveTab][1])
  113. shell.run(Tabs[ActiveTab][2])
  114. end
  115.  
  116. function DrawDesktop()
  117. local x = 2
  118. local y = 1
  119. local MW = w / 5
  120. for i = 1, #DeskItems do
  121.     if DeskItems[i][3] == "n" then
  122.         paintutils.drawFilledBox(x,y,x+3,y+2,colors.white)
  123.     else
  124.         local Image = paintutils.loadImage(DeskItems[i][3])
  125.         paintutils.drawImage(Image,x,y)
  126.     end
  127.     term.setBackgroundColor(colors.black)
  128.     term.setCursorPos(x, y + 3)
  129.     term.write(DeskItems[i][1])
  130.     if x + 5 > w then
  131.         x = 2
  132.         y = y + 4
  133.     else
  134.         x = x + 5
  135.     end
  136. end
  137. end
  138.  
  139. function Loop()
  140. term.setBackgroundColor(colors.black)
  141. Clear()
  142.  
  143.  
  144. if FullScreen == false then
  145.     if ActiveTab > 0 then
  146.         parallel.waitForAny(Int,RunTask,TabBar)
  147.     else
  148.         parallel.waitForAny(Int,DesktopInt)
  149.     end
  150. else
  151.     parallel.waitForAny(BackInt,RunTask)
  152. end
  153. if ActiveTab > 0 then
  154.     term.redirect(term.native())
  155.     Tabs[ActiveTab][1].setVisible(false)
  156.     ActiveTab = 0
  157. end
  158. term.setBackgroundColor(colors.black)
  159. Clear()
  160.  
  161. Loop()
  162. end
  163.  
  164. function Int()
  165. local n = 0
  166. while true do
  167.     DrawTaskbar()
  168.     local a, b, c, d = os.pullEvent()
  169.     if a == "mouse_click" and d > h - 2 then
  170.         local x = 8
  171.         for i = 1, #Items do
  172.             if c >= x and c <=  x + 3 then n = i end
  173.             x = x + 4
  174.         end
  175.         if n == 0 and c < 6 then n = 50 end
  176.     end
  177.     if a == "key" and b == keys.p then n = 50 end
  178.     if n > 0 then break end
  179. end
  180. if n == 50 then Popup() end
  181. if n < 50 then CreateTab(Items[n][2]) end
  182. end
  183.  
  184. function DesktopInt()
  185. DrawDesktop()
  186. local n = 0
  187. while true do
  188.     DrawTaskbar()
  189.     local a, b, c, d = os.pullEvent("mouse_click")
  190.     local x = 2
  191.     local y = 1
  192.     for i = 1, #DeskItems do
  193.         if c >= x and c <= x+3 and d >= y and d <= y + 2 then n = i end
  194.         if x + 3 > w then x = 2 y = y + 4 else x = x + 5 end
  195.     end
  196.     if n > 0 then break end
  197. end
  198. CreateTab(DeskItems[n][2])
  199. end
  200.  
  201. function BackInt()
  202. local n = 0
  203. while true do
  204.     local event, key = os.pullEvent("key")
  205.     if key == keys.p then n = 50 end
  206.     if n > 0 then break end
  207. end
  208. if n == 50 then FullScreen = false end
  209. end
  210.  
  211. GetItems()
  212. Loop()
Add Comment
Please, Sign In to add comment