diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/EnergyDisplay.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/EnergyDisplay.java new file mode 100644 index 000000000..26741bc4f --- /dev/null +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/EnergyDisplay.java @@ -0,0 +1,67 @@ +/* + * This file ("EnergyDisplay.java") is part of the Actually Additions mod for Minecraft. + * It is created and owned by Ellpeck and distributed + * under the Actually Additions License to be found at + * http://ellpeck.de/actaddlicense + * View the source code at https://github.com/Ellpeck/ActuallyAdditions + * + * © 2015-2016 Ellpeck + */ + +package de.ellpeck.actuallyadditions.mod.inventory.gui; + +import cofh.api.energy.EnergyStorage; +import de.ellpeck.actuallyadditions.mod.util.AssetUtil; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Gui; +import net.minecraftforge.fml.client.config.GuiUtils; + +import java.util.Collections; + +public class EnergyDisplay extends Gui{ + + private final EnergyStorage rfReference; + private final int x; + private final int y; + private final boolean outline; + + public EnergyDisplay(int x, int y, EnergyStorage rfReference, boolean outline){ + this.x = x; + this.y = y; + this.rfReference = rfReference; + this.outline = outline; + } + + public EnergyDisplay(int x, int y, EnergyStorage rfReference){ + this(x, y, rfReference, false); + } + + public void draw(){ + Minecraft mc = Minecraft.getMinecraft(); + mc.getTextureManager().bindTexture(AssetUtil.GUI_INVENTORY_LOCATION); + + int barX = this.x; + int barY = this.y; + + if(this.outline){ + this.drawTexturedModalRect(this.x, this.y, 52, 163, 26, 93); + + barX += 4; + barY += 4; + } + this.drawTexturedModalRect(barX, barY, 18, 171, 18, 85); + + if(this.rfReference.getEnergyStored() > 0){ + int i = this.rfReference.getEnergyStored()*83/this.rfReference.getMaxEnergyStored(); + this.drawTexturedModalRect(barX+1, barY+84-i, 36, 172, 16, i); + } + } + + public void drawOverlay(int mouseX, int mouseY){ + if(mouseX >= this.x && mouseY >= this.y && mouseX < this.x+(this.outline ? 26 : 18) && mouseY < this.y+(this.outline ? 93 : 85)){ + Minecraft mc = Minecraft.getMinecraft(); + String text = this.rfReference.getEnergyStored()+"/"+this.rfReference.getMaxEnergyStored()+" RF"; + GuiUtils.drawHoveringText(Collections.singletonList(text), mouseX, mouseY, mc.displayWidth, mc.displayHeight, -1, mc.fontRendererObj); + } + } +} diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/FluidDisplay.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/FluidDisplay.java new file mode 100644 index 000000000..c5865346e --- /dev/null +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/FluidDisplay.java @@ -0,0 +1,96 @@ +/* + * This file ("FluidDisplay.java") is part of the Actually Additions mod for Minecraft. + * It is created and owned by Ellpeck and distributed + * under the Actually Additions License to be found at + * http://ellpeck.de/actaddlicense + * View the source code at https://github.com/Ellpeck/ActuallyAdditions + * + * © 2015-2016 Ellpeck + */ + +package de.ellpeck.actuallyadditions.mod.inventory.gui; + +import cofh.api.energy.EnergyStorage; +import de.ellpeck.actuallyadditions.mod.util.AssetUtil; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Gui; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.FluidTank; +import net.minecraftforge.fml.client.config.GuiUtils; + +import java.util.Collections; + +public class FluidDisplay extends Gui{ + + private final FluidTank fluidReference; + private Fluid oldFluid; + + private final int x; + private final int y; + private final boolean outline; + + private ResourceLocation resLoc; + + public FluidDisplay(int x, int y, FluidTank fluidReference, boolean outline){ + this.x = x; + this.y = y; + this.fluidReference = fluidReference; + this.outline = outline; + } + + public FluidDisplay(int x, int y, FluidTank fluidReference){ + this(x, y, fluidReference, false); + } + + public void draw(){ + Minecraft mc = Minecraft.getMinecraft(); + mc.getTextureManager().bindTexture(AssetUtil.GUI_INVENTORY_LOCATION); + + int barX = this.x; + int barY = this.y; + + if(this.outline){ + this.drawTexturedModalRect(this.x, this.y, 52, 163, 26, 93); + + barX += 4; + barY += 4; + } + this.drawTexturedModalRect(barX, barY, 0, 171, 18, 85); + + FluidStack stack = this.fluidReference.getFluid(); + Fluid fluid = stack == null ? null : stack.getFluid(); + + if(this.resLoc == null || this.oldFluid != fluid){ + this.oldFluid = fluid; + + if(fluid != null){ + this.resLoc = new ResourceLocation(fluid.getStill().getResourceDomain(), "textures/"+fluid.getStill().getResourcePath()+".png"); + } + } + + if(stack != null && fluid != null && this.resLoc != null){ + mc.getTextureManager().bindTexture(this.resLoc); + + GlStateManager.enableBlend(); + GlStateManager.disableAlpha(); + GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); + int i = this.fluidReference.getFluidAmount()*83/this.fluidReference.getCapacity(); + GuiInputter.drawModalRectWithCustomSizedTexture(barX+1, barY+84-i, 36, 172, 16, i, 16, 512); + GlStateManager.disableBlend(); + GlStateManager.enableAlpha(); + } + } + + public void drawOverlay(int mouseX, int mouseY){ + if(mouseX >= this.x && mouseY >= this.y && mouseX < this.x+(this.outline ? 26 : 18) && mouseY < this.y+(this.outline ? 93 : 85)){ + FluidStack stack = this.fluidReference.getFluid(); + Minecraft mc = Minecraft.getMinecraft(); + + String text = stack == null || stack.getFluid() == null ? "0/"+this.fluidReference.getCapacity()+" mB" : this.fluidReference.getFluidAmount()+"/"+this.fluidReference.getCapacity()+" mB "+stack.getLocalizedName(); + GuiUtils.drawHoveringText(Collections.singletonList(text), mouseX, mouseY, mc.displayWidth, mc.displayHeight, -1, mc.fontRendererObj); + } + } +} diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiCanolaPress.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiCanolaPress.java index 2d28853e6..3e2c0e1c9 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiCanolaPress.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiCanolaPress.java @@ -29,6 +29,8 @@ public class GuiCanolaPress extends GuiContainer{ private static final ResourceLocation RES_LOC = AssetUtil.getGuiLocation("guiCanolaPress"); private final TileEntityCanolaPress press; + private EnergyDisplay energy; + private FluidDisplay fluid; public GuiCanolaPress(InventoryPlayer inventory, TileEntityBase tile){ super(new ContainerCanolaPress(inventory, tile)); @@ -37,18 +39,19 @@ public class GuiCanolaPress extends GuiContainer{ this.ySize = 93+86; } + @Override + public void initGui(){ + super.initGui(); + this.energy = new EnergyDisplay(this.guiLeft+42, this.guiTop+5, this.press.storage); + this.fluid = new FluidDisplay(this.guiLeft+116, this.guiTop+5, this.press.tank); + } + @Override public void drawScreen(int x, int y, float f){ super.drawScreen(x, y, f); - String text1 = this.press.storage.getEnergyStored()+"/"+this.press.storage.getMaxEnergyStored()+" RF"; - if(x >= this.guiLeft+43 && y >= this.guiTop+6 && x <= this.guiLeft+58 && y <= this.guiTop+88){ - this.drawHoveringText(Collections.singletonList(text1), x, y); - } - String text2 = StringUtil.getFluidInfo(this.press.tank); - if(x >= this.guiLeft+117 && y >= this.guiTop+6 && x <= this.guiLeft+132 && y <= this.guiTop+88){ - this.drawHoveringText(Collections.singletonList(text2), x, y); - } + this.energy.drawOverlay(x, y); + this.fluid.drawOverlay(x, y); } @Override @@ -66,19 +69,12 @@ public class GuiCanolaPress extends GuiContainer{ this.mc.getTextureManager().bindTexture(RES_LOC); this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, 176, 93); - if(this.press.storage.getEnergyStored() > 0){ - int i = this.press.getEnergyScaled(83); - this.drawTexturedModalRect(this.guiLeft+43, this.guiTop+89-i, 176, 29, 16, i); - } - - if(this.press.tank.getFluidAmount() > 0){ - int i = this.press.getTankScaled(83); - this.drawTexturedModalRect(this.guiLeft+117, this.guiTop+89-i, 192, 29, 16, i); - } - if(this.press.currentProcessTime > 0){ int i = this.press.getProcessScaled(29); this.drawTexturedModalRect(this.guiLeft+83, this.guiTop+32, 176, 0, 12, i); } + + this.energy.draw(); + this.fluid.draw(); } } \ No newline at end of file diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/util/StringUtil.java b/src/main/java/de/ellpeck/actuallyadditions/mod/util/StringUtil.java index edd6df90d..486fd1e64 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/util/StringUtil.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/util/StringUtil.java @@ -48,8 +48,7 @@ public final class StringUtil{ } } - @SideOnly(Side.CLIENT) public static String getFluidInfo(FluidTank tank){ - return tank.getFluid() == null || tank.getFluid().getFluid() == null ? "0/"+tank.getCapacity()+" mB" : tank.getFluidAmount()+"/"+tank.getCapacity()+" mB "+tank.getFluid().getLocalizedName(); + return ""; } } diff --git a/src/main/resources/assets/actuallyadditions/textures/gui/guiCanolaPress.png b/src/main/resources/assets/actuallyadditions/textures/gui/guiCanolaPress.png index 329ca83de..0390bd765 100644 Binary files a/src/main/resources/assets/actuallyadditions/textures/gui/guiCanolaPress.png and b/src/main/resources/assets/actuallyadditions/textures/gui/guiCanolaPress.png differ diff --git a/src/main/resources/assets/actuallyadditions/textures/gui/guiFermentingBarrel.png b/src/main/resources/assets/actuallyadditions/textures/gui/guiFermentingBarrel.png index a50af9b98..8372dd152 100644 Binary files a/src/main/resources/assets/actuallyadditions/textures/gui/guiFermentingBarrel.png and b/src/main/resources/assets/actuallyadditions/textures/gui/guiFermentingBarrel.png differ diff --git a/src/main/resources/assets/actuallyadditions/textures/gui/guiFluidCollector.png b/src/main/resources/assets/actuallyadditions/textures/gui/guiFluidCollector.png index c99b5f194..b03da459d 100644 Binary files a/src/main/resources/assets/actuallyadditions/textures/gui/guiFluidCollector.png and b/src/main/resources/assets/actuallyadditions/textures/gui/guiFluidCollector.png differ diff --git a/src/main/resources/assets/actuallyadditions/textures/gui/guiInventory.png b/src/main/resources/assets/actuallyadditions/textures/gui/guiInventory.png index 52d44be19..78f0e7a1a 100644 Binary files a/src/main/resources/assets/actuallyadditions/textures/gui/guiInventory.png and b/src/main/resources/assets/actuallyadditions/textures/gui/guiInventory.png differ diff --git a/src/main/resources/assets/actuallyadditions/textures/gui/guiOilGenerator.png b/src/main/resources/assets/actuallyadditions/textures/gui/guiOilGenerator.png index 117ca75a8..7cb551df5 100644 Binary files a/src/main/resources/assets/actuallyadditions/textures/gui/guiOilGenerator.png and b/src/main/resources/assets/actuallyadditions/textures/gui/guiOilGenerator.png differ