Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.pullEvent = os.pullEventRaw
- local w, h = term.getSize()
- local nOption = 1
- local isStartMenuOpen = false
- local menuOptions = {"Command", "Programs", "Shutdown", "Sign out"}
- -- Create a window for the taskbar
- local taskbar = window.create(term.current(), 1, h, w, 1)
- -- Create a window for the start menu
- local startMenu = window.create(term.current(), 1, h - 8, 20, 8, false)
- -- Helper function to draw the taskbar
- local function drawTaskbar()
- taskbar.setBackgroundColor(colors.gray)
- taskbar.clear()
- taskbar.setCursorPos(1, 1)
- taskbar.setTextColor(colors.white)
- taskbar.write("[ Start ]")
- taskbar.setCursorPos(10, 1)
- taskbar.write(string.rep("-", w - 10)) -- Rest of the taskbar
- end
- -- Helper function to draw the start menu
- local function drawStartMenu()
- if not isStartMenuOpen then
- startMenu.setVisible(false)
- return
- end
- startMenu.setVisible(true)
- startMenu.setBackgroundColor(colors.lightGray)
- startMenu.clear()
- -- Draw the start menu title
- startMenu.setTextColor(colors.white)
- startMenu.setCursorPos(2, 1)
- startMenu.write("=== Start Menu ===")
- -- Draw the options in the start menu
- for i, option in ipairs(menuOptions) do
- startMenu.setCursorPos(2, 2 + i)
- if nOption == i then
- startMenu.setTextColor(colors.black)
- startMenu.setBackgroundColor(colors.white)
- startMenu.write("[ " .. option .. " ]")
- startMenu.setBackgroundColor(colors.lightGray)
- startMenu.setTextColor(colors.white)
- else
- startMenu.write(" " .. option .. " ")
- end
- end
- end
- -- Function to redraw the entire UI
- local function redrawUI()
- term.setBackgroundColor(colors.black)
- term.clear()
- drawTaskbar()
- drawStartMenu()
- end
- -- Initial UI drawing
- redrawUI()
- -- Function to handle mouse clicks on the taskbar and start menu
- local function handleMouseClick(x, y)
- if y == h and x >= 1 and x <= 7 then
- isStartMenuOpen = not isStartMenuOpen
- redrawUI()
- elseif isStartMenuOpen and x >= 1 and x <= 20 and y >= h - 8 and y <= h - 1 then
- local clickedOption = y - (h - 8) - 1
- if clickedOption >= 1 and clickedOption <= #menuOptions then
- nOption = clickedOption
- return true
- end
- end
- return false
- end
- -- Main event handling loop
- while true do
- local e, p1, p2, p3 = os.pullEvent()
- if e == "mouse_click" then
- local button, x, y = p1, p2, p3
- if handleMouseClick(x, y) then
- break
- end
- elseif e == "key" and isStartMenuOpen then
- local key = p1
- if key == keys.up then -- Up key
- if nOption > 1 then
- nOption = nOption - 1
- else
- nOption = #menuOptions
- end
- redrawUI()
- elseif key == keys.down then -- Down key
- if nOption < #menuOptions then
- nOption = nOption + 1
- else
- nOption = 1
- end
- redrawUI()
- elseif key == keys.enter then -- Enter key
- break
- end
- end
- end
- term.clear()
- -- Conditions based on the selected option
- if nOption == 1 then
- shell.run("/disk/os/home.lua")
- elseif nOption == 2 then
- term.clear()
- term.setCursorPos(1, 1)
- shell.run("/disk/os/programs")
- elseif nOption == 3 then
- shell.run("/disk/ACPI/shutdown")
- else
- shell.run("/disk/ACPI/logoff")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement