DOGGYWOOF

Untitled

Mar 10th, 2024 (edited)
18
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.60 KB | None | 0 0
  1. local buttons = {
  2. { name = "Command", x = 2, y = 3, width = 15, height = 1, color = colors.gray, command = "/disk/os/home.lua" },
  3. { name = "Programs", x = 2, y = 5, width = 15, height = 1, color = colors.gray, command = "/disk/os/programs" },
  4. { name = "Power Menu", x = 2, y = 7, width = 15, height = 1, color = colors.gray, command = "showPowerMenu" }
  5. }
  6.  
  7. local function drawButton(button)
  8. term.setBackgroundColor(button.color)
  9. term.setTextColor(colors.white)
  10. term.setCursorPos(button.x, button.y)
  11. term.clearLine()
  12. term.write(" " .. button.name .. " ")
  13. end
  14.  
  15. local function drawPowerMenu()
  16. term.setBackgroundColor(colors.gray)
  17. term.setTextColor(colors.white)
  18. term.setCursorPos(2, 8)
  19. term.clearLine()
  20. term.write(" Shut Down ")
  21.  
  22. term.setCursorPos(2, 9)
  23. term.clearLine()
  24. term.write(" Reboot ")
  25.  
  26. term.setCursorPos(2, 10)
  27. term.clearLine()
  28. term.write(" Lock ")
  29. end
  30.  
  31. local function drawHomescreen()
  32. term.setBackgroundColor(colors.black)
  33. term.clear()
  34.  
  35. term.setCursorPos(1, 1)
  36. term.setBackgroundColor(colors.blue)
  37. term.setTextColor(colors.white)
  38. term.write(" Doggy OS 12.0 ")
  39. term.setBackgroundColor(colors.black)
  40.  
  41. for _, button in ipairs(buttons) do
  42. drawButton(button)
  43. end
  44. end
  45.  
  46. local function handleAppClick(x, y)
  47. for _, button in ipairs(buttons) do
  48. if x >= button.x and x <= (button.x + button.width - 1) and y == button.y then
  49. term.setBackgroundColor(colors.black) -- Reset background color
  50. return button.command
  51. end
  52. end
  53. return nil
  54. end
  55.  
  56. local function handlePowerMenuClick(x, y)
  57. if x >= 2 and x <= 16 then
  58. if y == 8 then
  59. term.setBackgroundColor(colors.black) -- Reset background color
  60. return "shutdown"
  61. elseif y == 9 then
  62. term.setBackgroundColor(colors.black) -- Reset background color
  63. return "reboot"
  64. elseif y == 10 then
  65. term.setBackgroundColor(colors.black) -- Reset background color
  66. return "lock"
  67. end
  68. end
  69. term.setBackgroundColor(colors.black) -- Reset background color
  70. return nil
  71. end
  72.  
  73. local function launchApp(command)
  74. term.clear()
  75. term.setCursorPos(1, 1)
  76.  
  77. -- Terminate the program
  78. os.pullEvent = os.pullEventRaw
  79.  
  80. -- Launch the command or show power menu
  81. if command == "/disk/os/home.lua" or command == "/disk/os/programs" then
  82. shell.run(command)
  83. elseif command == "showPowerMenu" then
  84. drawPowerMenu()
  85. local event, _, x, y = os.pullEvent("mouse_click")
  86.  
  87. local powerMenuCommand = handlePowerMenuClick(x, y)
  88. if powerMenuCommand then
  89. if powerMenuCommand == "shutdown" then
  90. os.shutdown()
  91. elseif powerMenuCommand == "reboot" then
  92. os.reboot()
  93. elseif powerMenuCommand == "lock" then
  94. shell.run("/disk/os/lock")
  95. end
  96. end
  97. else
  98. shell.run("start " .. command)
  99. end
  100.  
  101. -- Re-enable the event handling
  102. os.pullEvent = os.pullEventRaw
  103. end
  104.  
  105. local function homescreen()
  106. while true do
  107. drawHomescreen()
  108. local event, _, x, y = os.pullEvent("mouse_click")
  109.  
  110. if event == "mouse_click" then
  111. local appCommand = handleAppClick(x, y)
  112. if appCommand then
  113. launchApp(appCommand)
  114. return -- Terminate the program after launching the app or showing power menu
  115. end
  116. end
  117. end
  118. end
  119.  
  120. homescreen()
  121.  
Add Comment
Please, Sign In to add comment