Advertisement
Guest User

Untitled

a guest
Nov 17th, 2019
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.97 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. local countMekanism = 0
  66.  
  67. local TEcell = component.list( "energy_device" )
  68. local DcOrb = component.list("draconic_rf_storage")
  69. local RfTCell = component.list("rftools_powercell")
  70. local Mekanism = component.list("mekanism_induction_port")
  71.  
  72. local cellsID = {}
  73. for address, name in pairs(DcOrb) do
  74. countDcOrb = countDcOrb + 1
  75. if countDcOrb > 1 then
  76. cellsID[address] = "Draconic Power Orb".." "..countDcOrb
  77. else
  78. cellsID[address] ="Draconic Power Orb"
  79. end
  80. end
  81. for address, name in pairs(TEcell) do
  82. countTEcell = countTEcell + 1
  83.  
  84. if countTEcell > 1 then
  85. cellsID[address] = "Thermal Expansion Power Cell".." "..countTEcell
  86. else
  87. cellsID[address] = "Thermal Expansion Power Cell"
  88. end
  89. end
  90. for address, name in pairs(RfTCell) do
  91. countRfTCell = countRfTCell + 1
  92.  
  93. if countRfTCell > 1 then
  94. cellsID[address] = "RfTools Power Cell".." "..countRfTCell
  95. else
  96. cellsID[address] = "RfTools Power Cell"
  97. end
  98. end
  99. for address, name in pairs(Mekanism) do
  100. countMekanism = countMekanism + 1
  101.  
  102. if countMekanism > 1 then
  103. cellsID[address] = "Mekanism Power Cell".." "..countMekanism
  104. else
  105. cellsID[address] = "Mekanism Expansion Power Cell"
  106. end
  107. end
  108. return cellsID
  109. end
  110.  
  111. function getTotal()
  112. local totalPower = 0
  113. local totalMaxPower = 0
  114. local cellid = getCells()
  115. for address, name in pairs(cellid) do
  116. local cell = component.proxy( address )
  117. totalPower = totalPower + cell.getEnergyStored()
  118. totalMaxPower = totalMaxPower + cell.getMaxEnergyStored()
  119. end
  120. return totalPower, totalMaxPower
  121.  
  122. end
  123.  
  124. clearScreen()
  125. gpu.set( 67, 1, "Power Monitor" )
  126. local cellsID = getCells()
  127.  
  128. while true do
  129. local _,_,x,y = event.pull( 1, "touch" )
  130. local count = 0
  131. if x and y then goto quit end
  132. for address, name in pairs(cellsID) do
  133. local cell = component.proxy( address )
  134. count = count + 1
  135. local t = count * 3
  136. progressBar( name, t , cell.getEnergyStored(), cell.getMaxEnergyStored() , 0x00bb00, true, "RF" )
  137. end
  138.  
  139. local totalPower, totalMaxPower = getTotal()
  140. progressBar( "TotalPower", 48 - count , totalPower, totalMaxPower, 0x00bb00, true, "RF" )
  141.  
  142. os.sleep(0.25)
  143. end
  144.  
  145.  
  146. ::quit::
  147. gpu.setResolution( oldW, oldH )
  148. clearScreen()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement