Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Peripheral setup
- local colony = peripheral.find("colonyIntegrator")
- local monitor = peripheral.find("monitor")
- if not colony then
- print("No colonyIntegrator peripheral found.")
- return
- end
- if not monitor then
- print("No monitor found.")
- return
- end
- -- Adjust text scale based on monitor size
- local function adjustTextScale()
- local w, _ = monitor.getSize()
- if w >= 39 then
- monitor.setTextScale(0.5)
- elseif w >= 29 then
- monitor.setTextScale(0.75)
- else
- monitor.setTextScale(1)
- end
- end
- -- Pagination globals
- local currentPage = 1
- local pagedRequests = {}
- local requestsPerPage = 1
- local totalPages = 1
- -- Paginate builder work orders
- local function paginateRequests(orders, perPage)
- local pages = {}
- local page = {}
- for _, order in ipairs(orders) do
- if order.builder then
- table.insert(page, order)
- if #page >= perPage then
- table.insert(pages, page)
- page = {}
- end
- end
- end
- if #page > 0 then
- table.insert(pages, page)
- end
- return pages
- end
- -- Draw buttons
- local function drawButtons(width, height)
- monitor.setCursorPos(2, height)
- monitor.write("[Prev]")
- monitor.setCursorPos(width - 6, height)
- monitor.write("[Next]")
- end
- -- Display a single page
- local function displayPage()
- adjustTextScale()
- monitor.clear()
- local width, height = monitor.getSize()
- requestsPerPage = math.floor((height - 4) / 3)
- local orders = colony.getWorkOrders() or {}
- pagedRequests = paginateRequests(orders, requestsPerPage)
- totalPages = math.max(1, #pagedRequests)
- if currentPage > totalPages then
- currentPage = totalPages
- end
- monitor.setCursorPos(1, 1)
- monitor.write("== Builder Requests (Page " .. currentPage .. "/" .. totalPages .. ") ==")
- local y = 3
- for _, order in ipairs(pagedRequests[currentPage] or {}) do
- local name = order.name or "Unknown"
- if #name > width - 10 then
- name = name:sub(1, width - 13) .. "..."
- end
- monitor.setCursorPos(1, y)
- monitor.write("[" .. order.id .. "] " .. name)
- y = y + 1
- monitor.setCursorPos(1, y)
- monitor.write(" " .. order.status .. " @ " .. order.target.x .. "," .. order.target.y .. "," .. order.target.z)
- y = y + 2
- end
- drawButtons(width, height)
- end
- -- Touch input handler
- local function waitForTouch()
- while true do
- local _, _, x, y = os.pullEvent("monitor_touch")
- local w, h = monitor.getSize()
- if y == h then
- if x >= 2 and x <= 7 and currentPage > 1 then
- currentPage = currentPage - 1
- displayPage()
- elseif x >= w - 6 and x <= w and currentPage < totalPages then
- currentPage = currentPage + 1
- displayPage()
- end
- end
- end
- end
- -- Refresh every 15 seconds
- local function autoRefresh()
- while true do
- displayPage()
- sleep(15)
- end
- end
- -- Run both loops safely
- parallel.waitForAny(waitForTouch, autoRefresh)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement