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", "Power Menu"}
- local powerOptions = {"Shutdown", "Reboot", "Cancel"}
- -- Create windows for taskbar, start menu, and power menu
- local taskbar = window.create(term.current(), 1, h, w, 1)
- local startMenu = window.create(term.current(), 1, h - 10, 20, 10, false)
- -- Function to display the security error popup
- local function showSecurityError()
- local popupWidth = 30
- local popupHeight = 7
- local popupX = math.floor((w - popupWidth) / 2)
- local popupY = math.floor((h - popupHeight) / 2)
- local popup = window.create(term.current(), popupX, popupY, popupWidth, popupHeight)
- popup.setBackgroundColor(colors.gray)
- popup.clear()
- popup.setTextColor(colors.white)
- popup.setCursorPos(2, 1)
- popup.write("=== Security Alert ===")
- popup.setCursorPos(2, 3)
- popup.write("Security Card Removed!!!")
- popup.setCursorPos(2, 5)
- popup.write("Press any key to lock...")
- popup.setVisible(true)
- os.pullEvent("key") -- Wait for any key press
- shell.run("/disk/os/lock.lua")
- end
- -- Function to check for the security card
- local function checkSecurityCard()
- if not fs.exists("/disk2/card.lua") then
- showSecurityError()
- return false
- end
- return true
- end
- -- Helper function to draw the taskbar with the current time
- local function drawTaskbar()
- taskbar.setBackgroundColor(colors.green)
- taskbar.clear()
- taskbar.setCursorPos(1, 1)
- taskbar.setTextColor(colors.white)
- taskbar.write("[ Start ]")
- -- Display the current time on the right side
- local currentTime = os.date("%H:%M:%S")
- local timeX = w - string.len(currentTime) - 1
- taskbar.setCursorPos(timeX, 1)
- taskbar.write(currentTime)
- 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.green)
- startMenu.clear()
- startMenu.setTextColor(colors.white)
- startMenu.setCursorPos(2, 1)
- startMenu.write("=== 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.green)
- startMenu.setTextColor(colors.white)
- else
- startMenu.write("[ " .. option .. " ]")
- end
- end
- end
- -- Helper function to draw ASCII art in the center
- local function drawASCIIArt()
- local art = {
- " |\\_/| ",
- " | @ @ Woof! ",
- " | <> _ ",
- " | _/\\------____ ((| |))",
- " | `--' | ",
- " ____|_ ___| |___.' ",
- "/_/_____/____/_______| "
- }
- local startX = math.floor((w - 26) / 2)
- local startY = math.floor((h - #art) / 2)
- term.setTextColor(colors.white)
- for i, line in ipairs(art) do
- term.setCursorPos(startX, startY + i - 1)
- term.write(line)
- end
- end
- -- Function to redraw the entire UI
- local function redrawUI()
- term.setBackgroundColor(colors.blue)
- term.clear()
- drawTaskbar()
- drawASCIIArt()
- drawStartMenu()
- end
- -- Initial security check
- if not checkSecurityCard() then
- return
- end
- -- Initial UI drawing
- redrawUI()
- -- Start the timer for updating the time every second
- local timerId = os.startTimer(1)
- -- Main event handling loop
- while true do
- local e, p1, p2, p3 = os.pullEvent()
- -- Security card check on every event
- if not checkSecurityCard() then
- break
- end
- if e == "timer" and p1 == timerId then
- drawTaskbar()
- timerId = os.startTimer(1)
- elseif e == "key" then
- if p1 == keys.enter then
- isStartMenuOpen = not isStartMenuOpen
- redrawUI()
- end
- end
- end
- -- Final screen settings before ending
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.clear()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement