diff options
author | Alexdoru <57050655+Alexdoru@users.noreply.github.com> | 2022-09-11 01:02:13 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-11 01:02:13 +0200 |
commit | 930d4392b82129a413fd23e700a94052ad3e4632 (patch) | |
tree | 168784ac687eddb72b67c6c1ee92194d818c29d1 /src | |
parent | f05a5aaffdd8187c2f864d7ee25316778530ee4b (diff) | |
download | GT5-Unofficial-930d4392b82129a413fd23e700a94052ad3e4632.tar.gz GT5-Unofficial-930d4392b82129a413fd23e700a94052ad3e4632.tar.bz2 GT5-Unofficial-930d4392b82129a413fd23e700a94052ad3e4632.zip |
Use pre-defined methods to draw tooltips in GT_GUIContainer_DigitalTank (#1374)
* use pre defined methods to draw tooltip in GT_GUIContainer_DigitalTank
* introduce private static final fields for string tooltip names
Diffstat (limited to 'src')
4 files changed, 59 insertions, 67 deletions
diff --git a/src/main/java/gregtech/api/gui/GT_Container_DigitalTank.java b/src/main/java/gregtech/api/gui/GT_Container_DigitalTank.java index 59cc42fb61..f12f2a2ad0 100644 --- a/src/main/java/gregtech/api/gui/GT_Container_DigitalTank.java +++ b/src/main/java/gregtech/api/gui/GT_Container_DigitalTank.java @@ -14,11 +14,18 @@ import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; public class GT_Container_DigitalTank extends GT_Container_BasicTank { - public boolean outputFluid = false, - mLockFluid = false, - mVoidFluidPart = false, - mVoidFluidFull = false, - mAllowInputFromOutputSide = false; + + public boolean outputFluid = false; + public boolean mLockFluid = false; + public boolean mVoidFluidPart = false; + public boolean mVoidFluidFull = false; + public boolean mAllowInputFromOutputSide = false; + + public Slot slotAutoOutput; + public Slot slotLockFLuid; + public Slot slotVoidOverFlow; + public Slot slotVoidFull; + public Slot slotInputFromOutput; public GT_Container_DigitalTank(InventoryPlayer aInventoryPlayer, IGregTechTileEntity aTileEntity) { super(aInventoryPlayer, aTileEntity); @@ -29,11 +36,11 @@ public class GT_Container_DigitalTank extends GT_Container_BasicTank { addSlotToContainer(new Slot(mTileEntity, 0, 81, 17)); addSlotToContainer(new GT_Slot_Output(mTileEntity, 1, 81, 44)); addSlotToContainer(new GT_Slot_Render(mTileEntity, 2, 59, 42)); - addSlotToContainer(new GT_Slot_Holo(mTileEntity, 3, 8, 64, false, true, 1)); - addSlotToContainer(new GT_Slot_Holo(mTileEntity, 4, 26, 64, false, true, 1)); - addSlotToContainer(new GT_Slot_Holo(mTileEntity, 5, 152, 8, false, true, 1)); - addSlotToContainer(new GT_Slot_Holo(mTileEntity, 6, 152, 26, false, true, 1)); - addSlotToContainer(new GT_Slot_Holo(mTileEntity, 7, 44, 64, false, true, 1)); + addSlotToContainer(slotAutoOutput = new GT_Slot_Holo(mTileEntity, 3, 8, 64, false, true, 1)); + addSlotToContainer(slotLockFLuid = new GT_Slot_Holo(mTileEntity, 4, 26, 64, false, true, 1)); + addSlotToContainer(slotVoidOverFlow = new GT_Slot_Holo(mTileEntity, 5, 152, 8, false, true, 1)); + addSlotToContainer(slotVoidFull = new GT_Slot_Holo(mTileEntity, 6, 152, 26, false, true, 1)); + addSlotToContainer(slotInputFromOutput = new GT_Slot_Holo(mTileEntity, 7, 44, 64, false, true, 1)); } @Override diff --git a/src/main/java/gregtech/api/gui/GT_GUIContainer_DigitalTank.java b/src/main/java/gregtech/api/gui/GT_GUIContainer_DigitalTank.java index 08248b5333..163aaa2929 100644 --- a/src/main/java/gregtech/api/gui/GT_GUIContainer_DigitalTank.java +++ b/src/main/java/gregtech/api/gui/GT_GUIContainer_DigitalTank.java @@ -3,25 +3,30 @@ package gregtech.api.gui; import static gregtech.api.enums.GT_Values.RES_PATH_GUI; import gregtech.api.enums.GT_Values; +import gregtech.api.gui.widgets.GT_GuiSlotTooltip; import gregtech.api.interfaces.IDragAndDropSupport; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.net.GT_Packet_SetLockedFluid; import gregtech.api.util.GT_Utility; import gregtech.common.tileentities.storage.GT_MetaTileEntity_DigitalTankBase; -import java.util.ArrayList; -import java.util.List; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; -import net.minecraft.util.StatCollector; import net.minecraftforge.fluids.FluidStack; public class GT_GUIContainer_DigitalTank extends GT_GUIContainerMetaTile_Machine implements IDragAndDropSupport { private final String mName; - private final int textColor = this.getTextColorOrDefault("text", 0xFAFAFF), - textColorTitle = this.getTextColorOrDefault("title", 0x404040), - textColorValue = this.getTextColorOrDefault("value", 0xFAFAFF); + private final int textColor = this.getTextColorOrDefault("text", 0xFAFAFF); + private final int textColorTitle = this.getTextColorOrDefault("title", 0x404040); + private final int textColorValue = this.getTextColorOrDefault("value", 0xFAFAFF); + + private static final String DIGITALTANK_AUTOOUTPUT_TOOLTIP = "GT5U.machines.digitaltank.autooutput.tooltip"; + private static final String DIGITALTANK_LOCKFLUID_TOOLTIP = "GT5U.machines.digitaltank.lockfluid.tooltip"; + private static final String DIGITALTANK_VOIDOVERFLOW_TOOLTIP = "GT5U.machines.digitaltank.voidoverflow.tooltip"; + private static final String DIGITALTANK_VOIDFULL_TOOLTIP = "GT5U.machines.digitaltank.voidfull.tooltip"; + private static final String DIGITALTANK_INPUTFROMOUTPUT_TOOLTIP = + "GT5U.machines.digitaltank.inputfromoutput.tooltip"; public GT_GUIContainer_DigitalTank( InventoryPlayer aInventoryPlayer, IGregTechTileEntity aTileEntity, String aName) { @@ -30,39 +35,21 @@ public class GT_GUIContainer_DigitalTank extends GT_GUIContainerMetaTile_Machine } @Override - public void drawScreen(int par1, int par2, float par3) { - super.drawScreen(par1, par2, par3); - drawTooltip(par1, par2); + protected void setupTooltips() { + addToolTip(new GT_GuiSlotTooltip( + getContainer().slotAutoOutput, mTooltipCache.getData(DIGITALTANK_AUTOOUTPUT_TOOLTIP))); + addToolTip(new GT_GuiSlotTooltip( + getContainer().slotLockFLuid, mTooltipCache.getData(DIGITALTANK_LOCKFLUID_TOOLTIP))); + addToolTip(new GT_GuiSlotTooltip( + getContainer().slotVoidOverFlow, mTooltipCache.getData(DIGITALTANK_VOIDOVERFLOW_TOOLTIP))); + addToolTip(new GT_GuiSlotTooltip( + getContainer().slotVoidFull, mTooltipCache.getData(DIGITALTANK_VOIDFULL_TOOLTIP))); + addToolTip(new GT_GuiSlotTooltip( + getContainer().slotInputFromOutput, mTooltipCache.getData(DIGITALTANK_INPUTFROMOUTPUT_TOOLTIP))); } - private void drawTooltip(int x2, int y2) { - int xStart = (width - xSize) / 2; - int yStart = (height - ySize) / 2; - int x = x2 - xStart; - int y = y2 - yStart + 5; - List<String> list = new ArrayList<>(); - if (y >= 68 && y <= 84) { - if (x >= 8 && x <= 24) { - list.add(StatCollector.translateToLocal("GT5U.machines.digitaltank.autooutput.name")); - } else if (x >= 26 && x <= 42) { - list.add(StatCollector.translateToLocal("GT5U.machines.digitaltank.lockfluid.name")); - list.add(StatCollector.translateToLocal("GT5U.machines.digitaltank.lockfluid.tooltip")); - list.add(StatCollector.translateToLocal("GT5U.machines.digitaltank.lockfluid.tooltip1")); - } - if (x >= 44 && x <= 60) { - list.add(StatCollector.translateToLocal("GT5U.machines.digitaltank.inputfromoutput.name")); - } - } else if (x >= 152 && x <= 168) { - if (y >= 12 && y <= 28) { - list.add(StatCollector.translateToLocal("GT5U.machines.digitaltank.voidoverflow.name")); - list.add(StatCollector.translateToLocal("GT5U.machines.digitaltank.voidoverflow.tooltip")); - } - if (y >= 30 && y <= 46) { - list.add(StatCollector.translateToLocal("GT5U.machines.digitaltank.voidfull.name")); - list.add(StatCollector.translateToLocal("GT5U.machines.digitaltank.voidfull.tooltip")); - } - } - if (!list.isEmpty()) drawHoveringText(list, x2, y2, fontRendererObj); + private GT_Container_DigitalTank getContainer() { + return (GT_Container_DigitalTank) mContainer; } @Override diff --git a/src/main/java/gregtech/api/gui/GT_GUIContainer_MultiMachine.java b/src/main/java/gregtech/api/gui/GT_GUIContainer_MultiMachine.java index 98268cd667..1f9170f3fb 100644 --- a/src/main/java/gregtech/api/gui/GT_GUIContainer_MultiMachine.java +++ b/src/main/java/gregtech/api/gui/GT_GUIContainer_MultiMachine.java @@ -20,7 +20,7 @@ import net.minecraft.item.ItemStack; */ public class GT_GUIContainer_MultiMachine extends GT_GUIContainerMetaTile_Machine { - String mName = ""; + String mName; private final int textColor = this.getTextColorOrDefault("text", 0xFAFAFF), textColorTitle = this.getTextColorOrDefault("title", 0xFAFAFF); @@ -45,7 +45,7 @@ public class GT_GUIContainer_MultiMachine extends GT_GUIContainerMetaTile_Machin String[] split = mName.split(" "); int total_line_length = 0; - String current_line = ""; + StringBuilder current_line = new StringBuilder(); int index = 0; @@ -54,26 +54,25 @@ public class GT_GUIContainer_MultiMachine extends GT_GUIContainerMetaTile_Machin total_line_length += str.length(); if (total_line_length > max_chars_per_line) { - fontRendererObj.drawString(current_line, 10, line_counter, textColorTitle); + fontRendererObj.drawString(current_line.toString(), 10, line_counter, textColorTitle); line_counter += 8; - current_line = ""; + current_line = new StringBuilder(); index = 0; total_line_length = str.length(); } if (index == 0) { - current_line += str; + current_line.append(str); } else { - current_line += " " + str; + current_line.append(" ").append(str); } index++; } - fontRendererObj.drawString(current_line, 10, line_counter, textColorTitle); - line_counter += 8; + fontRendererObj.drawString(current_line.toString(), 10, line_counter, textColorTitle); } else { fontRendererObj.drawString(mName, 10, line_counter, textColorTitle); - line_counter += 8; } + line_counter += 8; if (mContainer != null) { // (mWrench ? 0 : 1) | (mScrewdriver ? 0 : 2) | (mSoftHammer ? 0 : 4) | (mHardHammer ? 0 : 8) @@ -127,12 +126,11 @@ public class GT_GUIContainer_MultiMachine extends GT_GUIContainerMetaTile_Machin line_counter += 8; fontRendererObj.drawString( GT_Utility.trans("141", "if it doesn't start."), 10, line_counter, textColor); - line_counter += 8; } else { fontRendererObj.drawString( GT_Utility.trans("142", "Running perfectly."), 10, line_counter, textColor); - line_counter += 8; } + line_counter += 8; if (mContainer.mTileEntity.getMetaTileEntity() instanceof GT_MetaTileEntity_DrillerBase) { ItemStack tItem = mContainer.mTileEntity.getMetaTileEntity().getStackInSlot(1); if (tItem == null diff --git a/src/main/resources/assets/gregtech/lang/en_US.lang b/src/main/resources/assets/gregtech/lang/en_US.lang index b2cedefa4d..99010cc2bc 100644 --- a/src/main/resources/assets/gregtech/lang/en_US.lang +++ b/src/main/resources/assets/gregtech/lang/en_US.lang @@ -105,15 +105,15 @@ GT5U.machines.minermulti=Multiblock Miner GT5U.machines.digitaltank.tooltip=Stores %sL of fluid GT5U.machines.digitaltank.tooltip1=Can keep its contents when harvested GT5U.machines.digitaltank.tooltip2=Sneak when harvesting to void its contents -GT5U.machines.digitaltank.autooutput.name=Fluid Auto-Output -GT5U.machines.digitaltank.lockfluid.name=Lock Fluid Mode -GT5U.machines.digitaltank.lockfluid.tooltip=§7This tank will be locked to only accept one type of fluid -GT5U.machines.digitaltank.lockfluid.tooltip1=§7It will be locked to the first fluid that goes in -GT5U.machines.digitaltank.voidoverflow.name=Overflow Voiding Mode -GT5U.machines.digitaltank.voidoverflow.tooltip=§7Voids all fluid excess if the tank is full -GT5U.machines.digitaltank.voidfull.name=Void Full Mode -GT5U.machines.digitaltank.voidfull.tooltip=§7Voids all fluids that enter the tank -GT5U.machines.digitaltank.inputfromoutput.name=Input Fluid from Output Side +GT5U.machines.digitaltank.autooutput.tooltip=Fluid Auto-Output +GT5U.machines.digitaltank.lockfluid.tooltip=Lock Fluid Mode +GT5U.machines.digitaltank.lockfluid.tooltip.1=§7This tank will be locked to only accept one type of fluid +GT5U.machines.digitaltank.lockfluid.tooltip.2=§7It will be locked to the first fluid type that enters the tank +GT5U.machines.digitaltank.voidoverflow.tooltip=Overflow Voiding Mode +GT5U.machines.digitaltank.voidoverflow.tooltip.1=§7Voids all fluid excess if the tank is full +GT5U.machines.digitaltank.voidfull.tooltip=Void Full Mode +GT5U.machines.digitaltank.voidfull.tooltip.1=§7Voids all fluids that enter the tank +GT5U.machines.digitaltank.inputfromoutput.tooltip=Input Fluid from Output Side GT5U.machines.select_circuit=Select Machine Mode GT5U.machines.select_circuit.tooltip=Ghost Circuit Slot GT5U.machines.select_circuit.tooltip.1=§7LMB/RMB/scroll to cycle through the list |