domian844

[OpenComputers] Info Gregtech machines2

Jan 14th, 2021
498
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --- Конфиг / Config
  2.  
  3. --- Включение/Выключение отображения типа машины (Мультиблок или Базовая машина)
  4. --- Turn on / off the display of the machine type (Multi-block or Basic machine)
  5. writeTypeMachine = true
  6.  
  7. --- @textName - Название которое выводится на монитор / Name displayed on the monitor
  8. --- @textReplace - Название на которое вы хотите заменить @textName / Replacement name @textName
  9. --- Необходимо соблюдать порядок @textName должна совпадать с @textReplace / The order must be followed @textName must match @textReplace
  10.  
  11. textName = {
  12.     "boiler.bronze", "boiler.steel", "boiler.titan", "boiler.tungstensteel",
  13.     "chemicalreactor", "vacuumfreezer", "alloysmelter", "fluidcanner",
  14.     "blastfurnace", "blastsmelter", "freezsolidifier"
  15. }
  16. textReplace = {
  17.     "Boiler Bronze", "Boiler Steel", "Boiler Titan", "Boiler Tungstensteel",
  18.     "Chemical Reactor", "VF", "Alloy Smelter", "Fluid Canner",
  19.     "EBF", "EBS", "FS"
  20. }
  21.  
  22. comp = require("component")
  23. screen = require("term")
  24. computer = require("computer")
  25. event = require("event")
  26. GPU1 = comp.gpu
  27. sides = require("sides")
  28. local text = require("text")
  29. local unicode = require("unicode")
  30.  
  31. screenWidth = 160
  32. screenHeight = 50
  33. borderColor = 0x1A1A1A
  34. backgroundColor = 0x0D0D0D
  35. progressBarColor = 0x00CC00
  36. errorColor = 0xCC0000
  37. workingColor = 0x00FF00
  38. idleColor = 0xFFFF00
  39. textColor = 0xFFFFFF
  40.  
  41. GPU1.setResolution(screenWidth, screenHeight)
  42. readings = {}
  43. machines = {}
  44.  
  45. function progressText(current, max)
  46.     formattedProgress = {}
  47.     formattedProgress[1] = current
  48.     formattedProgress[2] = max
  49.     return table.concat(formattedProgress, "/")
  50. end
  51.  
  52. function box(x, y, w, h, color)
  53.     local oldColor = GPU1.setBackground(color)
  54.     GPU1.fill(x, y, w, h, " ")
  55.     GPU1.setBackground(oldColor)
  56. end
  57.  
  58. function write(x, y, text, color)
  59.     color = color or textColor
  60.     screen.setCursor(x, y)
  61.     oldColor = GPU1.setForeground(color)
  62.     screen.write(text)
  63.     GPU1.setForeground(oldColor)
  64. end
  65.  
  66. function replace(label)
  67.     basic = ""
  68.     multi = ""
  69.  
  70.     if writeTypeMachine then
  71.         basic = "[B] "
  72.         multi = "[M] "
  73.     end
  74.  
  75.     label = string.gsub(label, "(basicmachine.)", basic)
  76.     label = string.gsub(label, "(multimachine.)", multi)
  77.     label = string.gsub(label, "(impact.multimachine.)", "")
  78.     label = string.gsub(label, "(impact.)", "")
  79.  
  80.     for i = 1, 15 do
  81.         label = string.gsub(label, "(.tier.0)".. i, "")
  82.     end
  83.  
  84.     for i = 1, #textName do
  85.         label = string.gsub(label, "("..textName[i]..")", textReplace[i])
  86.     end
  87.  
  88.     label = string.gsub(label, "(.)", string.upper, #basic + 1)
  89.  
  90.     if #label > 18 then
  91.         label = unicode.wtrunc(label, 18)
  92.     end
  93.  
  94.     return label
  95. end
  96.  
  97. function MachineGT(x, y, address, label)
  98.     machine = comp.proxy(comp.get(address))
  99.     label = machine.getInventoryName()
  100.     maintenanceIndex = 0
  101.     uses = 0
  102.     if machines[address] == nil then
  103.         machines[address] = machine
  104.         box(x, y, 4, 3, borderColor)
  105.         box(x + 4, y, 19, 3, backgroundColor)
  106.         write(x + 5, y, replace(label), textColor)
  107.     end
  108.  
  109.     box(x + 4, y + 1, 19, 2, backgroundColor)
  110.     box(x + 5 + #replace(label), y, 23 - #replace(label) - 5, 1, backgroundColor)
  111.     for i = 1, #machine.getSensorInformation() do
  112.         if string.match(machine.getSensorInformation()[i], "Problems") then
  113.             maintenanceIndex = i
  114.         end
  115.     end
  116.     for i = 1, #machine.getSensorInformation() do
  117.         if string.match(machine.getSensorInformation()[i], "Probably") then
  118.             uses = i
  119.         end
  120.     end
  121.     if (machine.hasWork()) then
  122.         GPU1.setBackground(backgroundColor)
  123.         box(x + 1, y + 1, 2, 1, workingColor)
  124.         box(x + 5, y + 1, math.floor(18 * (machine.getWorkProgress() / machine.getWorkMaxProgress())), 1, progressBarColor)
  125.         local progressString = progressText(math.floor(machine.getWorkProgress() / 20), math.floor(machine.getWorkMaxProgress() / 20)) .. "s"
  126.         write(x + 23 - #progressString, y, progressString)
  127.         if uses == 0 then
  128.         else
  129.             textrep = string.gsub(machine.getSensorInformation()[uses], "Probably uses:", "")
  130.             textrep = string.gsub(textrep, "§c", "")
  131.             textrep = string.gsub(textrep, "§r", "")
  132.             write(x + 23 - #textrep, y+2, textrep, errorColor)
  133.        
  134.         end
  135.     else
  136.         box(x + 1, y + 1, 2, 1, idleColor)
  137.     end
  138.     GPU1.setBackground(backgroundColor)
  139.     if (maintenanceIndex == 0 or string.match(machine.getSensorInformation()[maintenanceIndex], "c0")) and machine.isWorkAllowed() then
  140.     else
  141.         if (machine.isWorkAllowed()) then
  142.             box(x + 1, y + 1, 2, 1, idleColor)
  143.             write(x + 5, y + 2, "Needs maintenance!", errorColor)
  144.         else
  145.             box(x + 1, y + 1, 2, 1, errorColor)
  146.             write(x + 5, y + 2, "Machine disabled!", errorColor)
  147.         end
  148.     end
  149. end
  150.  
  151. local gt = comp.list("gt_machine")
  152. function updategt()
  153.     gt = comp.list("gt_machine")
  154. end
  155. function checkGT()
  156.     y = 5;
  157.     x = 1;
  158.     i = 0
  159.     for address, type in pairs(gt) do
  160.         gtAddress = comp.proxy(address)
  161.         if i % 11  == 0 then
  162.             y = 5
  163.             x=x+25
  164.         end
  165.         MachineGT(x-19, y, address, "Machine #"..i)
  166.         y=y+4
  167.         i=i+1
  168.     end
  169. end
  170.  
  171. function offProgram(x)
  172.     write(screenWidth-15, 1, "Off - Ctrl+C", 0x858585)
  173.     write(screenWidth-15, 1, "Off - Ctrl+C", 0x858585)
  174.     x = x + 1
  175.     if (x % 2 == 0) then
  176.         box(screenWidth-2, 1, 2, 1, 0x858585)
  177.     else
  178.         box(screenWidth-2, 1, 2, 1, 0xffffff)
  179.     end
  180.  
  181. end
  182.  
  183. screen.clear()
  184. step = 1
  185.  
  186. while (true) do
  187.     updategt()
  188.     checkGT()
  189.     offProgram(step)
  190.     step = step + 1
  191.     os.sleep(0.1)
  192.     if event.pull(.5, "interrupted") then
  193.         screen.clear()
  194.         break
  195.     end
  196. end
RAW Paste Data