Advertisement
DOGGYWOOF

Untitled

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