RandomShovel

[1.6] [CC][IC2][AE][TE] Monitor GUI v1

Feb 22nd, 2014
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.09 KB | None | 0 0
  1. --[[ Config  ]]--
  2.  
  3. terminalSide = "bottom"
  4. wiredModemSide = "back"
  5.  
  6. refreshTime = 1
  7. -- Time in seconds until the screen GUI refreshes
  8.  
  9. AppliedEnergistics = true
  10. -- Gets the stored item count and turn red if full
  11.  
  12. IndustrialCraft = true
  13. -- Gets the capacity | remaining amount of EU stored in your "MFSUs/Batboxes/MFEs/CESUs/"
  14.  
  15. ThermalExpansion = true
  16. -- Gets capacity | remaining amount of MJ stored in your energy cells
  17.  
  18.  
  19. --[[  Tables  ]]--
  20.  
  21. EnergyUnits = {}
  22. AppliedStorage = {}
  23. MinecraftJoules = {}
  24. tArgs = { ... }
  25.  
  26.  
  27. --[[ Variables ]]--
  28.  
  29. bridge = peripheral.wrap(terminalSide)
  30. net = peripheral.wrap(wiredModemSide)
  31.  
  32. currentEU = 0
  33. maxEU = 0
  34.  
  35. currentStorage = 0
  36.  
  37. currentMJ = 0
  38. maxMJ = 0
  39.  
  40.  
  41. --[[  Functions  ]]--
  42.  
  43. function checkPeripherals()
  44.  MinecraftJoules = {}
  45.  EnergyUnits = {}
  46.  MinecraftJoules = {}
  47.  
  48.  connectedPers = peripheral.getNames()
  49.  
  50.  for i=1, #connectedPers do
  51.   if string.find(connectedPers[i], "mfsu") or string.find(connectedPers[i], "batbox") or string.find(connectedPers[i], "cesu") or string.find(connectedPers[i], "mfe") then
  52.    table.insert(EnergyUnits, connectedPers[i])
  53.   elseif string.find(connectedPers[i], "appeng") then
  54.    table.insert(AppliedStorage, connectedPers[i])
  55.   elseif string.find(connectedPers[i], "cofh_thermalexpansion") then
  56.    table.insert(MinecraftJoules, connectedPers[i])
  57.   end
  58.  end
  59. end
  60.  
  61. function displayText()
  62.  bridge.clear()
  63.  bridge.addText(3, 44, "Made by RandomShovel", math.random(0, 999999))
  64.  
  65.  if IndustrialCraft then
  66.   cEU = bridge.addText(3, 16, "0", 0xFFFFFF)
  67.   mEU = bridge.addText(3, 16, "0", 0xFFFFFF)
  68.   divEU = bridge.addText(3, 16, "|", 0xFFFFFF)
  69.   cEU.setZIndex(1)
  70.   mEU.setZIndex(1)
  71.   divEU.setZIndex(1)
  72.  end
  73.  
  74.  if AppliedEnergistics then
  75.   cAE = bridge.addText(5, 32, "0", 0xFFFFFF)
  76.   cAE.setZIndex(1)
  77.  end
  78.  
  79.  if ThermalExpansion then
  80.   cMJ = bridge.addText(3, 74, "0", 0xFFFFFF)
  81.   mMJ = bridge.addText(3, 74, "0", 0xFFFFFF)
  82.   divMJ = bridge.addText(3, 74, "|", 0xFFFFFF)
  83.   cMJ.setZIndex(1)
  84.   mMJ.setZIndex(1)
  85.   divMJ.setZIndex(1)
  86.  end
  87. end
  88.  
  89. function formNum(input)
  90.  input2 = string.gsub(input, "(%d)(%d%d%d)$", "%1, %2", 1)
  91.  while true do
  92.   input2, found = string.gsub(input2, "(%d)(%d%d%d),", "%1, %2,", 1)
  93.   if found == 0 then
  94.    return input2
  95.   end
  96.  end
  97. end
  98.  
  99. function grabData()
  100.  if IndustrialCraft then
  101.   for i = 1, #EnergyUnits do
  102.    currentEU = currentEU + net.callRemote(EnergyUnits[i], "getEUStored")
  103.    maxEU = maxEU + net.callRemote(EnergyUnits[i], "getEUCapacity")
  104.   end
  105.   fmaxEU = formNum(maxEU)
  106.   fcurrentEU = formNum(currentEU)
  107.   if currentEU >= maxEU then
  108.    cEU.setText(""..fmaxEU)
  109.   else
  110.    cEU.setText(""..fcurrentEU)
  111.   end
  112.   divEU.setX(bridge.getStringWidth(fcurrentEU)-30)
  113.   mEU.setX(bridge.getStringWidth(fcurrentEU)-24)
  114.   mEU.setText(""..fmaxEU.." EU")
  115.  end
  116.  
  117.  if AppliedEnergistics then
  118.   for i = 1, #AppliedStorage do
  119.    currentStorage = currentStorage + net.callRemote(AppliedStorage[i], "getStoredItemCount")
  120.   end
  121.   currentStorage = formNum(currentStorage)
  122.   cAE.setText("AE | "..currentStorage.." Stored")
  123.   if remainingStorage == 0 then
  124.    cAE.setColor(0xFF0000)
  125.   else
  126.    cAE.setColor(0xFFFFFF)
  127.   end
  128.  end
  129.  
  130.  if ThermalExpansion then
  131.   for i=1, #MinecraftJoules do
  132.    if string.find(MinecraftJoules[i], "energycellcreative") then
  133.     MJCreative = true
  134.     currentMJ = "Infinite"
  135.     break
  136.    else
  137.     MJCreative = false
  138.     currentMJ = currentMJ + net.callRemote(MinecraftJoules[i], "getEnergyStored", "unknown")
  139.     maxMJ = maxMJ + net.callRemote(MinecraftJoules[i], "getMaxEnergyStored", "unknown")
  140.    end
  141.   end
  142.   fcurrentMJ = formNum(currentMJ)
  143.   fmaxMJ = formNum(maxMJ)
  144.   if MJCreative then
  145.    cMJ.setText("Infinite")
  146.    divMJ.setText("")
  147.    mMJ.setText("")
  148.   else
  149.    if currentMJ >= maxMJ then
  150.     cMJ.setText(""..fmaxMJ)
  151.    else
  152.     cMJ.setText(""..fcurrentMJ)
  153.    end
  154.   end
  155.   if not MJCreative then
  156.    divMJ.setText("|")
  157.    divMJ.setX(bridge.getStringWidth(currentMJ)-15)
  158.    mMJ.setX(bridge.getStringWidth(currentMJ)-9)
  159.    mMJ.setText(""..fmaxMJ.." MJ")
  160.   end
  161.  end
  162. end
  163.  
  164. function displayBars()
  165.  if IndustrialCraft then
  166.   EUBack.setZIndex(0)
  167.   EUBar.setZIndex(1)
  168.   EURatio = currentEU / maxEU
  169.   EUWidth = 100 * EURatio
  170.   EUBar.setWidth(EUWidth)
  171.  end
  172.  
  173.  if AppliedEnergistics then
  174.   AEBack.setZIndex(0)
  175.   AEBack.setWidth(bridge.getStringWidth("AE | "..currentStorage.." Stored")-20)
  176.  end
  177.  
  178.  if ThermalExpansion then
  179.   MJBack.setZIndex(0)
  180.   MJBar.setZIndex(1)
  181.   if not MJCreative then
  182.    MJRatio = currentMJ / maxMJ
  183.    MJWidth = 100 * MJRatio
  184.    MJBar.setWidth(MJWidth)
  185.   else
  186.    MJBar.setWidth(100)
  187.   end
  188.  end
  189. end
  190.  
  191. function resetValues()
  192.  -- I could've merged this with grabData(), but this is somewhat better in my opinion
  193.  currentEU = 0
  194.  maxEU = 0
  195.  
  196.  currentMJ = 0
  197.  maxMJ = 0
  198.  
  199.  currentStorage = 0
  200. end
  201.  
  202.  
  203. --[[  Main  ]]--
  204.  
  205. term.clear()
  206. term.setCursorPos(1, 1)
  207.  
  208. if #tArgs >= 1 then
  209.  if string.lower(tArgs[1]) == "annoying" then
  210.   printError("Message remove due to being annoying!")
  211.   printError("Will now move on..")
  212.   sleep(2)
  213.  end
  214. end
  215.  
  216. if #tArgs == 0 then
  217.  print("By default, the glasses bridge must be on the right")
  218.  print("By default, the wired modem must be on the back")
  219.  print("Do you want to edit that?")
  220.  write("> ")
  221.  response = read()
  222.  if response == "Yes" or response == "yes" then
  223.   term.clear()
  224.   term.setCursorPos(1, 1)
  225.   print("Opening config...")
  226.   sleep(2)
  227.   shell.run("edit", shell.getRunningProgram())
  228.  end
  229. end
  230.  
  231.  
  232.  
  233. term.clear()
  234. term.setCursorPos(1, 1)
  235. textutils.slowPrint("Activating GUI...")
  236. sleep(1)
  237. term.clear()
  238. term.setCursorPos(1, 1)
  239. print("GUI Activated")
  240. displayText()
  241. AEBack = bridge.addGradientBox(3, 30, 0, 11, 0x666666, 0.5, 0x999999, 0.5, 1)
  242. EUBar = bridge.addGradientBox(4, 3, 0, 10, 0x0000FF, 0.5, 0x99FFFF, 0.7, 1)
  243. EUBack = bridge.addGradientBox(3, 2, 102, 12, 0x666666, 0.5, 0x999999, 0.5, 1)
  244. MJBack = bridge.addGradientBox(3, 60, 102, 12, 0x666666, 0.5, 0x999999, 0.5, 1)
  245. MJBar = bridge.addGradientBox(4, 61, 0, 10, 0x0000FF, 0.5, 0x99FFFF, 0.7, 1)
  246.  
  247. while true do
  248.  resetValues()
  249.  checkPeripherals()
  250.  grabData()
  251.  displayBars()
  252.  
  253.  sleep(refreshTime)
  254. end
Advertisement
Add Comment
Please, Sign In to add comment