Advertisement
DOGGYWOOF

touch screen home w power menu

Jan 8th, 2024
7
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.72 KB | None | 0 0
  1. local buttons = {
  2. { name = "Calculator", x = 2, y = 3, width = 15, height = 1, color = colors.lightBlue, command = "calc.lua" },
  3. { name = "Notes", x = 2, y = 5, width = 15, height = 1, color = colors.orange, command = "notes.lua" },
  4. { name = "Settings", x = 2, y = 7, width = 15, height = 1, color = colors.green, command = "settings.lua" },
  5. { name = "Power Menu", x = 2, y = 9, width = 15, height = 1, color = colors.magenta, command = "powerMenu" },
  6. { name = "File Manager", x = 2, y = 11, width = 15, height = 1, color = colors.yellow, command = "files.lua" }
  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 drawHomescreen()
  18. term.setBackgroundColor(colors.black)
  19. term.clear()
  20.  
  21. term.setCursorPos(1, 1)
  22. term.setBackgroundColor(colors.blue)
  23. term.setTextColor(colors.white)
  24. term.write(" My Minecraft Device ")
  25. term.setBackgroundColor(colors.black)
  26.  
  27. for _, button in ipairs(buttons) do
  28. drawButton(button)
  29. end
  30. end
  31.  
  32. local function handleAppClick(x, y)
  33. for _, button in ipairs(buttons) do
  34. if x >= button.x and x <= (button.x + button.width - 1) and y == button.y then
  35. return button.command
  36. end
  37. end
  38. return nil
  39. end
  40.  
  41. local function launchApp(command)
  42. term.clear()
  43. term.setCursorPos(1, 1)
  44. print("Launching " .. command .. "...")
  45. sleep(2)
  46. term.clear()
  47. term.setCursorPos(1, 1)
  48. if command == "powerMenu" then
  49. return "powerMenu"
  50. else
  51. shell.run(command) -- Executes the command associated with the app
  52. end
  53. sleep(3)
  54. end
  55.  
  56. local function powerMenu()
  57. term.clear()
  58. term.setCursorPos(1, 1)
  59. print("------ Power Menu ------")
  60. print("1. Reboot")
  61. print("2. Lock")
  62. print("3. Shutdown")
  63. local choice = read("Select an option: ")
  64. if choice == "1" then
  65. os.reboot()
  66. elseif choice == "2" then
  67. -- Add lock functionality
  68. print("Locking...")
  69. sleep(2)
  70. elseif choice == "3" then
  71. os.shutdown()
  72. else
  73. print("Invalid choice.")
  74. sleep(2)
  75. end
  76. end
  77.  
  78. local function homescreen()
  79. while true do
  80. drawHomescreen()
  81. local event, _, x, y = os.pullEvent("mouse_click")
  82.  
  83. if event == "mouse_click" then
  84. local appCommand = handleAppClick(x, y)
  85. if appCommand == "powerMenu" then
  86. powerMenu()
  87. elseif appCommand then
  88. launchApp(appCommand)
  89. end
  90. end
  91. end
  92. end
  93.  
  94. homescreen()
  95.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement