Marlingaming

CC Tweaked CCSPS 20 - Window Manager

Mar 1st, 2022 (edited)
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 12.42 KB | None | 0 0
  1. local FilePath
  2. local UserPath
  3. local ProgramPaths
  4.  
  5. local Windows = {}
  6. local Items = {}
  7. local DeskItems = {}
  8. local Notifications = {}
  9. local Buttons = {}
  10. local Videos = 0
  11. local Popup = {false,1,1,{},nil}
  12. local DesktopDraw = true
  13. local FullScreen = false
  14. local w, h = term.getSize()
  15.  
  16. function GetPaths()
  17. local file = fs.open("os/SystemFiles/Paths.txt","r")
  18. local Content
  19. repeat
  20.     Content = file.readLine()
  21.     if Content ~= nil and string.find(Content,"Files = ") then FilePath = string.sub(Content,9,string.len(Content)) end
  22.     if Content ~= nil and string.find(Content,"User = ") then UserPath = string.sub(Content,8,string.len(Content)) end
  23.     if Content ~= nil and string.find(Content,"Programs = ") then ProgramPaths = string.sub(Content,12,string.len(Content)) end
  24. until Content == nil
  25. file.close()
  26. end
  27.  
  28. local function Clear()
  29. term.clear()
  30. term.setCursorPos(1,1)
  31. end
  32.  
  33. function GetItems()
  34. local file = fs.open("os/SystemFiles/TaskbarShortcuts.txt","r")
  35. local Name
  36. local Path
  37. local Image
  38. repeat
  39.     Name = file.readLine()
  40.     Path = file.readLine()
  41.     Image = file.readLine()
  42.     if Name ~= nil then Items[#Items + 1] = {Name,Path,Image} end
  43. until Name == nil
  44. file.close()
  45. if fs.getSize("os/SystemFiles/TaskbarShortcuts.txt") < 2 then Items = {} end
  46. GetDesktop()
  47. end
  48.  
  49. function GetDesktop()
  50. local file = fs.open("os/SystemFiles/DesktopShortcuts.txt","r")
  51. local Name
  52. local Path
  53. local Image
  54. repeat
  55.     Name = file.readLine()
  56.     Path = file.readLine()
  57.     Image = file.readLine()
  58.     if Name ~= nil then DeskItems[#DeskItems + 1] = {Name,Path,Image} end
  59. until Name == nil
  60. file.close()
  61.  
  62. if fs.getSize("os/SystemFiles/DesktopShortcuts.txt") < 2 then DeskItems = {} end
  63.  
  64. end
  65.  
  66. function OpenPopup(x,y,details)
  67. local Options = {}
  68. if details[2] == "file" then
  69.     Options = {"open","open loc","properties","delete"}
  70. end
  71. Popup = {true,x,y,Options,details[1]}
  72. end
  73.  
  74. function CheckEvent(E,a,b,c,d,e,f)
  75. local i
  76. Pass = false
  77. for j = 1, #Windows do
  78.     if Windows[j][1] == a then i = j end
  79. end
  80. if E == "newWindow" then
  81.     Windows[#Windows + 1] = {a,{b,c},d,e,{},true,false,f}
  82.     Pass = true
  83. elseif E == "closeWindow" then
  84.     Windows[i] = nil
  85.     Pass = true
  86. elseif E == "clearWindow" then
  87.     Windows[i][5] = {}
  88.     Pass = true
  89. elseif E == "windowText" then
  90.     Windows[i][5][#Windows[i][5] + 1] = {"text",b,c,d}
  91.     Pass = true
  92. elseif E == "windowImage" then
  93.     Windows[i][5][#Windows[i][5] + 1] = {"image",b,c,d}
  94.     Pass = true
  95. elseif E == "windowButton" then
  96.     Windows[i][5][#Windows[i][5]+ 1] = {"button",b,c,d,e}
  97.     Pass = true
  98.     Buttons[#Buttons + 1] = {i,b,c,d,e}
  99. elseif E == "windowInputBox" then
  100.     Windows[i][5][#Windows[i][5] + 1 ] = {"input",b,c,d,e,f}
  101.     Pass = true
  102. elseif E == "windowVideo" then
  103.     Windows[i][5][#Windows[i][5] + 1] = {"video",b,c,1,d,e}
  104.     Videos = Videos + 1
  105.     Pass = true
  106. elseif E == "windowFullscreen" then
  107.     if b == true then FullScreen = true Windows[i][6] = true end
  108.     Pass = true
  109. elseif E == "windowVideoUpdate" then
  110.     UpdateItem(i,b,"video",c)
  111.     Pass = true
  112. elseif E == "mouse_click" then
  113.     if CheckWindows(b,c) == true then Pass = true end
  114. elseif E == "mouse_drag" then
  115.     GetDragWindow(b,c)
  116.     Pass = true
  117. elseif E == "modem_message" then
  118.     Notifications[#Notifications + 1] = {"message",b,c,d,e}
  119.     Pass = true
  120. end
  121. return Pass
  122. end
  123.  
  124. function Event()
  125. local Pass = false
  126. while true do
  127.     Pass = false
  128.     os.startTimer(1)
  129.     local event, a, b, c, d, e, f= os.pullEvent()
  130.     Pass = CheckEvent(event,a,b,c,d,e,f)
  131.     term.setBackgroundColor(colors.black)
  132.     if event == "timer" and Pass == false then
  133.         Time()
  134.         if Videos > 0 then Draw() end
  135.     elseif Pass == true then
  136.         Clear()
  137.         drawDesktop()
  138.         Draw()
  139.     end
  140. end
  141. end
  142.  
  143. function UpdateItem(win,item,set,t)
  144. local I = 3
  145. local J
  146. if set == "video" then
  147.     I = 3
  148. end
  149. for i = 1, #Windows[win][5] do
  150.     if Windows[win][5][i][2] == item then J = i end
  151. end
  152. Windows[win][5][J][I] = set
  153. end
  154.  
  155. function GetDragWindow(x,y)
  156.  
  157. local I = 1
  158. for i = 1, #Windows do
  159.     if Windows[i][6] == true and Windows[i][7] == false then
  160.         if x >= Windows[i][2][1] + 1 and x < (Windows[i][2][1] + Windows[i][3]) - 2 and y == Windows[i][2][2] then DragWindow(i,x,y) elseif y == Windows[i][2][2] + Windows[i][4] and x == Windows[i][2][1] + Windows[i][3] then ResizeWindow(i) end
  161.     end
  162. end
  163. end
  164.  
  165. function ResizeWindow(I)
  166. while true do
  167.     local event, a, b, c = os.pullEvent()
  168.     if event == "mouse_up" then
  169.         break
  170.     elseif event == "mouse_drag" then
  171.         Windows[I][3] = b - Windows[I][2][1]
  172.         Windows[I][4] = c - Windows[I][2][2]
  173.         term.setBackgroundColor(colors.black)
  174.         Clear()
  175.         drawDesktop()
  176.         Draw()
  177.     end
  178. end
  179. end
  180.  
  181. function DragWindow(I,x1,y1)
  182. local x, y
  183. local x2 = x1 - Windows[I][2][1]
  184. while true do
  185.     local event, a, b, c = os.pullEvent()
  186.     if event == "mouse_up" then
  187.         break
  188.     elseif event == "mouse_drag" then
  189.         Windows[I][2] = {b - x2,c}
  190.         term.setBackgroundColor(colors.black)
  191.         Clear()
  192.         drawDesktop()
  193.         Draw()
  194.         x, y = b, c
  195.     end
  196. end
  197. if x == Windows[I][2][1] + Windows[I][3] and y == Windows[I][2][2] then Windows[I] = nil end
  198. end
  199.  
  200. function CheckWindows(x,y)
  201. local I = 3
  202.  
  203. local Found = false
  204. for i = 1, #Items do
  205.     if x >= I and x <= I + 2 and y >= h - 2 then
  206.         for t = 1, #Windows do
  207.             if Windows[t][1] == Items[i][1] then Windows[t][6] = true Found = true end
  208.         end
  209.         if Found == false then Found = true shell.run(Items[i][2],"start") end
  210.     end
  211.     I = I + 5
  212. end
  213. if Found == false then
  214.     for i = 1, #Windows do
  215.         if Windows[i][6] == true then
  216.             local X1, Y1, W1, H1 = Windows[i][2][1], Windows[i][2][2], Windows[i][3], Windows[i][4]
  217.             if Windows[i][7] == true then X1 = 1 Y1 = 1 W1 = w - 1 H1 = h - 2 end
  218.             if x >= Windows[i][2][1] and x <= Windows[i][2][1] + Windows[i][3] and y >= Windows[i][2][2] + 1 and y <= Windows[i][2][2] + Windows[i][4] then
  219.                 for c = 1, #Windows[i][5] do
  220.                     if Windows[i][5][c][1] == "button" and y == Windows[i][2][2] + Windows[i][5][c][5] and x >= Windows[i][2][1] + Windows[i][5][c][4] and x <= (Windows[i][2][1] + Windows[i][5][c][4]) + string.len(Windows[i][5][c][2]) then Found = true shell.run(Windows[i][5][c][3],Windows[i][5][c][2]) end
  221.                 end
  222.             end
  223.             if x == (X1 + W1) - 2 and y == Y1 then Windows[i][6] = false Found = true end
  224.             if x == (X1 + W1) - 1 and y == Windows[i][2][2] then
  225.                 if Windows[i][7] == true then Windows[i][7] = false else Windows[i][7] = true end
  226.                 Found = true
  227.             end
  228.             if x == X1 + W1 and y == Y1 then Windows[i] = nil Found = true end
  229.  
  230.         else
  231.             if x >= I and x <= I + 2 and y >= h - 2 then Windows[i][6] = true Found = true end
  232.             I = I + 5
  233.         end
  234.     end
  235. end
  236. if Found == false and DesktopDraw == true then
  237.     local X = 2
  238.     local Y = 2
  239.     local Blocked = false
  240.     for i = 1, #DeskItems do
  241.         Blocked = false
  242.         for l = 1, #Windows do
  243.             if X >= Windows[i][2][1] and X <= Windows[i][2][1] + Windows[i][3] and Y >= Windows[i][2][2] and Y <= Windows[i][2][2] + Windows[i][4] then Blocked = true end
  244.         end
  245.         if x >= X and x <= X + 3 and y >= Y and y <= Y + 3 and Blocked == false then Found = true shell.run(DeskItems[i][2],"start") end
  246.         if X + 8 < w then X = X + 6 else X = 2 Y = Y + 5 end
  247.     end
  248. end
  249. Found = true
  250. if Found == false then
  251.     for i = 1, #Buttons do
  252.         if y == Windows[Buttons[i][1]][2][2] + Buttons[i][5] and x >= Windows[Buttons[i][1]][2][1] + Buttons[i][4] and x <= Windows[Buttons[i][1]][2][1] + Buttons[i][4] + 5 then shell.run(Buttons[i][3],Buttons[i][2]) end
  253.     end
  254. end
  255. return Found
  256. end
  257.  
  258. function DrawPopup()
  259. term.setBackgroundColor(colors.white)
  260. term.setCursorPos(Popup[2],Popup[3])
  261. for i = 1, #Popup[4] do
  262.     term.write(Popup[4][i])
  263.     term.setCursorPos(Popup[2],Popup[3] + i)
  264. end
  265. end
  266.  
  267. function CheckPopup(x,y)
  268. local R = false
  269. local Cords = {}
  270. for i = 1, #Popup[4] do
  271.     Cords[i] = {Popup[2],Popup[2] + string.len(Popup[4][i]),Popup[3] - 1 + i, Popup[4][i]}
  272. end
  273. for i = 1, #Cords do
  274.     if x >= Cords[i][1] and x <= Cords[i][2] and y == Cords[i][3] then R = Cords[i][3] end
  275. end
  276. Popup[1] = false
  277. if R == "open" then
  278.  
  279. elseif R == "open loc" then
  280.     shell.run("FInav","start",Popup[5])
  281. elseif R == "properties" then
  282.  
  283. end
  284. return R
  285. end
  286.  
  287. function DrawTaskbar()
  288. if FullScreen == false then
  289. paintutils.drawFilledBox(1,h-1,w,h-1,colors.gray)
  290. paintutils.drawFilledBox(1,h,w,h,colors.lightGray)
  291. local x = 3
  292. Time()
  293. local Tabs = {}
  294. for i = 1, #Items do
  295.     paintutils.drawFilledBox(x, h -2, x + 2, h, colors.white)
  296.     Tabs[i] = 0
  297.     x = x + 5
  298. end
  299. local Found = false
  300. for i = 1, #Windows do
  301.     Found = false
  302.     if Windows[i][6] == false then
  303.         for I = 1, #Items do
  304.             if Windows[i][1] == Items[I][1] then Tabs[I] = Tabs[I] + 1 Found = true end
  305.         end
  306.         if Found == false then
  307.             paintutils.drawFilledBox(x, h-2, x + 2, h, colors.yellow)
  308.             x = x + 5
  309.         end
  310.     end
  311. end
  312. x = 3
  313. term.setBackgroundColor(colors.lightGray)
  314. for i = 1, #Tabs do
  315.     term.setCursorPos(x, h)
  316.     if Tabs[i] > 0 then
  317.         term.write(Tabs[i])
  318.     end
  319.     x = x + 5
  320. end
  321. if #Notifications > 0 then paintutils.drawPixel(w,h,colors.red) end
  322. term.setBackgroundColor(colors.black)
  323. end
  324. end
  325.  
  326. function drawDesktop()
  327. DesktopDraw = true
  328. for i = 1, #Windows do
  329.     if Windows[i][7] == true and Windows[i][6] == true then DesktopDraw = false end
  330. end
  331. if DesktopDraw == true then
  332. local y = 2
  333. local x = 2
  334. for i = 1, #DeskItems do
  335.     paintutils.drawFilledBox(x,y,x + 3, y + 3, colors.blue)
  336.     if x + 8 < w then x = x + 6 else x = 2 y = y + 5 end
  337. end
  338. end
  339. term.setBackgroundColor(colors.black)
  340. end
  341.  
  342. function Draw()
  343.     DrawTaskbar()
  344.     term.setBackgroundColor(colors.black)
  345.     local I = 1
  346.     term.setTextColor(colors.black)
  347.     local Cords = {}
  348.     for i = 1, #Windows do
  349.         if Windows[i][6] == true then
  350.         local X1, Y1, W1, H1 = Windows[i][2][1], Windows[i][2][2], Windows[i][3], Windows[i][4]
  351.             if Windows[i][7] == true then X1 = 1 Y1 = 1 W1 = w - 1 H1 = h - 2 end
  352.             paintutils.drawFilledBox(X1,Y1,X1 + W1,Y1 + H1,colors.white)
  353.             paintutils.drawBox(X1,Y1,X1 + W1, Y1 + H1, colors.gray)
  354.             paintutils.drawBox(X1,Y1,X1 + W1 - 2,Y1,colors.lightGray)
  355.             paintutils.drawPixel(X1 + W1, Y1,colors.red)
  356.             paintutils.drawPixel((X1 + W1) - 2, Y1, colors.blue)
  357.             paintutils.drawPixel((X1 + W1) - 1, Y1, colors.yellow)
  358.             term.setCursorPos(X1,Y1)
  359.             term.setBackgroundColor(colors.lightGray)
  360.             term.write(string.sub(Windows[i][1],1,Windows[i][3] - 5))
  361.             term.setBackgroundColor(colors.white)
  362.             for t = 1, #Windows[i][5] do
  363.                 if Windows[i][5][t][1] == "text" then term.setCursorPos(X1 + Windows[i][5][t][3], Y1 + Windows[i][5][t][4]) term.write(string.sub(Windows[i][5][t][2],1,Windows[i][3] - Windows[i][5][t][3])) elseif Windows[i][5][t][1] == "image" then local Image = paintutils.loadImage(Windows[i][5][t][2]) paintutils.drawImage(Image,X1 + Windows[i][5][t][3], Y1 + Windows[i][5][t][4]) elseif Windows[i][5][t][1] == "button" then term.setBackgroundColor(colors.red) term.setCursorPos(X1 + Windows[i][5][t][4], Y1 + Windows[i][5][t][5]) term.write(string.sub(Windows[i][5][t][2],1,Windows[i][3] - Windows[i][5][t][4])) elseif Windows[i][5][t][1] == "video" then VideoPlayer(i,t) end
  364.             end
  365.         end
  366.     end
  367. end
  368.  
  369. function VideoPlayer(Window,Item)
  370. local List = fs.list(Windows[Window][5][Item][3])
  371. local Image = paintutils.loadImage(fs.combine(Windows[Window][5][Item][3],List[Windows[Window][5][Item][4]]))
  372. paintutils.drawImage(Image,Windows[Window][2][1] + Windows[Window][5][Item][5], Windows[Window][2][2] + Windows[Window][5][Item][6])
  373. if Windows[Window][5][Item][4] < #List then
  374.     Windows[Window][5][Item][4] = Windows[Window][5][Item][4] + 1
  375. else
  376.     Videos = Videos - 1
  377.     if Windows[Window][8] ~= nil then shell.run(Windows[Window][8],Windows[Window][5][Item][2]) end
  378.     Windows[Window][5][Item] = nil
  379. end
  380. end
  381.  
  382. function Time()
  383. term.setBackgroundColor(colors.lightBlue)
  384. term.setCursorPos(w - 7, h - 1)
  385. term.write(textutils.formatTime(os.time()))
  386. end
  387.  
  388. GetPaths()
  389. GetItems()
  390. Event()
Add Comment
Please, Sign In to add comment