Advertisement
DOGGYWOOF

DKSTOP

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