The return of Mr. Gui Builder
This commit is contained in:
parent
19cdb5b4eb
commit
6acded92ed
9 changed files with 203 additions and 45 deletions
|
@ -1,12 +1,9 @@
|
|||
package techreborn.client.container.builder;
|
||||
|
||||
import org.apache.commons.lang3.Range;
|
||||
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.EntityEquipmentSlot;
|
||||
|
||||
import org.apache.commons.lang3.Range;
|
||||
import reborncore.client.gui.slots.BaseSlot;
|
||||
|
||||
import techreborn.client.container.builder.slot.ArmorSlot;
|
||||
|
||||
public final class ContainerPlayerInventoryBuilder {
|
||||
|
@ -40,15 +37,31 @@ public final class ContainerPlayerInventoryBuilder {
|
|||
}
|
||||
|
||||
public ContainerPlayerInventoryBuilder inventory() {
|
||||
return this.inventory(8, 84);
|
||||
return this.inventory(8, 94);
|
||||
}
|
||||
|
||||
public ContainerPlayerInventoryBuilder hotbar() {
|
||||
return this.hotbar(8, 142);
|
||||
return this.hotbar(8, 152);
|
||||
}
|
||||
|
||||
public ContainerPlayerInventoryBuilder inventory(boolean old) {
|
||||
if (old) {
|
||||
return this.inventory(8, 84);
|
||||
} else {
|
||||
return inventory();
|
||||
}
|
||||
}
|
||||
|
||||
public ContainerPlayerInventoryBuilder hotbar(boolean old) {
|
||||
if (old) {
|
||||
return this.hotbar(8, 142);
|
||||
} else {
|
||||
return hotbar();
|
||||
}
|
||||
}
|
||||
|
||||
private ContainerPlayerInventoryBuilder armor(final int index, final int xStart, final int yStart,
|
||||
final EntityEquipmentSlot slotType) {
|
||||
final EntityEquipmentSlot slotType) {
|
||||
this.parent.slots.add(new ArmorSlot(slotType, this.player, index, xStart, yStart));
|
||||
return this;
|
||||
}
|
||||
|
@ -71,7 +84,7 @@ public final class ContainerPlayerInventoryBuilder {
|
|||
|
||||
public ContainerPlayerInventoryBuilder armor(final int xStart, final int yStart) {
|
||||
return this.helmet(xStart, yStart).chestplate(xStart, yStart + 19).leggings(xStart, yStart + 38).boots(xStart,
|
||||
yStart + 57);
|
||||
yStart + 57);
|
||||
}
|
||||
|
||||
public ContainerBuilder addInventory() {
|
||||
|
@ -95,7 +108,7 @@ public final class ContainerPlayerInventoryBuilder {
|
|||
}
|
||||
|
||||
private ContainerPlayerArmorInventoryBuilder armor(final int index, final int xStart, final int yStart,
|
||||
final EntityEquipmentSlot slotType) {
|
||||
final EntityEquipmentSlot slotType) {
|
||||
this.parent.parent.slots.add(new ArmorSlot(slotType, this.parent.player, index, xStart, yStart));
|
||||
return this;
|
||||
}
|
||||
|
@ -118,7 +131,7 @@ public final class ContainerPlayerInventoryBuilder {
|
|||
|
||||
public ContainerPlayerArmorInventoryBuilder complete(final int xStart, final int yStart) {
|
||||
return this.helmet(xStart, yStart).chestplate(xStart, yStart + 19).leggings(xStart, yStart + 38)
|
||||
.boots(xStart, yStart + 57);
|
||||
.boots(xStart, yStart + 57);
|
||||
}
|
||||
|
||||
public ContainerPlayerInventoryBuilder addArmor() {
|
||||
|
|
83
src/main/java/techreborn/client/gui/GuiBase.java
Normal file
83
src/main/java/techreborn/client/gui/GuiBase.java
Normal file
|
@ -0,0 +1,83 @@
|
|||
package techreborn.client.gui;
|
||||
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.text.translation.I18n;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
/**
|
||||
* Created by Prospector
|
||||
*/
|
||||
public class GuiBase extends GuiContainer {
|
||||
|
||||
public int xSize = 176;
|
||||
public int ySize = 176;
|
||||
public TRBuilder builder = new TRBuilder();
|
||||
public TileEntity tile;
|
||||
public Container container;
|
||||
|
||||
public GuiBase(EntityPlayer player, TileEntity tile, Container container) {
|
||||
super(container);
|
||||
this.tile = tile;
|
||||
this.container = container;
|
||||
}
|
||||
|
||||
protected void drawSlotForeground(int x, int y) {
|
||||
builder.drawSlot(this, x - 1, y - 1);
|
||||
}
|
||||
|
||||
protected void drawSlotBackground(int x, int y) {
|
||||
drawSlotForeground(guiLeft + x, guiTop + y);
|
||||
}
|
||||
|
||||
protected void drawOutputSlotForeground(int x, int y) {
|
||||
builder.drawOutputSlot(this, x - 1, y - 1);
|
||||
}
|
||||
|
||||
protected void drawOutputSlotBackground(int x, int y) {
|
||||
drawOutputSlotForeground(guiLeft + x, guiTop + y);
|
||||
}
|
||||
|
||||
protected void drawSelectedStackForeground(int x, int y) {
|
||||
builder.drawSelectedStack(this, x, y);
|
||||
}
|
||||
|
||||
protected void drawSelectedStackBackground(int x, int y) {
|
||||
drawSelectedStackForeground(guiLeft + x, guiTop + y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(float p_146976_1_, int mouseX, int mouseY) {
|
||||
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
builder.drawDefaultBackground(this, guiLeft, guiTop, xSize, ySize);
|
||||
builder.drawPlayerSlots(this, guiLeft + xSize / 2, guiTop + 93, true);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
|
||||
drawTitle();
|
||||
}
|
||||
|
||||
protected void drawTitle() {
|
||||
drawCentredString(I18n.translateToLocal(tile.getBlockType().getUnlocalizedName() + ".name"), 6, 4210752);
|
||||
}
|
||||
|
||||
protected void drawCentredString(String string, int y, int colour) {
|
||||
drawString(string, (xSize / 2 - mc.fontRendererObj.getStringWidth(string) / 2), y, colour);
|
||||
}
|
||||
|
||||
protected void drawString(String string, int x, int y, int colour) {
|
||||
mc.fontRendererObj.drawString(string, x, y, colour);
|
||||
GlStateManager.color(1, 1, 1, 1);
|
||||
}
|
||||
}
|
|
@ -5,7 +5,6 @@ import net.minecraft.client.renderer.GlStateManager;
|
|||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.text.translation.I18n;
|
||||
|
||||
import techreborn.client.container.builder.ContainerBuilder;
|
||||
import techreborn.tiles.TileChargeBench;
|
||||
|
||||
|
@ -16,9 +15,9 @@ public class GuiChargeBench extends GuiContainer {
|
|||
TileChargeBench chargebench;
|
||||
|
||||
public GuiChargeBench(final EntityPlayer player, final TileChargeBench tile) {
|
||||
super(new ContainerBuilder().player(player.inventory).inventory().hotbar().addInventory().tile(tile)
|
||||
.energy(0, 62, 21).energy(1, 80, 21).energy(2, 98, 21).energy(3, 62, 39).energy(4, 80, 39)
|
||||
.energy(5, 98, 39).addInventory().create());
|
||||
super(new ContainerBuilder().player(player.inventory).inventory(true).hotbar(true).addInventory().tile(tile)
|
||||
.energy(0, 62, 21).energy(1, 80, 21).energy(2, 98, 21).energy(3, 62, 39).energy(4, 80, 39)
|
||||
.energy(5, 98, 39).addInventory().create());
|
||||
this.xSize = 176;
|
||||
this.ySize = 167;
|
||||
chargebench = tile;
|
||||
|
|
|
@ -1,50 +1,35 @@
|
|||
package techreborn.client.gui;
|
||||
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.text.translation.I18n;
|
||||
|
||||
import techreborn.client.container.builder.ContainerBuilder;
|
||||
import techreborn.tiles.TileDigitalChest;
|
||||
|
||||
public class GuiDigitalChest extends GuiContainer {
|
||||
|
||||
private static final ResourceLocation texture = new ResourceLocation("techreborn",
|
||||
"textures/gui/thermal_generator.png");
|
||||
public class GuiDigitalChest extends GuiBase {
|
||||
|
||||
TileDigitalChest tile;
|
||||
|
||||
public GuiDigitalChest(final EntityPlayer player, final TileDigitalChest tile) {
|
||||
super(new ContainerBuilder().player(player.inventory).inventory().hotbar().addInventory().tile(tile).slot(0, 80, 17)
|
||||
.output(1, 80, 53).fake(2, 59, 42).addInventory().create());
|
||||
this.xSize = 176;
|
||||
this.ySize = 167;
|
||||
super(player, tile, new ContainerBuilder().player(player.inventory).inventory().hotbar().addInventory().tile(tile).slot(0, 80, 20).output(1, 80, 70).fake(2, 80, 45).addInventory().create());
|
||||
this.tile = tile;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(float p_146976_1_, int p_146976_2_, int p_146976_3_) {
|
||||
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
this.mc.getTextureManager().bindTexture(texture);
|
||||
int k = (this.width - this.xSize) / 2;
|
||||
int l = (this.height - this.ySize) / 2;
|
||||
this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize);
|
||||
protected void drawGuiContainerBackgroundLayer(float f, int mouseX, int mouseY) {
|
||||
super.drawGuiContainerBackgroundLayer(f, mouseX, mouseY);
|
||||
|
||||
drawSlotBackground(80, 20);
|
||||
drawSelectedStackBackground(80, 45);
|
||||
drawSlotBackground(80, 70);
|
||||
}
|
||||
|
||||
protected void drawGuiContainerForegroundLayer(int p_146979_1_, int p_146979_2_) {
|
||||
String name = I18n.translateToLocal("tile.techreborn.digitalChest.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("Amount", 10, 20, 16448255);
|
||||
if (tile.storedItem != ItemStack.EMPTY && tile.getStackInSlot(1) != null)
|
||||
this.fontRendererObj.drawString(tile.storedItem.getCount() + tile.getStackInSlot(1).getCount() + "", 10, 30,
|
||||
16448255);
|
||||
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
|
||||
super.drawGuiContainerForegroundLayer(mouseX, mouseY);
|
||||
this.fontRendererObj.drawString("Amount", 105, 43, 0);
|
||||
if (tile.storedItem != ItemStack.EMPTY && tile.getStackInSlot(1) != null) {
|
||||
drawString(tile.storedItem.getCount() + tile.getStackInSlot(1).getCount() + "", 105, 53, 0);
|
||||
}
|
||||
if (tile.storedItem == ItemStack.EMPTY && tile.getStackInSlot(1) != null)
|
||||
this.fontRendererObj.drawString(tile.getStackInSlot(1).getCount() + "", 10, 30, 16448255);
|
||||
drawString(tile.getStackInSlot(1).getCount() + "", 105, 53, 0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ public class GuiQuantumChest extends GuiContainer {
|
|||
TileQuantumChest tile;
|
||||
|
||||
public GuiQuantumChest(final EntityPlayer player, final TileQuantumChest tile) {
|
||||
super(new ContainerBuilder().player(player.inventory).inventory().hotbar().addInventory().tile(tile)
|
||||
super(new ContainerBuilder().player(player.inventory).inventory(true).hotbar(true).addInventory().tile(tile)
|
||||
.slot(0, 80, 17).output(1, 80, 53).fake(2, 59, 42).addInventory().create());
|
||||
this.xSize = 176;
|
||||
this.ySize = 167;
|
||||
|
|
78
src/main/java/techreborn/client/gui/TRBuilder.java
Normal file
78
src/main/java/techreborn/client/gui/TRBuilder.java
Normal file
|
@ -0,0 +1,78 @@
|
|||
package techreborn.client.gui;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraftforge.fml.client.config.GuiUtils;
|
||||
import reborncore.client.guibuilder.GuiBuilder;
|
||||
import reborncore.common.powerSystem.PowerSystem;
|
||||
import techreborn.lib.ModInfo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by Prospector
|
||||
*/
|
||||
public class TRBuilder extends GuiBuilder {
|
||||
public static final ResourceLocation GUI_SHEET = new ResourceLocation(ModInfo.MOD_ID.toLowerCase() + ":" + "textures/gui/gui_sheet.png");
|
||||
public static final ResourceLocation SPRITE_SHEET = new ResourceLocation(ModInfo.MOD_ID.toLowerCase() + ":" + "textures/gui/slot_sprites.png");
|
||||
|
||||
public TRBuilder() {
|
||||
super(GUI_SHEET);
|
||||
}
|
||||
|
||||
public void drawMultiEnergyBar(GuiScreen gui, int x, int y, int energyStored, int maxEnergyStored, int mouseX, int mouseY) {
|
||||
Minecraft.getMinecraft().getTextureManager().bindTexture(GUI_SHEET);
|
||||
|
||||
gui.drawTexturedModalRect(x, y, PowerSystem.getDisplayPower().xBar - 15, PowerSystem.getDisplayPower().yBar - 1, 14, 50);
|
||||
|
||||
int draw = (int) ((double) energyStored / (double) maxEnergyStored * (48));
|
||||
if (energyStored > maxEnergyStored) {
|
||||
draw = (int) ((double) maxEnergyStored / (double) maxEnergyStored * (48));
|
||||
}
|
||||
gui.drawTexturedModalRect(x + 1, y + 49 - draw, PowerSystem.getDisplayPower().xBar, 48 + PowerSystem.getDisplayPower().yBar - draw, 12, draw);
|
||||
int percentage = percentage(maxEnergyStored, energyStored);
|
||||
if (isInRect(x + 1, y + 1, 11, 48, mouseX, mouseY)) {
|
||||
GlStateManager.disableLighting();
|
||||
GlStateManager.disableDepth();
|
||||
GlStateManager.colorMask(true, true, true, false);
|
||||
GuiUtils.drawGradientRect(0, x + 1, y + 1, x + 13, y + 49, 0x80FFFFFF, 0x80FFFFFF);
|
||||
GlStateManager.colorMask(true, true, true, true);
|
||||
GlStateManager.enableDepth();
|
||||
|
||||
List<String> list = new ArrayList<>();
|
||||
TextFormatting powerColour = TextFormatting.GOLD;
|
||||
list.add(powerColour + PowerSystem.getLocaliszedPowerFormattedNoSuffix(energyStored) + "/" + PowerSystem.getLocaliszedPowerFormattedNoSuffix(maxEnergyStored) + " " + PowerSystem.getDisplayPower().abbreviation);
|
||||
if (gui.isShiftKeyDown()) {
|
||||
list.add(getPercentageColour(percentage) + "" + percentage + "%" + TextFormatting.GRAY + " Charged");
|
||||
}
|
||||
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 void drawSelectedStack(GuiScreen gui, int x, int y) {
|
||||
Minecraft.getMinecraft().getTextureManager().bindTexture(GUI_SHEET);
|
||||
gui.drawTexturedModalRect(x - 4, y - 4, 202, 44, 24, 24);
|
||||
}
|
||||
|
||||
public TextFormatting getPercentageColour(int percentage) {
|
||||
if (percentage <= 10) {
|
||||
return TextFormatting.RED;
|
||||
} else if (percentage >= 75) {
|
||||
return TextFormatting.GREEN;
|
||||
} else {
|
||||
return TextFormatting.YELLOW;
|
||||
}
|
||||
}
|
||||
|
||||
public int percentage(int MaxValue, int CurrentValue) {
|
||||
if (CurrentValue == 0)
|
||||
return 0;
|
||||
return (int) ((CurrentValue * 100.0f) / MaxValue);
|
||||
}
|
||||
}
|
BIN
src/main/resources/assets/techreborn/textures/gui/gui_sheet.png
Normal file
BIN
src/main/resources/assets/techreborn/textures/gui/gui_sheet.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 9 KiB |
Binary file not shown.
Before Width: | Height: | Size: 15 KiB |
Binary file not shown.
After Width: | Height: | Size: 3.3 KiB |
Loading…
Reference in a new issue