charlesthepenguin

Untitled

Jul 28th, 2020
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.64 KB | None | 0 0
  1. --[[ this based in code from Nonsanity https://www.youtube.com/user/Nonsanity. mosty using the GUI!
  2. The code was edited and changed by jennifer cally "ebony"
  3. --]]
  4.  
  5.  
  6. local component = require( "component" )
  7. local gpu = component.gpu
  8. local event = require( "event" )
  9.  
  10. local oldW, oldH = gpu.getResolution()
  11. gpu.setResolution( 160, 50 )
  12.  
  13. function clearScreen()
  14. local oldColor = gpu.getBackground( false )
  15. local w,h = gpu.getResolution()
  16. gpu.setBackground( 0x000000, false )
  17. gpu.fill( 1, 1, w, h, " " )
  18. gpu.setBackground( oldColor, false )
  19. end
  20.  
  21.  
  22. function progressBar( label, y, value, maxVal, color, show, unit )
  23. local oldColor = gpu.getBackground( false )
  24. gpu.setBackground(0x000000, false)
  25. gpu.fill( 3, y, 155, 2, " " )
  26. w = math.floor( value * (155 / maxVal) )
  27. p = math.floor( (w / 155) * 100 )
  28. gpu.set( 3, y, label .. ": " .. tostring( p ) .. "%" )
  29. gpu.setBackground( 0x222222, false )
  30. gpu.fill( 3, y+1, 155, 1, " " )
  31. gpu.setBackground( color, false )
  32. gpu.fill( 3, y+1, w, 1, " " )
  33. gpu.setBackground( oldColor, false )
  34. if show then
  35. local valStr = formatBig( value ) .. unit
  36. local n = string.len( valStr )
  37. gpu.set( 158 - n, y, valStr )
  38. end
  39. end
  40.  
  41.  
  42. function formatBig( value )
  43. local output = ""
  44. local valRem = 0
  45. local valPart = 0
  46. while value > 0 do
  47. valRem = math.floor( value / 1000 )
  48. valPart = value - (valRem * 1000)
  49. if output == "" then
  50. output = string.format( "%03d", valPart )
  51. elseif valRem == 0 then
  52. output = valPart .. "," .. output
  53. else
  54. output = string.format( "%03d", valPart ) .. "," .. output
  55. end
  56. value = valRem
  57. end
  58. return output
  59. end
  60.  
  61. function getCells()
  62. local countDcOrb = 0
  63. local countTEcell = 0
  64. local countRfTCell = 0
  65.  
  66. local TEcell = component.list( "energy_device" )
  67. local DcOrb = component.list("draconic_rf_storage")
  68. local RfTCell = component.list("rftools_powercell")
  69.  
  70. local cellsID = {}
  71. for address, name in pairs(DcOrb) do
  72. countDcOrb = countDcOrb + 1
  73. if countDcOrb > 1 then
  74. cellsID[address] = "Draconic Power Orb".." "..countDcOrb
  75. else
  76. cellsID[address] ="Draconic Power Orb"
  77. end
  78. end
  79. for address, name in pairs(TEcell) do
  80. countTEcell = countTEcell + 1
  81.  
  82. if countTEcell > 1 then
  83. cellsID[address] = "Thermal Expansion Power Cell".." "..countTEcell
  84. else
  85. cellsID[address] = "Thermal Expansion Power Cell"
  86. end
  87. end
  88. for address, name in pairs(RfTCell) do
  89. countRfTCell = countRfTCell + 1
  90.  
  91. if countRfTCell > 1 then
  92. cellsID[address] = "RfTools Power Cell".." "..countRfTCell
  93. else
  94. cellsID[address] = "RfTools Power Cell"
  95. end
  96. end
  97. return cellsID
  98. end
  99.  
  100. function getTotal()
  101. local totalPower = 0
  102. local totalMaxPower = 0
  103. local cellid = getCells()
  104. for address, name in pairs(cellid) do
  105. local cell = component.proxy( address )
  106. totalPower = totalPower + cell.getEnergyStored()
  107. totalMaxPower = totalMaxPower + cell.getMaxEnergyStored()
  108. end
  109. return totalPower, totalMaxPower
  110.  
  111. end
  112.  
  113. clearScreen()
  114. gpu.set( 67, 1, "Power Monitor" )
  115. local cellsID = getCells()
  116.  
  117. while true do
  118. local _,_,x,y = event.pull( 1, "touch" )
  119. local count = 0
  120. if x and y then goto quit end
  121. for address, name in pairs(cellsID) do
  122. local cell = component.proxy( address )
  123. count = count + 1
  124. local t = count * 3
  125. progressBar( name, t , cell.getEnergyStored(), cell.getMaxEnergyStored() , 0x00bb00, true, "RF" )
  126. end
  127.  
  128. local totalPower, totalMaxPower = getTotal()
  129. progressBar( "TotalPower", 48 - count , totalPower, totalMaxPower, 0x00bb00, true, "RF" )
  130.  
  131. os.sleep(0.25)
  132. end
  133.  
  134.  
  135. ::quit::
  136. gpu.setResolution( oldW, oldH )
  137. clearScreen()
Add Comment
Please, Sign In to add comment