Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local buttons = {
- { name = "Calculator", x = 2, y = 3, width = 15, height = 1, color = colors.lightBlue, command = "calc.lua" },
- { name = "Notes", x = 2, y = 5, width = 15, height = 1, color = colors.orange, command = "notes.lua" },
- { name = "Settings", x = 2, y = 7, width = 15, height = 1, color = colors.green, command = "settings.lua" },
- { name = "Power Menu", x = 2, y = 9, width = 15, height = 1, color = colors.magenta, command = "powerMenu" },
- { name = "File Manager", x = 2, y = 11, width = 15, height = 1, color = colors.yellow, command = "files.lua" }
- }
- local function drawButton(button)
- term.setBackgroundColor(button.color)
- term.setTextColor(colors.white)
- term.setCursorPos(button.x, button.y)
- term.clearLine()
- term.write(" " .. button.name .. " ")
- end
- local function drawHomescreen()
- term.setBackgroundColor(colors.black)
- term.clear()
- term.setCursorPos(1, 1)
- term.setBackgroundColor(colors.blue)
- term.setTextColor(colors.white)
- term.write(" My Minecraft Device ")
- term.setBackgroundColor(colors.black)
- for _, button in ipairs(buttons) do
- drawButton(button)
- end
- end
- local function handleAppClick(x, y)
- for _, button in ipairs(buttons) do
- if x >= button.x and x <= (button.x + button.width - 1) and y == button.y then
- return button.command
- end
- end
- return nil
- end
- local function launchApp(command)
- term.clear()
- term.setCursorPos(1, 1)
- print("Launching " .. command .. "...")
- sleep(2)
- term.clear()
- term.setCursorPos(1, 1)
- if command == "powerMenu" then
- -- Add your power menu functionality here
- print("Power menu clicked. Add power menu functionality.")
- sleep(2)
- else
- shell.run(command) -- Executes the command associated with the app
- end
- sleep(3)
- end
- local function homescreen()
- while true do
- drawHomescreen()
- local event, _, x, y = os.pullEvent("mouse_click")
- if event == "mouse_click" then
- local appCommand = handleAppClick(x, y)
- if appCommand then
- launchApp(appCommand)
- end
- end
- end
- end
- homescreen()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement