Advertisement
DOGGYWOOF

Untitled

Jan 7th, 2025 (edited)
14
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.50 KB | None | 0 0
  1. os.pullEvent = os.pullEventRaw
  2.  
  3. local w, h = term.getSize()
  4. local nOption = 1
  5. local isStartMenuOpen = false
  6. local isPowerMenuOpen = false
  7. local menuOptions = {"Command", "Programs", "Power Menu"}
  8. local powerOptions = {"Shutdown", "Reboot", "Sign Out", "Cancel"}
  9.  
  10. -- Get the current user
  11. local function getCurrentUser()
  12. local file = fs.open("/disk/config/currentusr", "r")
  13. if file then
  14. local username = file.readLine()
  15. file.close()
  16. return username
  17. end
  18. return nil
  19. end
  20.  
  21. -- Check if the user is an admin
  22. local function isAdminUser(username)
  23. return fs.exists("/disk/users/" .. username .. "/admin.txt")
  24. end
  25.  
  26. -- Check if shell access is blocked for non-admin users
  27. local function isShellAccessBlocked()
  28. return fs.exists("/disk/config/security/BlockShellForNonAdminUsers.cfg")
  29. end
  30.  
  31. -- Create windows for taskbar, start menu, and power menu
  32. local taskbar = window.create(term.current(), 1, h, w, 1)
  33. local startMenu = window.create(term.current(), 1, h - 10, 20, 10, false)
  34. local powerMenu = window.create(term.current(), math.floor(w / 2) - 12, math.floor(h / 2) - 7, 24, 15, false)
  35.  
  36. -- Helper function to draw the taskbar
  37. local function drawTaskbar()
  38. taskbar.setBackgroundColor(colors.green)
  39. taskbar.clear()
  40. taskbar.setCursorPos(1, 1)
  41. taskbar.setTextColor(colors.white)
  42. taskbar.write("[ Start ]")
  43. end
  44.  
  45. -- Helper function to draw the start menu
  46. local function drawStartMenu()
  47. if not isStartMenuOpen then
  48. startMenu.setVisible(false)
  49. return
  50. end
  51.  
  52. startMenu.setVisible(true)
  53. startMenu.setBackgroundColor(colors.green)
  54. startMenu.clear()
  55.  
  56. startMenu.setTextColor(colors.white)
  57. startMenu.setCursorPos(2, 1)
  58. startMenu.write("=== Start Menu ===")
  59.  
  60. for i, option in ipairs(menuOptions) do
  61. startMenu.setCursorPos(2, 2 + i)
  62. if nOption == i then
  63. startMenu.setTextColor(colors.black)
  64. startMenu.setBackgroundColor(colors.white)
  65. startMenu.write("[ " .. option .. " ]")
  66. startMenu.setBackgroundColor(colors.green)
  67. startMenu.setTextColor(colors.white)
  68. else
  69. startMenu.write("[ " .. option .. " ]")
  70. end
  71. end
  72. end
  73.  
  74. -- Helper function to draw the power menu
  75. local function drawPowerMenu()
  76. if not isPowerMenuOpen then
  77. powerMenu.setVisible(false)
  78. return
  79. end
  80.  
  81. powerMenu.setVisible(true)
  82. powerMenu.setBackgroundColor(colors.black)
  83. powerMenu.clear()
  84.  
  85. powerMenu.setTextColor(colors.white)
  86. powerMenu.setCursorPos(2, 1)
  87. powerMenu.write("=== Power Menu ===")
  88.  
  89. for i, option in ipairs(powerOptions) do
  90. powerMenu.setCursorPos(2, 3 + i)
  91. if nOption == i then
  92. powerMenu.setTextColor(colors.black)
  93. powerMenu.setBackgroundColor(colors.white)
  94. powerMenu.write("[ " .. option .. " ]")
  95. powerMenu.setBackgroundColor(colors.black)
  96. powerMenu.setTextColor(colors.white)
  97. else
  98. powerMenu.write("[ " .. option .. " ]")
  99. end
  100. end
  101. end
  102.  
  103. -- Helper function to draw ASCII art in the center
  104. local function drawASCIIArt()
  105. local art = {
  106. " |\\_/| ",
  107. " | @ @ Woof! ",
  108. " | <> _ ",
  109. " | _/\\------____ ((| |))",
  110. " | `--' | ",
  111. " ____|_ ___| |___.' ",
  112. "/_/_____/____/_______| "
  113. }
  114. local startX = math.floor((w - 26) / 2) -- Centering the art horizontally
  115. local startY = math.floor((h - #art) / 2) -- Centering the art vertically
  116.  
  117. term.setTextColor(colors.white)
  118. for i, line in ipairs(art) do
  119. term.setCursorPos(startX, startY + i - 1)
  120. term.write(line)
  121. end
  122. end
  123.  
  124. -- Function to redraw the entire UI
  125. local function redrawUI()
  126. term.setBackgroundColor(colors.blue)
  127. term.clear()
  128. drawTaskbar()
  129. drawASCIIArt() -- Draw ASCII art
  130. if isPowerMenuOpen then
  131. drawPowerMenu()
  132. else
  133. drawStartMenu()
  134. end
  135. end
  136.  
  137. -- Initial UI drawing
  138. redrawUI()
  139.  
  140. -- Function to handle mouse clicks
  141. local function handleMouseClick(x, y)
  142. if y == h and x >= 1 and x <= 7 then
  143. isStartMenuOpen = not isStartMenuOpen
  144. isPowerMenuOpen = false
  145. redrawUI()
  146. elseif isStartMenuOpen and x >= 1 and x <= 20 and y >= h - 10 and y <= h - 1 then
  147. local clickedOption = y - (h - 10) - 1
  148. if clickedOption >= 1 and clickedOption <= #menuOptions then
  149. nOption = clickedOption
  150. if nOption == 3 then
  151. isStartMenuOpen = false
  152. isPowerMenuOpen = true
  153. redrawUI()
  154. else
  155. return true
  156. end
  157. end
  158. end
  159. return false
  160. end
  161.  
  162. -- Function to manage running programs and power options
  163. local function runProgramOrAction(option)
  164. if isPowerMenuOpen then
  165. if option == 1 then
  166. shell.run("/disk/ACPI/shutdown") -- Shutdown
  167. elseif option == 2 then
  168. shell.run("/disk/ACPI/reboot") -- Reboot
  169. elseif option == 3 then
  170. shell.run("/disk/ACPI/logoff") -- Sign Out
  171. elseif option == 4 then
  172. shell.run("/disk/os/gui") -- Run GUI when Cancel is selected
  173. return true
  174. end
  175. return true -- Indicate an action was taken
  176. end
  177.  
  178. if option == 1 then
  179. local username = getCurrentUser()
  180. if isShellAccessBlocked() and username and not isAdminUser(username) then
  181. term.setBackgroundColor(colors.red)
  182. term.setTextColor(colors.white)
  183. term.clear()
  184. term.setCursorPos(1, 1)
  185. term.write("Access Denied: Non-admin users cannot access the Command app.")
  186. sleep(3)
  187. redrawUI()
  188. return false
  189. end
  190. shell.run("/disk/os/home.lua")
  191. elseif option == 2 then
  192. shell.run("/disk/os/programs")
  193. end
  194.  
  195. return false -- Indicate no action was taken
  196. end
  197.  
  198. -- Main event handling loop
  199. while true do
  200. local e, p1, p2, p3 = os.pullEvent()
  201.  
  202. if e == "mouse_click" then
  203. local button, x, y = p1, p2, p3
  204. if handleMouseClick(x, y) then
  205. runProgramOrAction(nOption) -- Execute action
  206. end
  207. elseif e == "key" and (isStartMenuOpen or isPowerMenuOpen) then
  208. local key = p1
  209.  
  210. if key == keys.up then
  211. if nOption > 1 then
  212. nOption = nOption - 1
  213. else
  214. nOption = #menuOptions
  215. end
  216. redrawUI()
  217. elseif key == keys.down then
  218. if isPowerMenuOpen then
  219. if nOption < #powerOptions then
  220. nOption = nOption + 1
  221. else
  222. nOption = 1 -- Wrap around to "Shutdown"
  223. end
  224. else
  225. if nOption < #menuOptions then
  226. nOption = nOption + 1
  227. else
  228. nOption = 1
  229. end
  230. end
  231. redrawUI()
  232. elseif key == keys.enter then
  233. if runProgramOrAction(nOption) then
  234. -- Do nothing, action taken
  235. else
  236. break -- Exit loop only if no action taken
  237. end
  238. end
  239. end
  240. end
  241.  
  242. -- Final screen settings before running the selected action
  243. term.setBackgroundColor(colors.black)
  244. term.setTextColor(colors.white)
  245. term.clear()
  246.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement