diff options
Diffstat (limited to 'src/main/java/gregtech/api')
19 files changed, 265 insertions, 179 deletions
diff --git a/src/main/java/gregtech/api/enums/GuiColors.java b/src/main/java/gregtech/api/enums/GuiColors.java deleted file mode 100644 index 8c0a32954a..0000000000 --- a/src/main/java/gregtech/api/enums/GuiColors.java +++ /dev/null @@ -1,101 +0,0 @@ -package gregtech.api.enums; - -import gregtech.api.util.GT_Log; - -import java.util.function.Function; - -public enum GuiColors { - //RGB Colors: Name and default value - oneByOne(0x404040), - twoByTwo(0x404040), - twoByTwoFluid(0x404040), - twoByTwoFluidInventory(0x404040), - threeByThree(0x404040), - fourByFour(0x404040), - basicMachine(0x404040), - basicTankTitle(0x404040), - basicTankInventory(0x404040), - basicTankLiquidAmount(0xFAFAFF), - basicTankLiquidValue(0xFAFAFF), - maintenanceHatch(0x404040), - maintenanceHatchRepair(0x404040), - - multiMachineTitle(0xFAFAFF), - multiMachineDrillBaseText(0xFAFAFF), - multiMachineIncompleteStructure(0xFAFAFF), - multiMachineLargeTurbineText(0xFAFAFF), - multiMachineMaintenanceText(0xFAFAFF), - multiMachineMalletRestart(0xFAFAFF), - multiMachineRunningPerfectly(0xFAFAFF), - - outputHatchTitle(0x404040), - outputHatchInventory(0x404040), - outputHatchAmount(0xFAFAFF), - outputHatchValue(0xFAFAFF), - outputHatchFluidName(0xFAFAFF), - outputHatchLockedFluid(0xFAFAFF), - - boiler(0x404040), - bronzeBlastFurnace(0x404040), - fusionReactor(0xFF0000), - industrialApiary(0x404040), - microwaveEnergyTransmitter(0xFAFAFF), - primitiveBlastFurnace(0x404040), - quantumChestTitle(0x404040), - quantumChestAmount(0xFAFAFF), - regulator(0xFAFAFF), - teleporter(0xFAFAFF), - - fluidDisplayStackRenderer(0xFFFFFF), - - //ARGB Colors: Name and default value - dialogSelectItem(0xFF555555), - pollutionRenderer(0xFFFFFFFF), - screenText(0xFF222222), - - coverArm(0xFF555555), - coverControlsWork(0xFF555555), - coverConveyor(0xFF555555), - coverDoesWork(0xFF555555), - coverEUMeter(0xFF555555), - coverFluidFilterName(0xFF222222), - coverFluidFilter(0xFF555555), - coverFluidRegulatorWarn(0xFFFF0000), - coverFluidRegulator(0xFF555555), - coverItemFilter(0xFF555555), - coverItemMeter(0xFF555555), - coverLiquidMeter(0xFF555555), - coverMaintenance(0xFF555555), - coverPlayerDetector(0xFF555555), - coverPump(0xFF555555), - coverRedstoneWirelessBase(0xFF555555), - coverShutter(0xFF555555), - - NEIText(0xFF000000); - - private final int defaultColor; - private int color; - - GuiColors(final int hex) { - this.defaultColor = hex; - this.color = hex; - } - - public void reload(Function<String, String> l) { - color = this.defaultColor; - - String hex = l.apply("GT5U.gui.color." + this); - - try { - if (!hex.isEmpty()) { - color = Integer.parseUnsignedInt(hex, 16); - } - } catch (final NumberFormatException e) { - GT_Log.err.println("Couldn't format color correctly for: GT5U.gui.color." + this + " -> " + hex); - } - } - - public int getColor() { - return color; - } -} diff --git a/src/main/java/gregtech/api/gui/GT_GUIColorOverride.java b/src/main/java/gregtech/api/gui/GT_GUIColorOverride.java new file mode 100644 index 0000000000..c2a833503e --- /dev/null +++ b/src/main/java/gregtech/api/gui/GT_GUIColorOverride.java @@ -0,0 +1,39 @@ +package gregtech.api.gui; + +import gregtech.api.util.ColorsMetadataSection; +import gregtech.api.GregTech_API; +import net.minecraft.client.Minecraft; +import net.minecraft.client.resources.IResource; +import net.minecraft.util.ResourceLocation; + +import java.io.IOException; + +public class GT_GUIColorOverride { + + private ColorsMetadataSection cmSection; + + public GT_GUIColorOverride(String guiTexturePath) { + try { + IResource ir = Minecraft.getMinecraft().getResourceManager().getResource(new ResourceLocation(guiTexturePath)); + if (ir.hasMetadata()) { + cmSection = (ColorsMetadataSection) ir.getMetadata("colors"); + } + } catch (IOException ignore) {} + } + + public int getTextColorOrDefault(String textType, int defaultColor) { + return sLoaded() ? cmSection.getTextColorOrDefault(textType, defaultColor) : defaultColor; + } + + public int getGuiTintOrDefault(String key, int defaultColor) { + return sLoaded() ? cmSection.getGuiTintOrDefault(key, defaultColor) : defaultColor; + } + + public boolean sGuiTintingEnabled() { + return sLoaded() ? cmSection.sGuiTintingEnabled() : GregTech_API.sColoredGUI; + } + + public boolean sLoaded() { + return cmSection != null; + } +} diff --git a/src/main/java/gregtech/api/gui/GT_GUIContainer.java b/src/main/java/gregtech/api/gui/GT_GUIContainer.java index 1f1ae9037e..5d3f0a59a1 100644 --- a/src/main/java/gregtech/api/gui/GT_GUIContainer.java +++ b/src/main/java/gregtech/api/gui/GT_GUIContainer.java @@ -1,5 +1,6 @@ package gregtech.api.gui; +import gregtech.api.gui.GT_GUIColorOverride; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.client.renderer.Tessellator; import net.minecraft.inventory.Container; @@ -7,6 +8,8 @@ import net.minecraft.inventory.Slot; import net.minecraft.util.ResourceLocation; import org.lwjgl.input.Mouse; +import java.io.IOException; + import static gregtech.GT_Mod.GT_FML_LOGGER; /** @@ -20,11 +23,18 @@ public class GT_GUIContainer extends GuiContainer { public ResourceLocation mGUIbackground; + public GT_GUIColorOverride colorOverride; + public String mGUIbackgroundPath; public GT_GUIContainer(Container aContainer, String aGUIbackground) { super(aContainer); mGUIbackground = new ResourceLocation(mGUIbackgroundPath = aGUIbackground); + colorOverride = new GT_GUIColorOverride(aGUIbackground); + } + + protected int getTextColorOrDefault(String textType, int defaultColor) { + return colorOverride.getTextColorOrDefault(textType, defaultColor); } public int getLeft() { diff --git a/src/main/java/gregtech/api/gui/GT_GUIContainerMetaTile_Machine.java b/src/main/java/gregtech/api/gui/GT_GUIContainerMetaTile_Machine.java index d25abd9137..4ab5f9f921 100644 --- a/src/main/java/gregtech/api/gui/GT_GUIContainerMetaTile_Machine.java +++ b/src/main/java/gregtech/api/gui/GT_GUIContainerMetaTile_Machine.java @@ -13,9 +13,10 @@ import gregtech.api.gui.widgets.GT_GuiTabLine.GT_ITabRenderer; import gregtech.api.gui.widgets.GT_GuiTooltipManager.GT_IToolTipRenderer; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.util.GT_TooltipDataCache; +import gregtech.api.util.GT_Util; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.renderer.entity.RenderItem; -import gregtech.api.util.GT_TooltipDataCache; import net.minecraft.entity.player.InventoryPlayer; import java.util.List; @@ -34,6 +35,8 @@ public class GT_GUIContainerMetaTile_Machine extends GT_GUIContainer implements protected GT_GuiTooltipManager mTooltipManager = new GT_GuiTooltipManager(); protected GT_TooltipDataCache mTooltipCache = new GT_TooltipDataCache(); + private final int guiTint; + // Cover Tabs support. Subclasses can override display position, style and visuals by overriding setupCoverTabs public GT_GuiCoverTabLine coverTabs; private static final int @@ -63,6 +66,8 @@ public class GT_GUIContainerMetaTile_Machine extends GT_GUIContainer implements if (GT_Mod.gregtechproxy.mTooltipVerbosity > 0 || GT_Mod.gregtechproxy.mTooltipShiftVerbosity > 0) { setupTooltips(); } + + guiTint = getColorization(); } public GT_GUIContainerMetaTile_Machine(InventoryPlayer aInventoryPlayer, IGregTechTileEntity aTileEntity, @@ -106,8 +111,7 @@ public class GT_GUIContainerMetaTile_Machine extends GT_GUIContainer implements coverTabs.drawTabs(parTicks, mouseX, mouseY); // Applying machine coloration, which subclasses rely on - Dyes color = getColorization(); - GL11.glColor3ub((byte) color.mRGBa[0], (byte) color.mRGBa[1], (byte) color.mRGBa[2]); + GL11.glColor3ub((byte) ((guiTint >> 16) & 0xFF), (byte) ((guiTint >> 8) & 0xFF), (byte) (guiTint & 0xFF)); // Binding machine's own texture, which subclasses rely on being set super.drawGuiContainerBackgroundLayer(parTicks, mouseX, mouseY); @@ -116,20 +120,25 @@ public class GT_GUIContainerMetaTile_Machine extends GT_GUIContainer implements /** * @return The color used to render this machine's GUI */ - private Dyes getColorization() { - if (GregTech_API.sMachineMetalGUI) { - return Dyes.MACHINE_METAL; - } else if (GregTech_API.sColoredGUI && mContainer != null && mContainer.mTileEntity != null) { - byte colorByte = mContainer.mTileEntity.getColorization(); - Dyes color; - if (colorByte != -1) - color = Dyes.get(colorByte); - else - color = Dyes.MACHINE_METAL; - return color; - } else { - return Dyes.dyeWhite; + private int getColorization() { + Dyes dye = Dyes.dyeWhite; + if (this.colorOverride.sLoaded()) { + if (this.colorOverride.sGuiTintingEnabled()) { + dye = getDyeFromIndex(mContainer.mTileEntity.getColorization()); + return this.colorOverride.getGuiTintOrDefault(dye.mName, GT_Util.getRGBInt(dye.getRGBA())); + } + } else if (GregTech_API.sColoredGUI) { + if (GregTech_API.sMachineMetalGUI) { + dye = Dyes.MACHINE_METAL; + } else if (mContainer != null && mContainer.mTileEntity != null) { + dye = getDyeFromIndex(mContainer.mTileEntity.getColorization()); + } } + return GT_Util.getRGBInt(dye.getRGBA()); + } + + private Dyes getDyeFromIndex(short index) { + return index != -1 ? Dyes.get(index) : Dyes.MACHINE_METAL; } /** diff --git a/src/main/java/gregtech/api/gui/GT_GUIContainer_1by1.java b/src/main/java/gregtech/api/gui/GT_GUIContainer_1by1.java index 8682a77bae..7e85cb60f0 100644 --- a/src/main/java/gregtech/api/gui/GT_GUIContainer_1by1.java +++ b/src/main/java/gregtech/api/gui/GT_GUIContainer_1by1.java @@ -1,6 +1,5 @@ package gregtech.api.gui; -import gregtech.api.enums.GuiColors; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import net.minecraft.entity.player.InventoryPlayer; @@ -9,7 +8,7 @@ import static gregtech.api.enums.GT_Values.RES_PATH_GUI; public class GT_GUIContainer_1by1 extends GT_GUIContainerMetaTile_Machine { private final String mName; - private final int textColor = GuiColors.oneByOne.getColor(); + private final int textColor = this.getTextColorOrDefault("title", 0x404040); public GT_GUIContainer_1by1(InventoryPlayer aInventoryPlayer, IGregTechTileEntity aTileEntity, String aName) { super(new GT_Container_1by1(aInventoryPlayer, aTileEntity), RES_PATH_GUI + "1by1.png"); diff --git a/src/main/java/gregtech/api/gui/GT_GUIContainer_2by2.java b/src/main/java/gregtech/api/gui/GT_GUIContainer_2by2.java index 72afda851b..acefe12459 100644 --- a/src/main/java/gregtech/api/gui/GT_GUIContainer_2by2.java +++ b/src/main/java/gregtech/api/gui/GT_GUIContainer_2by2.java @@ -1,6 +1,5 @@ package gregtech.api.gui; -import gregtech.api.enums.GuiColors; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import net.minecraft.entity.player.InventoryPlayer; @@ -9,7 +8,7 @@ import static gregtech.api.enums.GT_Values.RES_PATH_GUI; public class GT_GUIContainer_2by2 extends GT_GUIContainerMetaTile_Machine { private final String mName; - private final int textColor = GuiColors.twoByTwo.getColor(); + private final int textColor = this.getTextColorOrDefault("title", 0x404040); public GT_GUIContainer_2by2(InventoryPlayer aInventoryPlayer, IGregTechTileEntity aTileEntity, String aName) { super(new GT_Container_2by2(aInventoryPlayer, aTileEntity), RES_PATH_GUI + "2by2.png"); diff --git a/src/main/java/gregtech/api/gui/GT_GUIContainer_2by2_Fluid.java b/src/main/java/gregtech/api/gui/GT_GUIContainer_2by2_Fluid.java index 860f33c2bb..afabaa0a80 100644 --- a/src/main/java/gregtech/api/gui/GT_GUIContainer_2by2_Fluid.java +++ b/src/main/java/gregtech/api/gui/GT_GUIContainer_2by2_Fluid.java @@ -1,6 +1,5 @@ package gregtech.api.gui; -import gregtech.api.enums.GuiColors; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.util.StatCollector; @@ -10,9 +9,7 @@ import static gregtech.api.enums.GT_Values.RES_PATH_GUI; public class GT_GUIContainer_2by2_Fluid extends GT_GUIContainerMetaTile_Machine { private final String mName; - private final int - textColorTitle = GuiColors.twoByTwoFluid.getColor(), - textColorInventory = GuiColors.twoByTwoFluidInventory.getColor(); + private final int textColor = this.getTextColorOrDefault("title", 0x404040); public GT_GUIContainer_2by2_Fluid(InventoryPlayer aInventoryPlayer, IGregTechTileEntity aTileEntity, String aName) { super(new GT_Container_2by2_Fluid(aInventoryPlayer, aTileEntity), RES_PATH_GUI + "2by2fluid.png"); @@ -21,8 +18,8 @@ public class GT_GUIContainer_2by2_Fluid extends GT_GUIContainerMetaTile_Machine @Override protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { - fontRendererObj.drawString(StatCollector.translateToLocal("container.inventory"), 8, ySize - 96 + 2, textColorInventory); - fontRendererObj.drawString(mName, 8, 6, textColorTitle); + fontRendererObj.drawString(StatCollector.translateToLocal("container.inventory"), 8, ySize - 96 + 2, textColor); + fontRendererObj.drawString(mName, 8, 6, textColor); } @Override diff --git a/src/main/java/gregtech/api/gui/GT_GUIContainer_3by3.java b/src/main/java/gregtech/api/gui/GT_GUIContainer_3by3.java index 12b3f81754..c2911fc67f 100644 --- a/src/main/java/gregtech/api/gui/GT_GUIContainer_3by3.java +++ b/src/main/java/gregtech/api/gui/GT_GUIContainer_3by3.java @@ -1,6 +1,5 @@ package gregtech.api.gui; -import gregtech.api.enums.GuiColors; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import net.minecraft.entity.player.InventoryPlayer; @@ -9,7 +8,7 @@ import static gregtech.api.enums.GT_Values.RES_PATH_GUI; public class GT_GUIContainer_3by3 extends GT_GUIContainerMetaTile_Machine { private final String mName; - private final int textColor = GuiColors.threeByThree.getColor(); + private final int textColor = this.getTextColorOrDefault("title", 0x404040); public GT_GUIContainer_3by3(InventoryPlayer aInventoryPlayer, IGregTechTileEntity aTileEntity, String aName) { super(new GT_Container_3by3(aInventoryPlayer, aTileEntity), RES_PATH_GUI + "3by3.png"); diff --git a/src/main/java/gregtech/api/gui/GT_GUIContainer_4by4.java b/src/main/java/gregtech/api/gui/GT_GUIContainer_4by4.java index fa2695b633..b28129eede 100644 --- a/src/main/java/gregtech/api/gui/GT_GUIContainer_4by4.java +++ b/src/main/java/gregtech/api/gui/GT_GUIContainer_4by4.java @@ -1,6 +1,5 @@ package gregtech.api.gui; -import gregtech.api.enums.GuiColors; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import net.minecraft.entity.player.InventoryPlayer; @@ -9,7 +8,7 @@ import static gregtech.api.enums.GT_Values.RES_PATH_GUI; public class GT_GUIContainer_4by4 extends GT_GUIContainerMetaTile_Machine { private final String mName; - private final int textColor = GuiColors.fourByFour.getColor(); + private final int textColor = this.getTextColorOrDefault("title", 0x404040); public GT_GUIContainer_4by4(InventoryPlayer aInventoryPlayer, IGregTechTileEntity aTileEntity, String aName) { super(new GT_Container_4by4(aInventoryPlayer, aTileEntity), RES_PATH_GUI + "4by4.png"); diff --git a/src/main/java/gregtech/api/gui/GT_GUIContainer_BasicMachine.java b/src/main/java/gregtech/api/gui/GT_GUIContainer_BasicMachine.java index 29168a53bb..8f26c00216 100644 --- a/src/main/java/gregtech/api/gui/GT_GUIContainer_BasicMachine.java +++ b/src/main/java/gregtech/api/gui/GT_GUIContainer_BasicMachine.java @@ -1,7 +1,6 @@ package gregtech.api.gui; import gregtech.api.enums.GT_Values; -import gregtech.api.enums.GuiColors; import gregtech.api.gui.widgets.GT_GuiIcon; import gregtech.api.gui.widgets.GT_GuiTabLine.GT_GuiTabIconSet; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; @@ -41,7 +40,7 @@ public class GT_GUIContainer_BasicMachine extends GT_GUIContainerMetaTile_Machin GT_GuiIcon.TAB_NORMAL_STEEL, GT_GuiIcon.TAB_HIGHLIGHT_STEEL, GT_GuiIcon.TAB_DISABLED_STEEL); - private final int textColor = GuiColors.basicMachine.getColor(); + private final int textColor = this.getTextColorOrDefault("title", 0x404040); public final String mName, mNEI; diff --git a/src/main/java/gregtech/api/gui/GT_GUIContainer_BasicTank.java b/src/main/java/gregtech/api/gui/GT_GUIContainer_BasicTank.java index 4a9e6751a6..a24060aaa4 100644 --- a/src/main/java/gregtech/api/gui/GT_GUIContainer_BasicTank.java +++ b/src/main/java/gregtech/api/gui/GT_GUIContainer_BasicTank.java @@ -1,6 +1,5 @@ package gregtech.api.gui; -import gregtech.api.enums.GuiColors; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.util.GT_Utility; import net.minecraft.entity.player.InventoryPlayer; @@ -11,11 +10,10 @@ import static gregtech.api.enums.GT_Values.RES_PATH_GUI; public class GT_GUIContainer_BasicTank extends GT_GUIContainerMetaTile_Machine { private final String mName; - private final int - textColorTitle = GuiColors.basicTankTitle.getColor(), - textColorInventory = GuiColors.basicTankInventory.getColor(), - textColorLiquidAmount = GuiColors.basicTankLiquidAmount.getColor(), - textColorLiquidValue = GuiColors.basicTankLiquidValue.getColor(); + private final int + textColor = this.getTextColorOrDefault("text", 0xFAFAFF), + textColorTitle = this.getTextColorOrDefault("title", 0x404040), + textColorValue = this.getTextColorOrDefault("value", 0xFAFAFF); public GT_GUIContainer_BasicTank(InventoryPlayer aInventoryPlayer, IGregTechTileEntity aTileEntity, String aName) { super(new GT_Container_BasicTank(aInventoryPlayer, aTileEntity), RES_PATH_GUI + "BasicTank.png"); @@ -24,11 +22,11 @@ public class GT_GUIContainer_BasicTank extends GT_GUIContainerMetaTile_Machine { @Override protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { - fontRendererObj.drawString(StatCollector.translateToLocal("container.inventory"), 8, ySize - 96 + 2, textColorInventory); + fontRendererObj.drawString(StatCollector.translateToLocal("container.inventory"), 8, ySize - 96 + 2, textColorTitle); fontRendererObj.drawString(mName, 8, 6, textColorTitle); if (mContainer != null) { - fontRendererObj.drawString("Liquid Amount", 10, 20, textColorLiquidAmount); - fontRendererObj.drawString(GT_Utility.parseNumberToString(((GT_Container_BasicTank) mContainer).mContent), 10, 30, textColorLiquidValue); + fontRendererObj.drawString("Liquid Amount", 10, 20, textColor); + fontRendererObj.drawString(GT_Utility.parseNumberToString(((GT_Container_BasicTank) mContainer).mContent), 10, 30, textColorValue); } } diff --git a/src/main/java/gregtech/api/gui/GT_GUIContainer_MaintenanceHatch.java b/src/main/java/gregtech/api/gui/GT_GUIContainer_MaintenanceHatch.java index e1b57e2028..fe3c47fa95 100644 --- a/src/main/java/gregtech/api/gui/GT_GUIContainer_MaintenanceHatch.java +++ b/src/main/java/gregtech/api/gui/GT_GUIContainer_MaintenanceHatch.java @@ -1,6 +1,5 @@ package gregtech.api.gui; -import gregtech.api.enums.GuiColors; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import net.minecraft.entity.player.InventoryPlayer; @@ -8,8 +7,8 @@ import static gregtech.api.enums.GT_Values.RES_PATH_GUI; public class GT_GUIContainer_MaintenanceHatch extends GT_GUIContainerMetaTile_Machine { private final int - textColorTitle = GuiColors.maintenanceHatch.getColor(), - textColorRepair = GuiColors.maintenanceHatchRepair.getColor(); + textColor = this.getTextColorOrDefault("text", 0x404040), + textColorTitle = this.getTextColorOrDefault("title", 0x404040); public GT_GUIContainer_MaintenanceHatch(InventoryPlayer aInventoryPlayer, IGregTechTileEntity aTileEntity) { @@ -19,7 +18,7 @@ public class GT_GUIContainer_MaintenanceHatch extends GT_GUIContainerMetaTile_Ma @Override protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { fontRendererObj.drawString("Maintenance Hatch", 8, 4, textColorTitle); - fontRendererObj.drawString("Click with Tool to repair.", 8, 12, textColorRepair); + fontRendererObj.drawString("Click with Tool to repair.", 8, 12, textColor); } @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 6943b33a21..69a3d26b2e 100644 --- a/src/main/java/gregtech/api/gui/GT_GUIContainer_MultiMachine.java +++ b/src/main/java/gregtech/api/gui/GT_GUIContainer_MultiMachine.java @@ -1,6 +1,5 @@ package gregtech.api.gui; -import gregtech.api.enums.GuiColors; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.util.GT_ModHandler; import gregtech.api.util.GT_Utility; @@ -23,15 +22,9 @@ import static gregtech.api.enums.GT_Values.RES_PATH_GUI; public class GT_GUIContainer_MultiMachine extends GT_GUIContainerMetaTile_Machine { String mName = ""; - private final int - textColorTitle = GuiColors.multiMachineTitle.getColor(), - textColorMaintenance = GuiColors.multiMachineMaintenanceText.getColor(), - textColorIncompleteStructure = GuiColors.multiMachineIncompleteStructure.getColor(), - textColorMalletRestart = GuiColors.multiMachineMalletRestart.getColor(), - textColorRunningPerfectly = GuiColors.multiMachineRunningPerfectly.getColor(), - textColorDrillBase = GuiColors.multiMachineDrillBaseText.getColor(), - textColorLargeTurbine = GuiColors.multiMachineLargeTurbineText.getColor(); - + private final int + textColor = this.getTextColorOrDefault("text", 0xFAFAFF), + textColorTitle = this.getTextColorOrDefault("title", 0xFAFAFF); public GT_GUIContainer_MultiMachine(InventoryPlayer aInventoryPlayer, IGregTechTileEntity aTileEntity, String aName, String aTextureFile) { super(new GT_Container_MultiMachine(aInventoryPlayer, aTileEntity), RES_PATH_GUI + "multimachines/" + (aTextureFile == null ? "MultiblockDisplay" : aTextureFile)); @@ -84,61 +77,61 @@ public class GT_GUIContainer_MultiMachine extends GT_GUIContainerMetaTile_Machin if (mContainer != null) {//(mWrench ? 0 : 1) | (mScrewdriver ? 0 : 2) | (mSoftHammer ? 0 : 4) | (mHardHammer ? 0 : 8) | (mSolderingTool ? 0 : 16) | (mCrowbar ? 0 : 32) | (mMachine ? 0 : 64)); if ((mContainer.mDisplayErrorCode & 1) != 0) { - fontRendererObj.drawString(GT_Utility.trans("132", "Pipe is loose."), 10, line_counter, textColorMaintenance); + fontRendererObj.drawString(GT_Utility.trans("132", "Pipe is loose."), 10, line_counter, textColor); line_counter += 8; } if ((mContainer.mDisplayErrorCode & 2) != 0) { - fontRendererObj.drawString(GT_Utility.trans("133", "Screws are loose."), 10, line_counter, textColorMaintenance); + fontRendererObj.drawString(GT_Utility.trans("133", "Screws are loose."), 10, line_counter, textColor); line_counter += 8; } if ((mContainer.mDisplayErrorCode & 4) != 0) { - fontRendererObj.drawString(GT_Utility.trans("134", "Something is stuck."), 10, line_counter, textColorMaintenance); + fontRendererObj.drawString(GT_Utility.trans("134", "Something is stuck."), 10, line_counter, textColor); line_counter += 8; } if ((mContainer.mDisplayErrorCode & 8) != 0) { - fontRendererObj.drawString(GT_Utility.trans("135", "Platings are dented."), 10, line_counter, textColorMaintenance); + fontRendererObj.drawString(GT_Utility.trans("135", "Platings are dented."), 10, line_counter, textColor); line_counter += 8; } if ((mContainer.mDisplayErrorCode & 16) != 0) { - fontRendererObj.drawString(GT_Utility.trans("136", "Circuitry burned out."), 10, line_counter, textColorMaintenance); + fontRendererObj.drawString(GT_Utility.trans("136", "Circuitry burned out."), 10, line_counter, textColor); line_counter += 8; } if ((mContainer.mDisplayErrorCode & 32) != 0) { - fontRendererObj.drawString(GT_Utility.trans("137", "That doesn't belong there."), 10, line_counter, textColorMaintenance); + fontRendererObj.drawString(GT_Utility.trans("137", "That doesn't belong there."), 10, line_counter, textColor); line_counter += 8; } if ((mContainer.mDisplayErrorCode & 64) != 0) { - fontRendererObj.drawString(GT_Utility.trans("138", "Incomplete Structure."), 10, line_counter, textColorIncompleteStructure); + fontRendererObj.drawString(GT_Utility.trans("138", "Incomplete Structure."), 10, line_counter, textColor); line_counter += 8; } if (mContainer.mDisplayErrorCode == 0) { if (mContainer.mActive == 0) { - fontRendererObj.drawString(GT_Utility.trans("139", "Hit with Soft Mallet"), 10, line_counter, textColorMalletRestart); + fontRendererObj.drawString(GT_Utility.trans("139", "Hit with Soft Mallet"), 10, line_counter, textColor); line_counter += 8; - fontRendererObj.drawString(GT_Utility.trans("140", "to (re-)start the Machine"), 10, line_counter, textColorMalletRestart); + fontRendererObj.drawString(GT_Utility.trans("140", "to (re-)start the Machine"), 10, line_counter, textColor); line_counter += 8; - fontRendererObj.drawString(GT_Utility.trans("141", "if it doesn't start."), 10, line_counter, textColorMalletRestart); + 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, textColorRunningPerfectly); + fontRendererObj.drawString(GT_Utility.trans("142", "Running perfectly."), 10, line_counter, textColor); line_counter += 8; } if (mContainer.mTileEntity.getMetaTileEntity() instanceof GT_MetaTileEntity_DrillerBase) { ItemStack tItem = mContainer.mTileEntity.getMetaTileEntity().getStackInSlot(1); if (tItem == null || !GT_Utility.areStacksEqual(tItem, GT_ModHandler.getIC2Item("miningPipe", 1L))) { - fontRendererObj.drawString(GT_Utility.trans("143", "Missing Mining Pipe"), 10, line_counter, textColorDrillBase); + fontRendererObj.drawString(GT_Utility.trans("143", "Missing Mining Pipe"), 10, line_counter, textColor); } } else if (mContainer.mTileEntity.getMetaTileEntity() instanceof GT_MetaTileEntity_LargeTurbine) { ItemStack tItem = mContainer.mTileEntity.getMetaTileEntity().getStackInSlot(1); if (tItem == null || !(tItem.getItem() == GT_MetaGenerated_Tool_01.INSTANCE && tItem.getItemDamage() >= 170 && tItem.getItemDamage() <= 177)) { - fontRendererObj.drawString(GT_Utility.trans("144", "Missing Turbine Rotor"), 10, line_counter, textColorLargeTurbine); + fontRendererObj.drawString(GT_Utility.trans("144", "Missing Turbine Rotor"), 10, line_counter, textColor); } } } diff --git a/src/main/java/gregtech/api/gui/GT_GUIDialogSelectItem.java b/src/main/java/gregtech/api/gui/GT_GUIDialogSelectItem.java index 245803ebc7..0aec243967 100644 --- a/src/main/java/gregtech/api/gui/GT_GUIDialogSelectItem.java +++ b/src/main/java/gregtech/api/gui/GT_GUIDialogSelectItem.java @@ -1,6 +1,5 @@ package gregtech.api.gui; -import gregtech.api.enums.GuiColors; import gregtech.api.gui.widgets.GT_GuiFakeItemButton; import gregtech.api.gui.widgets.GT_GuiIcon; import gregtech.api.gui.widgets.GT_GuiIconButton; @@ -18,7 +17,7 @@ public class GT_GUIDialogSelectItem extends GT_GUIScreen { public static final int UNSELECTED = -1; private static final int cols = 9; private static final int rows = 3; - private final int textColor = GuiColors.dialogSelectItem.getColor(); + private final int textColor = this.getTextColorOrDefault("text",0xff555555); private final GuiScreen parent; private final Consumer<ItemStack> selectedCallback; // passed in stack diff --git a/src/main/java/gregtech/api/gui/GT_GUIScreen.java b/src/main/java/gregtech/api/gui/GT_GUIScreen.java index 1b01f17ec8..1efaddea35 100644 --- a/src/main/java/gregtech/api/gui/GT_GUIScreen.java +++ b/src/main/java/gregtech/api/gui/GT_GUIScreen.java @@ -1,7 +1,7 @@ package gregtech.api.gui; import gregtech.api.enums.Dyes; -import gregtech.api.enums.GuiColors; +import gregtech.api.gui.GT_GUIColorOverride; import gregtech.api.gui.widgets.GT_GuiFakeItemButton; import gregtech.api.gui.widgets.GT_GuiIntegerTextBox; import gregtech.api.gui.widgets.GT_GuiTooltip; @@ -19,6 +19,7 @@ import org.lwjgl.input.Mouse; import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL12; +import java.io.IOException; import java.util.ArrayList; import java.util.List; @@ -30,20 +31,27 @@ public abstract class GT_GUIScreen extends GuiScreen implements GT_IToolTipRende protected int gui_height = 107; protected int guiTop, guiLeft; protected boolean drawButtons = true; - private final int textColor = GuiColors.multiMachineTitle.getColor(); + + private ResourceLocation mGUIbackgroundLocation; private GuiButton selectedButton; + private GT_GUIColorOverride colorOverride; + private final int textColor; + private final static String guiTexturePath = "gregtech:textures/gui/GuiCover.png"; + public String header; public GT_GuiFakeItemButton headerIcon; - protected List<IGuiElement> elements = new ArrayList<>(); protected List<GT_GuiIntegerTextBox> textBoxes = new ArrayList<>(); public GT_GUIScreen(int width, int height, String header) { - this.gui_width = width; + this.gui_width = width; this.gui_height = height; this.header = header; this.headerIcon = new GT_GuiFakeItemButton(this, 5, 5, null); + this.mGUIbackgroundLocation = new ResourceLocation(guiTexturePath); + this.colorOverride = new GT_GUIColorOverride(guiTexturePath); + this.textColor = getTextColorOrDefault("title", 0xFF222222); } @Override @@ -68,6 +76,10 @@ public abstract class GT_GUIScreen extends GuiScreen implements GT_IToolTipRende protected abstract void onInitGui(int guiLeft, int guiTop, int gui_width, int gui_height); + protected int getTextColorOrDefault(String textType, int defaultColor) { + return colorOverride.getTextColorOrDefault(textType, defaultColor); + } + public void onMouseWheel(int x, int y, int delta) { } @@ -122,7 +134,7 @@ public abstract class GT_GUIScreen extends GuiScreen implements GT_IToolTipRende public void drawBackground(int mouseX, int mouseY, float parTicks) { short[] color = Dyes.MACHINE_METAL.getRGBA(); GL11.glColor3ub((byte) color[0], (byte) color[1], (byte) color[2]); - this.mc.renderEngine.bindTexture(new ResourceLocation("gregtech:textures/gui/GuiCover.png")); + this.mc.renderEngine.bindTexture(mGUIbackgroundLocation); drawTexturedModalRect(guiLeft, guiTop, 0,0, gui_width, gui_height); } diff --git a/src/main/java/gregtech/api/gui/widgets/GT_GuiCoverTabLine.java b/src/main/java/gregtech/api/gui/widgets/GT_GuiCoverTabLine.java index c470936db2..8f729771f6 100644 --- a/src/main/java/gregtech/api/gui/widgets/GT_GuiCoverTabLine.java +++ b/src/main/java/gregtech/api/gui/widgets/GT_GuiCoverTabLine.java @@ -35,7 +35,7 @@ public class GT_GuiCoverTabLine extends GT_GuiTabLine { // Not sure there's a point in JIT translation but that's what this is private String[] translatedSides; private IGregTechTileEntity tile; - private Dyes colorization; + private int colorization; /** * Let's you access an IGregTechTileEntity's covers as tabs on the GUI's sides @@ -58,7 +58,7 @@ public class GT_GuiCoverTabLine extends GT_GuiTabLine { */ public GT_GuiCoverTabLine(GT_GUIContainerMetaTile_Machine gui, int tabLineLeft, int tabLineTop, int tabHeight, int tabWidth, int tabSpacing, DisplayStyle xDir, DisplayStyle yDir, DisplayStyle displayMode, - GT_GuiTabIconSet tabBackground, IGregTechTileEntity tile, Dyes colorization) { + GT_GuiTabIconSet tabBackground, IGregTechTileEntity tile, int colorization) { super(gui, 6, tabLineLeft, tabLineTop, tabHeight, tabWidth, tabSpacing, xDir, yDir, displayMode, tabBackground); this.tile = tile; this.colorization = colorization; @@ -81,7 +81,7 @@ public class GT_GuiCoverTabLine extends GT_GuiTabLine { @Override protected void drawBackground(float parTicks, int mouseX, int mouseY) { // Apply this tile's coloration to draw the background - GL11.glColor3ub((byte) colorization.mRGBa[0], (byte) colorization.mRGBa[1], (byte) colorization.mRGBa[2]); + GL11.glColor3ub((byte) ((colorization >> 16) & 0xFF), (byte) ((colorization >> 8) & 0xFF), (byte) (colorization & 0xFF)); super.drawBackground(parTicks, mouseX, mouseY); } diff --git a/src/main/java/gregtech/api/util/ColorsMetadataSection.java b/src/main/java/gregtech/api/util/ColorsMetadataSection.java new file mode 100644 index 0000000000..2851435061 --- /dev/null +++ b/src/main/java/gregtech/api/util/ColorsMetadataSection.java @@ -0,0 +1,61 @@ +package gregtech.api.util; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import java.util.Map; +import java.util.HashMap; +import gregtech.api.util.GT_Log; +import gregtech.api.GregTech_API; +import net.minecraft.client.resources.data.IMetadataSection; + +@SideOnly(Side.CLIENT) +public class ColorsMetadataSection implements IMetadataSection { + private final Map<String, Integer> textColors; + private final Map<String, String> hexTextColors; + private final Map<String, Integer> guiTints; + private final Map<String, String> hexGuiTints; + private final boolean guiTintEnabled; + + public ColorsMetadataSection(Map<String, String> hexTextColorMap, Map<String, String> hexGuiTintMap, boolean guiTintEnabled) { + this.hexTextColors = hexTextColorMap; + this.textColors = convertHexMapToIntMap(hexTextColorMap); + + this.hexGuiTints = hexGuiTintMap; + this.guiTints = convertHexMapToIntMap(hexGuiTintMap); + + this.guiTintEnabled = guiTintEnabled; + } + + private Map<String, Integer> convertHexMapToIntMap(Map <String, String> hexMap) { + Map<String, Integer> intMap = new HashMap<>(); + + for (String key : hexMap.keySet()) { + int colorValue = -1; + String hex = hexMap.get(key); + try { + if (!hex.isEmpty()) colorValue = Integer.parseUnsignedInt(hex,16); + } + catch (final NumberFormatException e) { + GT_Log.err.println("Couldn't format color correctly of " + key + " -> " + hex); + } + intMap.put(key, colorValue); + } + return intMap; + } + + public int getTextColorOrDefault(String key, int defaultColor) { + return sColorInMap(key, this.hexTextColors) ? defaultColor : this.textColors.get(key); + } + + public int getGuiTintOrDefault(String key, int defaultColor) { + return sColorInMap(key, this.hexGuiTints) ? defaultColor : this.guiTints.get(key); + } + + private boolean sColorInMap(String key, Map<String,String> hexMap) { + return hexMap.containsKey(key) && hexMap.get(key).isEmpty(); + } + + public boolean sGuiTintingEnabled() { + return this.guiTintEnabled; + } +} diff --git a/src/main/java/gregtech/api/util/ColorsMetadataSectionSerializer.java b/src/main/java/gregtech/api/util/ColorsMetadataSectionSerializer.java new file mode 100644 index 0000000000..4de8463685 --- /dev/null +++ b/src/main/java/gregtech/api/util/ColorsMetadataSectionSerializer.java @@ -0,0 +1,71 @@ +package gregtech.api.util; + +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import java.lang.reflect.Type; +import java.util.Map; +import java.util.HashMap; +import gregtech.api.GregTech_API; +import gregtech.api.enums.Dyes; +import net.minecraft.util.JsonUtils; +import net.minecraft.client.resources.data.BaseMetadataSectionSerializer; + +@SideOnly(Side.CLIENT) +public class ColorsMetadataSectionSerializer extends BaseMetadataSectionSerializer implements JsonSerializer { + public ColorsMetadataSection deserialize(JsonElement metadataColors, Type type, JsonDeserializationContext context) { + // Default values + boolean enableGuiTint = GregTech_API.sColoredGUI; + Map<String, String> hexGuiTintMap = new HashMap<String, String>(); + Map<String, String> hexTextColorMap = new HashMap<String, String>() {{ + put("title", ""); + put("text", ""); + put("value", ""); + put("nei", ""); + }}; + + JsonObject jsonObject = JsonUtils.getJsonElementAsJsonObject(metadataColors, "metadata section"); + if (jsonObject.has("textColor")) { + JsonObject textColors = JsonUtils.func_152754_s(jsonObject, "textColor"); + for (String key : hexTextColorMap.keySet()) { + hexTextColorMap.replace(key, JsonUtils.getJsonObjectStringFieldValueOrDefault(textColors, key, "")); + } + } + + if (jsonObject.has("guiTint")) { + JsonObject guiTints = JsonUtils.func_152754_s(jsonObject, "guiTint"); + enableGuiTint = JsonUtils.getJsonObjectBooleanFieldValueOrDefault(guiTints, "enableGuiTintWhenPainted", true); + + for (Dyes dye : Dyes.values()) { + hexGuiTintMap.put(dye.mName, GT_Util.toHexString(dye.getRGBA())); + } + + for (String key : hexGuiTintMap.keySet()) { + if (enableGuiTint) { + hexGuiTintMap.replace(key, JsonUtils.getJsonObjectStringFieldValueOrDefault(guiTints, key, hexGuiTintMap.get(key))); + } else { + hexGuiTintMap.replace(key, GT_Util.toHexString(Dyes.dyeWhite.getRGBA())); + } + } + } + + return new ColorsMetadataSection(hexTextColorMap, hexGuiTintMap, enableGuiTint); + } + + public JsonElement serialize(ColorsMetadataSection colorsMetaSection, Type type, JsonSerializationContext context) { + JsonObject jsonObject = new JsonObject(); + return jsonObject; + } + + public String getSectionName() { + return "colors"; + } + + public JsonElement serialize(Object object, Type type, JsonSerializationContext context) { + return this.serialize((ColorsMetadataSection) object, type, context); + } +} diff --git a/src/main/java/gregtech/api/util/GT_Util.java b/src/main/java/gregtech/api/util/GT_Util.java index 1079da6c26..45c005bdff 100644 --- a/src/main/java/gregtech/api/util/GT_Util.java +++ b/src/main/java/gregtech/api/util/GT_Util.java @@ -132,6 +132,10 @@ public class GT_Util { return aColors == null ? 16777215 : (aColors[0]) << 16 | (aColors[1] << 8) | aColors[2] | (aColors[3] << 24); } + public static String toHexString(short[] aColors) { + return aColors == null ? "FFFFFF" : Integer.toString((aColors[0] << 16) | (aColors[1] << 8) | aColors[2], 16); + } + public static int getRGBInt(short aR, short aG, short aB) { return (aR << 16) | (aG << 8) | aB; } |