Advertisement
TechManDylan

BuilderManager

May 31st, 2025 (edited)
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.19 KB | None | 0 0
  1. -- Peripheral setup
  2. local colony = peripheral.find("colonyIntegrator")
  3. local monitor = peripheral.find("monitor")
  4.  
  5. if not colony then
  6.     print("No colonyIntegrator peripheral found.")
  7.     return
  8. end
  9.  
  10. if not monitor then
  11.     print("No monitor found.")
  12.     return
  13. end
  14.  
  15. -- Adjust text scale based on monitor size
  16. local function adjustTextScale()
  17.     local w, _ = monitor.getSize()
  18.     if w >= 39 then
  19.         monitor.setTextScale(0.5)
  20.     elseif w >= 29 then
  21.         monitor.setTextScale(0.75)
  22.     else
  23.         monitor.setTextScale(1)
  24.     end
  25. end
  26.  
  27. -- Pagination globals
  28. local currentPage = 1
  29. local pagedRequests = {}
  30. local requestsPerPage = 1
  31. local totalPages = 1
  32.  
  33. -- Paginate builder work orders
  34. local function paginateRequests(orders, perPage)
  35.     local pages = {}
  36.     local page = {}
  37.  
  38.     for _, order in ipairs(orders) do
  39.         if order.builder then
  40.             table.insert(page, order)
  41.             if #page >= perPage then
  42.                 table.insert(pages, page)
  43.                 page = {}
  44.             end
  45.         end
  46.     end
  47.  
  48.     if #page > 0 then
  49.         table.insert(pages, page)
  50.     end
  51.  
  52.     return pages
  53. end
  54.  
  55. -- Draw buttons
  56. local function drawButtons(width, height)
  57.     monitor.setCursorPos(2, height)
  58.     monitor.write("[Prev]")
  59.     monitor.setCursorPos(width - 6, height)
  60.     monitor.write("[Next]")
  61. end
  62.  
  63. -- Display a single page
  64. local function displayPage()
  65.     adjustTextScale()
  66.     monitor.clear()
  67.  
  68.     local width, height = monitor.getSize()
  69.     requestsPerPage = math.floor((height - 4) / 3)
  70.     local orders = colony.getWorkOrders() or {}
  71.     pagedRequests = paginateRequests(orders, requestsPerPage)
  72.     totalPages = math.max(1, #pagedRequests)
  73.  
  74.     if currentPage > totalPages then
  75.         currentPage = totalPages
  76.     end
  77.  
  78.     monitor.setCursorPos(1, 1)
  79.     monitor.write("== Builder Requests (Page " .. currentPage .. "/" .. totalPages .. ") ==")
  80.  
  81.     local y = 3
  82.     for _, order in ipairs(pagedRequests[currentPage] or {}) do
  83.         local name = order.name or "Unknown"
  84.         if #name > width - 10 then
  85.             name = name:sub(1, width - 13) .. "..."
  86.         end
  87.  
  88.         monitor.setCursorPos(1, y)
  89.         monitor.write("[" .. order.id .. "] " .. name)
  90.         y = y + 1
  91.  
  92.         monitor.setCursorPos(1, y)
  93.         monitor.write("  " .. order.status .. " @ " .. order.target.x .. "," .. order.target.y .. "," .. order.target.z)
  94.         y = y + 2
  95.     end
  96.  
  97.     drawButtons(width, height)
  98. end
  99.  
  100. -- Touch input handler
  101. local function waitForTouch()
  102.     while true do
  103.         local _, _, x, y = os.pullEvent("monitor_touch")
  104.         local w, h = monitor.getSize()
  105.         if y == h then
  106.             if x >= 2 and x <= 7 and currentPage > 1 then
  107.                 currentPage = currentPage - 1
  108.                 displayPage()
  109.             elseif x >= w - 6 and x <= w and currentPage < totalPages then
  110.                 currentPage = currentPage + 1
  111.                 displayPage()
  112.             end
  113.         end
  114.     end
  115. end
  116.  
  117. -- Refresh every 15 seconds
  118. local function autoRefresh()
  119.     while true do
  120.         displayPage()
  121.         sleep(15)
  122.     end
  123. end
  124.  
  125. -- Run both loops safely
  126. parallel.waitForAny(waitForTouch, autoRefresh)
  127.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement