Advertisement
Koridev

me crafting display

Mar 30th, 2025
8
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.24 KB | None | 0 0
  1. -- ae_cpu_dashboard.lua
  2. -- Zeigt grafisch alle Crafting-CPUs (CPU-Kerne) von AE2 an.
  3. -- Holt Daten per rednet vom Client (mit meBridge).
  4.  
  5. -----------------------------------------
  6. -- 1) KONFIG
  7. -----------------------------------------
  8. local modemSide = "top" -- Wo dein Modem ist
  9. local monSide = "right" -- Wo dein Monitor ist
  10. local clientID = 5 -- ID des Computers, der am meBridge steht
  11. local refreshInterval = 5 -- Sekunden pro Update
  12.  
  13. -----------------------------------------
  14. -- 2) INIT
  15. -----------------------------------------
  16. local modem = peripheral.wrap(modemSide)
  17. if not modem then
  18. error("Modem an Seite '"..modemSide.."' nicht gefunden!")
  19. end
  20. rednet.open(modemSide)
  21.  
  22. local mon = peripheral.wrap(monSide)
  23. if not mon then
  24. error("Monitor an Seite '"..monSide.."' nicht gefunden!")
  25. end
  26. mon.setTextScale(0.5)
  27.  
  28. local w, h = mon.getSize()
  29.  
  30. -----------------------------------------
  31. -- 3) GLOBALE VARS
  32. -----------------------------------------
  33. local currentScreen = "main" -- "main" oder "detail"
  34. local cpus = {} -- Liste der CPUs: { {name, coProcessors, storage, busy}, ... }
  35. local selectedCPU = 1 -- Index in cpus
  36.  
  37. -----------------------------------------
  38. -- 4) HILFSFUNKTIONEN
  39. -----------------------------------------
  40. local function clear()
  41. mon.setBackgroundColor(colors.black)
  42. mon.clear()
  43. mon.setCursorPos(1,1)
  44. end
  45.  
  46. local function centerText(y, text, color)
  47. color = color or colors.white
  48. mon.setTextColor(color)
  49. local x = math.floor((w - #text)/2)
  50. mon.setCursorPos(x+1, y)
  51. mon.write(text)
  52. end
  53.  
  54. -- Hole CPU-Liste vom Client
  55. local function fetchCPUs()
  56. rednet.send(clientID, {cmd="GET_CPUS"}, "ae2_cpus")
  57. local sender, resp, proto = rednet.receive("ae2_cpus", 3)
  58. if sender == clientID and type(resp)=="table" and resp.cpus then
  59. cpus = resp.cpus
  60. else
  61. cpus = {}
  62. end
  63. end
  64.  
  65. -----------------------------------------
  66. -- 5) MAIN-SCREEN (Grafische Kaestchen)
  67. -----------------------------------------
  68. local function drawMainScreen()
  69. clear()
  70. centerText(1, "AE2 CPU Overview", colors.cyan)
  71.  
  72. mon.setTextColor(colors.white)
  73. if #cpus == 0 then
  74. centerText(math.floor(h/2), "Keine CPUs gefunden", colors.red)
  75. return
  76. end
  77.  
  78. -- Wir zeichnen pro CPU ein Rechteck, z.B. 3 Spalten a 10x5
  79. local boxW, boxH = 14, 5
  80. local cols = math.floor(w / (boxW+1))
  81. local startY = 3
  82. local i=1
  83.  
  84. for row=0,10 do
  85. for col=0,cols-1 do
  86. local c = cpus[i]
  87. if not c then return end
  88.  
  89. local x = col*(boxW+1)+2
  90. local y = row*(boxH+1)+startY
  91.  
  92. -- Rahmen
  93. mon.setCursorPos(x, y)
  94. mon.write("+"..string.rep("-", boxW-2).."+")
  95. for rrow=1, boxH-2 do
  96. mon.setCursorPos(x, y+rrow)
  97. mon.write("|"..string.rep(" ", boxW-2).."|")
  98. end
  99. mon.setCursorPos(x, y+boxH-1)
  100. mon.write("+"..string.rep("-", boxW-2).."+")
  101.  
  102. -- Name
  103. mon.setCursorPos(x+2, y+1)
  104. mon.setTextColor(colors.white)
  105. if c.name then
  106. mon.write(c.name)
  107. else
  108. mon.write("CPU #"..i)
  109. end
  110.  
  111. -- Info: Busy / Not Busy
  112. mon.setCursorPos(x+2, y+2)
  113. if c.busy then
  114. mon.setTextColor(colors.red)
  115. mon.write("Crafting...")
  116. else
  117. mon.setTextColor(colors.lime)
  118. mon.write("Idle")
  119. end
  120.  
  121. -- Co-Proz
  122. mon.setCursorPos(x+2, y+3)
  123. mon.setTextColor(colors.white)
  124. local co = c.coProcessors or 0
  125. local sto = c.storage or 0
  126. mon.write("Co: "..co..", "..sto.."k")
  127.  
  128. i=i+1
  129. if i>#cpus then return end
  130. end
  131. end
  132. end
  133.  
  134. -----------------------------------------
  135. -- 6) DETAIL-SCREEN
  136. -----------------------------------------
  137. local function drawDetailScreen(idx)
  138. clear()
  139. centerText(1, "AE2 CPU Detail", colors.cyan)
  140.  
  141. local c = cpus[idx]
  142. if not c then
  143. centerText(math.floor(h/2), "CPU nicht gefunden", colors.red)
  144. return
  145. end
  146.  
  147. mon.setCursorPos(2,3)
  148. mon.setTextColor(colors.white)
  149. mon.write("Name: "..(c.name or ("CPU #"..idx)))
  150.  
  151. mon.setCursorPos(2,4)
  152. mon.write("Busy: ")
  153. if c.busy then
  154. mon.setTextColor(colors.red)
  155. mon.write("Ja")
  156. else
  157. mon.setTextColor(colors.lime)
  158. mon.write("Nein")
  159. end
  160.  
  161. mon.setCursorPos(2,5)
  162. mon.setTextColor(colors.white)
  163. mon.write("Co-Prozessoren: "..(c.coProcessors or 0))
  164.  
  165. mon.setCursorPos(2,6)
  166. mon.write("Storage: "..(c.storage or 0).."k")
  167.  
  168. -- Evtl. mehr Felder, falls deine Version mehr Infos hat (z.B. "processingJob", "cpuIndex", etc.)
  169.  
  170. mon.setCursorPos(2,h)
  171. mon.setTextColor(colors.yellow)
  172. mon.write("[ Zurueck ]")
  173. end
  174.  
  175. -----------------------------------------
  176. -- 7) TOUCH-HANDLER
  177. -----------------------------------------
  178. local function clickMain(x,y)
  179. local boxW, boxH = 14,5
  180. local cols = math.floor(w / (boxW+1))
  181. local startY=3
  182.  
  183. local i=1
  184. for row=0,10 do
  185. for col=0,cols-1 do
  186. local rx = col*(boxW+1)+2
  187. local ry = row*(boxH+1)+startY
  188. if x>=rx and x<=rx+boxW-1 and y>=ry and y<=ry+boxH-1 then
  189. -- CPU i geklickt
  190. if cpus[i] then
  191. selectedCPU = i
  192. currentScreen = "detail"
  193. drawDetailScreen(i)
  194. end
  195. return
  196. end
  197. i=i+1
  198. if i>#cpus then return end
  199. end
  200. end
  201. end
  202.  
  203. local function clickDetail(x,y)
  204. if y==h then
  205. -- [ Zurueck ]
  206. currentScreen = "main"
  207. drawMainScreen()
  208. end
  209. end
  210.  
  211. -----------------------------------------
  212. -- 8) UPDATE-SCHRITTE
  213. -----------------------------------------
  214. local function updateAll()
  215. fetchCPUs()
  216. end
  217.  
  218. -----------------------------------------
  219. -- 9) HAUPT-LOOP
  220. -----------------------------------------
  221. local function main()
  222. updateAll()
  223. drawMainScreen()
  224.  
  225. local timerID = os.startTimer(refreshInterval)
  226. while true do
  227. local e,p1,p2,p3 = os.pullEvent()
  228. if e=="timer" and p1==timerID then
  229. updateAll()
  230. if currentScreen=="main" then
  231. drawMainScreen()
  232. else
  233. drawDetailScreen(selectedCPU)
  234. end
  235. timerID = os.startTimer(refreshInterval)
  236.  
  237. elseif e=="monitor_touch" then
  238. local x,y = p2,p3
  239. if currentScreen=="main" then
  240. clickMain(x,y)
  241. else
  242. clickDetail(x,y)
  243. end
  244. end
  245. end
  246. end
  247.  
  248. main()
  249.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement