Advertisement
Guest User

Untitled

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