Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MonitorSide = "top"
- Monitor = peripheral.wrap(MonitorSide)
- cell1 = peripheral.wrap("cofh_thermalexpansion_energycell_107")
- cell2 = peripheral.wrap("cofh_thermalexpansion_energycell_108")
- function ClearMonitor()
- Monitor.setTextColor(colours.black)
- Monitor.setBackgroundColor(colours.black)
- Monitor.clear()
- Monitor.setCursorPos(1,1)
- end
- function DrawText(xPos, yPos, text, textColour, backgroundColour)
- Monitor.setBackgroundColor(backgroundColour)
- Monitor.setTextColor(textColour)
- Monitor.setCursorPos(xPos,yPos)
- Monitor.write(text)
- end
- function DrawLine(xPos, yPos, lineLength, colour)
- Monitor.setBackgroundColor(colour)
- Monitor.setTextColor(colour)
- Monitor.setCursorPos(xPos,yPos)
- Monitor.write(string.rep(" ", lineLength))
- end
- function ProgressBar(xPos, yPos, barLength, value, maxValue, backgroundColour, progressColour)
- DrawLine(xPos, yPos, barLength, backgroundColour) --backgoround bar
- local barSize = math.floor((value/maxValue) * barLength)
- DrawLine(xPos, yPos, barSize, progressColour) --progress so far
- end
- function GroupBox(xPos, yPos, height, header, textColour, headerBackgroundColour, rightPadding)
- GroupBoxHeader(xPos, yPos, header, textColour, headerBackgroundColour, rightPadding)
- GroupBoxFooter(xPos, yPos + height + 1, textColour, headerBackgroundColour, rightPadding)
- end
- function GroupBoxHeader(xPos, yPos, header, textColour, backgroundColour, rightPadding)
- local repeatChars
- local headerLength = string.len(header)
- local monX, monY = Monitor.getSize()
- repeatChars = monX - 4 - headerLength - rightPadding
- if (repeatChars < 0) then
- repeatChars = 0
- end
- local head = "--- " .. header .. " " .. string.rep("-", repeatChars - rightPadding)
- DrawText(xPos, yPos, head, textColour, backgroundColour)
- end
- function GroupBoxFooter(xPos, yPos, textColour, backgroundColour, rightPadding)
- local repeatChars
- local monX, monY = Monitor.getSize()
- repeatChars = monX - rightPadding
- if (repeatChars < 0) then
- repeatChars = 0
- end
- local head = string.rep("-", repeatChars)
- DrawText(xPos, yPos, head, textColour, backgroundColour)
- end
- function GetColourFromPercent(percentage)
- local colourOut = colours.red
- if (percentage > 15) then colourOut = colours.orange end
- if (percentage > 45) then colourOut = colours.yellow end
- if (percentage > 70) then colourOut = colours.green end
- if (percentage > 90) then colourOut = colours.cyan end
- return colourOut
- end
- function MainFunc()
- Monitor.setTextScale(1)
- while (true) do
- local monX, monY = Monitor.getSize()
- local cell1Energy = cell1.getEnergyStored("unknown")
- local cell2Energy = cell2.getEnergyStored("unknown")
- local cell1MaxEnergy = cell1.getMaxEnergyStored("unknown")
- local cell2MaxEnergy = cell2.getMaxEnergyStored("unknown")
- local cell1Percent = math.floor((cell1Energy / cell1MaxEnergy) * 100)
- local cell2Percent = math.floor((cell2Energy / cell2MaxEnergy) * 100)
- local c1c
- local c2c
- if (cell1Percent == 0) then c1c = colours.red else c1c = colours.grey end
- if (cell2Percent == 0) then c2c = colours.red else c2c = colours.grey end
- ClearMonitor()
- GroupBox(2, 2, 4, "ME Backup Cells Power", colours.orange, colours.black, 0)
- DrawText(3, 4, "Cell 1", colours.white, colours.black)
- ProgressBar(10, 4, monX - 15, cell1Energy, cell1MaxEnergy, c1c, GetColourFromPercent(cell1Percent))
- DrawText(monX - 4, 4, cell1Percent .. "%", colours.white, colours.black)
- DrawText(3, 6, "Cell 2", colours.white, colours.black)
- ProgressBar(10, 6, monX - 15, cell2Energy, cell2MaxEnergy, c2c, GetColourFromPercent(cell2Percent))
- DrawText(monX - 4, 6, cell2Percent .. "%", colours.white, colours.black)
- sleep(1)
- end
- end
- MainFunc()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement