Start work on gas gauge gui element. Very rough so far.

This commit is contained in:
Ben Spiers 2014-04-07 01:44:11 +01:00
parent a15a408739
commit 00388cb875
2 changed files with 131 additions and 9 deletions

View file

@ -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;
}
}
}

View file

@ -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);
}
}