Marlingaming

CC Tweaked Main Program Menu (KeyBoard)

Jan 7th, 2022 (edited)
671
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.68 KB | None | 0 0
  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","os.reboot","os.shutdown"}
  7. local ProgramNames = {"Account","Online Items","Settings","reboot","shutdown"}
  8. local TimeSpot = #ProgramNames + 5
  9. local function Clear()
  10. term.clear()
  11. term.setCursorPos(1,1)
  12. end
  13.  
  14. local function CenterText(y,text)
  15.     local x = math.floor((w - string.len(text)) /2)
  16.     term.setCursorPos(x,y)
  17.     term.clearLine()
  18.     term.write(text)
  19. end
  20.  
  21. local function LoadInstalled()
  22. ProgramNames = {}
  23. IntPrograms = {}
  24. settings.load(".settings")
  25. ProgramNames = settings.get("ClientApps_Names")
  26. IntPrograms = settings.get("ClientApps_Paths")
  27. ProgramNames[#ProgramNames + 1] = "reboot"
  28. ProgramNames[#ProgramNames + 1] = "shutdown"
  29. IntPrograms[#IntPrograms + 1] = "reboot"
  30. IntPrograms[#IntPrograms + 1] = "shutdown"
  31. TimeSpot = #ProgramNames + 5
  32. end
  33.  
  34. local function NonBetaTestMode()
  35. IntPrograms = {"os/os_Programs/os_AccountPgScript","os/os_Programs/os_LinksProvider","os/os_Programs/os_SettingsMenu", "os.reboot","os.shutdown"}
  36. ProgramNames = {"AccountPage","Online Programs","Settings","Reboot","PowerOff"}
  37. end
  38.  
  39. local function MenuDrawer()
  40. term.setBackgroundColor(colors.cyan)
  41. Clear()
  42. local Background = paintutils.loadImage("os/os_SystemFiles/Images/MenuBackground")
  43. paintutils.drawImage(Background,1,1)
  44. term.setBackgroundColor(colors.cyan)
  45. CenterText(1,"==Desktop==version"..version.."==")
  46. CenterText(3,"-=Applications=-")
  47. CenterText(TimeSpot,os.date())
  48. if settings.get("os_BetaTest") == true then
  49.     CenterText(TimeSpot - 1,"Experimental Mode")
  50. end
  51. DrawNetworkStatus()
  52. end
  53.  
  54. function DrawNetworkStatus()
  55. local Modem = peripheral.find("modem")
  56. local NetworkState = 0
  57. if Modem ~= nil then
  58.     NetworkState = 1
  59. else
  60.     NetworkState = 0
  61. end
  62. if NetworkState == 1 then
  63.     rednet.open(Modem)
  64.     rednet.broadcast("ping")
  65.     local id, message, protocol = rednet.receive()
  66.     if message == "pong" then
  67.         NetworkState = 3
  68.     else
  69.         NetworkState = 2
  70.     end
  71. end
  72. paintutils.drawFilledBox(w-3,h-3,w,h,colors.lightGray)
  73. if NetworkState == 3 then paintutils.drawFilledBox(w-2,h-2,w,h, colors.white) end
  74. if NetworkState > 1 then paintutils(w-1, h-1, w, h, colors.lightGray) end
  75. if NetworkState == 0 then
  76.     paintutils.drawPixel(w,h,colors.gray)
  77. elseif NetworkState == 1 then
  78.     paintutils.drawPixel(w,h,colors.white)
  79. end
  80. end
  81.    
  82. function CUI(m) --declare function
  83. n=1
  84. local l = #m
  85. while true do
  86. CenterText(TimeSpot, os.date())
  87. term.setCursorPos(1,5)
  88.  
  89. for i=1, #m, 1 do --traverse the table of options
  90. if i==n then term.clearLine() print(i, " ["..m[i].."]") else term.clearLine() print(i, " ", m[i]) end --print them
  91. end
  92. local event = {os.pullEvent()}
  93. local Cat = {event[3]}
  94. if event[1] == "rednet_message" and event[4] == settings.get("Secure_WirelessProtocol") and Cat == "Banking" then shell.run("os/os_Programs/os_BankingApp","Request Detected",event) end
  95. CenterText(TimeSpot, os.date())
  96. a, b= os.pullEvent("key") --wait for keypress
  97. if b==keys.w and n>1 then n=n-1 end
  98. if b==keys.s and n<l then n=n+1 end
  99. if b==keys.enter then break end
  100. CenterText(TimeSpot, os.date())
  101. end
  102. return n --return the value
  103. end
  104.  
  105. function MainInteraction()
  106. Clear()
  107. settings.load(".settings")
  108.  
  109. if settings.get("os_BetaTest") == true then
  110.  
  111. end
  112.  
  113. LoadInstalled()
  114.  
  115. MenuDrawer()
  116. local n = CUI(ProgramNames)
  117. if IntPrograms[n] == "reboot" then
  118.     os.reboot()
  119. elseif IntPrograms[n] == "shutdown" then
  120.     os.shutdown()
  121. else
  122.     shell.run(shell.resolve(IntPrograms[n]))
  123. end
  124. end
  125.  
  126. MainInteraction()
Add Comment
Please, Sign In to add comment