From fbb7cec7738251ba613317a86c7c6c00c409ce04 Mon Sep 17 00:00:00 2001 From: Matthias Mann Date: Thu, 12 Feb 2015 00:13:39 +0100 Subject: [PATCH] add remaining percentage/time/RF tooltip on stirling generator --- resources/assets/enderio/lang/en_US.lang | 1 + .../stirling/GuiStirlingGenerator.java | 21 +++++++++++++++- .../enderio/machine/gui/GuiMachineBase.java | 25 +++++++++++++------ 3 files changed, 38 insertions(+), 9 deletions(-) diff --git a/resources/assets/enderio/lang/en_US.lang b/resources/assets/enderio/lang/en_US.lang index 2f8c1d0e..6bd7ebf1 100644 --- a/resources/assets/enderio/lang/en_US.lang +++ b/resources/assets/enderio/lang/en_US.lang @@ -834,6 +834,7 @@ enderio.stirlingGenerator.output=Generating: enderio.stirlingGenerator.burnRate=Burn Rate: enderio.stirlingGenerator.upgradeslot=Upgrade slot enderio.stirlingGenerator.upgrades={0} gives {2}{1,number,#.#}x{3} efficiency +enderio.stirlingGenerator.remaining=Remaining {0,number,percent}|{1,choice,0#|0<{1}m }{2,number}s|{3,number,#,###} RF //Travel Blocks enderio.gui.travelAccessable.privateBlock1=Only diff --git a/src/main/java/crazypants/enderio/machine/generator/stirling/GuiStirlingGenerator.java b/src/main/java/crazypants/enderio/machine/generator/stirling/GuiStirlingGenerator.java index 7882fb70..d005f674 100644 --- a/src/main/java/crazypants/enderio/machine/generator/stirling/GuiStirlingGenerator.java +++ b/src/main/java/crazypants/enderio/machine/generator/stirling/GuiStirlingGenerator.java @@ -39,6 +39,8 @@ public class GuiStirlingGenerator extends GuiPoweredMachineBase 0) { + if(shouldRenderProgress()) { scaled = getTileEntity().getProgressScaled(12); drawTexturedModalRect(sx + 80, sy + 64 - scaled, 176, 12 - scaled, 14, scaled + 2); } diff --git a/src/main/java/crazypants/enderio/machine/gui/GuiMachineBase.java b/src/main/java/crazypants/enderio/machine/gui/GuiMachineBase.java index 0dd43b59..e001baf4 100644 --- a/src/main/java/crazypants/enderio/machine/gui/GuiMachineBase.java +++ b/src/main/java/crazypants/enderio/machine/gui/GuiMachineBase.java @@ -151,33 +151,42 @@ public abstract class GuiMachineBase extends Gu addToolTip(tt); } - private void updateProgressTooltips(int progress) { - if(lastProgressTooltipValue == progress || progressTooltips == null) { + private void updateProgressTooltips(int scaledProgress, float progress) { + if(lastProgressTooltipValue == scaledProgress || progressTooltips == null) { return; } - lastProgressTooltipValue = progress; + lastProgressTooltipValue = scaledProgress; - if(progress < 0) { + if(scaledProgress < 0) { for(GuiToolTip tt : progressTooltips) { tt.setVisible(false); } return; } - String msg = MessageFormat.format(Lang.localize("gui.progress"), progress); + String msg = formatProgressTooltip(scaledProgress, progress); + String[] tooltip = msg.split("\\|"); for(GuiToolTip tt : progressTooltips) { - tt.setToolTipText(msg); + tt.setToolTipText(tooltip); tt.setVisible(true); } } + protected String formatProgressTooltip(int scaledProgress, float progress) { + return MessageFormat.format(Lang.localize("gui.progress"), scaledProgress); + } + + protected int scaleProgressForTooltip(float progress) { + return (int)(progress * 100); + } + protected boolean shouldRenderProgress() { float progress = tileEntity.getProgress(); if(progress > 0 && progress < 1) { - updateProgressTooltips((int)(progress * 100)); + updateProgressTooltips(scaleProgressForTooltip(progress), progress); return true; } else { - updateProgressTooltips(-1); + updateProgressTooltips(-1, -1); return false; } }