Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- AE2 Stockpile Manager - Display Module
- local display = {}
- -- Private variables
- local monitor = nil
- -- Helper function for formatted printing
- local function printf(format, ...)
- print(string.format(format, ...))
- end
- -- Draw a colored progress bar
- local function drawProgressBar(monitor, x, y, width, current, target, threshold)
- monitor.setCursorPos(x, y)
- local percentage = math.min(current / target, 1.0)
- local filledWidth = math.floor(percentage * width)
- -- Choose color based on status
- local barColor = colors.red
- if current >= target then
- barColor = colors.lime
- elseif current >= threshold then
- barColor = colors.yellow
- end
- -- Draw filled portion
- monitor.setBackgroundColor(barColor)
- monitor.setTextColor(colors.white)
- for i = 1, filledWidth do
- monitor.write(" ")
- end
- -- Draw empty portion
- monitor.setBackgroundColor(colors.gray)
- monitor.setTextColor(colors.white)
- for i = filledWidth + 1, width do
- monitor.write(" ")
- end
- -- Reset background
- monitor.setBackgroundColor(colors.black)
- end
- -- Initialize monitor/display
- function display.initialize()
- local foundMonitor = peripheral.find("monitor")
- if foundMonitor then
- monitor = foundMonitor
- monitor.clear()
- monitor.setTextScale(0.5)
- print("Monitor connected")
- return true
- else
- print("No monitor found (optional)")
- return false
- end
- end
- -- Check if monitor is available
- function display.hasMonitor()
- return monitor ~= nil
- end
- -- Update monitor display
- function display.update(settings, currentCraftingJobs, running, quantities, systemStatus)
- if not monitor then return end
- monitor.clear()
- monitor.setCursorPos(1, 1)
- monitor.setBackgroundColor(colors.black)
- -- Header with gradient effect
- monitor.setTextColor(colors.cyan)
- monitor.write("AE2 Stockpile Manager")
- monitor.setCursorPos(1, 2)
- monitor.setTextColor(colors.lightBlue)
- monitor.write("Last Update: " .. os.date("%H:%M:%S"))
- local line = 4
- -- System Status Section
- monitor.setCursorPos(1, line)
- monitor.setTextColor(colors.orange)
- monitor.write("SYSTEM STATUS")
- line = line + 1
- monitor.setCursorPos(1, line)
- if systemStatus == "online" then
- monitor.setTextColor(colors.lime)
- monitor.write("[ONLINE] ME Bridge Active")
- elseif systemStatus == "test" then
- monitor.setTextColor(colors.yellow)
- monitor.write("[TEST] Simulation Mode")
- else
- monitor.setTextColor(colors.red)
- monitor.write("[OFFLINE] No Connection")
- end
- line = line + 2
- -- Current Crafting Jobs Section
- monitor.setCursorPos(1, line)
- monitor.setTextColor(colors.orange)
- monitor.write("ACTIVE CRAFTING JOBS")
- line = line + 1
- if #currentCraftingJobs > 0 then
- for i, job in ipairs(currentCraftingJobs) do
- if line <= 12 then -- Leave more room for items
- monitor.setCursorPos(1, line)
- monitor.setTextColor(colors.cyan)
- monitor.write("> ")
- monitor.setTextColor(colors.white)
- local itemName = job.item:gsub("minecraft:", ""):gsub("_", " ")
- monitor.write(job.amount .. "x " .. itemName)
- line = line + 1
- end
- end
- else
- monitor.setCursorPos(1, line)
- monitor.setTextColor(colors.gray)
- monitor.write("No active jobs")
- line = line + 1
- end
- line = line + 1
- -- Monitored Items Section
- monitor.setCursorPos(1, line)
- monitor.setTextColor(colors.orange)
- monitor.write("MONITORED ITEMS")
- line = line + 1
- if #settings > 0 then
- local maxY = select(2, monitor.getSize())
- for i, itemConfig in ipairs(settings) do
- if line <= maxY - 2 then -- Leave room for footer
- local currentAmount = quantities[itemConfig.item] or 0
- local itemName = itemConfig.item:gsub("minecraft:", ""):gsub("_", " ")
- monitor.setCursorPos(1, line)
- -- Status indicator
- if currentAmount >= itemConfig.target then
- monitor.setTextColor(colors.lime)
- monitor.write("[OK] ")
- elseif currentAmount >= itemConfig.threshold then
- monitor.setTextColor(colors.yellow)
- monitor.write("[LOW]")
- else
- monitor.setTextColor(colors.red)
- monitor.write("[OUT]")
- end
- -- Item name (longer names)
- monitor.setTextColor(colors.white)
- monitor.write(" " .. itemName:sub(1, 18))
- -- Numbers
- monitor.setCursorPos(25, line)
- monitor.setTextColor(colors.lightBlue)
- monitor.write(string.format("%d/%d", currentAmount, itemConfig.target))
- -- Progress bar
- if line + 1 <= maxY - 2 then
- drawProgressBar(monitor, 1, line + 1, 30, currentAmount, itemConfig.target, itemConfig.threshold)
- line = line + 2
- else
- line = line + 1
- end
- end
- end
- else
- monitor.setCursorPos(1, line)
- monitor.setTextColor(colors.gray)
- monitor.write("No items configured")
- end
- -- Footer with padding
- local maxY = select(2, monitor.getSize())
- monitor.setCursorPos(1, maxY - 1) -- Added padding-top
- monitor.setTextColor(colors.white)
- monitor.setBackgroundColor(running and colors.green or colors.gray)
- monitor.write(running and " MONITORING " or " IDLE ")
- monitor.setBackgroundColor(colors.black)
- end
- -- Show shutdown message on monitor
- function display.showShutdown()
- if not monitor then return end
- monitor.clear()
- monitor.setCursorPos(1, 1)
- monitor.setTextColor(colors.red)
- monitor.write("AE2 Stockpile Manager")
- monitor.setCursorPos(1, 2)
- monitor.setTextColor(colors.white)
- monitor.write("Program Stopped")
- end
- return display
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement