Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Set up peripherals
- rs = peripheral.find("rsBridge")
- monitor = peripheral.find('monitor')
- -- Dynamically locate left and right monitors by size
- local monitors = {peripheral.find("monitor")}
- local rightMonitor, leftMonitor
- for _, mon in pairs(monitors) do
- local width, height = mon.getSize()
- if width == 1 then
- rightMonitor = mon -- Vertical monitor (crafting manager)
- elseif height == 1 then
- leftMonitor = mon -- Horizontal monitor (item graph)
- end
- end
- term.redirect(monitor)
- -- Color Palette
- local backgroundColor = colors.black
- local borderColor = colors.cyan
- local itemColor = colors.lightGray
- local amountColor = colors.orange
- local lowStockColor = colors.red
- local headerColor = colors.blue
- local increaseColor = colors.green
- local decreaseColor = colors.red
- local itemHistory = {}
- local arrowHistory = {}
- local arrowColorHistory = {}
- local totalItemHistory = {}
- -- Scaling and Layout
- function calculateScaling()
- monitorWidth, monitorHeight = monitor.getSize()
- monitor.setTextScale(1.8)
- w, h = monitor.getSize()
- end
- -- Draw header
- function drawHeader(text)
- term.setBackgroundColor(headerColor)
- term.clearLine()
- term.setCursorPos(1, 1)
- term.setTextColor(colors.white)
- term.write(text)
- end
- -- Draw footer
- function drawFooter()
- term.setBackgroundColor(headerColor)
- term.setCursorPos(1, h)
- term.clearLine()
- end
- -- Draw separator line
- function drawSeparator(y)
- paintutils.drawLine(1, y, w, y, borderColor)
- end
- -- Draw item row with persistent up/down indicator and color
- function drawItemRow(y, itemName, itemAmount)
- if y < h then
- local previousAmount = itemHistory[itemName] or itemAmount
- local arrow = arrowHistory[itemName] or " "
- local textColor = itemColor
- local arrowColor = arrowColorHistory[itemName] or amountColor
- if itemAmount < 100 then
- textColor = lowStockColor
- end
- if itemAmount > previousAmount then
- arrow = "^"
- arrowColor = increaseColor
- elseif itemAmount < previousAmount then
- arrow = "v"
- arrowColor = decreaseColor
- end
- itemHistory[itemName] = itemAmount
- arrowHistory[itemName] = arrow
- arrowColorHistory[itemName] = arrowColor
- term.setCursorPos(2, y)
- term.setBackgroundColor(backgroundColor)
- term.clearLine()
- term.setTextColor(textColor)
- term.write(itemName:gsub("[%[%]]", ""))
- term.setCursorPos(w - #tostring(itemAmount) - 3, y)
- term.setTextColor(amountColor)
- term.write(tostring(itemAmount) .. " ")
- term.setTextColor(arrowColor)
- term.write(arrow)
- end
- end
- -- Draw crafting manager to right monitor
- function drawCraftingManager()
- if rightMonitor then
- term.redirect(rightMonitor)
- term.clear()
- term.setCursorPos(1, 1)
- term.write("Crafting Manager")
- local craftingItems = rs.listCrafting() -- Fetch crafting list
- local y = 2
- for _, item in pairs(craftingItems) do
- term.setCursorPos(1, y)
- term.write(item.displayName .. " [" .. item.status .. "]")
- y = y + 1
- if y > select(2, term.getSize()) then
- break
- end
- end
- term.redirect(monitor)
- end
- end
- -- Draw total item graph to left monitor
- function drawItemGraph()
- if leftMonitor then
- term.redirect(leftMonitor)
- term.clear()
- local totalAmount = 0
- for _, amount in pairs(itemHistory) do
- totalAmount = totalAmount + amount
- end
- table.insert(totalItemHistory, totalAmount)
- if #totalItemHistory > select(1, term.getSize()) then
- table.remove(totalItemHistory, 1)
- end
- term.setCursorPos(1, 1)
- term.write("Total Items Graph")
- for x = 1, #totalItemHistory do
- term.setCursorPos(x, 2)
- local height = math.min(select(2, term.getSize()), math.floor(totalItemHistory[x] / 100))
- for y = select(2, term.getSize()), select(2, term.getSize()) - height, -1 do
- term.setCursorPos(x, y)
- term.write("|")
- end
- end
- term.redirect(monitor)
- end
- end
- -- Display items in list format with smooth scrolling
- function displayList()
- term.setBackgroundColor(backgroundColor)
- term.clear()
- drawHeader(" Storage Overview ")
- drawSeparator(2)
- local scrollOffset = 0
- while true do
- rsitems = rs.listItems()
- local filteredItems = {}
- for _, item in pairs(rsitems) do
- if item.amount >= 32 then
- table.insert(filteredItems, item)
- end
- end
- table.sort(filteredItems, function(a, b) return a.amount > b.amount end)
- term.setBackgroundColor(backgroundColor)
- term.clear()
- drawHeader(" Storage Overview ")
- drawSeparator(2)
- drawFooter()
- local y = 3
- for i = 1 + scrollOffset, #filteredItems + scrollOffset do
- local index = ((i - 1) % #filteredItems) + 1
- if y < h then
- drawItemRow(y, filteredItems[index].displayName, filteredItems[index].amount)
- end
- y = y + 1
- if y >= h then
- break
- end
- end
- drawFooter()
- drawCraftingManager()
- drawItemGraph()
- sleep(0.35)
- scrollOffset = scrollOffset + 1
- end
- end
- function refreshDisplay()
- calculateScaling()
- displayList()
- end
- refreshDisplay()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement