Generator gui!

This commit is contained in:
ProfessorProspector 2017-01-08 14:07:34 -08:00
parent cd33860403
commit eea9b83a9c
6 changed files with 131 additions and 132 deletions

View file

@ -1,63 +1,35 @@
package techreborn.client.gui;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.translation.I18n;
import reborncore.common.powerSystem.PowerSystem;
import techreborn.tiles.generator.TileGenerator;
public class GuiGenerator extends GuiContainer {
public class GuiGenerator extends GuiBase {
public static final ResourceLocation texture = new ResourceLocation("techreborn", "textures/gui/generator.png");
TileGenerator tile;
TileGenerator generator;
public GuiGenerator(final EntityPlayer player, final TileGenerator generator) {
super(generator.createContainer(player));
this.xSize = 176;
this.ySize = 167;
this.generator = generator;
public GuiGenerator(final EntityPlayer player, final TileGenerator tile) {
super(player, tile, tile.createContainer(player));
this.tile = tile;
}
@Override
public void initGui() {
final int k = (this.width - this.xSize) / 2;
final int l = (this.height - this.ySize) / 2;
super.initGui();
protected void drawGuiContainerBackgroundLayer(final float f, final int mouseX, final int mouseY) {
super.drawGuiContainerBackgroundLayer(f, mouseX, mouseY);
final Layer layer = Layer.BACKGROUND;
this.drawSlot(8, 72, layer);
this.drawSlot(80, 54, layer);
this.builder.drawJEIButton(this, 150, 4, mouseX, mouseY, layer);
}
@Override
protected void drawGuiContainerBackgroundLayer(final float p_146976_1_, final int p_146976_2_, final int p_146976_3_) {
this.mc.getTextureManager().bindTexture(GuiGenerator.texture);
final int k = (this.width - this.xSize) / 2;
final int l = (this.height - this.ySize) / 2;
this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize);
protected void drawGuiContainerForegroundLayer(final int mouseX, final int mouseY) {
super.drawGuiContainerForegroundLayer(mouseX, mouseY);
final Layer layer = Layer.FOREGROUND;
int j = 0;
j = this.generator.getEnergyScaled(24);
if (j > 0) {
this.drawTexturedModalRect(k + 109, l + 21 + 12, 176, 0, j + 1, 16);
}
if (this.generator.burnTime != 0) {
j = this.generator.getScaledBurnTime(13);
this.drawTexturedModalRect(k + 80, l + 38 + 12 - j, 176, 30 - j, 14, j + 1);
}
}
@Override
protected void drawGuiContainerForegroundLayer(final int p_146979_1_, final int p_146979_2_) {
final String name = I18n.translateToLocal("tile.techreborn.generator.name");
this.fontRendererObj.drawString(name, this.xSize / 2 - this.fontRendererObj.getStringWidth(name) / 2, 6,
4210752);
this.fontRendererObj.drawString(I18n.translateToLocalFormatted("container.inventory", new Object[0]), 8,
this.ySize - 96 + 2, 4210752);
this.fontRendererObj.drawString(PowerSystem.getLocaliszedPower(this.generator.getEnergy()), 25,
this.ySize - 150, 4210752);
this.builder.drawBurnBar(this, this.tile.getScaledBurnTime(100), 100, 81, 38, mouseX, mouseY, layer);
this.builder.drawMultiEnergyBar(this, 9, 18, (int) this.tile.getEnergy(), (int) this.tile.getMaxPower(), mouseX, mouseY, 0, layer);
}
}

View file

@ -155,6 +155,37 @@ public class TRBuilder extends GuiBuilder {
gui.drawTexturedModalRect(x - 4, y - 4, 202, 44, 24, 24);
}
public void drawBurnBar(GuiBase gui, int progress, int maxProgress, int x, int y, int mouseX, int mouseY, GuiBase.Layer layer) {
if (layer == GuiBase.Layer.BACKGROUND) {
x += gui.getGuiLeft();
y += gui.getGuiTop();
}
if (layer == GuiBase.Layer.FOREGROUND) {
mouseX -= gui.getGuiLeft();
mouseY -= gui.getGuiTop();
}
gui.mc.getTextureManager().bindTexture(GUI_SHEET);
gui.drawTexturedModalRect(x, y, 171, 84, 13, 13);
int j = 13 - (int) ((double) progress / (double) maxProgress * 13);
if (j > 0) {
gui.drawTexturedModalRect(x, y + j, 171, 70 + j, 13, 13 - j);
}
if (isInRect(x, y, 12, 12, mouseX, mouseY)) {
int percentage = percentage(maxProgress, progress);
List<String> list = new ArrayList<>();
list.add(getPercentageColour(percentage) + "" + percentage + "%");
net.minecraftforge.fml.client.config.GuiUtils.drawHoveringText(list, mouseX, mouseY, gui.width, gui.height, -1, gui.mc.fontRendererObj);
GlStateManager.disableLighting();
GlStateManager.color(1, 1, 1, 1);
}
}
public int getScaledBurnTime(int scale, int burnTime, int totalBurnTime) {
return (int) (((float) burnTime / (float) totalBurnTime) * scale);
}
public TextFormatting getPercentageColour(int percentage) {
if (percentage <= 10) {
return TextFormatting.RED;