From 00388cb875390e27e2591a51cf80904567cbb9d9 Mon Sep 17 00:00:00 2001 From: Ben Spiers Date: Mon, 7 Apr 2014 01:44:11 +0100 Subject: [PATCH] Start work on gas gauge gui element. Very rough so far. --- common/mekanism/client/gui/GuiGasGauge.java | 119 ++++++++++++++++++ .../client/gui/GuiHydrogenGenerator.java | 21 ++-- 2 files changed, 131 insertions(+), 9 deletions(-) create mode 100644 common/mekanism/client/gui/GuiGasGauge.java diff --git a/common/mekanism/client/gui/GuiGasGauge.java b/common/mekanism/client/gui/GuiGasGauge.java new file mode 100644 index 000000000..e6d2593c2 --- /dev/null +++ b/common/mekanism/client/gui/GuiGasGauge.java @@ -0,0 +1,119 @@ +package mekanism.client.gui; + +import mekanism.api.gas.GasStack; +import mekanism.api.gas.GasTank; +import mekanism.client.render.MekanismRenderer; +import mekanism.common.util.MekanismUtils; +import mekanism.common.util.MekanismUtils.ResourceType; + +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.ResourceLocation; + +public class GuiGasGauge extends GuiElement +{ + private int xLocation; + private int yLocation; + + private int width = 6; + private int height = 56; + private int innerOffsetY = 2; + + private Type gaugeType; + + IGasInfoHandler infoHandler; + + public GuiGasGauge(IGasInfoHandler handler, Type type, GuiMekanism gui, TileEntity tile, ResourceLocation def, int x, int y) + { + super(MekanismUtils.getResource(ResourceType.GUI_ELEMENT, type.textureLocation), gui, tile, def); + + xLocation = x; + yLocation = y; + + width = type.width; + height = type.height; + infoHandler = handler; + } + + @Override + public void renderBackground(int xAxis, int yAxis, int guiWidth, int guiHeight) + { + int scale = getScaledGasLevel(height); + int start = 0; + GasStack gas = infoHandler.getTank().getGas(); + + while(true) + { + int renderRemaining = 0; + + if(scale > 16) + { + renderRemaining = 16; + scale -= 16; + } + else { + renderRemaining = scale; + scale = 0; + } + + mc.renderEngine.bindTexture(MekanismRenderer.getBlocksTexture()); + + guiObj.drawTexturedModelRectFromIcon(guiWidth + xLocation, guiHeight + yLocation + 58 - renderRemaining - start, gas.getGas().getIcon(), 16, 16 - (16 - renderRemaining)); + + start+=16; + + if(renderRemaining == 0 || scale == 0) + { + break; + } + } + + mc.renderEngine.bindTexture(defaultLocation); + guiObj.drawTexturedModalRect(guiWidth + xLocation, guiHeight + yLocation, 176, 40, 16, 59); + + } + + @Override + public void renderForeground(int xAxis, int yAxis) + { + + } + + @Override + public void preMouseClicked(int xAxis, int yAxis, int button) + { + + } + + @Override + public void mouseClicked(int xAxis, int yAxis, int button) + { + + } + + public static interface IGasInfoHandler + { + public GasTank getTank(); + } + + public int getScaledGasLevel(int i) + { + return infoHandler.getTank().getGas() != null ? infoHandler.getTank().getStored()*i / infoHandler.getTank().getMaxGas() : 0; + } + + public static enum Type + { + STANDARD(20, 58, "mekanism:gasGaugeStandard"), + WIDE(100, 58, "mekanism:gasGaugeWide"); + + public int width; + public int height; + public String textureLocation; + + private Type(int w, int h, String t) + { + width = w; + height = h; + textureLocation = t; + } + } +} diff --git a/common/mekanism/generators/client/gui/GuiHydrogenGenerator.java b/common/mekanism/generators/client/gui/GuiHydrogenGenerator.java index 321ef95c8..6c4a6646e 100644 --- a/common/mekanism/generators/client/gui/GuiHydrogenGenerator.java +++ b/common/mekanism/generators/client/gui/GuiHydrogenGenerator.java @@ -3,8 +3,12 @@ package mekanism.generators.client.gui; import java.util.List; import mekanism.api.ListUtils; +import mekanism.api.gas.GasTank; import mekanism.client.gui.GuiEnergyInfo; import mekanism.client.gui.GuiEnergyInfo.IInfoHandler; +import mekanism.client.gui.GuiGasGauge; +import mekanism.client.gui.GuiGasGauge.IGasInfoHandler; +import mekanism.client.gui.GuiGasGauge.Type; import mekanism.client.gui.GuiMekanism; import mekanism.client.gui.GuiRedstoneControl; import mekanism.common.Mekanism; @@ -37,6 +41,13 @@ public class GuiHydrogenGenerator extends GuiMekanism return ListUtils.asList("Producing: " + production + "/t", "Storing: " + MekanismUtils.getEnergyDisplay(tileEntity.getEnergy())); } }, this, tileEntity, MekanismUtils.getResource(ResourceType.GUI, "GuiHydrogenGenerator.png"))); + guiElements.add(new GuiGasGauge(new IGasInfoHandler() { + @Override + public GasTank getTank() + { + return tileEntity.fuelTank; + } + }, Type.WIDE, this, tileEntity, MekanismUtils.getResource(ResourceType.GUI, "GuiHydrogenGenerator.png"), 20, 20)); } @Override @@ -62,8 +73,6 @@ public class GuiHydrogenGenerator extends GuiMekanism @Override protected void drawGuiContainerBackgroundLayer(float partialTick, int mouseX, int mouseY) { - super.drawGuiContainerBackgroundLayer(partialTick, mouseX, mouseY); - mc.renderEngine.bindTexture(MekanismUtils.getResource(ResourceType.GUI, "GuiHydrogenGenerator.png")); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); int guiWidth = (width - xSize) / 2; @@ -73,12 +82,6 @@ public class GuiHydrogenGenerator extends GuiMekanism int xAxis = mouseX - guiWidth; int yAxis = mouseY - guiHeight; - int displayInt; - - displayInt = tileEntity.getScaledHydrogenLevel(52); - drawTexturedModalRect(guiWidth + 7, guiHeight + 17 + 52 - displayInt, 176, 52 + 52 - displayInt, 4, displayInt); - - displayInt = tileEntity.getScaledEnergyLevel(52); - drawTexturedModalRect(guiWidth + 165, guiHeight + 17 + 52 - displayInt, 176, 52 - displayInt, 4, displayInt); + super.drawGuiContainerBackgroundLayer(partialTick, mouseX, mouseY); } }