Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --CONFIG
- local monitor = peripheral.wrap('top')
- local monitor2 = peripheral.wrap('monitor_4')
- --
- monitor2.setTextScale(0.5)
- monitor2.setBackgroundColor(colors.black)
- monitor2.clear()
- monitor2.setCursorPos(1,1)
- monitor2.setTextColor(colors.green)
- monitor2.write('Passed arguments: ')
- local stargate = peripheral.find('stargate')
- stargate.disconnect()
- stargate.openIris()
- monitor.clear()
- monitor.setTextScale(0.5)
- rednet.open('modem_6')
- local keyboard = {
- '1234567890_',
- 'QWERTYUIOP',
- 'ASDFGHJKL',
- 'ZXCVBNM',
- }
- local file = fs.open('destinations.cfg','r')
- local destinations = textutils.unserialise(file.readAll())
- file.close()
- local selected = 1
- local hasQueuedClose = false
- local manualSelection = 1
- local manualAddress = {'_','_','_','_','_','_','_','_','_'}
- function getKey(x,y)
- local success = true
- local yIndex = y-13
- local xIndex = nil
- if yIndex and yIndex > 0 and keyboard[yIndex] then
- xIndex = (x/2)-(18-(#keyboard[yIndex]/2))+10
- end
- if xIndex and xIndex%1~=0 and xIndex > 0 then
- success = false
- end
- if xIndex then
- xIndex = math.floor(xIndex)
- end
- local letterToGet = string.sub(keyboard[yIndex],xIndex,xIndex)
- if not success then
- letterToGet = nil
- end
- return letterToGet
- end
- function redrawScreen(drawKeyboard)
- monitor.setBackgroundColor(colors.black)
- monitor.clear()
- if selected~=1 then
- manualSelection = 1
- end
- for i,v in pairs(destinations) do
- if selected == 1 and i == 1 then
- monitor.setTextColor(colors.white)
- monitor.setCursorPos(1,i)
- monitor.setBackgroundColor(colors.gray)
- monitor.clearLine()
- monitor.write(v[1])
- monitor.setTextColor(colors.green)
- monitor.write(' - ')
- for pos = 1,#v[2] do
- if pos == manualSelection then
- monitor.setBackgroundColor(colors.lightGray)
- monitor.setTextColor(colors.red)
- else
- monitor.setBackgroundColor(colors.gray)
- monitor.setTextColor(colors.cyan)
- end
- monitor.write(string.sub(v[2],pos,pos))
- end
- else
- monitor.setTextColor(colors.white)
- monitor.setCursorPos(1,i)
- if selected == i then
- monitor.setBackgroundColor(colors.gray)
- monitor.clearLine()
- else
- monitor.setBackgroundColor(colors.black)
- end
- monitor.write(v[1])
- monitor.setTextColor(colors.green)
- monitor.write(' - ')
- monitor.setTextColor(colors.cyan)
- monitor.write(v[2])
- end
- end
- monitor.setTextColor(colors.white)
- if drawKeyboard then
- for i,v in pairs(keyboard) do
- monitor.setCursorPos(18-(#v),i+13)
- for pos = 1,#v do
- monitor.setBackgroundColor(colors.gray)
- monitor.write(string.sub(v,pos,pos))
- monitor.setBackgroundColor(colors.black)
- monitor.write(' ')
- end
- end
- end
- monitor.setBackgroundColor(colors.green)
- monitor.setCursorPos(16,18)
- monitor.write('Dial')
- monitor.setTextColor(colors.gray)
- monitor.setCursorPos(2,23)
- monitor.setBackgroundColor(colors.black)
- monitor.write('Stargate ID: '..stargate.localAddress())
- end
- function queueClose(dialLength)
- hasQueuedClose = true
- redrawScreen(false)
- local oldTerm = term.current()
- if dialLength then
- repeat
- sleep()
- local state = {stargate.stargateState()}
- term.redirect(monitor)
- term.setBackgroundColor(colors.lightGray)
- paintutils.drawLine(2,20,35,20)
- term.setBackgroundColor(colors.green)
- paintutils.drawLine(2,20,2+math.min(33,(state[2]/dialLength)*34),20)
- until state[1] == 'Connected' or state[1] == 'Closed'
- end
- term.redirect(oldTerm)
- monitor.setCursorPos(2,24)
- monitor.setTextColor(colors.green)
- monitor.setBackgroundColor(colors.black)
- monitor.write('Connected to: '..stargate.remoteAddress())
- monitor.setCursorPos(1,20)
- monitor.setBackgroundColor(colors.green)
- monitor.clearLine()
- monitor.setBackgroundColor(colors.black)
- monitor.setCursorPos(1,20)
- monitor.write(' ')
- monitor.setCursorPos(36,20)
- monitor.write(' ')
- monitor.setBackgroundColor(colors.red)
- for progress = 1,68 do
- monitor.setCursorPos((math.floor((progress/68)*33))+2,20)
- monitor.write(' ')
- stargate.sendMessage('Time Remaining:',tostring(68-progress))
- sleep(1)
- end
- stargate.disconnect()
- hasQueuedClose = false
- monitor2.setBackgroundColor(colors.black)
- monitor2.clear()
- monitor2.setCursorPos(1,1)
- monitor2.setTextColor(colors.green)
- monitor2.write('Passed arguments: ')
- redrawScreen(selected==1)
- end
- function mainThread()
- while true do
- local state = stargate.stargateState()
- if not hasQueuedClose then
- redrawScreen(selected==1)
- end
- repeat
- sleep()
- until not hasQueuedClose
- local event = {os.pullEvent('monitor_touch')}
- state = stargate.stargateState()
- if event[4] < 13 and not hasQueuedClose then
- selected = math.min(event[4],#destinations)
- elseif event[4] >= 13 and event[4] < 18 and selected == 1 then
- local returnKey = getKey(event[3],event[4])
- if returnKey then
- manualAddress[manualSelection] = returnKey
- destinations[1][2] = ''
- for i,v in pairs(manualAddress) do
- destinations[1][2] = destinations[1][2]..v
- end
- manualSelection = manualSelection+1
- if manualSelection > 9 then
- manualSelection = 1
- end
- end
- elseif event[4] == 18 and not hasQueuedClose then
- if event[3] >= 16 and event[3] <= 20 then
- local dialAddress = destinations[selected][2]
- local newAddress = ''
- for num = 1,#dialAddress do
- if string.sub(dialAddress,num,num) ~= '_' then
- newAddress = newAddress..string.sub(dialAddress,num,num)
- end
- end
- local success = stargate.dial(newAddress)
- if not success then
- redrawScreen(false)
- monitor.setCursorPos(12,16)
- monitor.setBackgroundColor(colors.black)
- monitor.setTextColor(colors.red)
- monitor.write('Invalid Code')
- os.pullEvent('monitor_touch')
- else
- queueClose(#destinations[selected][2])
- end
- end
- end
- end
- end
- function irisManagement()
- while true do
- sleep()
- local state = {stargate.stargateState()}
- if state[1] ~= 'Idle' and state[1] ~= 'Connected' then
- stargate.closeIris()
- else
- stargate.openIris()
- end
- end
- end
- function manageIncomingConnections()
- while true do
- sleep()
- local state = {stargate.stargateState()}
- if state[1] == 'Connected' and state[3] == 'Incoming' then
- queueClose()
- end
- end
- end
- function drawPassedArgs()
- while true do
- sleep()
- local event = {os.pullEvent('sgMessageReceived')}
- monitor2.clear()
- monitor2.setCursorPos(1,1)
- monitor2.setTextColor(colors.green)
- monitor2.write('Passed arguments: ')
- monitor2.setTextColor(colors.white)
- for i,v in pairs(event) do
- monitor2.setCursorPos(1,i+2)
- monitor2.setTextColor(colors.cyan)
- monitor2.write(i..'- ')
- monitor2.setTextColor(colors.white)
- monitor2.write(tostring(v))
- end
- end
- end
- parallel.waitForAll(irisManagement,mainThread,manageIncomingConnections,drawPassedArgs)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement