Advertisement
Guest User

Untitled

a guest
Aug 24th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.86 KB | None | 0 0
  1. local component = require( "component" )
  2. local gpu = component.gpu
  3. local event = require( "event" )
  4.  
  5. local oldW, oldH = gpu.getResolution()
  6.  
  7. function clearScreen()
  8. local oldColor = gpu.getBackground( false )
  9. local w,h = gpu.getResolution()
  10. gpu.setBackground( 0x000000, false )
  11. gpu.fill( 1, 1, w, h, " " )
  12. gpu.setBackground( oldColor, false )
  13. end
  14.  
  15.  
  16. function progressBar( label, y, value, maxVal, color, show, unit )
  17. local oldColor = gpu.getBackground( false )
  18. gpu.setBackground(0x000000, false)
  19. gpu.fill( 3, y, 155, 2, " " )
  20. w = math.floor( value * (155 / maxVal) )
  21. p = math.floor( (w / 155) * 100 )
  22. gpu.set( 3, y, label .. ": " .. tostring( p ) .. "%" )
  23. gpu.setBackground( 0x222222, false )
  24. gpu.fill( 3, y+1, 155, 1, " " )
  25. gpu.setBackground( color, false )
  26. gpu.fill( 3, y+1, w, 1, " " )
  27. gpu.setBackground( oldColor, false )
  28. if show then
  29. local valStr = formatBig( value ) .. unit
  30. local n = string.len( valStr )
  31. gpu.set( 158 - n, y, valStr )
  32. end
  33. end
  34.  
  35.  
  36. function formatBig( value )
  37. local output = ""
  38. local valRem = 0
  39. local valPart = 0
  40. while value > 0 do
  41. valRem = math.floor( value / 1000 )
  42. valPart = value - (valRem * 1000)
  43. if output == "" then
  44. output = string.format( "%03d", valPart )
  45. elseif valRem == 0 then
  46. output = valPart .. "," .. output
  47. else
  48. output = string.format( "%03d", valPart ) .. "," .. output
  49. end
  50. value = valRem
  51. end
  52. return output
  53. end
  54.  
  55. function getCells()
  56. local MekanismCell = 0
  57.  
  58. local MekanismCell = component.list("mekanism")
  59.  
  60. local cellsID = {}
  61. for address, name in pairs(MekanismCell ) do
  62. countMekanismCell = countMekanismCell + 1
  63.  
  64. if countMekanismCell > 1 then
  65. cellsID[address] = "Mekanism Power Cell".." "..countMekanismCell
  66. else
  67. cellsID[address] = "Mekanism Power Cell"
  68. end
  69. end
  70. return cellsID
  71. end
  72.  
  73. function getTotal()
  74. local totalPower = 0
  75. local totalMaxPower = 0
  76. local cellid = getCells()
  77. for address, name in pairs(cellid) do
  78. local cell = component.proxy( address )
  79. totalPower = totalPower + cell.getEnergyStored()
  80. totalMaxPower = totalMaxPower + cell.getMaxEnergyStored()
  81. end
  82. return totalPower, totalMaxPower
  83.  
  84. end
  85.  
  86. clearScreen()
  87. gpu.set( 67, 1, "Power Monitor" )
  88. local cellsID = getCells()
  89.  
  90. while true do
  91. local _,_,x,y = event.pull( 1, "touch" )
  92. local count = 0
  93. if x and y then goto quit end
  94. for address, name in pairs(cellsID) do
  95. local cell = component.proxy( address )
  96. count = count + 1
  97. local t = count * 3
  98. progressBar( name, t , cell.getEnergyStored(), cell.getMaxEnergyStored() , 0x00bb00, true, "RF" )
  99. end
  100.  
  101. local totalPower, totalMaxPower = getTotal()
  102. progressBar( "TotalPower", 48 - count , totalPower, totalMaxPower, 0x00bb00, true, "RF" )
  103.  
  104. os.sleep(0.25)
  105. end
  106.  
  107.  
  108. ::quit::
  109. gpu.setResolution( oldW, oldH )
  110. clearScreen()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement