Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Names for the monitors and gateways.
- -- If using modems, check modem for name.
- -- If touching computer, use the side.
- local monitor = "top"
- local leftGateway = ""
- local rightGateway = ""
- -- Names to display above lists.
- local leftName = "Left"
- local rightName = "Right"
- -- Variable to set how long to wait
- -- before reconnecting to monitor or
- -- gateways. Recommended range is 1 to 5.
- local waitTime = 1
- -- Cosmetic variables, adjust to taste.
- local useColor = true
- local textSize = 1.5
- local primaryColor = colors.white
- local headerColor = colors.white
- local backgroundColor = colors.black
- local refreshTimer = 2
- -- Name alignment. Accepts "left", "right", "center"
- local alignment = "center"
- -- Other options for the gateway lists.
- local maxLength = 16
- local rightOffset = 18
- -- Fancy layout options, to add a nice layout to lists.
- local fancyLayout = true
- local borderColor = colors.yellow
- local fHoriz = "-"
- local fVert = "|"
- local fJoint = "+"
- -- Used internally. Do not adjust.
- local mon = nil
- local lGate = nil
- local rGate = nil
- local lList = nil
- local rList = nil
- -- Waits for peripherals to connect, in case
- -- setup is in multiple chunks.
- local function getConnected()
- while mon == nil do
- mon = peripheral.wrap(monitor)
- if mon == nil then
- print("Waiting for monitor.")
- os.sleep(waitTime)
- end
- end
- while lGate == nil do
- lGate = peripheral.wrap(leftGateway)
- if lGate == nil then
- print("Waiting for "..leftName..".")
- os.sleep(waitTime)
- end
- end
- while rGate == nil do
- rGate = peripheral.wrap(rightGateway)
- if rGate == nil then
- print("Waiting for "..rightName..".")
- os.sleep(waitTime)
- end
- end
- end
- -- Shortens names, if needed.
- local function trimName(oStr)
- local nStr = ""
- if string.len(oStr) > maxLength then
- nStr = string.sub(oStr, 1, 14)
- else
- nStr = oStr
- end
- return nStr
- end
- -- Adds spaces to artificially align names.
- local function alignText(oStr, align)
- local nStr = ""
- local offset = 0
- if string.len(oStr) < maxLength then
- if align == "center" then
- offset = math.floor((maxLength - string.len(oStr)) / 2)
- elseif align == "right" then
- offset = maxLength - string.len(oStr)
- end
- end
- for x = 1, offset, 1 do
- nStr = nStr.." "
- end
- nStr = nStr..oStr
- return nStr
- end
- -- Sets name color for specific people.
- local function getColor(name)
- local nColor = primaryColor
- if string.sub(name,1,3) == "Sly" then
- nColor = colors.purple
- elseif string.sub(name,1,4) == "Prof" then
- nColor = colors.lightBlue
- elseif string.sub(name,1,3) == "Nut" then
- nColor = colors.purple
- elseif string.sub(name,1,7) == "Khaycat" then
- nColor = colors.pink
- end
- return nColor
- end
- -- Prints the given list of names on screen.
- local function printNames(nameTable, offset)
- local curName = ""
- local curColor = colors.white
- local pos = 1
- while pos < 11 do
- if nameTable[pos] == nil then
- curName = " "
- else
- v = nameTable[pos]
- curName = trimName(v["name"])
- end
- mon.setCursorPos(offset, 2 + pos)
- if useColor then
- curColor = getColor(curName)
- mon.setTextColor(curColor)
- end
- mon.write(alignText(curName, alignment))
- pos = pos + 1
- end
- end
- -- Prints out borders to make screen look fancy.
- local function fancify()
- local width, height = mon.getSize()
- local mCenter = math.floor(width / 2) + 1
- if fancyLayout then
- if mon.isColor() then
- mon.setTextColor(borderColor)
- end
- mon.setCursorPos(mCenter, 1)
- mon.write(fVert)
- for y = 3, height, 1 do
- mon.setCursorPos(mCenter, y)
- mon.write(fVert)
- end
- for x = 1, width, 1 do
- mon.setCursorPos(x, 2)
- if x == mCenter then
- mon.write(fJoint)
- else
- mon.write(fHoriz)
- end
- end
- end
- end
- -- Main display function.
- local function displayLists()
- mon.clear()
- if mon.isColor() and useColor then
- mon.setTextColor(headerColor)
- end
- mon.setCursorPos(1,1)
- mon.write(alignText(leftName, "center"))
- mon.setCursorPos(rightOffset,1)
- mon.write(alignText(rightName, "center"))
- if fancyLayout then
- fancify()
- end
- printNames(lList, 1)
- printNames(rList, rightOffset)
- end
- print("Gateway display system online, connecting to peripherals.")
- getConnected()
- mon.setBackgroundColor(backgroundColor)
- mon.clear()
- mon.setTextScale(textSize)
- print("Peripherals connected. Starting primary loop.")
- while true do
- lList = lGate.getAllStacks()
- rList = rGate.getAllStacks()
- displayLists()
- os.sleep(refreshTimer)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement