Advertisement
DOGGYWOOF

Untitled

Jul 18th, 2024 (edited)
11
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.96 KB | None | 0 0
  1. os.pullEvent = os.pullEventRaw
  2.  
  3. local buttons = {
  4. { name = "Command", x = 2, y = 3, width = 15, height = 1, color = colors.gray, command = "/disk/os/home.lua" },
  5. { name = "Programs", x = 2, y = 5, width = 15, height = 1, color = colors.gray, command = "/disk/os/programs" },
  6. { name = "Power Menu", x = 2, y = 7, width = 15, height = 1, color = colors.gray, command = "showPowerMenu" }
  7. }
  8.  
  9. local function drawButton(button)
  10. term.setBackgroundColor(button.color)
  11. term.setTextColor(colors.white)
  12. term.setCursorPos(button.x, button.y)
  13. term.clearLine()
  14. term.write(" " .. button.name .. " ")
  15. end
  16.  
  17. local function drawPowerMenu()
  18. term.setBackgroundColor(colors.gray)
  19. term.setTextColor(colors.white)
  20. term.setCursorPos(2, 8)
  21. term.clearLine()
  22. term.write(" Shut Down ")
  23.  
  24. term.setCursorPos(2, 9)
  25. term.clearLine()
  26. term.write(" Reboot ")
  27.  
  28. term.setCursorPos(2, 10)
  29. term.clearLine()
  30. term.write(" Lock ")
  31. end
  32.  
  33. local function drawHomescreen()
  34. term.setBackgroundColor(colors.black)
  35. term.clear()
  36.  
  37. term.setCursorPos(1, 1)
  38. term.setBackgroundColor(colors.blue)
  39. term.setTextColor(colors.white)
  40. term.write(" Doggy OS 12.0 ")
  41. term.setBackgroundColor(colors.black)
  42.  
  43. for _, button in ipairs(buttons) do
  44. drawButton(button)
  45. end
  46. end
  47.  
  48. local function drawNavBar()
  49. local screenWidth, screenHeight = term.getSize()
  50. local navBarWidth = 20
  51. local navBarStart = math.floor((screenWidth - navBarWidth) / 2)
  52.  
  53. term.setCursorPos(navBarStart + 4, screenHeight)
  54. term.setBackgroundColor(colors.black)
  55. term.setTextColor(colors.white)
  56. term.write(" lll ")
  57.  
  58. term.setCursorPos(navBarStart + 9, screenHeight)
  59. term.setBackgroundColor(colors.black)
  60. term.setTextColor(colors.white)
  61. term.write(" () ")
  62.  
  63. term.setCursorPos(navBarStart + 14, screenHeight)
  64. term.setBackgroundColor(colors.black)
  65. term.setTextColor(colors.white)
  66. term.write(" < ")
  67. end
  68.  
  69. local function isClickOnButton(x, y)
  70. for _, button in ipairs(buttons) do
  71. if x >= button.x and x < button.x + button.width and y == button.y then
  72. return button.command
  73. end
  74. end
  75. return nil
  76. end
  77.  
  78. local function isClickOnPowerMenu(x, y)
  79. if x >= 2 and x <= 16 then
  80. if y == 8 then
  81. return "shutdown"
  82. elseif y == 9 then
  83. return "reboot"
  84. elseif y == 10 then
  85. return "lock"
  86. end
  87. end
  88. return nil
  89. end
  90.  
  91. local function launchApp(command)
  92. term.clear()
  93. term.setCursorPos(1, 1)
  94.  
  95. if command == "/disk/os/home.lua" or command == "/disk/os/programs" then
  96. shell.run(command)
  97. elseif command == "showPowerMenu" then
  98. drawPowerMenu()
  99. drawNavBar() -- Ensure navbar is redrawn
  100. local event, _, x, y = os.pullEvent("mouse_click")
  101.  
  102. local powerMenuCommand = isClickOnPowerMenu(x, y)
  103. if powerMenuCommand then
  104. if powerMenuCommand == "shutdown" then
  105. os.shutdown()
  106. elseif powerMenuCommand == "reboot" then
  107. os.reboot()
  108. elseif powerMenuCommand == "lock" then
  109. shell.run("/disk/os/lock")
  110. end
  111. end
  112. else
  113. shell.run("start " .. command)
  114. end
  115.  
  116. -- Redraw navbar after app exits
  117. drawNavBar()
  118. end
  119.  
  120. local function homescreen()
  121. while true do
  122. drawHomescreen()
  123. drawNavBar() -- Draw the navigation bar
  124. local event, _, x, y = os.pullEvent("mouse_click")
  125.  
  126. if event == "mouse_click" then
  127. local command = isClickOnButton(x, y)
  128. if command then
  129. launchApp(command)
  130. end
  131. end
  132. end
  133. end
  134.  
  135. -- Redraw the navbar at regular intervals
  136. local function keepNavBarVisible()
  137. while true do
  138. drawNavBar()
  139. sleep(1)
  140. end
  141. end
  142.  
  143. parallel.waitForAny(homescreen, keepNavBarVisible)
  144.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement