Marlingaming

CC Tweaked CCSPS Iron - Basic Desktop

Jan 25th, 2022 (edited)
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.76 KB | None | 0 0
  1. --this script acts as the Base for CCSPS Iron
  2. local IconSizes = {3,5}
  3. local AppPaths = {}
  4. local AppNames = {}
  5. local AppImages = {}
  6. local ShortcutCords = {}
  7. local PopItems = {}
  8. local PopPaths = {}
  9. local TaskbarItems = {}
  10. local TaskbarPaths = {}
  11. local TaskbarImages = {}
  12. local BImagePath = "n"
  13. local w, h = term.getSize()
  14.  
  15. local function GetApps()
  16. local Path = "os/System/Saved/Shortcuts"
  17. local Shortcuts = fs.list(Path)
  18. for i = 1, #Shortcuts do
  19.     local file = fs.open(fs.combine(Path,Shortcuts[i]),"r")
  20.     local Name = file.readLine()
  21.     local Path = file.readLine()
  22.     local Image = file.readLine()
  23.     local Type = file.readLine()
  24.     file.close()
  25.     if Type == "Desktop" then
  26.         AppNames[#AppNames + 1] = Name
  27.         AppPaths[#AppPaths + 1] = Path
  28.         AppImages[#AppImages + 1] = Image
  29.     elseif Type == "Taskbar" then
  30.         TaskbarItems[#TaskbarItems + 1] = Name
  31.         TaskbarPaths[#TaskbarPaths + 1] = Path
  32.         TaskbarImages[#TaskbarImages + 1] = Image
  33.     elseif Type == "Popup" then
  34.         PopItems[#PopItems + 1] = Name
  35.         PopPaths[#PopPaths + 1] = Path
  36.     end
  37. end
  38.  
  39. if w > 25 then
  40.     IconSizes = {4,3}
  41. elseif w <= 26 then
  42.     IconSizes = {4,3}
  43. end
  44.  
  45. SetCords()
  46. end
  47.  
  48. function SetCords()
  49. local y = 2
  50. local x = 3
  51. for i = 1, #AppNames do
  52.     ShortcutCords[i] = {x,y}
  53.     if x + (IconSizes[1] + 3) <= 26 then
  54.         x = x + (IconSizes[1] + 3)
  55.     else
  56.         x = 3
  57.         y = y + (IconSizes[2] + 3)
  58.     end
  59. end
  60. end
  61.  
  62. local function DrawShortcuts()
  63. local x
  64. local y
  65. for i = 1, #AppNames do
  66.     x = ShortcutCords[i][1]
  67.     y = ShortcutCords[i][2]
  68.     paintutils.drawBox( x,y,x+IconSizes[1],y+IconSizes[2], colors.white)
  69.     if AppImages[i] ~= "n" then
  70.         local Image = paintutils.loadImage(AppImages[i])
  71.         paintutils.drawImage(Image,x,y)
  72.     end
  73.     term.setBackgroundColor(colors.lightBlue)
  74.     local lines = require "cc.strings".wrap(AppNames[i], (IconSizes[1]+4))
  75.     for I = 1, #lines do
  76.       term.setCursorPos(x - 1, (y + IconSizes[2]) + I)
  77.       term.write(lines[I])
  78.     end
  79. end
  80. end
  81.  
  82. local function DrawTaskBar()
  83. paintutils.drawFilledBox(1,h, w, h, colors.blue)
  84. paintutils.drawFilledBox(1, h, 2, h, colors.lightGray)
  85. local ItemCol = {colors.blue,colors.yellow,colors.green}
  86. local X = 4
  87. for i = 1, #TaskbarItems do
  88.     paintutils.drawBox(X, h - 2,X+2, h, ItemCol[i])
  89.     if TaskbarImages[i] ~= "n" then
  90.         local Image = paintutils.loadImage(TaskbarImages[i])
  91.         paintutils.drawImage(Image,X, h - 2)
  92.     end
  93.     X = X + 4
  94. end
  95. end
  96.  
  97. local function Clear()
  98. term.clear()
  99. term.setCursorPos(1,1)
  100. end
  101.  
  102. local function CenterText(y,text)
  103.     local x = math.floor((w - string.len(text)) /2)
  104.     term.setCursorPos(x,y)
  105.     term.clearLine()
  106.     term.write(text)
  107. end
  108.  
  109. function CUI(m,y) --declare function
  110. n=0
  111. local l = #m
  112. while true do
  113. a, b, c, d= os.pullEvent("mouse_click") --wait for keypress
  114. for i = 1, #AppNames do
  115.     if c >= ShortcutCords[i][1] and c <= ShortcutCords[i][1] + IconSizes[1] and d >= ShortcutCords[i][2] and d <= ShortcutCords[i][2] + IconSizes[2] then n = i t = "Short" end
  116. end
  117. local X = 4
  118. for I = 1, #TaskbarItems do
  119.     if c >= X and c <= X + 2 and d >= h - 2 then n = I t = "Task" end
  120.     X = X + 4
  121. end
  122. if n == 0 and c < 3 and d > h - 1 then n = 50 end
  123. if n > 0 then break end
  124. end
  125. return n, t --return the value
  126. end
  127.  
  128. function popupCUI() --declare function
  129. n=0
  130. while true do
  131. a, b, c, d= os.pullEvent("mouse_click") --wait for keypress
  132. for i = 1, #PopItems do
  133.     if c > 2 and c < 10 and d >= (i  + (h - 15)) and d <= ( i + (h - 14)) then n = i end
  134. end
  135. if n == 0 and c <= 2 and d >=  h - 2 and d <= h - 1 then n = 50 elseif n == 0 then n = 51 end
  136. if n > 0 then break end
  137. end
  138. return n --return the value
  139. end
  140.  
  141. function PopupPanel()
  142. paintutils.drawFilledBox(1,h - 15 ,15,h - 1,colors.lightGray)
  143. paintutils.drawFilledBox(1,h - 2, 2, h - 1, colors.red)
  144. term.setBackgroundColor(colors.lightGray)
  145. for I = 1, #PopItems do
  146.     term.setCursorPos(2,I + (h - 15))
  147.     term.write(PopItems[I])
  148. end
  149.  
  150. local n = popupCUI()
  151. if n == 50 then
  152.     shell.run("os/System/Scripts/PowerOff.lua","shutdown")
  153. elseif n == 51 then
  154.  
  155. else
  156.     shell.run(PopPaths[n])
  157. end
  158. end
  159.  
  160. function Desktop()
  161. term.setBackgroundColor(colors.lightBlue)
  162. term.setTextColor(colors.white)
  163. Clear()
  164. if BImagePath ~= "n" then
  165.     local image = paintutils.loadImage(BImagePath)
  166.     paintutils.drawImage(image,1,1)
  167. end
  168. DrawTaskBar()
  169. DrawShortcuts()
  170. CenterText(1,"Desktop")
  171. local options = AppNames
  172. local n, t = CUI(options)
  173. if n == 50 then
  174.     PopupPanel()
  175. else
  176.     if t == "Task" then
  177.         shell.run(TaskbarPaths[n])
  178.     else
  179.         shell.run(AppPaths[n])
  180.     end
  181. end
  182. Desktop()
  183. end
  184.  
  185. local function Start()
  186. GetApps()
  187. term.setBackgroundColor(colors.cyan)
  188. Clear()
  189. if fs.exists("os/System/Client/Files/Password.txt") then
  190.     local file = fs.open("os/System/Client/Files/Password.txt","r")
  191.     local Password = file.readLine()
  192.     file.close()
  193.     CenterText(1,"==Login==")
  194.     local Image = paintutils.loadImage("os/System/Saved/Images/Default_ProfileIcon.nfp")
  195.     paintutils.drawImage(Image,10,3)
  196.     paintutils.drawBox(8,10,18,10,colors.lightBlue)
  197.     term.setBackgroundColor(colors.cyan)
  198.     term.setCursorPos(8,9)
  199.     term.write("Password")
  200.     term.setCursorPos(8,2)
  201.     term.write("account")
  202.     term.setCursorPos(8,10)
  203.     term.setBackgroundColor(colors.lightBlue)
  204.     local input
  205.     while true do
  206.         local event = {os.pullEvent("key")}
  207.         if event[2] == keys.enter then break end
  208.         input = read()
  209.     end
  210.     if input ~= Password then
  211.         Start()
  212.     else
  213.         Desktop()
  214.     end
  215. else
  216.     CenterText(1,"==Start==")
  217.     CenterText(3,"press enter to continue")
  218.     repeat
  219.         local event, key = os.pullEvent("key")
  220.     until key == keys.enter
  221.     Desktop()
  222. end
  223. end
  224.  
  225. Start()
Add Comment
Please, Sign In to add comment