Advertisement
DOGGYWOOF

Doggy OS Desktop

Sep 7th, 2024 (edited)
19
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.99 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 menuOptions = {"Command", "Programs", "Shutdown", "Sign out"}
  7.  
  8. -- Create a window for the taskbar
  9. local taskbar = window.create(term.current(), 1, h, w, 1)
  10. -- Create a window for the start menu
  11. local startMenu = window.create(term.current(), 1, h - 10, 20, 10, false)
  12.  
  13. -- Helper function to draw the taskbar
  14. local function drawTaskbar()
  15. taskbar.setBackgroundColor(colors.green) -- Green taskbar
  16. taskbar.clear()
  17. taskbar.setCursorPos(1, 1)
  18. taskbar.setTextColor(colors.white)
  19. taskbar.write("[ Start ]")
  20. end
  21.  
  22. -- Helper function to draw the start menu
  23. local function drawStartMenu()
  24. if not isStartMenuOpen then
  25. startMenu.setVisible(false)
  26. return
  27. end
  28.  
  29. startMenu.setVisible(true)
  30. startMenu.setBackgroundColor(colors.green) -- Dark green start menu
  31. startMenu.clear()
  32.  
  33. -- Draw the start menu title
  34. startMenu.setTextColor(colors.white)
  35. startMenu.setCursorPos(2, 1)
  36. startMenu.write("=== Start Menu ===")
  37.  
  38. -- Draw the options in the start menu
  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. -- Function to redraw the entire UI
  54. local function redrawUI()
  55. term.setBackgroundColor(colors.blue) -- Blue desktop
  56. term.clear()
  57. drawTaskbar()
  58. drawStartMenu()
  59. end
  60.  
  61. -- Initial UI drawing
  62. redrawUI()
  63.  
  64. -- Function to handle mouse clicks on the taskbar and start menu
  65. local function handleMouseClick(x, y)
  66. if y == h and x >= 1 and x <= 7 then
  67. isStartMenuOpen = not isStartMenuOpen
  68. redrawUI()
  69. elseif isStartMenuOpen and x >= 1 and x <= 20 and y >= h - 10 and y <= h - 1 then
  70. local clickedOption = y - (h - 10) - 1
  71. if clickedOption >= 1 and clickedOption <= #menuOptions then
  72. nOption = clickedOption
  73. return true
  74. end
  75. end
  76. return false
  77. end
  78.  
  79. -- Function to manage running programs
  80. local function runProgram(option)
  81. -- Clear the screen and set to black background with white text before running the selected program
  82. term.setBackgroundColor(colors.black)
  83. term.setTextColor(colors.white)
  84. term.clear()
  85.  
  86. -- Conditions based on the selected option
  87. if option == 1 then
  88. shell.run("/disk/os/home.lua")
  89. elseif option == 2 then
  90. shell.run("/disk/os/programs")
  91. elseif option == 3 then
  92. shell.run("/disk/ACPI/shutdown")
  93. else
  94. shell.run("/disk/ACPI/logoff")
  95. end
  96. end
  97.  
  98. -- Main event handling loop
  99. while true do
  100. local e, p1, p2, p3 = os.pullEvent()
  101.  
  102. if e == "mouse_click" then
  103. local button, x, y = p1, p2, p3
  104. if handleMouseClick(x, y) then
  105. runProgram(nOption)
  106. break
  107. end
  108. elseif e == "key" and isStartMenuOpen then
  109. local key = p1
  110.  
  111. if key == keys.up then -- Up key
  112. if nOption > 1 then
  113. nOption = nOption - 1
  114. else
  115. nOption = #menuOptions
  116. end
  117. redrawUI()
  118. elseif key == keys.down then -- Down key
  119. if nOption < #menuOptions then
  120. nOption = nOption + 1
  121. else
  122. nOption = 1
  123. end
  124. redrawUI()
  125. elseif key == keys.enter then -- Enter key
  126. runProgram(nOption)
  127. break
  128. end
  129. end
  130. end
  131.  
  132. -- Clear the screen and set to black background with white text before running the selected program
  133. term.setBackgroundColor(colors.black)
  134. term.setTextColor(colors.white)
  135. term.clear()
  136.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement