Advertisement
DOGGYWOOF

Untitled

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