Marlingaming

CC Tweaked Personal Device Main Menu Program - Version 2

Jan 18th, 2022 (edited)
665
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. local BaseAppsInstalled = {true,false,true}
  6. local IntPrograms = {"os/os_Programs/ClientApps/os_AccountPgScript","os/os_Programs/os_LinksProvider","os/os_Programs/os_SettingsMenu"}
  7. local ProgramNames = {"Account","Online Items","Settings"}
  8. local TimeSpot = h
  9.  
  10. local function Clear()
  11. term.clear()
  12. term.setCursorPos(1,1)
  13. end
  14.  
  15. local function CenterText(y,text)
  16.     local x = math.floor((w - string.len(text)) /2)
  17.     term.setCursorPos(x,y)
  18.     term.clearLine()
  19.     term.write(text)
  20. end
  21.  
  22. local function BetaAppsLoad()
  23. ProgramNames = {}
  24. IntPrograms = {}
  25. settings.load(".settings")
  26. ProgramNames = settings.get("ClientApps_Names")
  27. IntPrograms = settings.get("ClientApps_Paths")
  28. ProgramNames[#ProgramNames + 1] = "reboot"
  29. ProgramNames[#ProgramNames + 1] = "shutdown"
  30. IntPrograms[#IntPrograms + 1] = "reboot"
  31. IntPrograms[#IntPrograms + 1] = "shutdown"
  32. TimeSpot = #ProgramNames + 5
  33. end
  34.  
  35.  
  36. local function MenuDrawer()
  37. term.setBackgroundColor(colors.cyan)
  38. Clear()
  39. local Background = paintutils.loadImage("os/os_SystemFiles/Images/MenuBackground")
  40. paintutils.drawImage(Background,1,1)
  41. CenterText(1,"==Desktop==version"..version.."==")
  42. CenterText(3,"-=Applications=-")
  43. term.setBackgroundColor(colors.cyan)
  44. CenterText(TimeSpot,os.date())
  45. if settings.get("os_BetaTest") == true then CenterText(TimeSpot -1,"Experimental Mode") end
  46. end
  47.  
  48.  
  49.    
  50. function CUI(m) --declare function
  51. n=1
  52. local l = #m
  53. local BoxPositions = {{2,5},{8,5},{14,5},{2,13},{8,13},{14,13},{2,21},{8,21},{14,21}}
  54. while true do
  55.  
  56. for i=1, #m, 1 do --traverse the table of options
  57.     paintutils.drawFilledBox(BoxPositions[i][1],BoxPositions[i][2],BoxPositions[i][1] + 5, BoxPositions[i][2] + 7, colors.gray)
  58.     term.setCursorPos(BoxPositions[i][1],BoxPositions[i][2])
  59.     term.write(m[i])
  60. end
  61.  
  62. a, b, c, d = os.pullEvent("mouse_click") --wait for keypress
  63. for i = 1, #m do
  64.     n = i
  65.     if c < 2 and d < 2 then shell.run("os/os_Programs/os_PowerMenu") end
  66.     if c > BoxPositions[i][1] and c < BoxPositions[i][1] + 5 and d > BoxPositions[i][2] and d < BoxPositions[i][2] + 7 then break end
  67. end
  68. end
  69. return n --return the value
  70. end
  71.  
  72. Clear()
  73. if settings.get("os_BetaTest") == true then
  74.     BetaAppsLoad()
  75. end
  76.  
  77. MenuDrawer()
  78. local n = CUI(ProgramNames)
  79. if IntPrograms[n] == "reboot" then
  80.     os.reboot()
  81. elseif IntPrograms[n] == "shutdown" then
  82.     os.shutdown()
  83. else
  84.     shell.run(shell.resolve(IntPrograms[n]))
  85. end
  86.  
RAW Paste Data Copied