--[[ Display Functions Handles all monitor/screen drawing operations ]] local display = {} -- Will be set by startup.lua local mon local config local addresses local utils local localGateAddress -- State variables local buttonXY = {} local computerAddresses = {} local computerNames = {} local x, y = 0, 0 function display.init(monitor, cfg, addr, utilsModule, localAddr) mon = monitor config = cfg addresses = addr utils = utilsModule localGateAddress = localAddr end function display.getButtonData() return buttonXY, computerAddresses, computerNames end function display.clearButtonData() buttonXY = {} computerAddresses = {} computerNames = {} end --------------------------------------------- -- DRAWING FUNCTIONS --------------------------------------------- function display.drawDisconnectButton() local oldterm = term.redirect(mon) paintutils.drawFilledBox(20, 17, 28, 19, colors.red) mon.setCursorPos(21, 18) mon.write("CLOSE") term.redirect(oldterm) end function display.drawIrisStatus() mon.setCursorPos(1, 19) mon.setBackgroundColor(colors.black) local irisState = utils.getIrisState() if irisState == "OPEN" then mon.setTextColor(colors.green) elseif irisState == "CLOSED" then mon.setTextColor(colors.red) else mon.setTextColor(colors.gray) end mon.write("IRIS: " .. irisState .. " ") mon.setTextColor(colors.white) if irisState == "MOVING" then sleep(0.1) display.drawIrisStatus() end end function display.screenWrite(list, fcount, fy) for i = 1, #list do local entryAddress = list[i][2] -- Skip this entry if it matches local gate address local isLocalGate = false if localGateAddress and entryAddress then -- Compare addresses (excluding point of origin which is last element) if #localGateAddress == #entryAddress then isLocalGate = true for j = 1, #localGateAddress - 1 do -- Skip last element (point of origin) if localGateAddress[j] ~= entryAddress[j] then isLocalGate = false break end end end end -- Skip if this is the local gate if not isLocalGate then local x1, x2 = 0, 0 if fcount == 0 then x = 2 fcount = 1 elseif fcount == 1 then x = 11 fcount = 2 else x = 20 fcount = 0 fy = fy + 2 end mon.setCursorPos(x, fy) mon.write(list[i][1]) x1 = x x2 = x + 7 table.insert(buttonXY, { x1, x2, fy }) table.insert(computerNames, list[i][1]) table.insert(computerAddresses, list[i][2]) end end local oldterm = term.redirect(mon) paintutils.drawFilledBox(23, 17, 28, 19, colors.red) mon.setCursorPos(24, 18) mon.write("Back") term.redirect(oldterm) return fcount, fy end function display.selectionTabs() mon.setBackgroundColor(colors.black) mon.clear() local oldterm = term.redirect(mon) if #addresses.MainGates ~= 0 then paintutils.drawFilledBox(2, 2, 13, 6, colors.purple) mon.setCursorPos(4, 4) mon.setBackgroundColor(colors.purple) mon.write("Main Gates") end if #addresses.playerGates ~= 0 then paintutils.drawFilledBox(16, 2, 27, 6, colors.green) mon.setCursorPos(18, 4) mon.setBackgroundColor(colors.green) mon.write("Player") mon.setCursorPos(18, 5) mon.write("Base gates") end if (#addresses.hazardGates ~= 0) and (config.canAccessHazardGates == true) then paintutils.drawFilledBox(2, 8, 13, 12, colors.red) mon.setCursorPos(4, 9) mon.setBackgroundColor(colors.red) mon.write("Hazard") mon.setCursorPos(4, 11) mon.write("gates") end paintutils.drawFilledBox(23, 17, 28, 19, colors.red) mon.setCursorPos(24, 18) mon.write("Back") display.drawIrisStatus() term.redirect(oldterm) end function display.showIncoming(addressName, addressString, allowed, reason) mon.setBackgroundColor(colors.black) mon.clear() if allowed then mon.setBackgroundColor(colors.green) mon.setTextScale(1) mon.setCursorPos(1, 2) mon.write("INCOMING - AUTHORIZED") else mon.setBackgroundColor(colors.red) mon.setTextScale(1) mon.setCursorPos(1, 2) mon.write("INCOMING - UNAUTHORIZED") mon.setCursorPos(1, 4) mon.write(reason) end mon.setCursorPos(1, 6) mon.setBackgroundColor(colors.black) -- Show name if found in address book if addressName then mon.write("Name: " .. addressName) mon.setCursorPos(1, 7) mon.write("Address:") mon.setCursorPos(1, 8) mon.write(addressString) else mon.write("Address:") mon.setCursorPos(1, 7) mon.write(addressString) end display.drawIrisStatus() end function display.showEntity(entityType, entityName, allowed) mon.setTextScale(1) mon.setCursorPos(1, 10) mon.write("Type: " .. entityType) mon.setCursorPos(1, 12) mon.write("Name: " .. entityName) if not allowed then mon.setCursorPos(1, 14) mon.setTextColor(colors.red) mon.write("IRIS IMPACT!") mon.setTextColor(colors.white) end end function display.showDialing(chevron, symbol, gateType) mon.setBackgroundColor(colors.black) mon.clear() mon.setBackgroundColor(colors.red) mon.setTextScale(2) mon.setCursorPos(2, 3) mon.write("DIALING GATE") mon.setCursorPos(4, 5) mon.write("CHEVERON") mon.setCursorPos(7, 7) mon.setBackgroundColor(colors.black) mon.write(chevron) mon.setBackgroundColor(colors.red) if symbol ~= 0 then mon.setCursorPos(4, 9) mon.write("ENGAGED") else mon.setCursorPos(5, 9) mon.setBackgroundColor(colors.green) mon.write("LOCKED") end end function display.showConnected(destName, destAddr) mon.setBackgroundColor(colors.green) mon.clear() mon.setTextScale(1) mon.setCursorPos(6, 5) mon.write(destName) mon.setCursorPos(3, 10) for i = 1, #destAddr do mon.write(destAddr[i]) mon.write(" ") end -- Draw disconnect button local oldterm = term.redirect(mon) paintutils.drawFilledBox(20, 17, 28, 19, colors.red) mon.setCursorPos(21, 18) mon.write("CLOSE") term.redirect(oldterm) display.drawIrisStatus() end function display.showMainMenu() mon.setTextScale(1) mon.setBackgroundColor(colors.black) mon.clear() mon.setCursorPos(9, 1) mon.setBackgroundColor(colors.red) mon.write("press to start") display.drawIrisStatus() end --------------------------------------------- -- PASSWORD PROMPT --------------------------------------------- function display.showPasswordPrompt() mon.setBackgroundColor(colors.black) mon.clear() mon.setTextScale(1) mon.setBackgroundColor(colors.blue) mon.setCursorPos(7, 2) mon.write("IRIS PASSWORD") mon.setBackgroundColor(colors.black) mon.setCursorPos(7, 5) mon.write("Enter Code:") -- Draw number pad (3x4 grid) local oldterm = term.redirect(mon) -- Numbers 1-9 local row = 7 for i = 1, 9 do local col = 8 + ((i - 1) % 3) * 5 if (i - 1) % 3 == 0 and i > 1 then row = row + 3 end paintutils.drawFilledBox(col, row, col + 3, row + 2, colors.green) mon.setCursorPos(col + 1, row + 1) mon.write(tostring(i)) end -- Bottom row: Clear (0), Zero, Enter paintutils.drawFilledBox(8, 16, 11, 18, colors.red) mon.setCursorPos(9, 17) mon.write("CLR") paintutils.drawFilledBox(13, 16, 16, 18, colors.green) mon.setCursorPos(14, 17) mon.write("0") paintutils.drawFilledBox(18, 16, 21, 18, colors.blue) mon.setCursorPos(18, 17) mon.write("OK") term.redirect(oldterm) display.drawIrisStatus() end function display.updatePasswordDisplay(password) mon.setBackgroundColor(colors.black) mon.setCursorPos(7, 6) mon.write(string.rep("*", #password) .. " ") end function display.showPasswordResult(success) mon.setBackgroundColor(colors.black) mon.setCursorPos(7, 10) if success then mon.setTextColor(colors.green) mon.write("ACCESS GRANTED") mon.setTextColor(colors.white) else mon.setTextColor(colors.red) mon.write("ACCESS DENIED") mon.setTextColor(colors.white) end sleep(2) end return display