Advertisement
Marlingaming

CC Tweaked Settings Menu

Jan 7th, 2022 (edited)
334
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.31 KB | None | 0 0
  1. local SettingsOptions = {"os_BootMode","Allow_OsUpdates","os_Username","os_LockScreenPassword","os_BetaTest","exit"}
  2. local Type = {"Switch","Switch","string","string","Switch","Button"}
  3. local Popup = {"this is for wither the quick boot runs or the full boot runs","wither Updates are automatically checked and ran apon boot, this feature is WIP","username of the client","the password for the Lockscreen, set to n to skip lockscreen apon start","Enable / Disable Experiential Features", "exit to menu"}
  4. local w, h = term.getSize()
  5.  
  6. local function Clear()
  7. term.clear()
  8. term.setCursorPos(1,1)
  9. end
  10.  
  11. local function DrawBackground()
  12. term.setBackgroundColor(colors.lightGray)
  13. Clear()
  14. term.setTextColor(colors.black)
  15. term.setBackgroundColor(colors.gray)
  16. paintutils.drawFilledBox(1,1,w,3,colors.gray)
  17. term.setCursorPos(4,2)
  18. term.write("=====SettingsMenu======")
  19. term.setCursorPos(1,4)
  20. term.setBackgroundColor(colors.lightGray)
  21. term.setTextColor(colors.white)
  22. end
  23.  
  24. local function DrawEditBackground(option)
  25. term.setBackgroundColor(colors.cyan)
  26. Clear()
  27. paintutils.drawFilledBox(1,1,w,5,colors.lightGray)
  28. term.setBackgroundColor(colors.lightGray)
  29. term.setCursorPos(1,1)
  30. term.write(SettingsOptions[option])
  31. term.setCursorPos(1,2)
  32. local lines = require "cc.strings".wrap(Popup[option], w)
  33. for i = 1, #lines do
  34.   term.setCursorPos(1, i + 1)
  35.   term.write(lines[i])
  36. end
  37. term.setCursorPos(1,5)
  38. term.setBackgroundColor(colors.cyan)
  39. if Type[option] == "string" then
  40.     lines = require "cc.strings".wrap("type out string then press enter twice to save", w)
  41. elseif Type[option] == "Switch" then
  42.     lines = require "cc.strings".wrap("1 = true 0 = false", w)
  43. end
  44. for i = 1, #lines do
  45.   term.setCursorPos(1, i + 4)
  46.   term.write(lines[i])
  47. end
  48. term.setCursorPos(1,8)
  49. end
  50.  
  51. local function SettingManager(i)
  52. local event
  53. settings.load(".settings")
  54. DrawEditBackground(i)
  55. if Type[i] == "Switch" then
  56.     repeat
  57.         event = {os.pullEvent("key")}
  58.     until event[2] == keys.one or event[2] == keys.zero
  59.     if event[2] == keys.one then
  60.         settings.set(SettingsOptions[i],true)
  61.     elseif event[2] == keys.zero then
  62.         settings.set(SettingsOptions[i],false)
  63.     end
  64. elseif Type[i] == "string" then
  65.     local input
  66.     while true do
  67.         local event = {os.pullEvent("key")}
  68.         if event[2] == keys.enter then break end
  69.         input = read()
  70.     end
  71.     settings.set(SettingsOptions[i],input)
  72. end
  73. settings.save(".settings")
  74. Loop()
  75. end
  76.  
  77. function Loop()
  78. DrawBackground()
  79. settings.load(".settings")
  80. local n = CUI(SettingsOptions,4)
  81. if SettingsOptions[n] == "exit" then
  82.     shell.run(settings.get("os_DesktopLoc"))
  83. else
  84.     SettingManager(n)
  85. end
  86. end
  87.  
  88. function CUI(m,y) --declare function
  89. n=1
  90. local l = #m
  91. while true do
  92. term.setCursorPos(1,y)
  93. for i=1, #m, 1 do --traverse the table of options
  94. if i==n and m[i] == "exit" then term.clearLine() print(i," >exit") elseif i==n then term.clearLine() print(i, " >",m[i]," = ",settings.get(SettingsOptions[i])) elseif m[i] == "exit" then term.clearLine() print(i, " exit") else term.clearLine() print(i, " ", m[i], " = ",settings.get(SettingsOptions[i])) end --print them
  95. end
  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. end
  101. return n --return the value
  102. end
  103.  
  104. Clear()
  105. Loop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement