Advertisement
DOGGYWOOF

Untitled

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