Advertisement
DOGGYWOOF

touch based homescreen

Jan 8th, 2024 (edited)
12
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 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. -- Add your power menu functionality here
  50. print("Power menu clicked. Add power menu functionality.")
  51. sleep(2)
  52. else
  53. shell.run(command) -- Executes the command associated with the app
  54. end
  55. sleep(3)
  56. end
  57.  
  58. local function homescreen()
  59. while true do
  60. drawHomescreen()
  61. local event, _, x, y = os.pullEvent("mouse_click")
  62.  
  63. if event == "mouse_click" then
  64. local appCommand = handleAppClick(x, y)
  65. if appCommand then
  66. launchApp(appCommand)
  67. end
  68. end
  69. end
  70. end
  71.  
  72. homescreen()
  73.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement