From f29e1dd55818a7ce4889ac2a69af97a335887e46 Mon Sep 17 00:00:00 2001 From: CrushedPixel Date: Fri, 29 May 2015 20:33:09 +0200 Subject: [PATCH] Added optional parameter to GuiProgressBar to be able to customize the progress text --- .../gui/elements/GuiProgressBar.java | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/main/java/eu/crushedpixel/replaymod/gui/elements/GuiProgressBar.java b/src/main/java/eu/crushedpixel/replaymod/gui/elements/GuiProgressBar.java index 5a4717c4..f53f8d8f 100644 --- a/src/main/java/eu/crushedpixel/replaymod/gui/elements/GuiProgressBar.java +++ b/src/main/java/eu/crushedpixel/replaymod/gui/elements/GuiProgressBar.java @@ -15,6 +15,8 @@ public class GuiProgressBar extends Gui { private float progress = 0; + private String progressString = null; + public GuiProgressBar(int xPosition, int yPosition, int width, int height) { this(xPosition, yPosition, width, height, 0); } @@ -49,9 +51,25 @@ public class GuiProgressBar extends Gui { this.height = height; } + /** + * Replaces the default progress String that is being displayed (x%) with a custom String. + * This has to be called whenever the progress itself changes. + * Setting progressString to null uses the default progress String. + * @param progressString + */ + public void setProgressString(String progressString) { + this.progressString = progressString; + } + public void drawProgressBar() { int progressWidth = Math.round((width - (2*BORDER_WIDTH)) * progress); - String progressString = (int)Math.floor(progress * 100) + "%"; + + String progressString; + if(this.progressString == null) { + progressString = (int) Math.floor(progress * 100) + "%"; + } else { + progressString = this.progressString; + } // Draws black outline drawRect(xPosition, yPosition, xPosition + width, yPosition + height, Color.BLACK.getRGB());