BlissSilence

Untitled

Jan 3rd, 2025 (edited)
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.29 KB | None | 0 0
  1. -- Set up peripherals
  2. rs = peripheral.find("rsBridge")
  3. local monitors = {peripheral.find("monitor")}
  4.  
  5. local topMonitor = monitors[1] -- Main top monitor
  6. local rightMonitor = monitors[2] -- Modem-connected right monitor
  7. local leftMonitor = monitors[3] -- Left monitor (if needed later)
  8.  
  9. -- Clear right and left monitors if they exist
  10. if rightMonitor then
  11. term.redirect(rightMonitor)
  12. term.setBackgroundColor(colors.black)
  13. term.clear()
  14. end
  15.  
  16. if leftMonitor then
  17. term.redirect(leftMonitor)
  18. term.setBackgroundColor(colors.black)
  19. term.clear()
  20. end
  21.  
  22. -- Default to top monitor for now
  23. term.redirect(topMonitor)
  24.  
  25. -- Color Palette
  26. local backgroundColor = colors.black
  27. local borderColor = colors.cyan
  28. local itemColor = colors.lightGray
  29. local amountColor = colors.orange
  30. local lowStockColor = colors.red
  31. local headerColor = colors.blue
  32. local increaseColor = colors.green
  33. local decreaseColor = colors.red
  34. local batteryColor = colors.green
  35. local batteryLowColor = colors.red
  36. local batteryFrameColor = colors.gray
  37.  
  38. local itemHistory = {}
  39. local arrowHistory = {}
  40. local arrowColorHistory = {}
  41.  
  42. -- Scaling and Layout
  43. function calculateScaling()
  44. topMonitor.setTextScale(1.8) -- Increased text scale for better readability
  45. w, h = topMonitor.getSize()
  46. end
  47.  
  48. -- Draw battery status on bottom monitor
  49. function drawBattery()
  50. if leftMonitor then
  51. term.redirect(leftMonitor)
  52. leftMonitor.setTextScale(1.0) -- Reset to ensure correct scaling
  53. local lw, lh = leftMonitor.getSize()
  54. term.redirect(leftMonitor)
  55. term.setBackgroundColor(colors.black)
  56.  
  57. local energy = rs.getEnergyStorage()
  58. local maxEnergy = rs.getMaxEnergyStorage()
  59. local energyUsage = rs.getEnergyUsage()
  60.  
  61. -- Display battery status text
  62. local statusText = string.format("FE Status: %d FE / %d FE Usage: %d FE", energy, maxEnergy, energyUsage)
  63. local startX = math.floor((lw - #statusText) / 2) + 1
  64. term.setCursorPos(startX, 1)
  65. term.setTextColor(colors.white)
  66. term.write(statusText)
  67.  
  68. local barWidth = 35
  69. local barHeight = 2
  70. local fill = math.floor((energy / maxEnergy) * barWidth)
  71. local batteryX = math.floor(lw / 2) - math.floor(barWidth / 2)
  72. local batteryY = math.floor(lh / 2)
  73.  
  74. -- Draw battery frame
  75. paintutils.drawBox(batteryX, batteryY, batteryX + barWidth, batteryY + barHeight, batteryFrameColor)
  76.  
  77. -- Draw battery fill
  78. local color = energy / maxEnergy < 0.2 and batteryLowColor or batteryColor
  79. paintutils.drawBox(batteryX + 1, batteryY + 1, batteryX + fill, batteryY + barHeight - 1, color)
  80. paintutils.drawBox(batteryX + fill + 1, batteryY + 1, batteryX + barWidth - 1, batteryY + barHeight - 1, batteryLowColor)
  81.  
  82. end
  83. end
  84.  
  85. -- Draw header
  86. function drawHeader(text)
  87. term.setBackgroundColor(headerColor)
  88. term.clearLine()
  89. term.setCursorPos(1, 1)
  90. term.setTextColor(colors.white)
  91. term.write(text)
  92. end
  93.  
  94. -- Draw footer
  95. function drawFooter()
  96. term.setBackgroundColor(headerColor)
  97. term.setCursorPos(1, h)
  98. term.clearLine()
  99. term.setTextColor(colors.white)
  100. term.write(" Updated: " .. os.date("%X"))
  101. end
  102.  
  103. -- Draw separator line
  104. function drawSeparator(y)
  105. paintutils.drawLine(1, y, w, y, borderColor)
  106. end
  107.  
  108. -- Draw item row with persistent up/down indicator and color
  109. function drawItemRow(y, itemName, itemAmount)
  110. if y < h then -- Prevent overwriting the footer
  111. local previousAmount = itemHistory[itemName] or itemAmount
  112. local arrow = arrowHistory[itemName] or " "
  113. local textColor = itemColor
  114. local arrowColor = arrowColorHistory[itemName] or amountColor
  115.  
  116. if itemAmount < 100 then
  117. textColor = lowStockColor
  118. end
  119.  
  120. if itemAmount > previousAmount then
  121. arrow = "^"
  122. arrowColor = increaseColor
  123. elseif itemAmount < previousAmount then
  124. arrow = "v"
  125. arrowColor = decreaseColor
  126. end
  127.  
  128. itemHistory[itemName] = itemAmount
  129. arrowHistory[itemName] = arrow
  130. arrowColorHistory[itemName] = arrowColor
  131.  
  132. term.setCursorPos(2, y)
  133. term.setBackgroundColor(backgroundColor)
  134. term.clearLine()
  135. term.setTextColor(textColor)
  136. term.write(itemName:gsub("[%[%]]", "")) -- Remove brackets
  137.  
  138. term.setCursorPos(w - #tostring(itemAmount) - 3, y)
  139. term.setTextColor(amountColor)
  140. term.write(tostring(itemAmount) .. " ")
  141. term.setTextColor(arrowColor)
  142. term.write(arrow)
  143. end
  144. end
  145.  
  146. -- Display items in list format with smooth scrolling
  147. function displayList()
  148. term.redirect(topMonitor)
  149. term.setBackgroundColor(backgroundColor)
  150. term.clear()
  151.  
  152. drawHeader(" Storage Overview ")
  153. drawSeparator(2)
  154.  
  155. local scrollOffset = 0
  156. local visibleRows = h - 4 -- Ensure footer space is not overwritten
  157.  
  158. while true do
  159. term.redirect(topMonitor)
  160. rsitems = rs.listItems() -- Refresh items every loop
  161. local filteredItems = {}
  162.  
  163. for _, item in pairs(rsitems) do
  164. if item.amount >= 32 then
  165. table.insert(filteredItems, item)
  166. end
  167. end
  168. table.sort(filteredItems, function(a, b) return a.amount > b.amount end)
  169.  
  170. term.setBackgroundColor(backgroundColor)
  171. term.clear()
  172. drawHeader(" Storage Overview ")
  173. drawSeparator(2)
  174. drawFooter()
  175.  
  176. local y = 3
  177. for i = 1 + scrollOffset, #filteredItems + scrollOffset do
  178. local index = ((i - 1) % #filteredItems) + 1 -- Loop smoothly
  179. if y < h then -- Ensure rows stop before footer
  180. drawItemRow(y, filteredItems[index].displayName, filteredItems[index].amount)
  181. end
  182. y = y + 1
  183. if y >= h then -- Stop drawing when footer is reached
  184. break
  185. end
  186. end
  187.  
  188. drawFooter()
  189.  
  190. sleep(0.35) -- Faster scroll speed
  191. scrollOffset = scrollOffset + 1
  192.  
  193. drawBattery()
  194. end
  195. end
  196.  
  197. -- Main execution loop
  198. function refreshDisplay()
  199. calculateScaling()
  200. displayList()
  201. end
  202.  
  203. -- Start display
  204. refreshDisplay()
  205.  
Advertisement
Add Comment
Please, Sign In to add comment