Advertisement
BlissSilence

Untitled

Dec 30th, 2024 (edited)
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.79 KB | None | 0 0
  1. rs = peripheral.find("rsBridge")
  2. monitor = peripheral.find('monitor')
  3.  
  4. term.redirect(monitor)
  5.  
  6. selectedItem = nil
  7.  
  8. charMap = {
  9. ["A"] = {
  10. "0110",
  11. "1001",
  12. "1111",
  13. "1001",
  14. "1001"
  15. },
  16. ["B"] = {
  17. "1110",
  18. "1001",
  19. "1110",
  20. "1001",
  21. "1110"
  22. },
  23. ["C"] = {
  24. "0111",
  25. "1000",
  26. "1000",
  27. "1000",
  28. "0111"
  29. },
  30. ["D"] = {
  31. "1110",
  32. "1001",
  33. "1001",
  34. "1001",
  35. "1110"
  36. },
  37. ["E"] = {
  38. "1111",
  39. "1000",
  40. "1111",
  41. "1000",
  42. "1111"
  43. },
  44. ["F"] = {
  45. "1111",
  46. "1000",
  47. "1111",
  48. "1000",
  49. "1000"
  50. },
  51. ["G"] = {
  52. "0111",
  53. "1000",
  54. "1011",
  55. "1001",
  56. "0111"
  57. },
  58. ["H"] = {
  59. "1001",
  60. "1001",
  61. "1111",
  62. "1001",
  63. "1001"
  64. },
  65. ["I"] = {
  66. "111",
  67. "010",
  68. "010",
  69. "010",
  70. "111"
  71. },
  72. ["J"] = {
  73. "111",
  74. "001",
  75. "001",
  76. "101",
  77. "010"
  78. },
  79. ["K"] = {
  80. "1001",
  81. "1010",
  82. "1100",
  83. "1010",
  84. "1001"
  85. },
  86. ["L"] = {
  87. "1000",
  88. "1000",
  89. "1000",
  90. "1000",
  91. "1111"
  92. },
  93. ["M"] = {
  94. "10001",
  95. "11011",
  96. "10101",
  97. "10001",
  98. "10001"
  99. },
  100. ["N"] = {
  101. "10001",
  102. "11001",
  103. "10101",
  104. "10011",
  105. "10001"
  106. },
  107. ["O"] = {
  108. "0110",
  109. "1001",
  110. "1001",
  111. "1001",
  112. "0110"
  113. },
  114. ["P"] = {
  115. "1110",
  116. "1001",
  117. "1110",
  118. "1000",
  119. "1000"
  120. },
  121. ["Q"] = {
  122. "0110",
  123. "1001",
  124. "1011",
  125. "1001",
  126. "0111"
  127. },
  128. ["R"] = {
  129. "1110",
  130. "1001",
  131. "1110",
  132. "1010",
  133. "1001"
  134. },
  135. ["S"] = {
  136. "0111",
  137. "1000",
  138. "0110",
  139. "0001",
  140. "1110"
  141. },
  142. ["T"] = {
  143. "11111",
  144. "00100",
  145. "00100",
  146. "00100",
  147. "00100"
  148. },
  149. ["U"] = {
  150. "1001",
  151. "1001",
  152. "1001",
  153. "1001",
  154. "0110"
  155. },
  156. ["V"] = {
  157. "1001",
  158. "1001",
  159. "1001",
  160. "0101",
  161. "0010"
  162. },
  163. ["W"] = {
  164. "10001",
  165. "10001",
  166. "10101",
  167. "11011",
  168. "10001"
  169. },
  170. ["X"] = {
  171. "10001",
  172. "01010",
  173. "00100",
  174. "01010",
  175. "10001"
  176. },
  177. ["Y"] = {
  178. "10001",
  179. "01010",
  180. "00100",
  181. "00100",
  182. "00100"
  183. },
  184. ["Z"] = {
  185. "1111",
  186. "0001",
  187. "0010",
  188. "0100",
  189. "1111"
  190. },
  191. ["0"] = {
  192. "0110",
  193. "1001",
  194. "1001",
  195. "1001",
  196. "0110"
  197. },
  198. ["1"] = {
  199. "010",
  200. "110",
  201. "010",
  202. "010",
  203. "111"
  204. },
  205. ["2"] = {
  206. "1110",
  207. "0001",
  208. "0110",
  209. "1000",
  210. "1111"
  211. },
  212. ["3"] = {
  213. "1110",
  214. "0001",
  215. "0110",
  216. "0001",
  217. "1110"
  218. },
  219. ["4"] = {
  220. "1001",
  221. "1001",
  222. "1111",
  223. "0001",
  224. "0001"
  225. },
  226. ["5"] = {
  227. "1111",
  228. "1000",
  229. "1110",
  230. "0001",
  231. "1110"
  232. },
  233. ["6"] = {
  234. "0111",
  235. "1000",
  236. "1110",
  237. "1001",
  238. "0110"
  239. },
  240. ["7"] = {
  241. "1111",
  242. "0001",
  243. "0010",
  244. "0100",
  245. "0100"
  246. },
  247. ["8"] = {
  248. "0110",
  249. "1001",
  250. "0110",
  251. "1001",
  252. "0110"
  253. },
  254. ["9"] = {
  255. "0110",
  256. "1001",
  257. "0111",
  258. "0001",
  259. "0110"
  260. },
  261. [":"] = {
  262. "0",
  263. "1",
  264. "0",
  265. "1",
  266. "0"
  267. },
  268. [" "] = {
  269. "0",
  270. "0",
  271. "0",
  272. "0",
  273. "0"
  274. }
  275. }
  276.  
  277. -- Calculate dynamic scaling based on monitor size
  278. function calculateScaling()
  279. monitorWidth, monitorHeight = monitor.getSize()
  280.  
  281. targetWidth = 9
  282. targetHeight = 5
  283.  
  284. local textScaleX = monitorWidth / (targetWidth * 6)
  285. local textScaleY = monitorHeight / (targetHeight * 3)
  286.  
  287. scale = math.min(textScaleX, textScaleY)
  288. scale = math.max(0.75, math.min(1, scale))
  289. monitor.setTextScale(scale)
  290.  
  291. w, h = monitor.getSize()
  292.  
  293. boxWidth = math.floor(w / targetWidth)
  294. boxHeight = math.floor(h / targetHeight)
  295. boxesPerRow = math.floor(w / boxWidth)
  296. rows = math.floor(h / boxHeight) - 1 -- Leave room for ticker
  297. end
  298.  
  299. -- Render a character at (x,y) using a 5x7 grid
  300. function drawChar(x, y, char, size, color)
  301. local pixels = charMap[char]
  302. if not pixels then return end -- Skip if character isn't mapped
  303.  
  304. term.setBackgroundColor(color)
  305.  
  306. for row = 1, #pixels do
  307. for col = 1, #pixels[row] do
  308. if pixels[row]:sub(col, col) == "1" then
  309. paintutils.drawBox(
  310. x + (col - 1) * size,
  311. y + (row - 1) * size,
  312. x + col * size - 1,
  313. y + row * size - 1
  314. )
  315. end
  316. end
  317. end
  318. end
  319.  
  320. -- Draw text using the char map
  321. function drawLargeText(x, y, text, size, color)
  322. for i = 1, #text do
  323. local char = text:sub(i, i)
  324. drawChar(x + (i - 1) * (6 * size), y, char, size, color)
  325. end
  326. end
  327.  
  328. -- Shorten item names
  329. function shortenItemName(name)
  330. name = name:gsub("[%[%]]", "")
  331.  
  332. if name:match("Ingot") then
  333. return name:gsub("Ingot", "I")
  334. elseif name:match("Raw") then
  335. return name:gsub("Raw", "R")
  336. elseif name:match("Ore") then
  337. return name:gsub("Ore", "O")
  338. elseif name:match("Essence") then
  339. return name:gsub("Essence", "E")
  340. elseif name:match("Nether") then
  341. return name:gsub("Nether", "N")
  342. elseif name:match("Seeds") or name:match("Seed") then
  343. return name:gsub("Seed[s]?", "S")
  344. elseif name:match("Log") then
  345. return name:gsub("Log", "L")
  346. else
  347. return name:match("^[^ ]+") or name
  348. end
  349. end
  350.  
  351. -- Shorten long text to fit within a box
  352. function dynamicallyShorten(text, maxWidth)
  353. while #text > maxWidth do
  354. if text:find(" ") then
  355. firstWord = text:match("^[^ ]+")
  356. rest = text:match(" .+") or ""
  357.  
  358. if firstWord and #firstWord > 2 then
  359. text = string.sub(firstWord, 1, #firstWord - 1) .. rest
  360. else
  361. text = string.sub(text, 1, #text - 1)
  362. end
  363. else
  364. if #text > 2 then
  365. text = string.sub(text, 1, #text - 1)
  366. else
  367. break
  368. end
  369. end
  370. end
  371. return text
  372. end
  373.  
  374. -- Draw item box
  375. function drawBox(x, y, width, height, innerColor, borderColor)
  376. paintutils.drawFilledBox(x - 1, y - 1, x + width, y + height, borderColor)
  377. paintutils.drawFilledBox(x, y, x + width - 2, y + height - 2, innerColor)
  378. end
  379.  
  380. -- Print left-aligned text in the box
  381. function printLeft(x, y, text, color)
  382. displayText = dynamicallyShorten(text, boxWidth - 2)
  383. term.setTextColor(color)
  384. term.setCursorPos(x + 1, y)
  385. term.write(displayText)
  386. end
  387.  
  388. -- Display item in fullscreen with large canvas text
  389. function displayFullScreen(item)
  390. term.setBackgroundColor(colors.black)
  391. term.clear()
  392.  
  393. -- Draw full-screen box
  394. drawBox(1, 1, w, h - 1, colors.lightGray, colors.green)
  395.  
  396. -- Determine text color based on item count
  397. local textColor
  398. if item.amount > 5000 then
  399. textColor = colors.red
  400. elseif item.amount > 2000 then
  401. textColor = colors.orange
  402. else
  403. textColor = colors.white
  404. end
  405.  
  406. -- Draw item name in large text
  407. centerX = math.floor(w / 4)
  408. centerY = math.floor(h / 4)
  409.  
  410. -- Draw item count below
  411. drawLargeText(centerX - 2, centerY, tostring(item.amount), 2, textColor)
  412.  
  413. -- Print exit instruction at the bottom
  414. term.setCursorPos(math.floor(w / 2) - 10, h - 3)
  415. term.setTextColor(colors.white)
  416. term.write("Tap anywhere to return")
  417. end
  418.  
  419. function scrollTicker(lowestItems)
  420. local tickerText = ""
  421. for _, item in ipairs(lowestItems) do
  422. tickerText = tickerText .. shortenItemName(item.displayName) .. ":" .. item.amount .. " "
  423. end
  424.  
  425. local pos = 1
  426. while true do
  427. term.setCursorPos(1, h)
  428. term.clearLine()
  429. term.setBackgroundColor(colors.green)
  430. term.setTextColor(colors.white) -- Force ticker text to be white
  431. term.write(string.sub(tickerText, pos, pos + w))
  432.  
  433. pos = pos + 1
  434. if pos > #tickerText then
  435. pos = 1
  436. end
  437. sleep(0.2)
  438. end
  439. end
  440.  
  441. -- Detect which box was clicked
  442. function detectClick(x, y)
  443. local boxX = math.floor((x - 2) / boxWidth) + 1
  444. local boxY = math.floor((y - 2) / boxHeight)
  445. local index = (boxY * boxesPerRow) + boxX
  446. return index
  447. end
  448.  
  449. calculateScaling()
  450.  
  451. parallel.waitForAny(
  452. function()
  453. filteredItems = {}
  454. local refreshTimer = os.startTimer(5) -- Start a timer for auto-refresh
  455. while true do
  456. term.setBackgroundColor(colors.green)
  457. term.clear()
  458. term.setCursorPos(1, 1)
  459. rsitems = rs.listItems()
  460.  
  461. filteredItems = {} -- Rebuild filtered list each refresh
  462. for _, item in pairs(rsitems) do
  463. if item.amount >= 32 then
  464. table.insert(filteredItems, item)
  465. end
  466. end
  467.  
  468. table.sort(filteredItems, function(a, b)
  469. return a.amount > b.amount
  470. end)
  471.  
  472. -- Display grid or zoomed item
  473. if selectedItem then
  474. displayFullScreen(selectedItem)
  475. else
  476. for i, item in ipairs(filteredItems) do
  477. col = ((i - 1) % boxesPerRow) * boxWidth + 2
  478. row = math.floor((i - 1) / boxesPerRow) * boxHeight + 2
  479.  
  480. if row + boxHeight > h - 1 then
  481. break
  482. end
  483.  
  484. -- Color logic for counts
  485. local textColor
  486. if item.amount > 5000 then
  487. textColor = colors.red
  488. elseif item.amount > 2000 then
  489. textColor = colors.orange
  490. else
  491. textColor = colors.white
  492. end
  493.  
  494. drawBox(col, row, boxWidth, boxHeight, colors.lightGray, colors.green)
  495. printLeft(col, row + 1, shortenItemName(item.displayName), textColor)
  496. printLeft(col, row + 3, tostring(item.amount), textColor)
  497. end
  498. end
  499.  
  500. -- Wait for touch or timer event
  501. local event, param1, param2, param3 = os.pullEvent()
  502.  
  503. if event == "monitor_touch" then
  504. local index = detectClick(param2, param3)
  505. if selectedItem then
  506. selectedItem = nil
  507. elseif filteredItems[index] then
  508. selectedItem = filteredItems[index]
  509. end
  510. elseif event == "timer" and param1 == refreshTimer then
  511. -- Timer event: refresh the grid and restart the timer
  512. refreshTimer = os.startTimer(5)
  513. end
  514. end
  515. end,
  516. function()
  517. while true do
  518. if #filteredItems > 0 then
  519. scrollTicker(filteredItems)
  520. else
  521. sleep(1)
  522. end
  523. end
  524. end
  525. )
  526.  
  527.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement