MarcosKoco

MenuPassW

Jun 5th, 2021 (edited)
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.27 KB | None | 0 0
  1. local Version = "1.0.0"
  2. local ComputerVersion = "1.0.0"
  3.  
  4. local System = os -- Used for System things like os.time() to System.time()
  5. local Screen = term -- Used for Screen thing on the turtle or computer like term.clear() to Screen.clear()
  6. local Per = peripheral -- Used shortcut for peripheral
  7. local Text = textutils -- Used shortcut for textilils
  8. local Pack = Text.serialize -- Makes a new command for packing ( shortcut used from local Text)
  9. local UnPack = Text.unserialize -- Makes a new command for unpacking ( shortcut used from local Text)
  10.  
  11. local OldpullEvent = System.pullEvent
  12. System.pullEvent = System.pullEventRaw
  13.  
  14. local file = fs.exists("/API/Functions.lua")
  15.  
  16. if not(file) then
  17.    
  18.     shell.run("pastebin get sujHjqXC /API/Functions.lua")
  19.    
  20. end
  21.  
  22. System.loadAPI("/API/Functions.lua")
  23.  
  24. local Modem = Per.wrap(Functions.FindWirelessModem())
  25. local Send = Modem.transmit
  26. Modem.closeAll()
  27.  
  28. local Monitor = Per.wrap(Functions.FindMonitor())
  29.  
  30. local Computer = { ComputerName = "Test_Computer",
  31.                 Status = true,
  32.                 LogOn = false,
  33. }
  34.  
  35. System.setComputerLabel(Computer.ComputerName)
  36.  
  37. function DelTemp()
  38.  
  39.     Functions.DelFile("OS/Temp")
  40.    
  41. end
  42.  
  43. function Temp()
  44.    
  45.     local Data = Functions.LoadFile("OS/Temp/Temp.Tem")
  46.    
  47.     if Data then
  48.        
  49.         Computer.ComputerName = Data.ComputerName
  50.         Computer.LogOn = Data.LogOn
  51.         Computer.Status = Data.Status
  52.         Computer.UserName = Data.UserName
  53.        
  54.     end
  55.    
  56. end
  57.  
  58. function Startup()
  59.    
  60.     if not(Modem) then
  61.        
  62.         print("No WirelessModem Found !")
  63.         error()
  64.        
  65.     end
  66.    
  67.     Temp()
  68.    
  69. end
  70.  
  71. Screen.clear()
  72. Screen.setCursorPos(1, 1)
  73.  
  74. Startup()
  75.  
  76. local w, h = Screen.getSize()
  77. local NameLen = 17
  78. local nOption = 1
  79. local MaxOptions = 4
  80.  
  81. function drawScreen()
  82.    
  83.     Screen.clear()
  84.    
  85.     if pocket then
  86.        
  87.         Screen.setCursorPos(1, 1)
  88.         Screen.write("User : "..Computer.UserName)
  89.         Screen.setCursorPos(1, 2)
  90.         Screen.write(Computer.ComputerName)
  91.        
  92.         Screen.setCursorPos(1, 3)
  93.        
  94.     else
  95.        
  96.         Screen.setCursorPos(1, 1)
  97.         Screen.write("User : "..Computer.UserName)
  98.         Screen.setCursorPos(1, 2)
  99.         Screen.write(Computer.ComputerName)
  100.        
  101.         Screen.setCursorPos(w-(NameLen+3), 1)
  102.        
  103.     end
  104.    
  105.     if nOption == 1 then
  106.        
  107.         Screen.write("Prog's")
  108.        
  109.     elseif nOption == 2 then
  110.    
  111.         Screen.write("Shell Command")
  112.        
  113.     elseif nOption == 3 then
  114.        
  115.         Screen.write("Shutdown")
  116.        
  117.     elseif nOption == 4 then
  118.        
  119.         Screen.write("Uninstall OS")
  120.     else
  121.        
  122.     end
  123.    
  124.     Functions.printCentered(math.floor(h/2) -3, "")
  125.     Functions.printCentered(math.floor(h/2) -2, Functions.PadString("  Head Menu",NameLen))
  126.     Functions.printCentered(math.floor(h/2) -1, "")
  127.     Functions.printCentered(math.floor(h/2) +0, ((nOption == 1) and string.format("%s%s",Functions.PadString("[ Prog's",NameLen-1),"]") or Functions.PadString("  Prog's",NameLen)))
  128.     Functions.printCentered(math.floor(h/2) +1, ((nOption == 2) and string.format("%s%s",Functions.PadString("[ Shell Command",NameLen-1),"]") or Functions.PadString("  Shell Command",NameLen)))
  129.     Functions.printCentered(math.floor(h/2) +2, ((nOption == 3) and string.format("%s%s",Functions.PadString("[ Shutdown",NameLen-1),"]") or Functions.PadString("  Shutdown",NameLen)))
  130.     Functions.printCentered(math.floor(h/2) +3, ((nOption == 4) and string.format("%s%s",Functions.PadString("[ Uninstall OS",NameLen-1),"]") or Functions.PadString("  Uninstall OS",NameLen)))
  131.    
  132. end
  133.  
  134. function onEnter()
  135.    
  136.     if nOption == 1 then
  137.        
  138.         shell.run("OS/.Progs")
  139.         Screen.clear()
  140.        
  141.     elseif nOption == 2 then
  142.        
  143.         System.pullEvent = OldpullEvent
  144.        
  145.         Computer.Status = false
  146.        
  147.     elseif nOption == 3 then
  148.        
  149.         DelTemp()
  150.         System.shutdown()
  151.        
  152.     elseif nOption == 4 then
  153.        
  154.         shell.run("OS/Uninstall")
  155.         error()
  156.        
  157.     end
  158.    
  159. end
  160.  
  161. repeat
  162.    
  163.     drawScreen()
  164.    
  165.     local Event, p1, p2, p3, p4, p5 = System.pullEvent()
  166.    
  167.     if Event == "key" then
  168.        
  169.         if p1 == keys.up or p1 == keys.numPad8 then
  170.            
  171.             if nOption > 1 then
  172.                
  173.                 nOption = nOption - 1
  174.                
  175.             end
  176.            
  177.         elseif p1 == keys.down or p1 == keys.numPad2 then
  178.            
  179.             if nOption < MaxOptions then
  180.                
  181.                 nOption = nOption + 1
  182.                
  183.             end
  184.            
  185.         elseif p1 == keys.enter or p1 == keys.numPadEnter then
  186.            
  187.             onEnter()
  188.            
  189.         end
  190.        
  191.     end
  192.    
  193. until Computer.Status == false
  194.  
  195. Screen.clear()
  196. Screen.setCursorPos(1, 1)
  197. print("Type 'Back' to go back to the menu.")
Add Comment
Please, Sign In to add comment