Advertisement
DOGGYWOOF

Untitled

Sep 7th, 2024 (edited)
11
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.53 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 - 8, 20, 8, false)
  12.  
  13. -- Helper function to draw the taskbar
  14. local function drawTaskbar()
  15. taskbar.setBackgroundColor(colors.gray)
  16. taskbar.clear()
  17. taskbar.setCursorPos(1, 1)
  18. taskbar.setTextColor(colors.white)
  19. taskbar.write("[ Start ]")
  20. taskbar.setCursorPos(10, 1)
  21. taskbar.write(string.rep("-", w - 10)) -- Rest of the taskbar
  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.lightGray)
  33. startMenu.clear()
  34.  
  35. -- Draw the start menu title
  36. startMenu.setTextColor(colors.white)
  37. startMenu.setCursorPos(2, 1)
  38. startMenu.write("=== Start Menu ===")
  39.  
  40. -- Draw the options in the start menu
  41. for i, option in ipairs(menuOptions) do
  42. startMenu.setCursorPos(2, 2 + i)
  43. if nOption == i then
  44. startMenu.setTextColor(colors.black)
  45. startMenu.setBackgroundColor(colors.white)
  46. startMenu.write("[ " .. option .. " ]")
  47. startMenu.setBackgroundColor(colors.lightGray)
  48. startMenu.setTextColor(colors.white)
  49. else
  50. startMenu.write(" " .. option .. " ")
  51. end
  52. end
  53. end
  54.  
  55. -- Function to redraw the entire UI
  56. local function redrawUI()
  57. term.setBackgroundColor(colors.black)
  58. term.clear()
  59. drawTaskbar()
  60. drawStartMenu()
  61. end
  62.  
  63. -- Initial UI drawing
  64. redrawUI()
  65.  
  66. -- Function to handle mouse clicks on the taskbar and start menu
  67. local function handleMouseClick(x, y)
  68. if y == h and x >= 1 and x <= 7 then
  69. isStartMenuOpen = not isStartMenuOpen
  70. redrawUI()
  71. elseif isStartMenuOpen and x >= 1 and x <= 20 and y >= h - 8 and y <= h - 1 then
  72. local clickedOption = y - (h - 8) - 1
  73. if clickedOption >= 1 and clickedOption <= #menuOptions then
  74. nOption = clickedOption
  75. return true
  76. end
  77. end
  78. return false
  79. end
  80.  
  81. -- Main event handling loop
  82. while true do
  83. local e, p1, p2, p3 = os.pullEvent()
  84.  
  85. if e == "mouse_click" then
  86. local button, x, y = p1, p2, p3
  87. if handleMouseClick(x, y) then
  88. break
  89. end
  90. elseif e == "key" and isStartMenuOpen then
  91. local key = p1
  92.  
  93. if key == keys.up then -- Up key
  94. if nOption > 1 then
  95. nOption = nOption - 1
  96. else
  97. nOption = #menuOptions
  98. end
  99. redrawUI()
  100. elseif key == keys.down then -- Down key
  101. if nOption < #menuOptions then
  102. nOption = nOption + 1
  103. else
  104. nOption = 1
  105. end
  106. redrawUI()
  107. elseif key == keys.enter then -- Enter key
  108. break
  109. end
  110. end
  111. end
  112.  
  113. term.clear()
  114.  
  115. -- Conditions based on the selected option
  116. if nOption == 1 then
  117. shell.run("/disk/os/home.lua")
  118. elseif nOption == 2 then
  119. term.clear()
  120. term.setCursorPos(1, 1)
  121. shell.run("/disk/os/programs")
  122. elseif nOption == 3 then
  123. shell.run("/disk/ACPI/shutdown")
  124. else
  125. shell.run("/disk/ACPI/logoff")
  126. end
  127.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement