Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- desktop.lua
- -- Initialize the desktop environment
- local termWidth, termHeight = term.getSize()
- local startMenuVisible = false
- local powerOptionsVisible = false
- -- Draw the desktop background
- local function drawBackground()
- term.setBackgroundColor(colors.blue)
- term.clear()
- end
- -- Draw the taskbar
- local function drawTaskbar()
- term.setBackgroundColor(colors.green)
- term.setTextColor(colors.white)
- term.setCursorPos(1, termHeight)
- term.write(string.rep(" ", termWidth))
- term.setCursorPos(1, termHeight)
- term.write(" Start ")
- end
- -- Draw the start menu
- local function drawStartMenu()
- local menuWidth, menuHeight = 20, 10
- term.setBackgroundColor(colors.gray)
- term.setTextColor(colors.white)
- for i = 1, menuHeight do
- term.setCursorPos(1, termHeight - menuHeight + i - 1)
- term.write(string.rep(" ", menuWidth))
- end
- -- Add start menu options
- term.setCursorPos(2, termHeight - menuHeight + 1)
- term.write("Command")
- term.setCursorPos(2, termHeight - menuHeight + 2)
- term.write("Programs")
- term.setCursorPos(2, termHeight - menuHeight + 3)
- term.write("Power Options")
- term.setCursorPos(2, termHeight - menuHeight + 4)
- term.write("Lock")
- end
- -- Draw the power options menu
- local function drawPowerOptions()
- local menuWidth, menuHeight = 20, 4
- term.setBackgroundColor(colors.gray)
- term.setTextColor(colors.white)
- for i = 1, menuHeight do
- term.setCursorPos(1, termHeight - menuHeight + i - 1)
- term.write(string.rep(" ", menuWidth))
- end
- -- Add power options
- term.setCursorPos(2, termHeight - menuHeight + 1)
- term.write("Shutdown")
- term.setCursorPos(2, termHeight - menuHeight + 2)
- term.write("Reboot")
- end
- -- Execute command based on the selected option
- local function executeCommand(option)
- if option == 1 then
- shell.run("/disk/os/home")
- elseif option == 2 then
- shell.run("/disk/os/programs")
- elseif option == 3 then
- powerOptionsVisible = true
- redraw()
- elseif option == 4 then
- shell.run("/disk/ACPI/logoff")
- end
- end
- -- Handle power option selection
- local function handlePowerOptionsSelection(y)
- local option = y - (termHeight - 4) + 1
- if option == 1 then
- os.shutdown()
- elseif option == 2 then
- os.reboot()
- end
- end
- -- Redraw the entire desktop
- local function redraw()
- drawBackground()
- drawTaskbar()
- if startMenuVisible then
- drawStartMenu()
- if powerOptionsVisible then
- drawPowerOptions()
- end
- end
- end
- -- Main event loop
- local function eventLoop()
- while true do
- redraw()
- local event, button, x, y = os.pullEvent("mouse_click")
- -- Handle taskbar interaction (toggle Start menu)
- if y == termHeight and x <= 7 then
- startMenuVisible = not startMenuVisible
- if not startMenuVisible then
- powerOptionsVisible = false
- end
- elseif startMenuVisible then
- if powerOptionsVisible then
- -- Handle power options menu interactions
- if y >= termHeight - 4 and y < termHeight then
- handlePowerOptionsSelection(y)
- powerOptionsVisible = false
- startMenuVisible = false
- end
- else
- -- Handle start menu interactions
- if y >= termHeight - 10 and y < termHeight then
- local selectedOption = y - (termHeight - 10) + 1
- executeCommand(selectedOption)
- startMenuVisible = false
- powerOptionsVisible = false
- end
- end
- end
- end
- end
- -- Initialize desktop
- redraw()
- -- Start the event loop
- eventLoop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement