Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- mon = peripheral.wrap("monitor_0")
- sg = peripheral.find("stargate")
- mon.setBackgroundColor(colors.black)
- mon.clear()
- maxEng = 50000
- dialling = {}
- function drawChevrons() --draws cheyvrons on the screen
- x,y = mon.getSize()
- chevX1 = x/3
- chevX2 = x/3*2+1
- chevY1 = y/3-2
- chevY2 = y/3*2 +2
- mon.setBackgroundColor(colors.black)
- for yc = chevY1-2, chevY2-2 do
- for xc = chevX1-2, chevX2-2 do
- mon.setCursorPos(xc, yc)
- mon.write(" ")
- end
- end
- mon.setBackgroundColor(colors.lightGray)
- for i = chevX1+2, chevX2-2 do
- mon.setCursorPos(i,chevY1)
- mon.write(" ")
- end
- for i = chevX1+2, chevX2-2 do
- mon.setCursorPos(i,chevY2)
- mon.write(" ")
- end
- for i = chevY1+2, chevY2-2 do
- mon.setCursorPos(chevX1,i)
- mon.write(" ")
- end
- for i = chevY1+2, chevY2-2 do
- mon.setCursorPos(chevX2, i)
- mon.write(" ")
- end
- chev1pos = {chevX1, chevY2 }
- mon.setBackgroundColor(colors.gray)
- mon.setTextColor(colors.black)
- mon.setCursorPos(math.floor(chev1pos[1]), math.floor(chev1pos[2])-1)
- mon.write(" > ")
- chev2pos = {chevX1, chevY1 + ((chevY2 - chevY1) / 2) }
- mon.setCursorPos(math.floor(chev2pos[1]-1), math.floor(chev2pos[2]))
- mon.write(" > ")
- chev3pos = {chevX1, chevY1 }
- mon.setCursorPos(math.floor(chev3pos[1]), math.floor(chev3pos[2]+1))
- mon.write(" > ")
- chev4pos = {chevX1 + ((chevX2 - chevX1) / 2), chevY1 }
- mon.setCursorPos(math.floor(chev4pos[1]-1), math.floor(chev4pos[2]))
- mon.write(" V ")
- chev5pos = {chevX2, chevY1 }
- mon.setCursorPos(math.floor(chev5pos[1]-2), math.floor(chev5pos[2])+1)
- mon.write(" < ")
- chev6pos = {chevX2, chevY1 + ((chevY2 - chevY1) / 2) }
- mon.setCursorPos(math.floor(chev6pos[1]-1), math.floor(chev6pos[2]))
- mon.write(" < ")
- chev7pos = {chevX2, chevY2 }
- mon.setCursorPos(math.floor(chev7pos[1]-2), math.floor(chev7pos[2]-1))
- mon.write(" < ")
- chev8pos = {chevX1 + ((chevX2 - chevX1) /2), chevY2 }
- mon.setCursorPos(math.floor(chev8pos[1]-1), math.floor(chev8pos[2]))
- mon.write(" ")
- -- chev9pos = {chevX1 + ((chevX2 - chevX1) /2), chevY2 }
- -- mon.setCursorPos(math.floor(chev8pos[1]-1), chevY1 + ((chevY2 - chevY1) / 2))
- -- mon.write(" 9 ")
- mon.setBackgroundColor(colors.black)
- mon.setCursorPos(x/2 - 4, y/2 - 1)
- mon.write(" ")
- mon.setCursorPos(x/2-1, y/2+4)
- mon.write(" ")
- end
- function drawChev( chevInfo )
- mon.setBackgroundColor(colors.gray)
- x,y = mon.getSize()
- chevX1 = x/3
- chevX2 = x/3*2+1
- chevY1 = y/3-2
- chevY2 = y/3*2 +2
- if chevInfo[1] == 1 then
- chev1pos = {chevX1, chevY2 }
- mon.setBackgroundColor(colors.gray)
- mon.setCursorPos(math.floor(chev1pos[1]), math.floor(chev1pos[2])-1)
- mon.write(" "..chevInfo[2].." ")
- elseif chevInfo[1] == 2 then
- chev2pos = {chevX1, chevY1 + ((chevY2 - chevY1) / 2) }
- mon.setCursorPos(math.floor(chev2pos[1]-1), math.floor(chev2pos[2]))
- mon.write(" "..chevInfo[2].." ")
- elseif chevInfo[1] == 3 then
- chev3pos = {chevX1, chevY1 }
- mon.setCursorPos(math.floor(chev3pos[1]), math.floor(chev3pos[2]+1))
- mon.write(" "..chevInfo[2].." ")
- elseif chevInfo[1] == 4 then
- chev4pos = {chevX1 + ((chevX2 - chevX1) / 2), chevY1 }
- mon.setCursorPos(math.floor(chev4pos[1]-1), math.floor(chev4pos[2]))
- mon.write(" "..chevInfo[2].." ")
- elseif chevInfo[1] == 5 then
- chev5pos = {chevX2, chevY1 }
- mon.setCursorPos(math.floor(chev5pos[1]-2), math.floor(chev5pos[2])+1)
- mon.write(" "..chevInfo[2].." ")
- elseif chevInfo[1] == 6 then
- chev6pos = {chevX2, chevY1 + ((chevY2 - chevY1) / 2) }
- mon.setCursorPos(math.floor(chev6pos[1]-1), math.floor(chev6pos[2]))
- mon.write(" "..chevInfo[2].." ")
- elseif chevInfo[1] == 7 then
- chev7pos = {chevX2, chevY2 }
- mon.setCursorPos(math.floor(chev7pos[1]-2), math.floor(chev7pos[2]-1))
- mon.write(" "..chevInfo[2].." ")
- elseif chevInfo[1] == 8 then
- chevsave8 = chevInfo[2]
- elseif chevInfo[1] == 9 then
- chev8pos = {chevX1 + ((chevX2 - chevX1) /2), chevY2 }
- mon.setCursorPos(math.floor(chev8pos[1]-1), math.floor(chev8pos[2]))
- mon.write(""..chevsave8.." "..chevInfo[2])
- mon.setBackgroundColor(colors.black)
- end
- end
- function drawSgStatus(status) -- draws stargate status
- if status ~= "Idle" then
- term.setCursorPos(1,2)
- write(status) --needed for sting length because sting.len() won't work with stargateStatus()
- xc, yc = term.getCursorPos()
- term.clear()
- term.setCursorPos(1,2)
- write("> ")
- if xc%2 == 1 then
- xc = xc+1
- even = true
- else
- even = false
- end
- mon.setBackgroundColor(colors.black)
- if status == "Connected" then
- mon.setTextColor(colors.lightBlue)
- elseif status == "Dialling" then
- mon.setTextColor(colors.orange)
- else
- mon.setTextColor(colors.green)
- end
- x,y = mon.getSize()
- mon.setCursorPos((x/2+1) - 6, y/2+2)
- mon.write(" ")
- mon.setCursorPos((x/2+1) - (xc/2-1), y/2+2)
- mon.write(status)
- if even == true then
- mon.write(".")
- end
- end
- end
- function drawLocalAddress() -- draws the address stargate being controlled
- x,y = mon.getSize()
- mon.setBackgroundColor(colors.black)
- mon.setTextColor(colors.lightGray)
- mon.setCursorPos(x/2-7, 1)
- mon.write("Stargate Address:")
- end
- function drawDial() -- draws the button to access the dialing menu
- x,y = mon.getSize()
- state, int = sg.stargateState()
- for yc = y-3, y-1 do
- for xc = x/2-15, x/2 do
- if state == "Idle" then
- mon.setBackgroundColor(colors.lightGray)
- else
- mon.setBackgroundColor(colors.gray)
- end
- mon.setCursorPos(xc,yc)
- mon.write(" ")
- end
- end
- mon.setCursorPos(x/2-7, y-2)
- mon.setTextColor(colors.black)
- mon.write("List")
- end
- function drawTerm() -- draws the button to terminate the stargate connection to another gate
- x,y = mon.getSize()
- state, int = sg.stargateState()
- for yc = y-3, y-1 do
- for xc = x/2+2, x/2+15 do
- if state == "Connected" or state == "Connecting" or state == "Dialling" then
- mon.setBackgroundColor(colors.lightGray)
- else
- mon.setBackgroundColor(colors.gray)
- end
- mon.setCursorPos(xc,yc)
- mon.write(" ")
- end
- end
- mon.setCursorPos(x/2+3, y-2)
- mon.setTextColor(colors.black)
- mon.write("Eteindre")
- end
- function drawHome() -- draws the home screen
- mon.setBackgroundColor(colors.black)
- x,y = mon.getSize()
- mon.clear()
- mon.setCursorPos(1,y)
- mon.setTextColor(colors.gray)
- mon.setBackgroundColor(colors.black)
- drawChevrons()
- status, int = sg.stargateState()
- drawSgStatus(tostring(status))
- drawLocalAddress()
- drawDial()
- mon.setCursorBlink(false)
- drawTerm()
- end
- function drawBookmarksPage()
- mon.setBackgroundColor(colors.black)
- mon.clear()
- mon.setTextColor(colors.black)
- x,y = mon.getSize()
- for yc = 1,y-3 do
- if yc%2 == 1 then
- mon.setBackgroundColor(colors.lightBlue)
- else
- mon.setBackgroundColor(colors.lightGray)
- end
- for xc = 1,x do
- mon.setCursorPos(xc, yc)
- mon.write(" ")
- end
- end
- for i= 1,y do
- if i%2 == 1 then
- mon.setBackgroundColor(colors.lightBlue)
- else
- mon.setBackgroundColor(colors.lightGray)
- end
- if fs.exists(tostring(i)) then
- file = fs.open(tostring(i),"r")
- bookmark = textutils.unserialize(file.readAll())
- file.close()
- mon.setCursorPos(1,i)
- for k,v in pairs(bookmark) do
- if k == "name" then
- mon.write(v)
- mon.setCursorPos(x/2, i)
- mon.write(bookmark.address)
- mon.setCursorPos(x,i)
- end
- end
- end
- end
- mon.setCursorPos(x/2, y-1)
- mon.setBackgroundColor(colors.black)
- mon.setTextColor(colors.white)
- mon.write("BACK")
- end
- function inputPage(type)
- mon.clear()
- term.redirect(mon)
- term.setBackgroundColor(colors.lightGray)
- term.clear()
- x,y = term.getSize()
- term.setCursorPos(x/2-8, y/2-2)
- print("Set an address name")
- term.setCursorPos(x/2 - 4, y/2)
- print(" ")
- term.setCursorPos(x/2 - 4, y/2)
- nameInput = read()
- addressInput = "nil"
- term.setBackgroundColor(colors.lightGray)
- term.clear()
- term.setCursorPos(x/2-9, y/2-4)
- print("Enter Stargate address")
- if type == "secEntry" then
- term.setCursorPos(x/2-10, y/2-2)
- print("DO NOT ENTER ANY HYPHONS")
- end
- term.setBackgroundColor(colors.black)
- term.setCursorPos(x/2 - 5, y/2)
- print(" ")
- term.setCursorPos(x/2 - 5, y/2)
- addressInput = string.upper(read())
- newGate ={name = nameInput, address = addressInput}
- term.redirect(term.native())
- return newGate
- end
- function drawRemoteAddress(name)
- mon.setBackgroundColor(colors.black)
- mon.setTextColor(colors.blue)
- x,y = mon.getSize()
- mon.setCursorPos((x/2+1) - string.len(name)/2, y/2-2)
- mon.write(name)
- end
- if fs.exists("currentSec") then -- checks to see if there's list of gates stored for security reasons
- file = fs.open("currentSec", "r")
- currentSec = file.readAll()
- file.close()
- else
- currentSec = "NONE"
- end
- mon.setTextScale(1)
- drawHome()
- while true do
- event, param1, param2, param3 = os.pullEvent()
- if event == "monitor_touch" then
- x,y = mon.getSize()
- if param2 > x/2-15 and param2 <= x/2 and param3 >= y-3 and param3 <= y-1 then -- Click has opened dial menu
- status, int = sg.stargateState()
- if status == "Idle" then
- while true do
- drawBookmarksPage()
- event, param1, param2, param3 = os.pullEvent()
- if event == "monitor_touch" then
- if param3 >= y-2 then -- user clicked back
- drawHome()
- break
- else -- user has clicked on a bookmark
- if fs.exists(tostring(param3)) then
- file = fs.open(tostring(param3), "r")
- gateData = textutils.unserialize(file.readAll()) -- GATE DATA VARIABLE!!!
- file.close()
- drawHome()
- for k,v in pairs(gateData) do
- if k == "address" then
- ok, result = pcall(sg.dial, v)
- if ok then
- chat.say("Attention, ne reste pas en face de la porte quand elle s'ouvre ou tu risque de mourrir")
- drawRemoteAddress(gateData.name)
- status, int = sg.stargateState()
- drawSgStatus(status)
- else
- drawSgStatus("Error")
- end
- end
- end
- break
- end
- end
- else
- drawHome()
- break
- end
- end
- end
- elseif param2 > x/2+2 and param2 <= x/2+15 and param3 >= y-3 and param3 <= y-1 then -- user clicked TERM
- ok, result = pcall(sg.disconnect)
- drawChevrons()
- drawRemoteAddress(" ")
- end
- elseif event == "sgDialIn" then
- mon.setTextColor(colors.orange)
- if fs.exists("currentSec") then
- file = fs.open("currentSec", "r")
- currentSec = file.readAll()
- file.close()
- end
- if fs.exists("secList") then
- file = fs.open("secList", "r")
- secList = textutils.unserialize(file.readAll())
- for k,v in pairs(secList) do
- address = v.address
- if string.sub(v.address,1,7) == param2 or v.address == param2 then
- secGate = true
- end
- end
- end
- elseif event == "sgStargateStateChange" or "sgChevronEngaged" then
- drawDial()
- drawTerm()
- status, int = sg.stargateState()
- drawSgStatus(tostring(status))
- if status == "idle" then
- isConnected = false
- else
- isConnected = true
- end
- if event == "sgChevronEngaged" then
- mon.setTextColor(colors.orange)
- drawChev({param2, param3})
- if param2 == 1 then
- dialling = {}
- end
- table.insert(dialling, param2, param3)
- --drawRemoteAddress()
- elseif param2 == "Idle" then
- drawChevrons()
- elseif param2 == "Connected" then
- mon.setTextColor(colors.lightBlue)
- for k,v in pairs(dialling) do
- drawChev({k,v})
- end
- sg.sendMessage(sg.irisState())
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment