Marlingaming

MCOS System - Base System - Base Menu

Sep 28th, 2021 (edited)
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.16 KB | None | 0 0
  1. --this is the base menu for my new CC Tweaked OS. this menu only appears when either a crash has happened, actual menu is missing, files corrupted, or a new Boot Update is avaliable
  2.  
  3.  
  4. tArg = {...}
  5. local w,h = term.getSize()
  6. local Reason = tArg[1]
  7. local Page = "Login"
  8. local User = nil
  9. local Password = nil
  10. local Misc1 = nil
  11. local Misc2 = nil
  12.  
  13. function Clear()
  14. term.clear()
  15. term.setCursorPos(1,1)
  16. end
  17.  
  18. function CenterText(y,text)
  19. local x = math.floor((w - string.len(text)) /2)
  20. term.setCursorPos(x,y)
  21. term.clearLine()
  22. term.write(text)
  23. end
  24.  
  25. function SlowCenterText(y,text)
  26. local x = math.floor((w - string.len(text)) /2)
  27. term.setCursorPos(x,y)
  28. term.clearLine()
  29. textutils.slowWrite(text)
  30. end
  31.  
  32. function GetPageData()
  33. if Page == "Login" then
  34. if fs.exists("AccountLogin") == true then
  35. local file = fs.open("AccountLogin","r")
  36. User = file.readLine(1)
  37. Password = file.readLine(2)
  38. file.close()
  39. else
  40. User = "Guest"
  41. Password = nil
  42. end
  43. elseif Page == "Menu" then
  44.  
  45. elseif Page == "Update" then
  46.  
  47. elseif Page == "Security" then
  48.  
  49. end
  50. end
  51.  
  52. function DrawMenu()
  53. Clear()
  54. if Page == "Login" then
  55. term.setBackground(colors.cyan)
  56. CenterText(1,"----BASE-MENU----")
  57. CenterText(2,"Login Menu")
  58. CenterText(3,"PLEASE LOGIN TO MAIN ACCOUNT")
  59. term.setCursorPos(1,5)
  60. term.write("Username")
  61. term.setCursorPos(1,6)
  62. term.write(User)
  63. term.setCursorPos(1,7)
  64. term.write("Password")
  65. elseif Page == "Menu" then
  66. term.setBackground(colors.cyan)
  67. CenterText(1,"---Menu---")
  68. CenterText(4,"1 - Updates")
  69. CenterText(6,"2 - Security")
  70. CenterText(8,"3 - Settings(WIP)")
  71. CenterText(10,"4 - Restart")
  72. elseif Page == "Update" then
  73.  
  74. elseif Page == "Security" then
  75.  
  76. end
  77. end
  78.  
  79. function UserInteraction()
  80. if Page == "Login" then
  81. if User == "Guest" or Password == nil then
  82. term.setCursorPos(1,9)
  83. term.write("Please Press Enter to Continue")
  84. repeat
  85. local event, key = os.pullEvent("key")
  86. until key == keys.enter
  87. Clear()
  88. Page = "Menu"
  89. GetPageData()
  90. DrawMenu()
  91. UserInteraction()
  92. else
  93. local input = read()
  94. term.setCursorPos(1,8)
  95. while true do
  96. local event, key = os.pullEvent("key")
  97. term.write(input)
  98. if key == keys.enter then
  99. break
  100. end
  101. end
  102. if input == Password then
  103. Page = "Menu"
  104. Clear()
  105. GetPageData()
  106. DrawMenu()
  107. UserInteraction()
  108. else
  109. Clear()
  110. GetPageData()
  111. DrawMenu()
  112. UserInteraction()
  113. end
  114. end
  115. elseif Page == "Menu" then
  116. while true do
  117. local event, key = os.pullEvent("key")
  118. if key == keys.one then
  119. Page = "Update"
  120. break
  121. elseif key == keys.two then
  122. Page = "Security"
  123. break
  124. elseif key == keys.three then
  125. Page = "Settings"
  126. break
  127. elseif key == keys.four then
  128. Page = "Reboot"
  129. break
  130. end
  131. end
  132. if Page == "Reboot" then
  133. os.reboot()
  134. else
  135. Clear()
  136. GetPageData()
  137. DrawMenu()
  138. UserInteraction()
  139. end
  140. elseif Page == "Update" then
  141.  
  142. elseif Page == "Security" then
  143.  
  144. end
  145. end
  146.  
  147. Clear()
  148. GetPageData()
  149. DrawMenu()
  150. UserInteraction()
Add Comment
Please, Sign In to add comment