Guest User

Sarcastic_Bannanas Menu Code

a guest
Nov 12th, 2012
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.61 KB | None | 0 0
  1. local w,h = term.getSize()
  2. local running = true
  3. local doors = false
  4. local lights = false
  5. local cooling = false
  6. local i = 1
  7.  
  8. function printCentred( y, s )
  9.     local x = math.floor((w - string.len(s)) / 2)
  10.     term.setCursorPos(x,y)
  11.     term.clearLine()
  12.     term.write( s )
  13. end
  14.  
  15. local nOption = 1
  16.  
  17. -- Display menu
  18. local function drawMenu()
  19.     term.clear()
  20.     term.setCursorPos(1,1)
  21.     term.write( "REACTOR ACCESS TERMINAL" )
  22.  
  23.     term.setCursorPos(w-25,1)
  24.     if nOption == 1 then
  25.         if door == false then do
  26.         term.write("OPEN REACTOR DOOR")
  27.         end
  28.         else do term.write("CLOSE REACTOR DOOR")
  29.         end
  30.         end
  31.     elseif nOption == 2 then
  32.         if lights == false then do
  33.         term.write("TURN LIGHTS ON")
  34.         end
  35.         else do term.write("TURN LIGHTS OFF")
  36.         end
  37.         end
  38.     elseif nOption == 3 then
  39.         if cooling == false then do
  40.         term.write("TURN COOLING OFF")
  41.         end
  42.         else do term.write("TURN COOLING ON")
  43.         end
  44.         end
  45.     else
  46.         term.write("Console")
  47.     end
  48.    
  49. end
  50.  
  51. -- Display the frontend
  52. term.clear()
  53. local function drawFrontend()
  54.     printCentred( math.floor(h/2) - 3, "" )
  55.     printCentred( math.floor(h/2) - 2, "AVALIABLE COMMANDS" )
  56.     printCentred( math.floor(h/2) - 1, "" )
  57.         if doors == false then do
  58.             printCentred( math.floor(h/2) + 0, ((nOption == 1) and "[ OPEN REACTOR DOOR ]") or "OPEN REACTOR DOOR" )
  59.         end
  60.  
  61.     elseif doors == true then do
  62.             printCentred( math.floor(h/2) + 0, ((nOption == 1) and "[ SEAL REACTOR DOOR ]") or "SEAL REACTOR DOOR" )
  63.         end
  64.     else
  65.         end
  66.  
  67.         if lights == false then do
  68.             printCentred( math.floor(h/2) + 1, ((nOption == 2) and "[ TURN LIGHTS ON ]") or "TURN LIGHTS ON" )
  69.         end
  70.  
  71.     elseif lights == true then do
  72.             printCentred( math.floor(h/2) + 1, ((nOption == 2) and "[ TURN LIGHTS OFF ]") or "TURN LIGHTS OFF" )
  73.         end
  74.     else
  75.         end
  76.  
  77.     if cooling == false then do
  78.             printCentred( math.floor(h/2) + 2, ((nOption == 3) and "[ DEACTIVATE COOLING ]") or "DEACTIVATE COOLING" )
  79.         end
  80.  
  81.     elseif cooling == true then do
  82.             printCentred( math.floor(h/2) + 2, ((nOption == 3) and "[ ACTIVATE COOLING ]") or "ACTIVATE COOLING" )
  83.         end
  84.         else
  85.         end
  86.  
  87.     printCentred( math.floor(h/2) + 3, ((nOption == 4) and "[ CONSOLE ]") or "CONSOLE" )
  88. end
  89.  
  90.  
  91.  
  92.  
  93. -- Call functions for display menu
  94.  
  95. while i == 1 do
  96.  
  97. drawMenu()
  98. drawFrontend()
  99.  
  100. while true do
  101.     local e,p = os.pullEvent()
  102.     if e == "key" then
  103.         local key = p
  104.         if key == 17 or key == 200 then
  105.             -- Up
  106.             if nOption > 1 then
  107.                 nOption = nOption - 1
  108.                 drawMenu()
  109.                 drawFrontend()
  110.             end
  111.         elseif key == 31 or key == 208 then
  112.             -- Down
  113.             if nOption < 4 then -- Change 3 by the number of option.
  114.                 nOption = nOption + 1
  115.                 drawMenu()
  116.                 drawFrontend()
  117.             end
  118.         elseif key == 28 then
  119.             -- Enter
  120.             break
  121.         end
  122.     end
  123. end
  124.  
  125. -- Conditions
  126. if nOption == 1 then
  127.     if doors == true then do
  128.     doors = false
  129.     rednet.send(39,"rdo1")
  130.     end
  131.     end
  132.     if doors == false then do
  133.     doors = true
  134.     rednet.send(39,"rdo0")
  135.     end
  136.     end
  137.  
  138.    
  139. elseif nOption == 2 then
  140.     if lights == true then do
  141.     lights = false
  142.     --rednet.send(39,"l1")
  143.     end
  144.     end
  145.     if lights == false then do
  146.     lights = true
  147.     --rednet.send(39,"l0")
  148.     end
  149.     end
  150.    
  151. elseif nOption == 3 then
  152.     if cooling == true then do
  153.     cooling = false
  154.     --rednet.send(39,"c0")
  155.     end
  156.     end
  157.     if cooling == false then do
  158.     cooling = true
  159.     --rednet.send(39,"c1")
  160.     end
  161.     end
  162.    
  163. elseif nOption == 4 then
  164.     running = false
  165.     term.clear()
  166.     term.setCursorPos(1, 1)
  167.     break end
  168.  
  169. end
Advertisement
Add Comment
Please, Sign In to add comment