Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local sg = component.stargate
- local gpu = component.gpu
- local keyboard = require("keyboard")
- local w, h = gpu.getResolution()
- local term = require("term")
- local event = require("event")
- local filesystem = require("filesystem")
- local running = true
- local iris = false
- --address tables
- characters = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}
- numbers = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}
- --[[
- function textField(x, y, lenx, leny)
- local typing = true
- local type = true
- local character
- local text = ""
- local index = 0
- while typing and index<=(lenx-1) do
- gpu.set(x+index+1, y, "_")
- local _,_,key,p1 = event.pull("key_down")
- local char = keyboard.keys[p1]
- index = index + 1
- if (index==lenx) or (key==13) then
- gpu.set(x+index, y, " ")
- type = false
- typing = false
- gpu.set(x+index+1, y, " ")
- for i=1,index-1 do
- character = gpu.get(x+i, y)
- text = text..character
- end
- end
- if (key == 8) and (index > 1) then --backspace
- index = index - 1
- --text = string.sub(text, 1, index+1)
- gpu.set(x+index+1, y, " ")
- gpu.set(x+index, y, "_")
- index=index-1
- elseif (index >= 1) and (key ~= 13) then
- if char == "lshift" or char == "rshift" or char == "back" or char == "enter" then
- index=index-1
- else
- if keyboard.isShiftDown() then
- character = string.upper(char)
- else
- character = char
- end
- if char == "space" then
- character = " "
- elseif char == "numpad0" then
- character = "0"
- elseif char == "numpad1" then
- character = "1"
- elseif char == "numpad2" then
- character = "2"
- elseif char == "numpad3" then
- character = "3"
- elseif char == "numpad4" then
- character = "4"
- elseif char == "numpad5" then
- character = "5"
- elseif char == "numpad6" then
- character = "6"
- elseif char == "numpad7" then
- character = "7"
- elseif char == "numpad8" then
- character = "8"
- elseif char == "numpad9" then
- character = "9"
- elseif char == "numpadsub" or char == "minus" then
- character = "-"
- elseif char == "period" then
- character = "."
- end
- if type then
- gpu.set(x+index, y, character)
- end
- end
- end
- end
- return text
- end
- ]]
- function removeLines(filename, startingLine, numLines)
- local fp = io.open(filename, "r")
- if fp == nil then return nil end
- content = {}
- i = 1;
- for line in fp:lines() do
- if i < startingLine or i >= startingLine + numLines then
- content[#content+1] = line
- end
- i = i + 1
- end
- if i > startingLine and i < startingLine + numLines then return nil end
- fp:close()
- fp = io.open(filename, "w")
- for i = 1, #content do
- fp:write(string.format("%s\n", content[i]))
- end
- fp:close()
- end
- function wrap(str, limit)
- if (str == nil) or (str == " ") then return nil end
- local Lines, here, limit = {}, 1, limit or 72
- Lines[1] = string.sub(str,1,str:find("(%s+)()(%S+)()")-1)
- str:gsub("(%s+)()(%S+)()",
- function(sp, st, word, fi)
- if fi-here > limit then
- here = st
- Lines[#Lines+1] = word
- else Lines[#Lines] = Lines[#Lines].." "..word end
- end)
- return Lines
- end
- function tablelength(T)
- local count = 0
- for _ in pairs(T) do count = count + 1 end
- return count
- end
- local currentPage = 1
- local index = 0
- local locations = {}
- local addresses = {}
- --local numLines = 0
- for location in string.gmatch(sg.getLocations(), '([^,]+)') do
- table.insert(locations, location)
- end
- local addressBookRunning = true
- while addressBookRunning do
- --print(tablelength(locations))
- for iter = 1+((currentPage-1)*5), tablelength(locations) do
- --numLines = numLines + 1
- --print(iter..tablelength(locations))
- if (sg.getAddressForLocation(locations[iter]) ~= "None") then
- index = index + 1
- local coords = sg.getCoordinatesForLocation(locations[iter])
- local atmosphere = sg.getAtmosphereForLocation(locations[iter])
- local galaxy = sg.getGalaxyNameForLocation(locations[iter])
- local address = sg.getAddressForLocation(locations[iter])
- gpu.set(110, 4+index*7, "# "..index+((currentPage-1)*5))
- gpu.set(120, 4+index*7, locations[iter])
- gpu.set(110, 5+index*7, "Additional symbols: ")
- gpu.set(110, 6+index*7, "Atmosphere: "..atmosphere)
- gpu.set(110, 7+index*7, "Galaxy: "..galaxy)
- table.insert(addresses, address)
- local j = 0
- for i = 1,10 do
- local symbol = address:sub(i,i)
- if i<8 then
- j = j + 1
- gpu.set(10+(j-1)*15, 5+index*7, symbol)
- elseif i==8 then
- gpu.set(130, 5+index*7, symbol)
- elseif i==9 then
- gpu.set(132, 5+index*7, symbol)
- end
- end
- if index > 4 then
- --currentPage = currentPage + 1
- break
- end
- end
- end
- if override then return nil end
- --click handling
- local clicking = true
- while clicking do
- local _,_,x,y = event.pull(1, "touch")
- if x then
- --exit
- if ((x<w) and (x>w-5)) and ((y<2) and (y>0)) then
- addressBookRunning = false
- clicking = false
- break
- end
- --next page
- if ((x<153) and (x>149)) and ((y<h-2) and (y>h-4)) and (currentPage < 20) then
- gpu.setBackground(0x000000)
- gpu.fill(4, 10, w-10, 35, " ")
- gpu.fill(70, h-2, 74, 1, " ")
- gpu.setBackground(0x339D8F)
- gpu.fill(70+(currentPage*4), h-2, 2, 1, " ")
- currentPage = currentPage+1
- index = 0
- clicking = false
- end
- --prev. page
- if ((x<68) and (x>64)) and ((y<h-2) and (y>h-4)) and (currentPage > 1) then
- gpu.setBackground(0x000000)
- gpu.fill(4, 10, w-10, 35, " ")
- gpu.fill(70, h-2, 74, 1, " ")
- currentPage = currentPage-1
- gpu.setBackground(0x339D8F)
- gpu.fill(70+((currentPage-1)*4), h-2, 2, 1, " ")
- index = 0
- clicking = false
- end
- for i=0,4 do
- --dial
- if ((x<153) and (x>143)) and ((y<(14+i*7)) and (y>(12+i*7))) then
- addressBookRunning = false
- clicking = false
- ok, result = pcall(sg.dial, addresses[(i+1)+((currentPage-1)*5)])
- end
- end
- end
- end
- end
- resetGUI()
- end
- resetGUI()
- --Main loop
- while running do
- --Information
- local state, engaged, direction = sg.stargateState()
- local iris = sg.irisState()
- --drawButtons()
- gpu.setBackground(0x000000)
- gpu.setForeground(0xFFFFFF)
- --iris
- gpu.set(14, 4, iris.." ")
- --energy available
- local energy = sg.energyAvailable()
- --if energy > 5000000 then
- -- energy = 5000000
- --end
- energy = string.format("%d", energy/1000)
- --gpu.set(8, 20, energy.."/5000 kSU ")
- gpu.set(8, 20, energy.." kSU ")
- --energy required
- if (not (address == nil)) and (string.len(address) > 6) then
- --gpu.set(8, 24, sg.energyToDial(address))
- end
- --click handling
- local _,_,x,y = event.pull(1, "touch")
- if x then
- --address book
- if ((x<30) and (x>4)) and ((y<29) and (y>27)) then
- addressBook()
- end
- --dialing
- if ((x<30) and (x>4)) and ((y<11) and (y>9)) then
- gpu.fill(5, 10, 26, 1, " ")
- local typing = true
- local type = true
- local symbol
- address = ""
- local index = 0
- while typing and index<=11 do
- gpu.set(11+index+1, 10, "_")
- local _,_,key = event.pull("key_down")
- index = index + 1
- if (key == 8) and (index > 1) then --backspace
- index = index - 1
- address = string.sub(address, 1, index+1)
- gpu.set(11+index+1, 10, " ")
- gpu.set(11+index, 10, "_")
- index=index-1
- elseif index >= 1 then
- if ((key>47) and (key<58)) then
- symbol = numbers[key-47]
- end
- if ((key>96) and (key<123)) then
- symbol = characters[key-96]
- end
- if type then
- if symbol ~= null then
- gpu.set(11+index, 10, symbol)
- end
- end
- if index==4 then
- index = index + 1
- gpu.set(11+index, 10, "-")
- end
- if index==8 then
- index = index + 1
- gpu.set(11+index, 10, "-")
- end
- if index==11 then
- type = false
- gpu.set(11+index+1, 10, "_")
- for i=1,11 do
- symbol = gpu.get(11+i, 10)
- if symbol == "-" then
- address = address.."-"
- else
- address = address..symbol
- end
- end
- while true do
- local _,_,key = event.pull("key_down")
- if key == 13 then
- gpu.set(11+index+1, 10, " ")
- typing = false
- break
- term.clear()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement