Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local buttons = {
- { name = "Command", x = 2, y = 3, width = 15, height = 1, color = colors.gray, command = "/disk/os/home.lua" },
- { name = "Programs", x = 2, y = 5, width = 15, height = 1, color = colors.gray, command = "/disk/os/programs" },
- { name = "Power Menu", x = 2, y = 7, width = 15, height = 1, color = colors.gray, command = "showPowerMenu" }
- }
- 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 drawPowerMenu()
- term.setBackgroundColor(colors.gray)
- term.setTextColor(colors.white)
- term.setCursorPos(2, 8)
- term.clearLine()
- term.write(" Shut Down ")
- term.setCursorPos(2, 9)
- term.clearLine()
- term.write(" Reboot ")
- term.setCursorPos(2, 10)
- term.clearLine()
- term.write(" Lock ")
- end
- local function drawHomescreen()
- term.setBackgroundColor(colors.black)
- term.clear()
- term.setCursorPos(1, 1)
- term.setBackgroundColor(colors.blue)
- term.setTextColor(colors.white)
- term.write(" Doggy OS 12.0 ")
- term.setBackgroundColor(colors.black)
- for _, button in ipairs(buttons) do
- drawButton(button)
- end
- end
- local function drawNavBar()
- local screenWidth, screenHeight = term.getSize()
- local navBarWidth = 20
- local navBarStart = math.floor((screenWidth - navBarWidth) / 2)
- term.setCursorPos(navBarStart + 4, screenHeight)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.write(" lll ")
- term.setCursorPos(navBarStart + 9, screenHeight)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.write(" () ")
- term.setCursorPos(navBarStart + 14, screenHeight)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.write(" < ")
- return {
- lll = { x = navBarStart + 4, y = screenHeight, width = 4 },
- -- Add coordinates for other nav buttons if needed
- }
- 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
- term.setBackgroundColor(colors.black) -- Reset background color
- return button.command
- end
- end
- return nil
- end
- local function handlePowerMenuClick(x, y)
- if x >= 2 and x <= 16 then
- if (y >= 8 and y <= 10) then
- term.setBackgroundColor(colors.black) -- Reset background color
- if y == 8 then return "shutdown"
- elseif y == 9 then return "reboot"
- elseif y == 10 then return "lock"
- end
- end
- end
- term.setBackgroundColor(colors.black) -- Reset background color
- return nil
- end
- local function launchApp(command)
- term.clear()
- term.setCursorPos(1, 1)
- -- Terminate the program
- os.pullEvent = os.pullEventRaw
- -- Launch the command or show power menu
- if command == "/disk/os/home.lua" or command == "/disk/os/programs" then
- shell.run(command)
- elseif command == "showPowerMenu" then
- drawPowerMenu()
- local event, _, x, y = os.pullEvent("mouse_click")
- local powerMenuCommand = handlePowerMenuClick(x, y)
- if powerMenuCommand then
- if powerMenuCommand == "shutdown" then
- os.shutdown()
- elseif powerMenuCommand == "reboot" then
- os.reboot()
- elseif powerMenuCommand == "lock" then
- shell.run("/disk/os/lock")
- end
- end
- else
- shell.run("start " .. command)
- end
- -- Re-enable the event handling
- os.pullEvent = os.pullEventRaw
- end
- local function homescreen()
- while true do
- drawHomescreen()
- local navBarButtons = drawNavBar() -- Draw the navigation bar and get the button coordinates
- local event, _, x, y = os.pullEvent("mouse_click")
- if event == "mouse_click" then
- local appCommand = handleAppClick(x, y)
- if appCommand then
- launchApp(appCommand)
- return -- Terminate the program after launching the app or showing the power menu
- end
- -- Check for nav bar button clicks
- if x >= navBarButtons.lll.x and x <= (navBarButtons.lll.x + navBarButtons.lll.width - 1) and y == navBarButtons.lll.y then
- launchApp("/disk/os/recents")
- return -- Terminate the program after launching the app
- end
- end
- end
- end
- homescreen()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement