Advertisement
El_Diablo256

Menu, lockdown and secret entrance

Apr 28th, 2013
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.30 KB | None | 0 0
  1. --[[ Local Variables ]]--
  2.  
  3. local termWidth, termHeight = termSize()
  4. local selectedItem = 1
  5. local inMainMenu = true
  6. local inLockdownMenu = false
  7.  
  8. --[[ Menu Methods ]]--
  9.  
  10. function SecretEntrance },
  11.   print("Opening")
  12.   rs.setOutput("back",true)
  13.   sleep(2)
  14.   rs.setOutput("false",false)
  15.   os.shutdown()
  16. end
  17.  
  18. function Lockdown()
  19.   inLockdownMenu = true
  20.   selectedItem = 1
  21.  
  22.   while inLockdownMenu do
  23.     term.clear()
  24.     term.setCursorPos(1,1)
  25.     printMenu(LockdownMenu)
  26.  
  27.     event, key = os.pullEvent("key")
  28.     onKeyPressed(key, LockdownMenu)
  29.   end
  30. end
  31.  
  32. function LockdownOn()
  33.   print("Activating Lockdown")
  34.   rs.setOutput("left",true)
  35.   sleep(2)
  36.   print("Lockdown activated")
  37.   sleep(10)
  38.   inLockdownMenu = false
  39.   selectedItem = 1
  40. end
  41.  
  42. function LockdownOff()
  43.   print("Deactivating Lockdown")
  44.   rs.setOutput("left",true)
  45.   sleep(2)
  46.   print("Lockdown deactivated")
  47.   inLockdownMenu = false
  48.   selectedItem = 1
  49. end
  50.  
  51. function Config()
  52.   inMainMenu = false
  53. end
  54.  
  55. function shutdown()
  56.   shell.run("stop")
  57. end
  58.  
  59. --[[ Menu Definitions ]]--
  60.  
  61. mainMenu = {
  62.   [1] = { text = "Secret Entrance", handler = SecretEntrance },
  63.   [2] = { text = "Lockdown", handler = Lockdown },
  64.   [3] = { text = "Config", handler = Config },
  65.   [4] = { text = "Shutdown", handler = shutdown }
  66. }
  67.  
  68. LockdownMenu = {
  69.   [1] = { text = "Activate Lockdown", handler = LockdownOn },
  70.   [2] = { text = "Deactivate Lockdown", handler = LockdownOff }
  71. }
  72.  
  73. --[[ Printing Methods ]]--
  74.  
  75. function printMenu( menu )
  76.   for i=1,#menu do
  77.     if i == selectedItem then
  78.       print(">> "..menu[i].text)
  79.     else
  80.       print("   "..menu[i].text)
  81.     end
  82.   end
  83. end
  84.  
  85. --[[ Handler Methods ]]--
  86. function onKeyPressed( key, menu)
  87.   if key == keys.enter then
  88.     onItemSelected(menu)
  89.   elseif key == keys.up then
  90.     if selectedItem > 1 then
  91.       selectedItem = selectedItem - 1
  92.     end
  93.   elseif key == keys.down then
  94.     if selectedItem < #menu then
  95.       selectedItem = selectedItem + 1
  96.     end
  97.   end
  98. end
  99.  
  100. function onItemSelected( menu )
  101.   menu[selectedItem].handler()
  102. end
  103.  
  104. --[[ Main Method ]]--
  105.  
  106. function main()
  107.   while inMainMenu do
  108.     term.clear()
  109.     term.setCursorPos(1,1)
  110.     printMenu(mainMenu)
  111.    
  112.     event, key = os.pullEvent("key")
  113.     onKeyPressed(key,mainMenu)
  114.   end
  115. end
  116.  
  117. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement