Advertisement
DOGGYWOOF

Untitled

Jan 25th, 2025 (edited)
14
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.84 KB | None | 0 0
  1. os.pullEvent = os.pullEventRaw
  2.  
  3. if not multishell then
  4. term.clear()
  5. term.setCursorPos(1, 1)
  6. print("Doggy OS Install Error: Unsupported System")
  7. read()
  8. disk.eject("back")
  9. disk.eject("bottom")
  10. disk.eject("left")
  11. disk.eject("right")
  12. disk.eject("top")
  13. disk.eject("front")
  14. os.reboot()
  15. return
  16. else
  17. -- Center the text within the given width
  18. function centerText(text, width)
  19. local padding = math.max(0, math.floor((width - #text) / 2))
  20. return string.rep(" ", padding) .. text
  21. end
  22.  
  23. -- Draw a border with specified width and height
  24. function drawBorder(width, height)
  25. term.setCursorPos(1, 1)
  26. term.write("+" .. string.rep("-", width - 2) .. "+")
  27. for i = 2, height - 1 do
  28. term.setCursorPos(1, i)
  29. term.write("|")
  30. term.setCursorPos(width, i)
  31. term.write("|")
  32. end
  33. term.setCursorPos(1, height)
  34. term.write("+" .. string.rep("-", width - 2) .. "+")
  35. end
  36.  
  37. -- Function to draw a graphical button
  38. function drawButton(x, y, width, height, label, color)
  39. term.setCursorPos(x, y)
  40. term.setBackgroundColor(color)
  41. term.setTextColor(colors.black)
  42. term.write(string.rep(" ", width)) -- Draw button
  43. term.setCursorPos(x + math.floor((width - #label) / 2), y + math.floor(height / 2))
  44. term.write(label)
  45. term.setBackgroundColor(colors.black) -- Reset background
  46. end
  47.  
  48. -- Draw the installation screen with GUI elements
  49. function drawGUI(width, height)
  50. -- Clear the screen and draw the border
  51. term.clear()
  52. drawBorder(width, height)
  53.  
  54. local y = 4
  55. term.setCursorPos(3, y)
  56. term.setTextColor(colors.white)
  57. print(centerText("Doggy OS Installation", width - 4))
  58.  
  59. y = y + 2
  60. term.setCursorPos(3, y)
  61. print(centerText("OS Version: Doggy OS 13.0", width - 4))
  62.  
  63. y = y + 1
  64. term.setCursorPos(3, y)
  65. print(centerText("UEFI: N3K0 Config", width - 4))
  66.  
  67. y = y + 1
  68. term.setCursorPos(3, y)
  69. print(centerText("Bootloader: VA11-ILLA 13.0", width - 4))
  70.  
  71. y = y + 3
  72. term.setCursorPos(3, y)
  73. print(centerText("Confirm Installation", width - 4))
  74.  
  75. -- Create two graphical buttons: Install (Y) and Cancel (N)
  76. drawButton(3, y + 2, width - 6, 3, "Install OS (Y)", colors.green)
  77. drawButton(3, y + 6, width - 6, 3, "Cancel Installation (N)", colors.red)
  78.  
  79. -- Footer line
  80. y = y + 9
  81. term.setCursorPos(3, y)
  82. print(centerText("================================", width - 4))
  83. end
  84.  
  85. -- Function to detect if a button is clicked
  86. function buttonClicked(x, y, width, height, mx, my)
  87. return mx >= x and mx <= x + width - 1 and my >= y and my <= y + height - 1
  88. end
  89.  
  90. -- Main function to handle the installation process
  91. function main()
  92. term.clear()
  93. local w, h = term.getSize()
  94. local contentHeight = 16
  95. local borderPadding = 2 -- Padding between border and content
  96.  
  97. -- Adjust height for border padding
  98. local heightWithBorders = contentHeight + borderPadding * 2
  99.  
  100. -- Make sure the height fits within the screen
  101. local displayHeight = math.min(h, heightWithBorders)
  102. drawGUI(w, displayHeight)
  103.  
  104. -- Track mouse clicks
  105. while true do
  106. local event, button, mx, my = os.pullEventRaw()
  107.  
  108. -- Check for mouse clicks on the "Install OS" or "Cancel Installation" buttons
  109. if event == "mouse_click" then
  110. if button == 1 then -- Left-click
  111. if buttonClicked(3, 9, w - 6, 3, mx, my) then
  112. runProgram()
  113. elseif buttonClicked(3, 13, w - 6, 3, mx, my) then
  114. term.clear()
  115. term.setCursorPos(1, 1)
  116. drawBorder(w, 7)
  117. term.setCursorPos(3, 2)
  118. print(centerText("Installation Cancelled", w - 4))
  119. term.setCursorPos(3, 3)
  120. print(centerText("Shutting Down...", w - 4))
  121. sleep(4)
  122. os.shutdown()
  123. end
  124. end
  125. end
  126. end
  127. end
  128.  
  129. function runProgram()
  130. -- Run the installation program
  131. shell.run("/disk/install") -- Replace with your actual program name
  132.  
  133. term.clear()
  134. term.setCursorPos(1, 1)
  135. print("Doggy OS Install Error")
  136. print("====================================")
  137. print("Unable to load installation program")
  138. print("Press enter to retry")
  139. read()
  140. os.reboot()
  141. end
  142.  
  143. main()
  144. end
  145.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement