Marlingaming

CC Tweaked CCSPS Main Menu (Mouse, V3, Advanced)

Jan 20th, 2022 (edited)
792
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --this acts as main script CSP
  2. version = "1.0.3"
  3. settings.load(".settings")
  4. local w, h = term.getSize()
  5. os.loadAPI("TouchPad")
  6.  
  7. local BaseAppsInstalled = {true,false,true}
  8. local IntPrograms = {"os/os_Programs/ClientApps/os_AccountPgScript","os/os_Programs/os_LinksProvider","os/os_Programs/os_SettingsMenu","os.reboot","os.shutdown"}
  9. local ProgramNames = {"Account","Online Items","Settings","reboot","shutdown"}
  10. --Display Var
  11. local TimeSpot = #ProgramNames + 5
  12. local TaskBarSettings = {1,h-3,w,h,colors.lightGray}
  13. local Shortcuts = {}
  14. local TaskbarItems = {}
  15. local ExtrasStates = {false,false,false} --show Searchbar, show
  16.  
  17.  
  18.  
  19. local function Clear()
  20. term.clear()
  21. term.setCursorPos(1,1)
  22. end
  23.  
  24. local function CenterText(y,text)
  25.     local x = math.floor((w - string.len(text)) /2)
  26.     term.setCursorPos(x,y)
  27.     term.clearLine()
  28.     term.write(text)
  29. end
  30.  
  31. local function BetaAppsLoad()
  32. ProgramNames = {}
  33. IntPrograms = {}
  34. settings.load(".settings")
  35. ProgramNames = settings.get("ClientApps_Names")
  36. IntPrograms = settings.get("ClientApps_Paths")
  37. ProgramNames[#ProgramNames + 1] = "reboot"
  38. ProgramNames[#ProgramNames + 1] = "shutdown"
  39. IntPrograms[#IntPrograms + 1] = "reboot"
  40. IntPrograms[#IntPrograms + 1] = "shutdown"
  41. TimeSpot = #ProgramNames + 5
  42. end
  43.  
  44. local function GetMenuFiles()
  45. local data
  46. local file = fs.open(shell.resolve("/MenuFiles/Shortcuts"),"r")
  47. while true do
  48.     data = {file.readLine()}
  49.     if data[1] == "end" then
  50.         break
  51.     else
  52.         ShortcutCreator( data[1],data[2],data[3],data[4],data[5])
  53.     end
  54. end
  55. file.close()
  56. data = {}
  57. local TaskFile = fs.open(shell.resolve("/MenuFiles/Taskbar")
  58. TaskbarSettings = {TaskFile.readLine()}
  59. while true do
  60.     data = {TaskFile.readLine()}
  61.     if data[1] == "end" then
  62.         break
  63.     else
  64.         TaskbarItemCreator( data[1], data[2], data[3])
  65.     end
  66. end
  67. TaskFile.close()
  68. end
  69.  
  70. local function TaskbarItemCreator (Name ,image ,Path)
  71. TaskbarItems[#TaskbarItems + 1] = {Name, image, Path}
  72. --leaving image as n will have a default image used
  73. end
  74.  
  75. local function ShortcutCreator(Name ,image , Path ,x ,y )
  76. Shortcuts[#Shortcuts + 1] = {Name, image, Path, x, y}
  77. --x and y are the cords for top left corner, leaving image as n will have a default image used
  78. end
  79.  
  80. local function DisplaySystem()
  81. MenuDrawer()
  82. DrawTaskbar()
  83. DrawShortcuts()
  84. end
  85.  
  86. local function DrawTaskbar()
  87. paintutils.drawFilledBox(TaskBarSettings)
  88. paintutils.drawFilledBox(1, h - 4, 4, h, colors.blue)
  89. DrawNetworkStatus()
  90. local X1
  91. local X2
  92. for i = 1, #TaskbarItems do
  93.     X1 = i * 6
  94.     X2 = i * 6 + 5
  95.     paintutils.drawFilledBox(X1, h - 5, X2, h, colors.yellow)
  96. end
  97. end
  98.  
  99. local function DrawShortcuts()
  100. for i = 1, #Shortcuts do
  101.     paintutils.drawFilledBox(Shortcuts[i][4],Shortcuts[i][5],Shortcuts[i][4] + 7, Shortcuts[i][5] + 12, colors.gray)
  102.     term.setTextColor(colors.white)
  103.     term.setCursorPos((Shortcuts[i][4] + 7) - string.len(Shortcuts[i][1], Shortcuts[i][5] + 10)
  104.     term.write(Shortcuts[i][1])
  105. end
  106. end
  107.  
  108. local function MenuDrawer()
  109. term.setBackgroundColor(colors.cyan)
  110. Clear()
  111. term.setBackgroundColor(colors.cyan)
  112. CenterText(1,"==Desktop==version"..version.."==")
  113. CenterText(3,"-=Applications=-")
  114. end
  115.  
  116. function DrawNetworkStatus()
  117. local Modem = peripheral.find("modem")
  118. local NetworkState = 0
  119. if Modem ~= nil then
  120.     NetworkState = 1
  121. else
  122.     NetworkState = 0
  123. end
  124. if NetworkState == 1 then
  125.     rednet.open(Modem)
  126.     rednet.broadcast("ping")
  127.     local id, message, protocol = rednet.receive()
  128.     if message == "pong" then
  129.         NetworkState = 3
  130.     else
  131.         NetworkState = 2
  132.     end
  133. end
  134. paintutils.drawFilledBox(w-5,h-3,w,h,colors.lightGray)
  135. if NetworkState == 0 then
  136.     paintutils.drawPixel(w,h,colors.gray)
  137. elseif NetworkState == 1 then
  138.     paintutils.drawPixel(w,h,colors.white)
  139. elseif NetworkState == 2 then
  140.     paintutils.drawPixel(w,h,colors.white)
  141.     paintutils.drawFilledBox(w-2,h-1,w-2,h,colors.white)
  142. elseif NetworkState == 3 then
  143.     paintutils.drawPixel(w,h,colors.white)
  144.     paintutils.drawFilledBox(w-2,h-1,w-2,h,colors.white)
  145.     paintutils.drawFilledBox(w-4,h-2,w-4,h,colors.white)
  146. end
  147. end
  148.    
  149. function CUI(m) --declare function
  150. n=1
  151. local l = #m
  152. while true do
  153. term.setCursorPos(1,5)
  154.  
  155. for i=1, #m, 1 do --traverse the table of options
  156. if i==n then term.clearLine() print(i, " ["..m[i].."]") else term.clearLine() print(i, " ", m[i]) end --print them
  157. end
  158. a, b= os.pullEvent("key") --wait for keypress
  159. if b==keys.w and n>1 then n=n-1 end
  160. if b==keys.s and n<l then n=n+1 end
  161. if b==keys.enter then break end
  162. end
  163. return n --return the value
  164. end
  165.  
  166. function CheckInteractables(event,x,y)
  167. local Result = "n"
  168. local Type
  169. for i = 1, #Shortcuts do
  170.     if x >= Shortcuts[i][4] and x <= Shortcuts[i][4] + 7 and y >= Shortcuts[i][5] and y <= Shortcuts[i][5] + 12 then
  171.         Result = Shortcuts[i][3]
  172.         Type = "Script"
  173.     end
  174. end
  175. if Result == "n" and y > h - 5 then
  176.     local X1
  177.     local X2
  178.     for i = 1, #TaskbarItems do
  179.         X1 = i * 6
  180.         X2 = i * 6 + 5
  181.         if x > = X1 and x <= X2 then
  182.             Result = TaskbarItems[i][3]
  183.             Type = "Script"
  184.         end
  185.     end
  186. elseif Result == "n" and x < 5 and y > h - 5 then
  187.     Result = "Home"
  188.     Type = "button"
  189. end
  190. return (Result, Type)
  191. end
  192.  
  193. function Interaction()
  194. Clear()
  195. DisplaySystem()
  196. local item
  197. while true do
  198.     local a, b, c, d = os.pullEvent()
  199.     if a == "key" then
  200.  
  201.     elseif a == "mouse_click" then
  202.         item = {CheckInteractables("click",c,d)}
  203.         if item[1] ~= "n" then break end
  204.     elseif a == "rednet_message" then
  205.  
  206.     end
  207. end
  208. if item[2] == "Script" then
  209.     shell.run(item[1])
  210. elseif item[2] == "button" then
  211.  
  212. end
  213. end
  214.  
  215. Interaction()
RAW Paste Data Copied