Advertisement
Guest User

Untitled

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