Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.pullEvent = os.pullEventRaw
- if not multishell then
- term.clear()
- term.setCursorPos(1, 1)
- print("Doggy OS Install Error: Unsupported System")
- read()
- disk.eject("back")
- disk.eject("bottom")
- disk.eject("left")
- disk.eject("right")
- disk.eject("top")
- disk.eject("front")
- os.reboot()
- return
- else
- -- Center the text within the given width
- function centerText(text, width)
- local padding = math.max(0, math.floor((width - #text) / 2))
- return string.rep(" ", padding) .. text
- end
- -- Draw a border with specified width and height
- function drawBorder(width, height)
- term.setCursorPos(1, 1)
- term.write("+" .. string.rep("-", width - 2) .. "+")
- for i = 2, height - 1 do
- term.setCursorPos(1, i)
- term.write("|")
- term.setCursorPos(width, i)
- term.write("|")
- end
- term.setCursorPos(1, height)
- term.write("+" .. string.rep("-", width - 2) .. "+")
- end
- -- Function to draw a graphical button
- function drawButton(x, y, width, height, label, color)
- term.setCursorPos(x, y)
- term.setBackgroundColor(color)
- term.setTextColor(colors.black)
- term.write(string.rep(" ", width)) -- Draw button
- term.setCursorPos(x + math.floor((width - #label) / 2), y + math.floor(height / 2))
- term.write(label)
- term.setBackgroundColor(colors.black) -- Reset background
- end
- -- Draw the installation screen with GUI elements
- function drawGUI(width, height)
- -- Clear the screen and draw the border
- term.clear()
- drawBorder(width, height)
- local y = 4
- term.setCursorPos(3, y)
- term.setTextColor(colors.white)
- print(centerText("Doggy OS Installation", width - 4))
- y = y + 2
- term.setCursorPos(3, y)
- print(centerText("OS Version: Doggy OS 13.0", width - 4))
- y = y + 1
- term.setCursorPos(3, y)
- print(centerText("UEFI: N3K0 Config", width - 4))
- y = y + 1
- term.setCursorPos(3, y)
- print(centerText("Bootloader: VA11-ILLA 13.0", width - 4))
- y = y + 3
- term.setCursorPos(3, y)
- print(centerText("Confirm Installation", width - 4))
- -- Create two graphical buttons: Install (Y) and Cancel (N)
- drawButton(3, y + 2, width - 6, 3, "Install OS (Y)", colors.green)
- drawButton(3, y + 6, width - 6, 3, "Cancel Installation (N)", colors.red)
- -- Footer line
- y = y + 9
- term.setCursorPos(3, y)
- print(centerText("================================", width - 4))
- end
- -- Function to detect if a button is clicked
- function buttonClicked(x, y, width, height, mx, my)
- return mx >= x and mx <= x + width - 1 and my >= y and my <= y + height - 1
- end
- -- Main function to handle the installation process
- function main()
- term.clear()
- local w, h = term.getSize()
- local contentHeight = 16
- local borderPadding = 2 -- Padding between border and content
- -- Adjust height for border padding
- local heightWithBorders = contentHeight + borderPadding * 2
- -- Make sure the height fits within the screen
- local displayHeight = math.min(h, heightWithBorders)
- drawGUI(w, displayHeight)
- -- Track mouse clicks
- while true do
- local event, button, mx, my = os.pullEventRaw()
- -- Check for mouse clicks on the "Install OS" or "Cancel Installation" buttons
- if event == "mouse_click" then
- if button == 1 then -- Left-click
- if buttonClicked(3, 9, w - 6, 3, mx, my) then
- runProgram()
- elseif buttonClicked(3, 13, w - 6, 3, mx, my) then
- term.clear()
- term.setCursorPos(1, 1)
- drawBorder(w, 7)
- term.setCursorPos(3, 2)
- print(centerText("Installation Cancelled", w - 4))
- term.setCursorPos(3, 3)
- print(centerText("Shutting Down...", w - 4))
- sleep(4)
- os.shutdown()
- end
- end
- end
- end
- end
- function runProgram()
- -- Run the installation program
- shell.run("/disk/install") -- Replace with your actual program name
- term.clear()
- term.setCursorPos(1, 1)
- print("Doggy OS Install Error")
- print("====================================")
- print("Unable to load installation program")
- print("Press enter to retry")
- read()
- os.reboot()
- end
- main()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement