Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[ LanteaCraft ]]--
- --[[ and SGCraft ]]--
- --[[ ccDHD Lite ]]--
- --[[ by Dog ]]--
- --[[ a k a ]]--
- --[[ HydrantHunter ]]--
- --[[ pastebin: ]]--
- --[[ ieFgzNMf ]]--
- local ccDHDliteVer = "2.0.00"
- --[[
- Tested with/requires:
- - Minecraft 1.7.10+ AND ComputerCraft 1.75+ || LanteaCraft LC2-16+ | OR | SGCraft1.11.x-mc1.7.10+
- - An advanced computer connected directly or via modem/network cable to...
- - A Stargate (LanteaCraft) or Stargate/CC adapter (SGCraft)
- Special thanks to theoriginalbit (custom read function, newButton function)
- IMPORTANT NOTE: DO NOT EDIT this script - all variables are set automatically
- ]]--
- local termX, termY = term.getSize()
- local gate, screen, currentGate, incomingAddress, updateTimer, drawHelpScreen, userInput
- local kernelState, irisState, lcGate, gateChange, addrRedraw, continueDialing, spinTime, autoDisengage = false, false, false, false, false, false, false, false
- local gatePage, gatePages, logPage, logPages, abCount, chevronNumber, fuelPercent, MAXFUEL_LC, MAXFUEL_SG = 1, 1, 1, 1, 1, 0, 0, 100, 200000
- local callHistory, guiElements = { }, { }
- local addressBook = { { name = "NEW GATE", addr = "ADDRESS", rating = "U", iris = "none", callDrop = false, note = "short note", loc = { x = 0, y = 0, z = 0, dim = "Unspecified", }, }, }
- local thisGate, gateStatus, gateTarget, cachedInput = "!!ERROR!!", "Idle", "No Target", ""
- local gateData, historyData = "/data/DHDgates", "/data/DHDhistory"
- local classifications = {
- B = { order = 1, color = colors.blue, label = "Base/Outpost/Hub" };
- H = { order = 2, color = colors.lightBlue, label = "Home/Camp" };
- V = { order = 3, color = colors.brown, label = "Village" };
- M = { order = 4, color = colors.purple, label = "Misc/Special" };
- S = { order = 5, color = colors.green, label = "Safe/Secured" };
- C = { order = 6, color = colors.orange, label = "Caution" };
- D = { order = 7, color = colors.red, label = "Danger" };
- U = { order = 8, color = colors.lightGray, label = "Unk/Unclassified", long = "Unknown/Unclassified" };
- }
- local sgStates = {
- Idle = "Idle",
- Dialing = "Dialing",
- Dialling = "Dialing",
- Opening = "Dialing",
- Connected = "Connected",
- Closing = "Closing",
- Offline = "Offline",
- }
- --# custom read function courtesy of theoriginalbit (modified by Dog)
- local function read(_mask, _history, _limit, _noTerminate, _noMouse, _gField)
- if _mask and type(_mask) ~= "string" then
- error("Invalid parameter #1: Expected string, got " .. type(_mask), 2)
- end
- if _history and type(_history) ~= "table" then
- error("Invalid parameter #2: Expected table, got " .. type(_history), 2)
- end
- if _limit and type(_limit) ~= "number" then
- error("Invalid parameter #3: Expected number, got " .. type(_limit), 2)
- end
- if _noTerminate and type(_noTerminate) ~= "boolean" then
- error("Invalid argument #4: Expected boolean, got " .. nativeType(_noTerminate), 2)
- end
- if _noMouse and type(_noMouse) ~= "boolean" then
- error("Invalid argument #5: Expected boolean, got " .. nativeType(_noMouse), 2)
- end
- if _gField and type(_gField) ~= "boolean" then
- error("Invalid argument #6: Expected boolean, got " .. nativeType(_gField), 2)
- end
- term.setCursorBlink(true)
- local symbols = { ["A"] = true, ["B"] = true, ["C"] = true, ["D"] = true, ["E"] = true , ["F"] = true, ["G"] = true, ["H"] = true, ["I"] = true, ["J"] = true, ["K"] = true, ["L"] = true, ["M"] = true, ["N"] = true, ["O"] = true, ["P"] = true, ["Q"] = true, ["R"] = true, ["S"] = true, ["T"] = true, ["U"] = true, ["V"] = true, ["W"] = true, ["X"] = true, ["Y"] = true, ["Z"] = true, ["0"] = true, ["1"] = true, ["2"] = true, ["3"] = true, ["4"] = true, ["5"] = true, ["6"] = true, ["7"] = true, ["8"] = true, ["9"] = true, ["-"] = true, ["+"] = true }
- local mouseLimit = _limit or 0
- local input = ""
- cachedInput = ""
- local pos = 0
- local historyPos = nil
- local pullEvent = _noTerminate and os.pullEventRaw or os.pullEvent
- local sw, sh = term.getSize()
- local sx, sy = term.getCursorPos()
- local function redraw(_special)
- local scroll = (sx + pos >= sw and (sx + pos) - sw or 0)
- local replace = _special or _mask
- local output = replace and (string.rep(replace, math.ceil(#input / #replace) - scroll)):sub(1, #input) or input:sub(scroll + 1)
- term.setCursorPos(sx, sy)
- term.write(output)
- term.setCursorPos(sx + pos - scroll, sy)
- end
- local nativeScroll = term.scroll
- term.scroll = function(_n) local ok, err = pcall(function() return nativeScroll(_n) end) if ok then sy = sy - _n return err end error(err, 2) end
- local function historyHandler(value)
- redraw(' ')
- if value == -1 or value == keys.up then
- if not historyPos then
- historyPos = #_history
- elseif historyPos > 1 then
- historyPos = historyPos - 1
- end
- else
- if historyPos ~= nil and historyPos < #_history then
- historyPos = historyPos + 1
- elseif historyPos == #_history then
- historyPos = nil
- end
- end
- if historyPos and #_history > 0 then
- input = string.sub(_history[historyPos], 1, _limit) or ""
- pos = #input
- cachedInput = input
- if not _limit then mouseLimit = pos end
- else
- input = ""
- pos = 0
- cachedInput = input
- if not _limit then mouseLimit = 0 end
- end
- end
- while true do
- local event, code, mX, mY = pullEvent()
- if event == "char" and (not _limit or #input < _limit) then
- local goodData = false
- if _gField then
- if symbols[code:upper()] then
- code = code:upper()
- goodData = true
- end
- else
- goodData = true
- end
- if goodData then
- input = input:sub(1, pos) .. code .. input:sub(pos + 1)
- pos = pos + 1
- cachedInput = input
- if not _limit then mouseLimit = math.min(mouseLimit + 1, sw - (sw - sx)) end
- end
- elseif event == "paste" and (not _limit or #input < _limit) then
- if _limit and #input + #code > _limit then
- code = code:sub(1, _limit - #input)
- end
- if _gField then
- local newWord, glyph = { }, ""
- for i = 1, #code do
- glyph = string.upper(code:sub(i, i))
- newWord[i] = symbols[glyph] and glyph or "?"
- end
- code = table.concat(newWord)
- end
- input = input:sub(1, pos) .. code .. input:sub(pos + 1)
- pos = pos + #code
- cachedInput = input
- if not _limit then mouseLimit = math.min(mouseLimit + #code, sw - (sw - sx)) end
- elseif event == "key" then
- if code == keys.enter or code == keys.numPadEnter then
- cachedInput = ""
- break
- elseif code == keys.backspace and pos > 0 then
- redraw(' ')
- input = input:sub(1, math.max(pos - 1, 0)) .. input:sub(pos + 1)
- pos = math.max(pos - 1, 0)
- cachedInput = input
- if not _limit then mouseLimit = math.max(mouseLimit - 1, 0) end
- elseif code == keys.delete and pos < #input then
- redraw(' ')
- input = input:sub(1, pos)..input:sub(pos + 2)
- cachedInput = input
- if not _limit then mouseLimit = math.max(mouseLimit - 1, 0) end
- elseif code == keys.home then
- pos = 0
- elseif code == keys["end"] then
- pos = #input
- elseif code == keys.left and pos > 0 then
- pos = math.max(pos - 1, 0)
- elseif code == keys.right and pos < #input then
- pos = math.min(pos + 1, #input)
- elseif _history and (code == keys.up or code == keys.down) then
- historyHandler(code)
- end
- elseif event == "mouse_click" and not _noMouse and ((mX < sx or mX >= sx + mouseLimit) or (mY ~= sy)) then
- cachedInput = ""
- break
- elseif event == "mouse_scroll" and _history then
- historyHandler(code)
- end
- redraw(_mask)
- end
- term.scroll = nativeScroll
- term.setCursorBlink(false)
- if sy + 1 > sh then
- term.scroll(sy + 1 - sh)
- term.setCursorPos(1, sy)
- else
- term.setCursorPos(1, sy + 1)
- end
- return input
- end
- --# newButton function courtesy of theoriginalbit (modified by Dog)
- local function newButton(x, y, w, h, text, bc, tc, action, name, mbtn)
- w = math.max(type(w) == "number" and w or 1, 1)
- h = math.max(type(h) == "number" and h or 1, 1)
- mbtn = (type(mbtn) == "number" and mbtn >= 1 and mbtn <= 3) and mbtn or 1
- action = action or function() end
- name = (type(name) == "string" and #name > 0) and name or "noName"
- local hx = x + math.ceil((w - #text) / 2)
- local hy = y + math.ceil(h / 2) - 1
- local enabled = true
- local dbc, dtc = colors.lightGray, colors.gray
- return {
- getType = function()
- return "button"
- end;
- getName = function()
- return name
- end;
- setDisabledColors = function(bc, tc)
- dbc = bc
- dtc = tc
- end;
- setText = function(t)
- text = t or ""
- hx = x + math.ceil((w - #text) / 2) --# recalculate offset
- end;
- setEnabled = function(e)
- enabled = e == true
- end;
- render = function()
- term.setBackgroundColor(enabled and bc or dbc)
- term.setTextColor(enabled and tc or dtc)
- for i = 0, h - 1 do
- term.setCursorPos(x, y + i)
- write(string.rep(' ', w))
- end
- term.setCursorPos(hx, hy)
- write(text)
- end;
- processEvent = function(event, button, xPos, yPos)
- if enabled and event == "mouse_click" and button == mbtn and
- xPos >= x and xPos <= (x + w - 1) and
- yPos >= y and yPos <= (y + h - 1) then
- return action()
- end
- end;
- }
- end
- local function saveData(fileName)
- local dhdData = fs.open(fileName, "w")
- dhdData.write(textutils.serialize(addressBook))
- dhdData.close()
- if fileName == gateData then gateChange = false end
- end
- local function ingestData(fileName)
- if fileName == "logs" then
- if fs.exists(historyData) then
- for log_entry in io.lines(historyData) do
- table.insert(callHistory, 1, log_entry)
- end
- end
- logPages = math.max(1, math.ceil(#callHistory / 11)) --# paginate call logs
- else
- if fs.exists(fileName) then
- for i = abCount, 1, -1 do
- addressBook[i] = nil
- end
- local dhdData = fs.open(fileName, "r")
- addressBook = textutils.unserialize(dhdData.readAll())
- dhdData.close()
- abCount = #addressBook
- local saveIt = false
- if addressBook[1].callDrop == nil then
- for i = 1, abCount do
- addressBook[i].callDrop = false
- end
- saveIt = true
- end
- for i = 1, abCount do
- if addressBook[i].iris == "open" then
- addressBook[i].iris, saveIt = true, true
- elseif addressBook[i].iris == "close" then
- addressBook[i].iris, saveIt = false, true
- end
- end
- if saveIt and fileName == gateData then saveData(gateData) end
- gatePage, gatePages = 1, math.ceil(abCount / 21) --# paginate address book
- gateChange = fileName ~= gateData
- end
- end
- end
- local function mergeData() --# merge two address books into one
- if not fs.exists("/disk/data/DHDgates") then return end
- local dhdData = fs.open("/disk/data/DHDgates", "r")
- local newGates = textutils.unserialize(dhdData.readAll())
- dhdData.close()
- local matchFound, abName, abNote, abDim, ngName, ngNote, ngDim = false --# matchFound indicates if a matching gate was found or not
- for i = 1, #newGates do --# start cycling through the 'new' list of gates
- for j = 1, abCount do --# search the address book for a matching address
- if newGates[i].addr == addressBook[j].addr then --# if the gate is already in the address book...
- matchFound = true --# ...set matchFound to true and...
- abName, ngName = addressBook[j].name, newGates[i].name
- if (abName == "Name" or abName == "NO GATES" or abName == "NEW GATE" or abName == addressBook[j].addr) and ngName ~= newGates[i].addr and ngName ~= "NEW GATE" and ngName ~= "NO GATES" and ngName ~= "Name" then
- addressBook[j].name = ngName
- gateChange = true
- end
- abNote, ngNote = addressBook[j].note, newGates[i].note
- if (abNote == "short note" or abNote == "Discovered gate" or abNote == "Added from logs") and ngNote ~= "short note" and ngNote ~= "Discovered gate" and ngNote ~= "Added from logs" then
- addressBook[j].note = ngNote
- gateChange = true
- end
- if addressBook[j].rating == "U" and newGates[i].rating ~= "U" then
- addressBook[j].rating = newGates[i].rating
- gateChange = true
- end
- abDim, ngDim = addressBook[j].loc.dim, newGates[i].loc.dim
- if (abDim == "Overworld" and ngDim ~= "Overworld" and ngDim ~= "Unspecified") or (abDim == "Unspecified" and ngDim ~= "Unspecified") then
- addressBook[j].loc.dim = ngDim
- gateChange = true
- end
- if addressBook[j].loc.x == 0 and addressBook[j].loc.y == 0 and addressBook[j].loc.z == 0 and (newGates[i].loc.x ~= 0 or newGates[i].loc.y ~= 0 or newGates[i].loc.z ~= 0) then
- addressBook[j].loc.x, addressBook[j].loc.y, addressBook[j].loc.z = newGates[i].loc.x, newGates[i].loc.y, newGates[i].loc.z
- gateChange = true
- end
- break --# stop the address book search loop and move on to the next gate in the 'new' list
- end
- end
- if matchFound then --# if a match was found...
- matchFound = false --# ...reset the variable for the next iteration of the loop
- else --# otherwise...
- addressBook[abCount + 1], abCount = { }, abCount + 1 --# initialize a new address book entry
- for k, v in pairs(newGates[i]) do --# loop through the gate entries...
- addressBook[abCount][k] = v --# ...and add them to the new address book entry
- end
- addressBook[abCount].iris = "none"
- addressBook[abCount].callDrop = false
- gateChange = true --# indicate that address book data has changed
- end
- end
- gatePages = math.ceil(abCount / 24) --# repaginate AddressBook
- end
- local function recordSessionData() --# Human readable log files
- local logAddress = gateTarget or "ERROR" --# set logAddress
- logAddress = gateTarget == "Wormhole " and "N/A" or logAddress
- local callDirection = incomingAddress and "Incoming" or "Outgoing" --# set callDirection
- local callTime = textutils.formatTime(os.time(), false) --# format the time
- if #callTime == 7 then callTime = " " .. callTime end --# move single digit hour times to the right one space
- local dataLine = tostring(os.day()) .. " @ " .. callTime .. " <" .. callDirection .. "> " .. logAddress
- local callArchive = fs.open(historyData, fs.exists(historyData) and "a" or "w")
- callArchive.writeLine(dataLine)
- callArchive.close()
- local previousCall = fs.open("/data/DHDlastCall", "w") --# record last call
- previousCall.writeLine(dataLine)
- previousCall.close()
- end
- local function getFuelLevel()
- return (lcGate and math.min(100, math.floor((100 / MAXFUEL_LC) * 100)) or math.min(100, math.floor((gate.energyAvailable() / MAXFUEL_SG) * 100)))
- end
- local function assignColor(gateNumber)
- return classifications[addressBook[gateNumber].rating].color or colors.lightGray
- end
- local function assignRating(gateNumber)
- return classifications[addressBook[gateNumber].rating].long or (classifications[addressBook[gateNumber].rating].label or "Unknown/Unclassified")
- end
- local function clearCallHistory()
- for i = #callHistory, 1, -1 do
- callHistory[i] = nil
- end
- end
- local function clearScreen()
- term.setBackgroundColor(colors.black)
- term.clear()
- end
- local function clearArea(area, bgColor)
- local x, y, w, h --# w, h are NOT width, height - they are the stopX, stopY values
- if area == "lower" then
- x, y, w, h = 1, 4, termX, termY
- elseif area == "data" then
- x, y, w, h = 14, 5, termX, termY - 1
- end
- paintutils.drawFilledBox(x, y, w, h, bgColor or colors.black)
- end
- local function redrawInput()
- term.setCursorPos(screen == "gatePage" and 31 or 24, termY - 2)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- if cachedInput ~= "" then term.write(cachedInput) end
- end
- local function drawAddressButton()
- term.setBackgroundColor(colors.blue)
- term.setTextColor(gateChange and colors.lime or colors.white)
- term.setCursorPos(2, 13)
- term.write("Addr Book")
- end
- local function drawControlSwitches(iris, callDrop)
- if iris ~= nil then
- term.setCursorPos(31, 5)
- if iris == "none" then
- term.setBackgroundColor(colors.green)
- term.write(" ")
- term.setBackgroundColor(colors.gray)
- term.write(" ")
- term.setBackgroundColor(colors.red)
- term.write(" ")
- else
- term.setBackgroundColor(iris and colors.green or colors.gray)
- term.write(" ")
- term.setBackgroundColor(iris and colors.gray or colors.red)
- term.write(" ")
- end
- end
- if callDrop ~= nil then
- term.setCursorPos(31, 7)
- term.setBackgroundColor(callDrop and colors.green or colors.gray)
- term.write(" ")
- term.setBackgroundColor(callDrop and colors.gray or colors.red)
- term.write(" ")
- end
- end
- local function drawPopUp(which)
- if which == "clearLogs" then
- term.setBackgroundColor(colors.blue)
- term.setTextColor(colors.white)
- term.setCursorPos(20, math.floor(termY / 2) - 2)
- term.write(" Clear Logs? ")
- paintutils.drawFilledBox(20, math.floor(termY / 2) - 1, 32, math.floor(termY /2 ) + 1, colors.gray)
- term.setBackgroundColor(colors.green)
- term.setCursorPos(21, math.floor(termY / 2))
- term.write(" YES ")
- term.setBackgroundColor(colors.red)
- term.setCursorPos(27, math.floor(termY / 2))
- term.write(" N O ")
- elseif which == "exodus" then
- term.setBackgroundColor(colors.blue)
- term.setTextColor(colors.white)
- term.setCursorPos(20, 9)
- term.write(" Save Addr Book? ")
- paintutils.drawFilledBox(20, 10, 38, 12, colors.gray)
- term.setBackgroundColor(colors.green)
- term.setCursorPos(22, 11)
- term.write(" Save ")
- term.setBackgroundColor(colors.orange)
- term.setCursorPos(31, 11)
- term.write(" Quit ")
- elseif which == "abManagement" then
- term.setBackgroundColor(colors.blue)
- term.setTextColor(colors.white)
- term.setCursorPos(16, 10)
- term.write(" Address Book Mgt. ")
- paintutils.drawFilledBox(16, 11, 34, 17, colors.gray)
- local buttonName
- for _, button in pairs(guiElements.addrBookMgt) do
- buttonName = button.getName()
- if buttonName == "ABSave" then
- button.setEnabled(gateChange)
- elseif buttonName == "ABLoad" then
- button.setEnabled(gateChange)
- elseif buttonName == "ABImport" then
- button.setEnabled(fs.exists("/disk/data/DHDgates"))
- elseif buttonName == "ABExport" then
- button.setEnabled(fs.exists("/disk"))
- end
- button.render()
- end
- elseif which == "page" then
- term.setBackgroundColor(colors.gray)
- term.setTextColor(colors.white)
- for i = 1, 3 do
- term.setCursorPos(screen == "gatePage" and 29 or 22, termY - 4 + i)
- term.write(i == 1 and " :Page: " or " ")
- end
- term.setBackgroundColor(colors.black)
- term.setCursorPos(screen == "gatePage" and 30 or 23, termY - 2)
- term.write(" ")
- end
- end
- local function drawHeader()
- term.setTextColor(colors.white)
- local line = string.rep(" ", 48)
- for i = 1, 3 do
- term.setCursorPos(1, i)
- term.setBackgroundColor(colors.blue)
- term.write(line)
- term.setBackgroundColor(colors.red)
- term.write(i == 2 and " X " or " ")
- end
- term.setBackgroundColor(colors.blue)
- term.setTextColor(colors.lightBlue)
- local headerText = thisGate
- for i = 1, abCount do
- if addressBook[i].addr == thisGate then
- headerText = addressBook[i].name .. " (" .. thisGate .. ")"
- break
- end
- end
- term.setCursorPos(math.floor((termX - #headerText) / 2), 2)
- term.write(headerText)
- end
- local function drawFooter()
- term.setBackgroundColor(colors.gray)
- term.setTextColor(colors.lightGray)
- term.setCursorPos((screen == "main" or screen == "manage") and 13 or 1, termY)
- term.write(string.rep(" ", (screen == "main" or screen == "manage") and termX - 12 or termX))
- local cX = (screen == "main" or screen == "manage") and (math.ceil(termX / 2) - (#tostring(gatePage) + #tostring(gatePages) + 4) / 2) + 7 or (math.ceil(termX / 2) - (#tostring(logPage) + #tostring(logPages) + 4) / 2)
- term.setCursorPos(cX, termY)
- term.write((screen == "main" or screen == "manage") and (tostring(gatePage) .. " of " .. tostring(gatePages)) or (tostring(logPage) .. " of " .. tostring(logPages)))
- if ((screen == "main" or screen == "manage") and gatePages > 1) or screen == "logs" then
- for _, button in pairs((screen == "main" or screen == "manage") and guiElements.mainFooter or guiElements.logButtons) do
- button.render()
- end
- end
- end
- local function drawGateFooter()
- term.setCursorPos(1, termY)
- if gateChange then
- term.setBackgroundColor(colors.orange)
- term.setTextColor(colors.black)
- term.write(" Change detected: Remember to save the Address Book ")
- term.setBackgroundColor(colors.black)
- else
- term.setBackgroundColor(colors.black)
- term.write(string.rep(" ", termX))
- end
- end
- do
- local helpTable = {
- [1] = { x = 2, y = 5, text = "Main Screen" };
- [2] = { x = 2, y = 10, text = "Addr Book Btn" };
- [3] = { x = 4, y = 12, text = "(popup)" };
- [4] = { x = 2, y = 16, text = "Log Screen" };
- [5] = { y = 6, text = "Left click" };
- [6] = { y = 7, text = "Right click" };
- [7] = { y = 8, text = "Middle click" };
- [8] = { y = 11, text = "Right click" };
- [9] = { y = 13, text = "Import/Export" };
- [10] = { y = 14, text = "Load/Save" };
- [11] = { y = 17, text = "Left click" };
- [12] = { y = 18, text = "Right click" };
- [13] = { y = 7, text = "an address to view/edit details" };
- [14] = { y = 8, text = "an address to delete" };
- [15] = { y = 11, text = "Save/update the Address Book" };
- [16] = { y = 13, text = "Copy Addr Book FROM/TO floppy disk" };
- [17] = { y = 14, text = "Load/Save the Address Book" };
- [18] = { y = 17, text = "an address to dial" };
- [19] = { y = 18, text = "an address to add to Address Book" };
- }
- drawHelpScreen = function()
- clearArea("lower", colors.white)
- paintutils.drawFilledBox(1, 4, 15, termY, colors.gray)
- term.setTextColor(colors.black)
- for i = 1, 4 do
- term.setCursorPos(helpTable[i].x, helpTable[i].y)
- term.write(helpTable[i].text)
- end
- term.setTextColor(colors.lightGray)
- for i = 5, 12 do
- term.setCursorPos(2, helpTable[i].y)
- term.write(helpTable[i].text)
- end
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.gray)
- term.setCursorPos(17, 6)
- term.write(lcGate and "an address to dial/pause" or "an address to dial")
- for i = 13, 19 do
- term.setCursorPos(17, helpTable[i].y)
- term.write(helpTable[i].text)
- end
- end
- end
- local function drawLogData()
- if logPage == logPages and logPages > 1 then
- paintutils.drawFilledBox(1, 6, termX, termY, colors.white)
- end
- drawFooter()
- term.setBackgroundColor(colors.white)
- local currentEntry = ((logPage - 1) * 11) + 1 --# Set the first entry to show (based on page number)
- local spacer = string.rep(" ", 9)
- local callHistoryCount = #callHistory
- local callDir, callAddr, addr, match
- for i = currentEntry, math.min(currentEntry + 10, callHistoryCount) do --# Display logs
- callDir = callHistory[i]:sub(callHistory[i]:find("<") + 1, callHistory[i]:find(">") - 1)
- term.setTextColor((callDir == "Inbound" or callDir == "Incoming") and colors.gray or ((callDir == "Outbound" or callDir == "Outgoing") and colors.lightGray or colors.red))
- term.setCursorPos(2, i - currentEntry + 7) --# position entry
- term.write(callHistory[i]:sub(1, callHistory[i]:find("@") - 2) .. " ") --# write day
- term.setCursorPos(8, i - currentEntry + 7) --# position entry
- term.write(callHistory[i]:sub(callHistory[i]:find("@") + 2, callHistory[i]:find("M")) .. " ") --# write time
- term.setCursorPos(18, i - currentEntry + 7) --# position entry
- term.write(callDir .. " ") --# write direction
- term.setCursorPos(28, i - currentEntry + 7) --# position entry
- callAddr = callHistory[i]:sub(callHistory[i]:find(">") + 2) --# set address
- term.setTextColor((callDir == "Inbound" or callDir == "Incoming") and colors.cyan or ((callDir == "Outbound" or callDir == "Outgoing") and colors.lightBlue or colors.orange))
- term.write(callAddr .. string.rep(" ", 9 - #callAddr)) --# write address
- term.setCursorPos(39, i - currentEntry + 7) --# position entry
- term.setTextColor((callDir == "Inbound" or callDir == "Incoming") and colors.gray or ((callDir == "Outbound" or callDir == "Outgoing") and colors.lightGray or colors.red))
- match = false
- for j = 1, abCount do
- addr = addressBook[j].addr
- if addr == callAddr or addr:sub(1, 7) == callAddr or addr == callAddr:sub(1, 7) then
- term.write(addressBook[j].name .. string.rep(" ", 12 - #addressBook[j].name)) --# write name
- match = true
- break
- end
- end
- if not match then term.write(" ") end
- end
- end
- local function drawLogScreen()
- if not callHistory[1] then
- term.setCursorPos(2, 6)
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.gray)
- term.write("No Logs")
- for _, button in pairs(guiElements.logButtons) do
- button.setEnabled(false)
- end
- return
- end
- for _, button in pairs(guiElements.logButtons) do
- button.setEnabled(true)
- end
- term.setBackgroundColor(colors.gray) --#
- term.setTextColor(colors.white) --#
- term.setCursorPos(1, 4) --# Header
- term.write(string.rep(" ", termX)) --#
- term.setCursorPos(1, 5) --#
- term.write(" Day Time Vector Address ") --#
- drawLogData()
- end
- local function drawRatingList(rating)
- local txtColor
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.blue)
- term.setCursorPos(18, 6)
- term.write(" Classification ")
- paintutils.drawFilledBox(18, 7, 37, 16, colors.gray)
- for k, v in pairs(classifications) do
- if rating == k then
- txtColor = rating == "U" and colors.white or v.color
- paintutils.drawPixel(37, v.order + 7, v.color) --# current rating color pip
- else
- txtColor = colors.lightGray
- end
- paintutils.drawPixel(18, v.order + 7, v.color) --# color pip
- term.setBackgroundColor(colors.gray)
- term.setTextColor(txtColor)
- term.setCursorPos(20, v.order + 7)
- term.write(v.label)
- end
- end
- local function drawGateData()
- term.setTextColor(colors.lightBlue)
- term.setCursorPos(11, 5)
- term.write(addressBook[currentGate].name .. string.rep(" ", 12 - #addressBook[currentGate].name))
- term.setTextColor(colors.brown)
- term.setCursorPos(13, 13)
- term.write(addressBook[currentGate].loc.dim .. string.rep(" ", 19 - #addressBook[currentGate].loc.dim))
- local gateNum = tostring(currentGate)
- term.setCursorPos(termX - 6, 5)
- term.setTextColor(colors.white)
- term.write(gateNum .. string.rep(" ", 6 - #gateNum))
- term.setCursorPos(8, 9)
- term.write(addressBook[currentGate].note .. string.rep(" ", 43 - #addressBook[currentGate].note))
- term.setTextColor(colors.yellow)
- term.setCursorPos(11, 7)
- term.write(addressBook[currentGate].addr .. " ")
- local ratingWord = assignRating(currentGate)
- term.setTextColor(assignColor(currentGate))
- term.setCursorPos(18, 11)
- term.write(ratingWord .. string.rep(" ", 20 - #ratingWord))
- if not lcGate then drawControlSwitches(addressBook[currentGate].iris, addressBook[currentGate].callDrop) term.setBackgroundColor(colors.black) end
- term.setCursorPos(termX - 14, 7)
- term.setTextColor(colors.gray)
- term.write(addressBook[currentGate].addr == thisGate and "< This Gate >" or " ")
- local xStr, yStr, zStr = tostring(addressBook[currentGate].loc.x), tostring(addressBook[currentGate].loc.y), tostring(addressBook[currentGate].loc.z)
- term.setTextColor(colors.lightGray)
- term.setCursorPos(14, 15)
- term.write(xStr .. string.rep(" ", 9 - #xStr))
- term.setCursorPos(28, 15)
- term.write(yStr .. string.rep(" ", 9 - #yStr))
- term.setCursorPos(42, 15)
- term.write(zStr .. string.rep(" ", 9 - #zStr))
- drawGateFooter()
- end
- local function drawGateLabels()
- clearArea("lower")
- term.setTextColor(colors.gray)
- term.setCursorPos(2, 5)
- term.write(lcGate and "Name: #" or "Name: Iris: #")
- term.setCursorPos(2, 7)
- term.write(lcGate and "Address:" or "Address: Drop:")
- term.setCursorPos(2, 9)
- term.write("Note:")
- term.setCursorPos(2, 11)
- term.write("Classification:")
- term.setCursorPos(2, 13)
- term.write("Dimension:")
- term.setCursorPos(2, 15)
- term.write("Coords: x: y: z:")
- drawGateData()
- end
- local function drawAddressList()
- local xPos, yPos = 14, 5
- local gName, spacer, addr, highlight
- local magicNumber = ((gatePage - 1) * 20) + gatePage --# 21 gates/page
- for i = magicNumber, math.min(abCount, gatePage * 21) do
- addr = addressBook[i].addr
- if addr == gateTarget or addr:sub(1, 7) == gateTarget or addr == gateTarget:sub(1, 7) then
- highlight = true
- else
- highlight = false
- end
- term.setBackgroundColor(addr == thisGate and colors.gray or assignColor(i))
- term.setTextColor((addr == thisGate or addr == thisGate:sub(1, 7) or addr:sub(1, 7) == thisGate) and colors.lightGray or (highlight and colors.black or colors.white))
- gName = addressBook[i].name
- spacer = (12 - #gName) / 2
- term.setCursorPos(xPos, yPos)
- term.write(string.rep(" ", math.floor(spacer)) .. gName .. string.rep(" ", math.ceil(spacer)))
- yPos = yPos + 2
- if yPos >= termY - 1 then xPos = xPos + 13 yPos = 5 end
- end
- addrRedraw = false
- end
- local function drawIrisStatus()
- paintutils.drawLine(10, 9, 11, 9, irisState and colors.lime or colors.orange)
- if screen == "gatePage" then redrawInput() end
- end
- local function drawIrisWaitingStatus()
- term.setBackgroundColor(colors.lightBlue)
- term.setCursorPos(2, 9)
- term.setTextColor(irisState and colors.orange or colors.green)
- term.write("I r i s")
- end
- local function drawIrisButton()
- term.setBackgroundColor(colors.lightBlue)
- term.setTextColor(colors.white)
- term.setCursorPos(2, 9)
- term.write("I r i s")
- drawIrisStatus()
- end
- local function drawDHDStatus()
- paintutils.drawFilledBox(1, 4, 12, 7, fuelPercent > 5 and colors.white or colors.red)
- term.setTextColor(colors.blue)
- term.setCursorPos(2, 5)
- term.write(gateStatus)
- if lcGate then
- term.setTextColor(gateStatus == "Dialing" and colors.lightGray or colors.gray)
- else
- term.setTextColor((gateStatus == "Dialing" or gateStatus == "Incoming") and colors.lightGray or colors.gray)
- end
- term.setCursorPos(2, 6)
- term.write(fuelPercent > 5 and gateTarget or (gateTarget == "No Target" and "Low Fuel" or gateTarget))
- if addrRedraw then drawAddressList() end
- if screen == "gatePage" then drawPopUp("page") redrawInput() end
- end
- local function drawLeftPane()
- drawDHDStatus()
- paintutils.drawFilledBox(1, 8, 12, termY, colors.gray)
- for _, button in pairs(guiElements.mainButtons) do
- button.render()
- end
- if gateChange then drawAddressButton() end
- drawIrisStatus()
- end
- local function drawMainScreen()
- drawLeftPane()
- drawFooter()
- drawAddressList()
- end
- local function flashDial(name, x, y, gateNum)
- local gColor = assignColor(gateNum)
- local spacer = (12 - #name) / 2
- local gLabel = string.rep(" ", math.floor(spacer)) .. name .. string.rep(" ", math.ceil(spacer))
- term.setBackgroundColor(colors.black)
- term.setTextColor(gColor)
- term.setCursorPos(x, y)
- term.write(gLabel)
- sleep(0.1)
- term.setBackgroundColor(gColor)
- term.setTextColor(colors.white)
- term.setCursorPos(x, y)
- term.write(gLabel)
- addrRedraw = true
- end
- local function flashChoice(x, y, txtCol, bgCol, text)
- term.setBackgroundColor(bgCol)
- term.setTextColor(txtCol)
- term.setCursorPos(x, y)
- term.write(text)
- sleep(0.1)
- term.setBackgroundColor(txtCol)
- term.setTextColor(bgCol)
- term.setCursorPos(x, y)
- term.write(text)
- end
- local function addNewAddress(newEntry, fast)
- abCount, gateChange = abCount + 1, true
- addressBook[abCount] = { name = newEntry or "NEW GATE", addr = newEntry or "ADDRESS", rating = "U", iris = "none", callDrop = false, note = newEntry and "Added from logs" or "short note", loc = { x = 0, y = 0, z = 0, dim = "Unspecified", }, }
- gatePages = math.ceil(abCount / 21)
- if fast then
- if gatePage == gatePages then drawAddressList() end
- drawFooter()
- drawAddressButton()
- else
- screen = "gate"
- currentGate = abCount
- drawGateLabels()
- end
- end
- local function disengageChevron(auto) --# LanteaCraft
- if auto then autoDisengage = true end
- pcall(gate.deactivateChevron)
- --local success = pcall(gate.deactivateChevron)
- --if success then
- gateStatus = "Closing"
- gateTarget = gateTarget:sub(1, numChevrons)
- if screen == "main" or screen == "gatePage" or screen == "manage" or screen == "exodus" then
- drawDHDStatus()
- end
- --end
- end
- local function hangUp() --# LanteaCraft & SGCraft
- local onHook = false
- if lcGate then
- if gateStatus == "Connected" then
- onHook = pcall(gate.disengageStargate)
- --if onHook then gateStatus = "Closing" end
- gateStatus = "Closing"
- if gate.getActivatedChevrons() > 0 then disengageChevron(true) end
- elseif gateStatus == "Dialing" or gateStatus == "Paused" then
- continueDialing = false
- while spinTime do
- os.queueEvent("spinWait")
- os.pullEvent("spinWait")
- end
- disengageChevron(true)
- end
- else
- onHook = gate.disconnect()
- if onHook then gateStatus = "Closing" end
- end
- if onHook then
- gateTarget = "No Target"
- incomingAddress = nil
- chevronNumber = 0
- end
- end
- local function lockChevron(glyphNum) --# LanteaCraft
- --local dialStatus = false
- if continueDialing then
- --[[
- dialStatus = pcall(gate.selectGlyph, gateTarget:sub(glyphNum, glyphNum))
- if not dialStatus then return false end
- dialStatus = pcall(gate.activateChevron)
- ]]--
- pcall(gate.selectGlyph, gateTarget:sub(glyphNum, glyphNum))
- pcall(gate.activateChevron)
- return true
- end
- --return dialStatus
- return false
- end
- local function pauseDial() --# LanteaCraft
- if gateStatus == "Dialing" then
- continueDialing = false
- gateStatus = "Paused"
- elseif gateStatus == "Paused" then
- continueDialing = true
- if lockChevron(chevronNumber + 1) then
- gateStatus = "Dialing"
- else
- continueDialing = false
- gateStatus = "Paused"
- end
- end
- --fuelPercent = getFuelLevel()
- term.setBackgroundColor(fuelPercent > 5 and colors.white or colors.red)
- term.setTextColor(colors.blue)
- term.setCursorPos(2, 5)
- term.write(gateStatus .. " ")
- if screen == "gatePage" then redrawInput() end
- end
- local function dialOut(addr) --# LanteaCraft & SGCraft
- if lcGate then
- gateTarget = addr
- continueDialing = true
- if lockChevron(1) then
- gateStatus = "Dialing"
- drawDHDStatus()
- else
- hangUp()
- end
- else
- local ok = gate.dial(addr)
- if ok then
- gateTarget = addr
- gateStatus = "Dialing"
- drawDHDStatus()
- end
- end
- end
- local function toggleIris() --# LanteaCraft & SGCraft
- local ok
- if lcGate then
- if irisState then
- pcall(gate.openIris)
- else
- pcall(gate.closeIris)
- end
- ok = true
- else
- if irisState then
- ok = gate.openIris()
- else
- ok = gate.closeIris()
- end
- end
- if ok then drawIrisWaitingStatus() end
- end
- local function manageIris()
- local ok
- for i = 1, abCount do
- if addressBook[i].addr == incomingAddress or addressBook[i].addr:sub(1, 7) == incomingAddress or addressBook[i].addr == incomingAddress:sub(1, 7) then
- if lcGate and type(addressBook[i].iris) == "boolean" then
- if addressBook[i].iris then
- pcall(gate.openIris)
- else
- pcall(gate.closeIris)
- end
- ok = true
- elseif not lcGate and type(addressBook[i].iris) == "boolean" then
- if addressBook[i].iris then
- ok = gate.openIris()
- else
- ok = gate.closeIris()
- end
- end
- if ok and (((addressBook[i].iris and irisState) or (not addressBook[i].iris and not irisState)) and (screen == "main" or screen == "gatePage" or screen == "manage" or screen == "exodus")) then
- drawIrisWaitingStatus()
- if screen == "gatePage" then redrawInput() end
- end
- break
- end
- end
- end
- local function lcIrisMonitor() --# LanteaCraft
- local event
- while true do
- event = os.pullEvent()
- if event == "irisDestroyed" or event == "irisOpened" then
- irisState = false
- if screen == "main" or screen == "gatePage" or screen == "manage" or screen == "exodus" then
- drawIrisButton()
- end
- elseif event == "irisClosed" then
- irisState = true
- if screen == "main" or screen == "gatePage" or screen == "manage" or screen == "exodus" then
- drawIrisButton()
- end
- end
- end
- end
- local function sgIrisMonitor() --# SGCraft
- while true do
- local irisEvent, _, newState, oldState = os.pullEvent("sgIrisStateChange")
- if newState == "Closed" or newState == "Open" or newState == "Offline" then
- irisState = newState == "Closed"
- if screen == "main" or screen == "gatePage" or screen == "manage" or screen == "exodus" then
- drawIrisButton()
- end
- end
- end
- end
- local function sgGateMonitor() --# SGCraft
- while true do
- local sgEvent, _, newState, oldState = os.pullEvent("sgStargateStateChange")
- gateStatus = sgStates[newState] or "Unknown"
- if gateStatus == "Closing" or gateStatus == "Idle" or gateStatus == "Offline" then
- gateTarget = "No Target"
- incomingAddress = nil
- chevronNumber = 0
- elseif gateStatus == "Connected" then
- if gateTarget:find("?") then
- gateTarget = gateTarget:sub(1, gateTarget:find("?") - 1)
- end
- fuelPercent = getFuelLevel()
- recordSessionData()
- if not incomingAddress then updateTimer = os.startTimer(5) end
- end
- if (gateStatus == "Idle" or gateStatus == "Offline" or gateStatus == "Connected") and (screen == "main" or screen == "gatePage" or screen == "manage" or screen == "exodus") then
- drawAddressList()
- end
- if gateStatus ~= "Dialing" and (screen == "main" or screen == "gatePage" or screen == "manage" or screen == "exodus") then
- drawDHDStatus()
- end
- end
- end
- local function lcGateMonitor() --# LanteaCraft
- local event, numChevrons
- while true do
- event = os.pullEvent()
- if event == "disengageGlyph" then
- numChevrons = gate.getActivatedChevrons()
- if numChevrons and type(numChevrons) == "number" and numChevrons > 0 then
- if autoDisengage then disengageChevron() end
- else
- gateStatus = "Idle"
- gateTarget = "No Target"
- incomingAddress = nil
- chevronNumber = 0
- autoDisengage = false
- if screen == "main" or screen == "gatePage" or screen == "manage" or screen == "exodus" then
- addrRedraw = true
- drawDHDStatus()
- end
- end
- elseif event == "spinToGlyph" then
- spinTime = true
- elseif event == "connect" then
- gateStatus = "Connected"
- spinTime = false
- if gateTarget:find("?") then gateTarget = gate.getActivatedGlyphs() end
- if not incomingAddress then updateTimer = os.startTimer(5) end
- --gateTarget = incomingAddress or gateTarget
- --if incomingAddress then manageIris() end
- fuelPercent = getFuelLevel()
- autoDisengage = false
- if gateTarget == "No Target" then
- gateTarget = "Wormhole "
- incomingAddress = true
- end
- recordSessionData()
- if screen == "main" or screen == "gatePage" or screen == "manage" or screen == "exodus" then
- --if incomingAddress then addrRedraw = true end
- drawDHDStatus()
- end
- elseif event == "disconnect" then
- gateStatus = "Idle"
- gateTarget = "No Target"
- incomingAddress = nil
- chevronNumber = 0
- autoDisengage = false
- if screen == "main" or screen == "gatePage" or screen == "manage" or screen == "exodus" then
- addrRedraw = true
- drawDHDStatus()
- end
- end
- end
- end
- local function lcChevronEncoder() --# LanteaCraft
- while true do
- os.pullEvent("engageGlyph")
- spinTime = false
- chevronNumber = chevronNumber + 1
- if gateTarget:find("?") or gateTarget == "No Target" then gateTarget = gate.getActivatedGlyphs() .. string.rep("?", 9 - gate.getActivatedChevrons()) end
- if chevronNumber == #gateTarget then
- continueDialing = false
- pcall(gate.engageStargate)
- if screen == "main" or screen == "gatePage" or screen == "manage" or screen == "exodus" then
- drawDHDStatus()
- end
- else
- local drawStatus = false
- if gateTarget:find("?") and chevronNumber == 1 then
- gateStatus = "Dialing"
- drawStatus = true
- end
- if screen == "main" or screen == "gatePage" or screen == "manage" or screen == "exodus" then
- if drawStatus then drawDHDStatus() end
- --fuelPercent = getFuelLevel()
- term.setCursorPos(2, 6)
- term.setBackgroundColor(fuelPercent > 5 and colors.white or colors.red)
- term.setTextColor(chevronNumber > 0 and colors.gray or colors.lightGray)
- term.write(chevronNumber > 0 and gateTarget:sub(1, chevronNumber) or gateTarget)
- if screen == "gatePage" then redrawInput() end
- end
- if continueDialing and not lockChevron(chevronNumber + 1) then
- continueDialing = false
- gateStatus = "Paused"
- if screen == "main" or screen == "gatePage" or screen == "manage" or screen == "exodus" then
- drawDHDStatus()
- end
- end
- end
- end
- end
- local function sgChevronEncoder() --# SGCraft
- local sgEvent, _, chevron
- while true do
- sgEvent, _, chevronNumber, chevron = os.pullEvent("sgChevronEngaged")
- if gateTarget:find("?") then
- gateTarget = gateTarget:sub(1, chevronNumber - 1) .. chevron .. string.rep("?", 9 - chevronNumber)
- end
- local drawStatus = false
- if gateTarget == "No Target" then
- gateTarget = chevron .. "????????"
- gateStatus = "Dialing"
- drawStatus = true
- end
- if screen == "main" or screen == "gatePage" or screen == "manage" or screen == "exodus" then
- if drawStatus then drawDHDStatus() end
- --fuelPercent = getFuelLevel()
- term.setCursorPos(2, 6)
- term.setBackgroundColor(fuelPercent > 5 and colors.white or colors.red)
- term.setTextColor(colors.gray)
- term.write(gateTarget:sub(1, chevronNumber))
- if incomingAddress then
- term.setTextColor(colors.lightGray)
- term.write(gateTarget:sub(chevronNumber + 1))
- end
- if screen == "gatePage" then redrawInput() end
- end
- end
- end
- local function sgChevronUnencoded() --# SGCraft
- local sgEvent, _
- while true do
- sgEvent, _, chevronNumber = os.pullEvent("sgChevronUnset")
- if gateStatus == "Dialing" then
- if chevronNumber == 0 then
- gateTarget, gateStatus = "No Target", "Idle"
- else
- gateTarget = gateTarget:sub(1, chevronNumber) .. string.rep("?", 9 - chevronNumber)
- end
- drawDHDStatus()
- end
- end
- end
- --[[
- local function gateClosing() --# LanteaCraft
- while true do
- os.pullEvent("sgWormholeClosing")
- gateStatus = "Closing"
- gateTarget = "No Target"
- incomingAddress = nil
- chevronNumber = 0
- if screen == "main" or screen == "gatePage" or screen == "manage" or screen == "exodus" then
- addrRedraw = true
- drawDHDStatus()
- end
- end
- end
- ]]--
- local function incomingCall() --# LanteaCraft & SGCraft
- local _, incomingChevron
- while true do
- if lcGate then
- _, incomingChevron = os.pullEvent("sgIncoming")
- incomingAddress = incomingAddress and incomingAddress .. incomingChevron or incomingChevron
- else
- os.pullEvent("sgDialIn")
- incomingAddress = gate.remoteAddress()
- end
- gateStatus = "Incoming"
- gateTarget = incomingAddress
- if not lcGate then
- for i = 1, abCount do
- if (addressBook[i].addr == gateTarget or addressBook[i].addr:sub(1, 7) == gateTarget or addressBook[i].addr == gateTarget:sub(1, 7)) and addressBook[i].callDrop then
- hangUp()
- break
- end
- end
- if incomingAddress then manageIris() end
- end
- if screen == "main" or screen == "gatePage" or screen == "manage" or screen == "exodus" then
- if not lcGate then addrRedraw = true end
- drawDHDStatus()
- end
- end
- end
- local function changePage()
- if gatePage == gatePages and gatePages > 1 then clearArea("data") end
- drawAddressList()
- drawFooter()
- end
- local function inputExodus()
- while true do
- local _, button, x, y = os.pullEvent("mouse_click")
- if y > 8 and y < 13 and x > 19 and x < 39 then
- if y == 11 and x > 21 and x < 28 and button == 1 then
- flashChoice(22, 11, colors.green, colors.white, " Save ")
- saveData(gateData)
- kernelState = false
- return
- elseif y == 11 and x > 30 and x < 37 and button == 1 then
- flashChoice(31, 11, colors.orange, colors.white, " Quit ")
- kernelState = false
- return
- end
- else
- screen = "main"
- paintutils.drawFilledBox(20, 9, 38, 12, colors.black) --# clear pop-up
- drawAddressList()
- return
- end
- end
- end
- local function inputHelp()
- while true do
- local event, data, x, y = os.pullEvent()
- if event == "mouse_click" then
- if x > termX - 3 and y < 4 and data == 1 then
- screen = "main"
- clearArea("lower")
- drawMainScreen()
- return
- end
- elseif event == "key" and data == keys.f1 then
- screen = "main"
- clearArea("lower")
- drawMainScreen()
- return
- end
- end
- end
- local function inputLogChangePage()
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.setCursorPos(24, termY - 2)
- local newPage = tonumber(read(nil, nil, 4))
- logPage = newPage or logPage
- logPage = math.floor(math.max(1, math.min(logPage, logPages)))
- screen = "logs"
- paintutils.drawFilledBox(22, termY - 3, 30, termY - 1, colors.white) --# clear pop-up
- drawLogData()
- end
- local function inputLogScreen()
- while true do
- local event, data, x, y = os.pullEvent()
- if event == "mouse_click" then
- if x > termX - 3 and y < 4 and data == 1 then
- clearCallHistory()
- screen = "main"
- clearArea("lower")
- drawMainScreen()
- return
- elseif x > 20 and x < 31 and y == termY and logPages > 1 then
- local pageStr, pagesStr = tostring(logPage), tostring(logPages)
- flashChoice((math.ceil(termX / 2) - (#pageStr + #pagesStr + 4) / 2), termY, colors.gray, colors.lightGray, pageStr .. " of " .. pagesStr)
- screen = "logPage"
- drawPopUp("page")
- return
- elseif y > 6 and y < termY - 1 and x > 27 and x < 37 then
- local currentEntry = ((logPage - 1) * 11) + 1 --# Set the first entry to show (based on page number)
- if callHistory[currentEntry + y - 7] then
- local targetAddress = callHistory[currentEntry + y - 7]:sub(callHistory[currentEntry + y - 7]:find(">") + 2)
- local taLen = #targetAddress
- if data == 1 and (taLen == 7 or taLen == 9) then
- clearCallHistory()
- screen = "main"
- dialOut(targetAddress)
- clearArea("lower")
- drawMainScreen()
- elseif data == 2 and (taLen == 7 or taLen == 9) then
- clearCallHistory()
- local foundAddr = false
- for i = 1, abCount do
- if targetAddress == addressBook[i].addr then
- screen = "gate"
- currentGate = i
- drawGateLabels()
- foundAddr = true
- break
- end
- end
- if not foundAddr then addNewAddress(targetAddress) end
- end
- return
- end
- else
- local modeSwitch = false
- for _, click in pairs(guiElements.logButtons) do
- modeSwitch = click.processEvent(event, data, x, y)
- if modeSwitch then return end
- end
- end
- elseif event == "mouse_scroll" and ((data == 1 and logPage < logPages) or (data == -1 and logPage > 1)) then
- logPage = logPage + data
- drawLogData()
- elseif event == "key" and logPages > 1 then --# pageUp, pageDn, Home, End
- if (data == keys.pageUp and logPage > 1) or (data == keys.pageDown and logPage < logPages) then
- logPage = data == keys.pageUp and logPage - 1 or logPage + 1
- elseif (data == keys.home and logPage > 1) or (data == keys["end"] and logPage < logPages) then
- logPage = data == keys.home and 1 or logPages
- end
- drawLogData()
- end
- end
- end
- local function inputClearLogs()
- while true do
- local _, button, x, y = os.pullEvent("mouse_click")
- if y == math.floor(termY / 2) then
- if x > math.floor(termX / 2) - 5 and x < math.floor(termX / 2) + 1 and button == 1 then --# yes
- flashChoice(math.floor(termX / 2) - 4, math.floor(termY / 2), colors.green, colors.white, " YES ")
- screen = "logs"
- local clearLog = fs.open(historyData, "w")
- clearLog.close()
- clearCallHistory()
- logPage, logPages = 1, 1
- clearArea("lower", colors.white)
- drawLogScreen()
- return
- elseif x > math.floor(termX / 2) + 1 and x < math.floor(termX / 2) + 7 and button == 1 then --# no
- flashChoice(math.floor(termX / 2) + 2, math.floor(termY / 2), colors.red, colors.white, " N O ")
- screen = "logs"
- paintutils.drawFilledBox(20, math.floor(termY / 2) - 2, 32, math.floor(termY / 2 ) + 1, colors.white)
- drawLogData()
- return
- end
- end
- end
- end
- local function inputAddressBookMgt()
- while true do
- local event, button, x, y = os.pullEvent("mouse_click")
- local modeSwitch = false
- for _, click in pairs(guiElements.addrBookMgt) do --# process buttons
- modeSwitch = click.processEvent(event, button, x, y) --# carry out action for clicked button
- if modeSwitch then return end
- end
- end
- end
- local function inputGateRating()
- local selected = false
- while true do
- local _, button, x, y = os.pullEvent("mouse_click")
- if x > 17 and x < 38 and y > 5 and y < 17 then
- if button == 1 and y > 7 and y < 16 then
- for k, v in pairs(classifications) do
- if y == v.order + 7 then
- if addressBook[currentGate].rating ~= k then
- addressBook[currentGate].rating = k
- gateChange = true
- end
- selected = true
- break
- end
- end
- if selected then break end
- end
- else
- break
- end
- end
- paintutils.drawFilledBox(18, 6, 37, 17, colors.black) --# clear menu body
- term.setTextColor(colors.gray)
- term.setCursorPos(25, 7)
- term.write("Drop:")
- term.setCursorPos(25, 15)
- term.write("y:")
- screen = "gate"
- drawGateData()
- end
- local function inputViewGate()
- while true do
- local event, data, x, y = os.pullEvent()
- if event == "mouse_click" then
- if x > termX - 3 and y < 4 and data == 1 then
- screen = "main"
- currentGate = nil
- clearArea("lower")
- drawMainScreen()
- return
- elseif y == 5 and data == 1 then --# Name, auto-iris, gate order
- if x > 10 and x < 23 then --# Name
- term.setTextColor(colors.gray)
- term.setCursorPos(11, 5)
- term.write(addressBook[currentGate].name)
- term.setTextColor(colors.lightBlue)
- term.setCursorPos(11, 5)
- local newName = read(nil, { addressBook[currentGate].addr, addressBook[currentGate].name }, 12)
- if newName ~= "" and newName ~= addressBook[currentGate].name then
- addressBook[currentGate].name = newName
- gateChange = true
- if addressBook[currentGate].addr == thisGate then drawHeader() end
- end
- term.setTextColor(colors.lightBlue)
- term.setCursorPos(11, 5)
- term.write(addressBook[currentGate].name .. string.rep(" ", 12 - #addressBook[currentGate].name))
- elseif x > 30 and x < 35 and not lcGate then --# iris blacklist/whitelist
- if addressBook[currentGate].iris == "none" then
- addressBook[currentGate].iris = true
- elseif addressBook[currentGate].iris then
- addressBook[currentGate].iris = false
- else
- addressBook[currentGate].iris = "none"
- end
- drawControlSwitches(addressBook[currentGate].iris)
- gateChange = true
- elseif x > termX - 7 and x < termX - 6 + #tostring(currentGate) then --# change entry #
- term.setCursorPos(termX - 6, 5)
- term.write(string.rep(" ", 6))
- term.setTextColor(colors.gray)
- term.setCursorPos(termX - 6, 5)
- term.write(tostring(currentGate))
- term.setTextColor(colors.white)
- term.setCursorPos(termX - 6, 5)
- local newPos = tonumber(read(nil, { tostring(currentGate) }, 3))
- if newPos and newPos ~= currentGate then
- local tempGate = { }
- for k, v in pairs(addressBook[currentGate]) do
- tempGate[k] = v
- end
- table.remove(addressBook, currentGate)
- table.insert(addressBook, newPos, tempGate)
- currentGate = newPos
- gateChange = true
- end
- term.setCursorPos(termX - 6, 5)
- term.write(string.rep(" ", 6))
- term.setCursorPos(termX - 6, 5)
- term.setTextColor(colors.white)
- term.write(tostring(currentGate))
- end
- elseif y == 7 then
- if x > 10 and x < 20 then --# Address
- if data == 1 then
- term.setTextColor(colors.gray)
- term.setCursorPos(11, 7)
- term.write(addressBook[currentGate].addr)
- term.setTextColor(colors.yellow)
- term.setCursorPos(11, 7)
- local newAddress = read(nil, { addressBook[currentGate].addr }, 9, nil, nil, true)
- local naLen = #newAddress
- if newAddress and (naLen == 7 or naLen == 9) and newAddress ~= addressBook[currentGate].addr and not newAddress:find("?") then
- addressBook[currentGate].addr = newAddress
- local gNames = { "NEW GATE", "NO GATES", "Name" }
- for _, tName in ipairs(gNames) do
- if addressBook[currentGate].name == tName then
- addressBook[currentGate].name = newAddress
- term.setTextColor(colors.lightBlue)
- term.setCursorPos(11, 5)
- term.write(addressBook[currentGate].name .. string.rep(" ", 12 - #addressBook[currentGate].name))
- break
- end
- end
- gateChange = true
- if addressBook[currentGate].addr == thisGate then drawHeader() end
- end
- term.setTextColor(colors.yellow)
- term.setCursorPos(11, 7)
- term.write(addressBook[currentGate].addr .. " ")
- elseif data == 2 and addressBook[currentGate].addr ~= thisGate then
- local dial = addressBook[currentGate].addr
- screen = "main"
- currentGate = nil
- clearArea("lower")
- dialOut(dial)
- drawMainScreen()
- return
- end
- elseif x > 30 and x < 35 and data == 1 and not lcGate then --# callDrop
- addressBook[currentGate].callDrop = not addressBook[currentGate].callDrop
- drawControlSwitches(nil, addressBook[currentGate].callDrop)
- gateChange = true
- end
- elseif y == 9 and x > 7 and x < 8 + #addressBook[currentGate].note:sub(1, 43) and data == 1 then --# Note
- term.setTextColor(colors.gray)
- term.setCursorPos(8, 9)
- term.write(addressBook[currentGate].note:sub(1, 43))
- term.setTextColor(colors.white)
- term.setCursorPos(8, 9)
- local newNote = read(nil, { addressBook[currentGate].note }, 43)
- if newNote ~= "" and newNote ~= addressBook[currentGate].note then
- addressBook[currentGate].note = newNote
- gateChange = true
- end
- term.setTextColor(colors.white)
- term.setCursorPos(8, 9)
- term.write(addressBook[currentGate].note:sub(1, 43) .. string.rep(" ", 43 - #addressBook[currentGate].note:sub(1, 43)))
- elseif y == 11 and x > 17 and x < 18 + #assignRating(currentGate) and data == 1 then --# Classification
- screen = "rating"
- drawRatingList(addressBook[currentGate].rating)
- return
- elseif y == 13 and x > 12 and x < 13 + #addressBook[currentGate].loc.dim and data == 1 then --# Dimension
- term.setTextColor(colors.gray)
- term.setCursorPos(13, 13)
- term.write(addressBook[currentGate].loc.dim)
- term.setTextColor(colors.brown)
- term.setCursorPos(13, 13)
- local newDim = read(nil, { "Overworld", "Nether", "The End", addressBook[currentGate].loc.dim }, 19)
- if newDim ~= "" and newDim ~= addressBook[currentGate].loc.dim then
- addressBook[currentGate].loc.dim = newDim
- gateChange = true
- end
- term.setCursorPos(13, 13)
- term.write(addressBook[currentGate].loc.dim .. string.rep(" ", 19 - #addressBook[currentGate].loc.dim))
- elseif y == 15 and data == 1 then --# x, y, z coords
- local xStr, yStr, zStr = tostring(addressBook[currentGate].loc.x), tostring(addressBook[currentGate].loc.y), tostring(addressBook[currentGate].loc.z)
- if x > 13 and x < 14 + #xStr then
- term.setTextColor(colors.gray)
- term.setCursorPos(14, 15)
- term.write(xStr)
- term.setTextColor(colors.lightGray)
- term.setCursorPos(14, 15)
- local newX = tonumber(read(nil, { xStr }, 9))
- if newX and newX ~= addressBook[currentGate].loc.x then
- addressBook[currentGate].loc.x = newX
- xStr = tostring(newX)
- gateChange = true
- end
- term.setTextColor(colors.lightGray)
- term.setCursorPos(14, 15)
- term.write(xStr .. string.rep(" ", 9 - #xStr))
- elseif x > 27 and x < 28 + #yStr then
- term.setTextColor(colors.gray)
- term.setCursorPos(28, 15)
- term.write(yStr)
- term.setTextColor(colors.lightGray)
- term.setCursorPos(28, 15)
- local newY = tonumber(read(nil, { yStr }, 9))
- if newY and newY ~= addressBook[currentGate].loc.y then
- addressBook[currentGate].loc.y = newY
- yStr = tostring(newY)
- gateChange = true
- end
- term.setTextColor(colors.lightGray)
- term.setCursorPos(28, 15)
- term.write(yStr .. string.rep(" ", 9 - #yStr))
- elseif x > 41 and x < 42 + #zStr then
- term.setTextColor(colors.gray)
- term.setCursorPos(42, 15)
- term.write(zStr)
- term.setTextColor(colors.lightGray)
- term.setCursorPos(42, 15)
- local newZ = tonumber(read(nil, { zStr }, 9))
- if newZ and newZ ~= addressBook[currentGate].loc.z then
- addressBook[currentGate].loc.z = newZ
- zStr = tostring(newZ)
- gateChange = true
- end
- term.setTextColor(colors.lightGray)
- term.setCursorPos(42, 15)
- term.write(zStr .. string.rep(" ", 9 - #zStr))
- end
- end
- if gateChange then drawGateFooter() end
- elseif event == "mouse_scroll" and ((data == 1 and currentGate < abCount) or (data == -1 and currentGate > 1)) then
- currentGate = currentGate + data
- drawGateData()
- end
- end
- end
- local function inputMainChangePage()
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.setCursorPos(31, termY - 2)
- local newPage = tonumber(read(nil, nil, 4))
- gatePage = newPage or gatePage
- gatePage = math.floor(math.max(1, math.min(gatePage, gatePages)))
- screen = "main"
- paintutils.drawFilledBox(29, termY - 3, 37, termY - 1, colors.black) --# clear pop-up
- changePage()
- end
- local function inputMainScreen()
- local event, data, x, y, continue
- while true do
- event, data, x, y = os.pullEvent()
- if event == "mouse_click" then
- continue = true
- if x > termX - 3 and y < 4 and data == 1 then --# 'X' (quit)
- if gateChange then
- screen = "exodus"
- drawPopUp("exodus")
- return
- end
- kernelState = false
- return
- elseif x > 27 and x < 38 and y == termY and gatePages > 1 then
- local pageStr, pagesStr = tostring(gatePage), tostring(gatePages)
- flashChoice((math.ceil(termX / 2) - (#pageStr + #pagesStr + 4) / 2) + 7, termY, colors.gray, colors.lightGray, pageStr .. " of " .. pagesStr)
- screen = "gatePage"
- drawPopUp("page")
- return
- end
- local xPos, yPos = 14, 5
- local magicNumber = ((gatePage - 1) * 20) + gatePage
- for i = magicNumber, math.min(abCount, gatePage * 21) do
- if x >= xPos and x <= xPos + 11 and y == yPos then
- if data == 1 then --# dial address
- if addressBook[i].addr == thisGate then
- continue = false
- break --# thisGate - don't dial
- else
- if gateStatus == "Idle" then
- flashDial(addressBook[i].name, xPos, yPos, i)
- dialOut(addressBook[i].addr) --# dial out
- continue = false
- break
- elseif lcGate and (gateStatus == "Dialing" or gateStatus == "Paused") and gateTarget == addressBook[i].addr then
- flashDial(addressBook[i].name, xPos, yPos, i)
- pauseDial() --# pause/resume dialing
- drawAddressList()
- continue = false
- break
- end
- end
- elseif data == 2 then --# view/edit address
- flashDial(addressBook[i].name, xPos, yPos, i)
- screen = "gate"
- currentGate = i
- drawGateLabels()
- return
- elseif data == 3 and abCount > 1 then --# delete address if there is more than one entry in the address book
- flashDial(addressBook[i].name, xPos, yPos, i)
- table.remove(addressBook, i)
- abCount = abCount - 1
- gatePages = math.ceil(abCount / 21)
- gatePage = math.min(gatePage, gatePages)
- if gatePage == gatePages then clearArea("data") end
- drawAddressList()
- drawFooter()
- drawAddressButton()
- gateChange = true
- continue = false
- break
- end
- else
- yPos = yPos + 2
- if yPos >= termY - 1 then xPos = xPos + 13 yPos = 5 end
- end
- end
- if continue then
- local modeSwitch = false
- for _, click in pairs(guiElements.mainButtons) do --# process buttons
- modeSwitch = click.processEvent(event, data, x, y) --# carry out action for clicked button
- if modeSwitch then return end
- end
- for _, click in pairs(guiElements.mainFooter) do
- click.processEvent(event, data, x, y)
- end
- end
- elseif event == "mouse_scroll" and ((data == 1 and gatePage < gatePages) or (data == -1 and gatePage > 1)) then
- gatePage = gatePage + data
- changePage()
- elseif event == "key" then --# pageUp, pageDn, Home, End, F1
- if (data == keys.pageUp and gatePage > 1) or (data == keys.pageDown and gatePage < gatePages) then
- gatePage = data == keys.pageUp and gatePage - 1 or gatePage + 1
- changePage()
- elseif (data == keys.home and gatePage > 1) or (data == keys["end"] and gatePage < gatePages) then
- gatePage = data == keys.home and 1 or gatePages
- changePage()
- elseif data == keys.f1 then
- screen = "help"
- drawHelpScreen()
- return
- end
- end
- end
- end
- do
- local screens = {
- main = function() inputMainScreen() end;
- gate = function() inputViewGate() end;
- gatePage = function() inputMainChangePage() end;
- rating = function() inputGateRating() end;
- manage = function() inputAddressBookMgt() end;
- logs = function() inputLogScreen() end;
- logPage = function() inputLogChangePage() end;
- clearLogs = function() inputClearLogs() end;
- help = function() inputHelp() end;
- exodus = function() inputExodus() end;
- }
- userInput = function()
- repeat
- if screens[screen] then screens[screen]() end
- until not kernelState
- end
- end
- local function dataPoller()
- local _, timer, newFuel, update
- while true do
- _, timer = os.pullEvent("timer")
- if timer == updateTimer then
- newFuel = getFuelLevel()
- update = newFuel ~= fuelPercent
- fuelPercent = newFuel
- if update and (screen == "main" or screen == "gatePage" or screen == "manage" or screen == "exodus") then drawDHDStatus() end
- if gateStatus == "Connected" and not incomingAddress then updateTimer = os.startTimer(5) end
- end
- end
- end
- local function errorMessage(id)
- clearScreen()
- term.setCursorPos(2, 2)
- if id == "color" then
- write("This program requires an advanced computer")
- term.setCursorPos(1, 5)
- elseif id == "size" then
- write("This program requires a 51x18 or 51x19 screen")
- term.setCursorPos(1, 5)
- elseif id == "gate" then
- term.setTextColor(colors.red)
- term.write("Unable to locate a stargate")
- term.setTextColor(colors.white)
- term.setCursorPos(2, 4)
- term.write("Please connect a stargate/adapter directly")
- term.setCursorPos(2, 5)
- term.write("or via modem and network cables")
- term.setCursorPos(1, 8)
- end
- end
- if not term.isColor() or pocket or turtle then return errorMessage("color") end
- if not os.getComputerLabel() then os.setComputerLabel("ccDHD.cc#" .. tostring(os.getComputerID())) end
- if termX ~= 51 or termY < 18 or termY > 19 then return errorMessage("size") end
- gate = peripheral.find("stargate")
- if not gate then
- lcGate = true
- gate = peripheral.find("StargateBase")
- if gate and not gate.isValid() then gate = nil end
- end
- if not gate then return errorMessage("gate") end
- if lcGate then
- local irisStates = {
- OPEN = "Open";
- CLOSED = "Closed";
- OPENING = "Closed";
- CLOSING = "Open";
- NONE = "Open";
- }
- thisGate = gate.getStargateAddressString()
- thisGate = thisGate ~= "default address" and thisGate or "!!ERROR!!"
- local chevs = gate.getActivatedChevrons()
- local glyphs = gate.getActivatedGlyphs()
- if glyphs and chevs > 0 then
- gateStatus = chevs == 9 and "Connected" or "Dialing"
- gateTarget = chevs == 9 and glyphs or glyphs .. string.rep("?", 9 - chevs)
- chevronNumber = chevs
- else
- gateStatus = "Idle"
- gateTarget = "No Target"
- end
- irisState = irisStates[gate.getIrisState()] == "Closed"
- else
- thisGate = gate.localAddress()
- local gateState, callDirection
- gateState, chevronNumber, callDirection = gate.stargateState()
- if gateState == "Offline" then return errorMessage("gate") end
- local irisStates = {
- Offline = "Open",
- Open = "Open",
- Opening = "Closed",
- Closed = "Closed",
- Closing = "Open",
- }
- irisState = irisStates[gate.irisState()] == "Closed"
- gateStatus = sgStates[gateState] or "Unknown"
- if gateStatus == "Dialing" or gateStatus == "Connected" then
- gateTarget = gate.remoteAddress()
- if callDirection == "Incoming" then
- incomingAddress = gateTarget
- if gateStatus == "Dialing" then gateStatus = "Incoming" end
- end
- end
- end
- fuelPercent = getFuelLevel()
- if fs.exists(gateData) then
- ingestData(gateData)
- else
- if not fs.exists("/data") then fs.makeDir("/data") end
- addressBook[1].name = thisGate
- addressBook[1].addr = thisGate
- saveData(gateData)
- end
- screen = "main"
- kernelState = true
- guiElements = {
- mainButtons = {
- newButton(1, 9, 11, 1, "I r i s ", colors.lightBlue, colors.white, function() toggleIris() drawIrisStatus() return false end, "Iris", 1);
- newButton(1, 11, 11, 1, "END Call ", colors.orange, colors.black, function() if gateStatus == "Dialing" or gateStatus == "Paused" or gateStatus == "Connected" or gateStatus == "Incoming" then flashChoice(1, 11, colors.orange, colors.black, " END Call ") hangUp() drawDHDStatus() end return false end, "EndCall", 1);
- newButton(1, 13, 11, 1, "Addr Book", colors.blue, colors.white, function() flashChoice(1, 13, colors.blue, gateChange and colors.lime or colors.white, " Addr Book ") screen = "manage" drawPopUp("abManagement") return true end, "AddrBook", 1);
- newButton(1, 13, 11, 1, "Addr Book", colors.blue, colors.white, function() if gateChange then flashChoice(1, 13, colors.blue, colors.white, " Addr Book ") saveData(gateData) end return false end, "SaveAB", 2);
- newButton(1, 15, 11, 1, "New Gate ", colors.green, colors.white, function() flashChoice(1, 15, colors.green, colors.white, " New Gate ") addNewAddress() return true end, "NewGate", 1);
- newButton(1, 15, 11, 1, "New Gate ", colors.green, colors.white, function() flashChoice(1, 15, colors.green, colors.white, " New Gate ") addNewAddress(nil, true) return false end, "NewGateFast", 3);
- newButton(1, 17, 11, 1, "Logs ", colors.yellow, colors.gray, function() flashChoice(1, 17, colors.yellow, colors.gray, " Logs ") screen = "logs" ingestData("logs") clearArea("lower", colors.white) drawLogScreen() return true end, "Logs", 1);
- newButton(1, termY, 11, 1, "[F1] Help", colors.gray, colors.lightGray, function() screen = "help" drawHelpScreen() return true end, "Help", 1);
- },
- mainFooter = {
- newButton(22, termY, 2, 1, "<<", colors.gray, colors.lightGray, function() if gatePage > 1 then gatePage = 1 changePage() end return false end, "firstPage", 1);
- newButton(25, termY, 1, 1, "<", colors.gray, colors.lightGray, function() if gatePage > 1 then gatePage = gatePage - 1 changePage() end return false end, "pageMinus", 1);
- newButton(40, termY, 1, 1, ">", colors.gray, colors.lightGray, function() if gatePage < gatePages then gatePage = gatePage + 1 changePage() end return false end, "pagePlus", 1);
- newButton(42, termY, 2, 1, ">>", colors.gray, colors.lightGray, function() if gatePage < gatePages then gatePage = gatePages changePage() end return false end, "lastPage", 1);
- },
- logButtons = {
- newButton(termX - 7, 5, 7, 1, "CLEAR", colors.lightGray, colors.black, function() flashChoice(termX - 7, 5, colors.lightGray, colors.black, " CLEAR ") screen = "clearLogs" drawPopUp("clearLogs") return true end, "logPageClear", 1);
- newButton(14, termY, 2, 1, "<<", colors.gray, colors.lightGray, function() if logPage > 1 then logPage = 1 drawLogData() end return false end, "logPageHome", 1);
- newButton(17, termY, 1, 1, "<", colors.gray, colors.lightGray, function() if logPage > 1 then logPage = logPage - 1 drawLogData() end return false end, "logPageMinus", 1);
- newButton(34, termY, 1, 1, ">", colors.gray, colors.lightGray, function() if logPage < logPages then logPage = logPage + 1 drawLogData() end return false end, "logPagePlus", 1);
- newButton(36, termY, 2, 1, ">>", colors.gray, colors.lightGray, function() if logPage < logPages then logPage = logPages drawLogData() end return false end, "logPageEnd", 1);
- },
- addrBookMgt = {
- newButton(17, 12, 8, 1, "Import", colors.yellow, colors.black, function() flashChoice(17, 12, colors.yellow, colors.black, " Import ") mergeData() if gateChange then saveData(gateData) drawAddressList() drawFooter() end drawAddressButton() drawPopUp("abManagement") return false end, "ABImport", 1);
- newButton(26, 12, 8, 1, "Export", colors.orange, colors.black, function() flashChoice(26, 12, colors.orange, colors.black, " Export ") if not fs.exists("/disk/data") then fs.makeDir("/disk/data") end saveData("/disk/data/DHDgates") drawPopUp("abManagement") return false end, "ABExport", 1);
- newButton(17, 14, 8, 1, "Load", colors.lightBlue, colors.white, function() flashChoice(17, 14, colors.lightBlue, colors.white, " Load ") ingestData(gateData) clearArea("data") drawAddressList() drawFooter() drawAddressButton() drawPopUp("abManagement") return false end, "ABLoad", 1);
- newButton(26, 14, 8, 1, "Save", colors.green, colors.white, function() flashChoice(26, 14, colors.green, colors.white, " Save ") saveData(gateData) drawAddressButton() drawPopUp("abManagement") return false end, "ABSave", 1);
- newButton(22, 16, 7, 1, "Close", colors.red, colors.white, function() flashChoice(22, 16, colors.red, colors.white, " Close ") screen = "main" paintutils.drawFilledBox(15, 10, 35, 17, colors.black) drawAddressList() return true end, "ABClose", 1);
- },
- }
- clearScreen()
- drawHeader()
- drawMainScreen()
- if gateStatus == "Connected" and not incomingAddress then updateTimer = os.startTimer(5) end
- repeat
- if lcGate then
- parallel.waitForAny(userInput, dataPoller, incomingCall, lcChevronEncoder, lcGateMonitor, lcIrisMonitor)
- else
- parallel.waitForAny(userInput, dataPoller, incomingCall, sgChevronEncoder, sgChevronUnencoded, sgGateMonitor, sgIrisMonitor)
- end
- until not kernelState
- clearScreen()
- term.setTextColor(colors.white)
- term.setCursorPos(1, 1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement