Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local w,h = term.getSize()
- local running = true
- local doors = false
- local lights = false
- local cooling = false
- local i = 1
- function printCentred( y, s )
- local x = math.floor((w - string.len(s)) / 2)
- term.setCursorPos(x,y)
- term.clearLine()
- term.write( s )
- end
- local nOption = 1
- -- Display menu
- local function drawMenu()
- term.clear()
- term.setCursorPos(1,1)
- term.write( "REACTOR ACCESS TERMINAL" )
- term.setCursorPos(w-25,1)
- if nOption == 1 then
- if door == false then do
- term.write("OPEN REACTOR DOOR")
- end
- else do term.write("CLOSE REACTOR DOOR")
- end
- end
- elseif nOption == 2 then
- if lights == false then do
- term.write("TURN LIGHTS ON")
- end
- else do term.write("TURN LIGHTS OFF")
- end
- end
- elseif nOption == 3 then
- if cooling == false then do
- term.write("TURN COOLING OFF")
- end
- else do term.write("TURN COOLING ON")
- end
- end
- else
- term.write("Console")
- end
- end
- -- Display the frontend
- term.clear()
- local function drawFrontend()
- printCentred( math.floor(h/2) - 3, "" )
- printCentred( math.floor(h/2) - 2, "AVALIABLE COMMANDS" )
- printCentred( math.floor(h/2) - 1, "" )
- if doors == false then do
- printCentred( math.floor(h/2) + 0, ((nOption == 1) and "[ OPEN REACTOR DOOR ]") or "OPEN REACTOR DOOR" )
- end
- elseif doors == true then do
- printCentred( math.floor(h/2) + 0, ((nOption == 1) and "[ SEAL REACTOR DOOR ]") or "SEAL REACTOR DOOR" )
- end
- else
- end
- if lights == false then do
- printCentred( math.floor(h/2) + 1, ((nOption == 2) and "[ TURN LIGHTS ON ]") or "TURN LIGHTS ON" )
- end
- elseif lights == true then do
- printCentred( math.floor(h/2) + 1, ((nOption == 2) and "[ TURN LIGHTS OFF ]") or "TURN LIGHTS OFF" )
- end
- else
- end
- if cooling == false then do
- printCentred( math.floor(h/2) + 2, ((nOption == 3) and "[ DEACTIVATE COOLING ]") or "DEACTIVATE COOLING" )
- end
- elseif cooling == true then do
- printCentred( math.floor(h/2) + 2, ((nOption == 3) and "[ ACTIVATE COOLING ]") or "ACTIVATE COOLING" )
- end
- else
- end
- printCentred( math.floor(h/2) + 3, ((nOption == 4) and "[ CONSOLE ]") or "CONSOLE" )
- end
- -- Call functions for display menu
- while i == 1 do
- drawMenu()
- drawFrontend()
- while true do
- local e,p = os.pullEvent()
- if e == "key" then
- local key = p
- if key == 17 or key == 200 then
- -- Up
- if nOption > 1 then
- nOption = nOption - 1
- drawMenu()
- drawFrontend()
- end
- elseif key == 31 or key == 208 then
- -- Down
- if nOption < 4 then -- Change 3 by the number of option.
- nOption = nOption + 1
- drawMenu()
- drawFrontend()
- end
- elseif key == 28 then
- -- Enter
- break
- end
- end
- end
- -- Conditions
- if nOption == 1 then
- if doors == true then do
- doors = false
- rednet.send(39,"rdo1")
- end
- end
- if doors == false then do
- doors = true
- rednet.send(39,"rdo0")
- end
- end
- elseif nOption == 2 then
- if lights == true then do
- lights = false
- --rednet.send(39,"l1")
- end
- end
- if lights == false then do
- lights = true
- --rednet.send(39,"l0")
- end
- end
- elseif nOption == 3 then
- if cooling == true then do
- cooling = false
- --rednet.send(39,"c0")
- end
- end
- if cooling == false then do
- cooling = true
- --rednet.send(39,"c1")
- end
- end
- elseif nOption == 4 then
- running = false
- term.clear()
- term.setCursorPos(1, 1)
- break end
- end
Advertisement
Add Comment
Please, Sign In to add comment