Advertisement
BlissSilence

Untitled

Jan 3rd, 2025 (edited)
5
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.70 KB | None | 0 0
  1. -- Set up peripherals
  2. rs = peripheral.find("rsBridge")
  3. monitor = peripheral.find('monitor')
  4.  
  5. -- Dynamically locate left and right monitors by size
  6. local monitors = {peripheral.find("monitor")}
  7. local rightMonitor, leftMonitor
  8.  
  9. for _, mon in pairs(monitors) do
  10. local width, height = mon.getSize()
  11. if width == 1 then
  12. rightMonitor = mon -- Vertical monitor (crafting manager)
  13. elseif height == 1 then
  14. leftMonitor = mon -- Horizontal monitor (item graph)
  15. end
  16. end
  17.  
  18. term.redirect(monitor)
  19.  
  20. -- Color Palette
  21. local backgroundColor = colors.black
  22. local borderColor = colors.cyan
  23. local itemColor = colors.lightGray
  24. local amountColor = colors.orange
  25. local lowStockColor = colors.red
  26. local headerColor = colors.blue
  27. local increaseColor = colors.green
  28. local decreaseColor = colors.red
  29.  
  30. local itemHistory = {}
  31. local arrowHistory = {}
  32. local arrowColorHistory = {}
  33. local totalItemHistory = {}
  34.  
  35. -- Scaling and Layout
  36. function calculateScaling()
  37. monitorWidth, monitorHeight = monitor.getSize()
  38. monitor.setTextScale(1.8)
  39. w, h = monitor.getSize()
  40. end
  41.  
  42. -- Draw header
  43. function drawHeader(text)
  44. term.setBackgroundColor(headerColor)
  45. term.clearLine()
  46. term.setCursorPos(1, 1)
  47. term.setTextColor(colors.white)
  48. term.write(text)
  49. end
  50.  
  51. -- Draw footer
  52. function drawFooter()
  53. term.setBackgroundColor(headerColor)
  54. term.setCursorPos(1, h)
  55. term.clearLine()
  56. end
  57.  
  58. -- Draw separator line
  59. function drawSeparator(y)
  60. paintutils.drawLine(1, y, w, y, borderColor)
  61. end
  62.  
  63. -- Draw item row with persistent up/down indicator and color
  64. function drawItemRow(y, itemName, itemAmount)
  65. if y < h then
  66. local previousAmount = itemHistory[itemName] or itemAmount
  67. local arrow = arrowHistory[itemName] or " "
  68. local textColor = itemColor
  69. local arrowColor = arrowColorHistory[itemName] or amountColor
  70.  
  71. if itemAmount < 100 then
  72. textColor = lowStockColor
  73. end
  74.  
  75. if itemAmount > previousAmount then
  76. arrow = "^"
  77. arrowColor = increaseColor
  78. elseif itemAmount < previousAmount then
  79. arrow = "v"
  80. arrowColor = decreaseColor
  81. end
  82.  
  83. itemHistory[itemName] = itemAmount
  84. arrowHistory[itemName] = arrow
  85. arrowColorHistory[itemName] = arrowColor
  86.  
  87. term.setCursorPos(2, y)
  88. term.setBackgroundColor(backgroundColor)
  89. term.clearLine()
  90. term.setTextColor(textColor)
  91. term.write(itemName:gsub("[%[%]]", ""))
  92.  
  93. term.setCursorPos(w - #tostring(itemAmount) - 3, y)
  94. term.setTextColor(amountColor)
  95. term.write(tostring(itemAmount) .. " ")
  96. term.setTextColor(arrowColor)
  97. term.write(arrow)
  98. end
  99. end
  100.  
  101. -- Draw crafting manager to right monitor
  102. function drawCraftingManager()
  103. if rightMonitor then
  104. term.redirect(rightMonitor)
  105. term.clear()
  106. term.setCursorPos(1, 1)
  107. term.write("Crafting Manager")
  108.  
  109. local craftingItems = rs.listCrafting() -- Fetch crafting list
  110. local y = 2
  111. for _, item in pairs(craftingItems) do
  112. term.setCursorPos(1, y)
  113. term.write(item.displayName .. " [" .. item.status .. "]")
  114. y = y + 1
  115. if y > select(2, term.getSize()) then
  116. break
  117. end
  118. end
  119. term.redirect(monitor)
  120. end
  121. end
  122.  
  123. -- Draw total item graph to left monitor
  124. function drawItemGraph()
  125. if leftMonitor then
  126. term.redirect(leftMonitor)
  127. term.clear()
  128. local totalAmount = 0
  129.  
  130. for _, amount in pairs(itemHistory) do
  131. totalAmount = totalAmount + amount
  132. end
  133.  
  134. table.insert(totalItemHistory, totalAmount)
  135. if #totalItemHistory > select(1, term.getSize()) then
  136. table.remove(totalItemHistory, 1)
  137. end
  138.  
  139. term.setCursorPos(1, 1)
  140. term.write("Total Items Graph")
  141.  
  142. for x = 1, #totalItemHistory do
  143. term.setCursorPos(x, 2)
  144. local height = math.min(select(2, term.getSize()), math.floor(totalItemHistory[x] / 100))
  145. for y = select(2, term.getSize()), select(2, term.getSize()) - height, -1 do
  146. term.setCursorPos(x, y)
  147. term.write("|")
  148. end
  149. end
  150. term.redirect(monitor)
  151. end
  152. end
  153.  
  154. -- Display items in list format with smooth scrolling
  155. function displayList()
  156. term.setBackgroundColor(backgroundColor)
  157. term.clear()
  158.  
  159. drawHeader(" Storage Overview ")
  160. drawSeparator(2)
  161.  
  162. local scrollOffset = 0
  163. while true do
  164. rsitems = rs.listItems()
  165. local filteredItems = {}
  166.  
  167. for _, item in pairs(rsitems) do
  168. if item.amount >= 32 then
  169. table.insert(filteredItems, item)
  170. end
  171. end
  172. table.sort(filteredItems, function(a, b) return a.amount > b.amount end)
  173.  
  174. term.setBackgroundColor(backgroundColor)
  175. term.clear()
  176. drawHeader(" Storage Overview ")
  177. drawSeparator(2)
  178. drawFooter()
  179.  
  180. local y = 3
  181. for i = 1 + scrollOffset, #filteredItems + scrollOffset do
  182. local index = ((i - 1) % #filteredItems) + 1
  183. if y < h then
  184. drawItemRow(y, filteredItems[index].displayName, filteredItems[index].amount)
  185. end
  186. y = y + 1
  187. if y >= h then
  188. break
  189. end
  190. end
  191.  
  192. drawFooter()
  193. drawCraftingManager()
  194. drawItemGraph()
  195.  
  196. sleep(0.35)
  197. scrollOffset = scrollOffset + 1
  198. end
  199. end
  200.  
  201. function refreshDisplay()
  202. calculateScaling()
  203. displayList()
  204. end
  205.  
  206. refreshDisplay()
  207.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement