Advertisement
DOGGYWOOF

Untitled

Jan 17th, 2025 (edited)
12
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.33 KB | None | 0 0
  1. os.pullEvent = os.pullEventRaw
  2.  
  3. local w, h = term.getSize()
  4. local nOption = 1
  5. local isStartMenuOpen = false
  6. local menuOptions = {"Command", "Programs", "Power Menu"}
  7. local powerOptions = {"Shutdown", "Reboot", "Cancel"}
  8.  
  9. -- Create windows for taskbar, start menu, and power menu
  10. local taskbar = window.create(term.current(), 1, h, w, 1)
  11. local startMenu = window.create(term.current(), 1, h - 10, 20, 10, false)
  12.  
  13. -- Function to display the security error popup
  14. local function showSecurityError()
  15. local popupWidth = 30
  16. local popupHeight = 7
  17. local popupX = math.floor((w - popupWidth) / 2)
  18. local popupY = math.floor((h - popupHeight) / 2)
  19.  
  20. local popup = window.create(term.current(), popupX, popupY, popupWidth, popupHeight)
  21. popup.setBackgroundColor(colors.gray)
  22. popup.clear()
  23. popup.setTextColor(colors.white)
  24.  
  25. popup.setCursorPos(2, 1)
  26. popup.write("=== Security Alert ===")
  27.  
  28. popup.setCursorPos(2, 3)
  29. popup.write("Security Card Removed!!!")
  30.  
  31. popup.setCursorPos(2, 5)
  32. popup.write("Press any key to lock...")
  33.  
  34. popup.setVisible(true)
  35. os.pullEvent("key") -- Wait for any key press
  36. shell.run("/disk/os/lock.lua")
  37. end
  38.  
  39. -- Function to check for the security card
  40. local function checkSecurityCard()
  41. if not fs.exists("/disk2/card.lua") then
  42. showSecurityError()
  43. return false
  44. end
  45. return true
  46. end
  47.  
  48. -- Helper function to draw the taskbar with the current time
  49. local function drawTaskbar()
  50. taskbar.setBackgroundColor(colors.green)
  51. taskbar.clear()
  52. taskbar.setCursorPos(1, 1)
  53. taskbar.setTextColor(colors.white)
  54. taskbar.write("[ Start ]")
  55.  
  56. -- Display the current time on the right side
  57. local currentTime = os.date("%H:%M:%S")
  58. local timeX = w - string.len(currentTime) - 1
  59. taskbar.setCursorPos(timeX, 1)
  60. taskbar.write(currentTime)
  61. end
  62.  
  63. -- Helper function to draw the start menu
  64. local function drawStartMenu()
  65. if not isStartMenuOpen then
  66. startMenu.setVisible(false)
  67. return
  68. end
  69.  
  70. startMenu.setVisible(true)
  71. startMenu.setBackgroundColor(colors.green)
  72. startMenu.clear()
  73.  
  74. startMenu.setTextColor(colors.white)
  75. startMenu.setCursorPos(2, 1)
  76. startMenu.write("=== Start Menu ===")
  77.  
  78. for i, option in ipairs(menuOptions) do
  79. startMenu.setCursorPos(2, 2 + i)
  80. if nOption == i then
  81. startMenu.setTextColor(colors.black)
  82. startMenu.setBackgroundColor(colors.white)
  83. startMenu.write("[ " .. option .. " ]")
  84. startMenu.setBackgroundColor(colors.green)
  85. startMenu.setTextColor(colors.white)
  86. else
  87. startMenu.write("[ " .. option .. " ]")
  88. end
  89. end
  90. end
  91.  
  92. -- Helper function to draw ASCII art in the center
  93. local function drawASCIIArt()
  94. local art = {
  95. " |\\_/| ",
  96. " | @ @ Woof! ",
  97. " | <> _ ",
  98. " | _/\\------____ ((| |))",
  99. " | `--' | ",
  100. " ____|_ ___| |___.' ",
  101. "/_/_____/____/_______| "
  102. }
  103. local startX = math.floor((w - 26) / 2)
  104. local startY = math.floor((h - #art) / 2)
  105.  
  106. term.setTextColor(colors.white)
  107. for i, line in ipairs(art) do
  108. term.setCursorPos(startX, startY + i - 1)
  109. term.write(line)
  110. end
  111. end
  112.  
  113. -- Function to redraw the entire UI
  114. local function redrawUI()
  115. term.setBackgroundColor(colors.blue)
  116. term.clear()
  117. drawTaskbar()
  118. drawASCIIArt()
  119. drawStartMenu()
  120. end
  121.  
  122. -- Initial security check
  123. if not checkSecurityCard() then
  124. return
  125. end
  126.  
  127. -- Initial UI drawing
  128. redrawUI()
  129.  
  130. -- Start the timer for updating the time every second
  131. local timerId = os.startTimer(1)
  132.  
  133. -- Main event handling loop
  134. while true do
  135. local e, p1, p2, p3 = os.pullEvent()
  136.  
  137. -- Security card check on every event
  138. if not checkSecurityCard() then
  139. break
  140. end
  141.  
  142. if e == "timer" and p1 == timerId then
  143. drawTaskbar()
  144. timerId = os.startTimer(1)
  145. elseif e == "key" then
  146. if p1 == keys.enter then
  147. isStartMenuOpen = not isStartMenuOpen
  148. redrawUI()
  149. end
  150. end
  151. end
  152.  
  153. -- Final screen settings before ending
  154. term.setBackgroundColor(colors.black)
  155. term.setTextColor(colors.white)
  156. term.clear()
  157.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement