Files
TinkersConstruct/src/main/java/tconstruct/tools/gui/PartCrafterGui.java
T

216 lines
8.8 KiB
Java
Raw Normal View History

package tconstruct.tools.gui;
2014-09-23 23:34:30 +02:00
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
2014-09-23 23:34:30 +02:00
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
2014-09-23 23:34:30 +02:00
import org.lwjgl.opengl.GL11;
2014-09-23 23:34:30 +02:00
import tconstruct.library.TConstructRegistry;
import tconstruct.library.crafting.PatternBuilder;
2014-06-30 22:26:00 -08:00
import tconstruct.library.tools.ToolMaterial;
import tconstruct.library.util.HarvestLevels;
2014-06-04 21:44:48 -08:00
import tconstruct.smeltery.inventory.ActiveContainer;
import tconstruct.tools.inventory.PartCrafterChestContainer;
import tconstruct.tools.logic.PartBuilderLogic;
2014-09-23 23:34:30 +02:00
public class PartCrafterGui extends GuiContainer
{
2013-08-16 13:51:33 -07:00
PartBuilderLogic logic;
String title, otherTitle = "";
boolean drawChestPart;
boolean hasTop, hasBottom;
ItemStack topMaterial, bottomMaterial;
2014-06-30 22:26:00 -08:00
ToolMaterial topEnum, bottomEnum;
2014-09-23 23:34:30 +02:00
// Panel positions
int craftingLeft = 0;
int craftingTop = 0;
int descLeft = 0;
int descTop = 0;
int chestLeft = 0;
int chestTop = 0;
2013-08-16 13:51:33 -07:00
public PartCrafterGui(InventoryPlayer inventoryplayer, PartBuilderLogic partlogic, World world, int x, int y, int z)
{
super((ActiveContainer) partlogic.getGuiContainer(inventoryplayer, world, x, y, z));
logic = partlogic;
2014-09-23 23:34:30 +02:00
drawChestPart = inventorySlots instanceof PartCrafterChestContainer;
2014-02-05 09:11:06 -05:00
title = "\u00A7n" + (StatCollector.translateToLocal("gui.partcrafter1"));
}
2014-09-23 23:34:30 +02:00
@Override
public void initGui ()
{
super.initGui();
this.xSize = 176;
this.ySize = 166;
this.guiLeft = (this.width - this.xSize) / 2;
this.guiTop = (this.height - this.ySize) / 2;
this.craftingLeft = this.guiLeft;
this.craftingTop = this.guiTop;
this.descTop = this.craftingTop;
this.descLeft = (this.width + this.xSize) / 2;
if (drawChestPart)
{
this.xSize += 122;
this.guiLeft -= 122;
this.chestLeft = this.guiLeft + 6;
this.chestTop = this.guiTop + 11;
}
}
2014-02-17 00:31:43 -05:00
@Override
protected void drawGuiContainerForegroundLayer (int par1, int par2)
{
2014-09-23 23:34:30 +02:00
int offsetX = 0;
if (drawChestPart)
2014-09-23 23:34:30 +02:00
{
this.fontRendererObj.drawString(StatCollector.translateToLocal("inventory.PatternChest"), 14, 17, 4210752);
offsetX = 122;
}
this.fontRendererObj.drawString(StatCollector.translateToLocal("crafters.PartBuilder"), offsetX + 6, 6, 4210752);
this.fontRendererObj.drawString(StatCollector.translateToLocal("container.inventory"), offsetX + 8, this.ySize - 96 + 2, 4210752);
drawMaterialInformation();
}
void drawDefaultInformation ()
{
2013-12-01 21:42:03 +00:00
title = "\u00A7n" + StatCollector.translateToLocal("gui.partcrafter2");
2014-02-05 08:28:53 -05:00
this.drawCenteredString(fontRendererObj, title, xSize + 63, 8, 16777215);
fontRendererObj.drawSplitString(StatCollector.translateToLocal("gui.partcrafter3"), xSize + 8, 24, 115, 16777215);
}
void drawMaterialInformation ()
{
ItemStack top = logic.getStackInSlot(2);
2014-02-17 01:27:15 -05:00
//ItemStack topResult = logic.getStackInSlot(4);
ItemStack bottom = logic.getStackInSlot(3);
2014-02-17 01:27:15 -05:00
//ItemStack bottomResult = logic.getStackInSlot(6);
if (topMaterial != top)
{
topMaterial = top;
int topID = PatternBuilder.instance.getPartID(top);
2013-07-17 02:04:28 -07:00
if (topID != Short.MAX_VALUE)// && topResult != null)
{
topEnum = TConstructRegistry.getMaterial(topID);
hasTop = true;
title = "\u00A7n" + topEnum.localizedName();
}
else
hasTop = false;
}
if (bottomMaterial != bottom)
{
bottomMaterial = bottom;
int bottomID = PatternBuilder.instance.getPartID(bottom);
2013-07-17 02:04:28 -07:00
if (bottomID != Short.MAX_VALUE)// && bottomResult != null)
{
bottomEnum = TConstructRegistry.getMaterial(bottomID);
hasBottom = true;
otherTitle = "\u00A7n" + bottomEnum.localizedName();
}
else
hasBottom = false;
}
int offset = 8;
if (hasTop)
{
2014-02-05 08:28:53 -05:00
this.drawCenteredString(fontRendererObj, title, xSize + 63, offset, 16777215);
this.fontRendererObj.drawString(StatCollector.translateToLocal("gui.partcrafter4") + topEnum.durability(), xSize + 8, offset + 16, 16777215);
this.fontRendererObj.drawString(StatCollector.translateToLocal("gui.partcrafter5") + topEnum.handleDurability() + "x", xSize + 8, offset + 27, 16777215);
this.fontRendererObj.drawString(StatCollector.translateToLocal("gui.partcrafter6") + topEnum.toolSpeed() / 100f, xSize + 8, offset + 38, 16777215);
this.fontRendererObj.drawString(StatCollector.translateToLocal("gui.partcrafter7") + HarvestLevels.getHarvestLevelName(topEnum.harvestLevel()), xSize + 8, offset + 49, 16777215);
int attack = topEnum.attack();
2013-12-01 20:39:36 +01:00
String heart = attack == 2 ? StatCollector.translateToLocal("gui.partcrafter8") : StatCollector.translateToLocal("gui.partcrafter9");
if (attack % 2 == 0)
2014-02-05 08:28:53 -05:00
this.fontRendererObj.drawString(StatCollector.translateToLocal("gui.partcrafter10") + attack / 2 + heart, xSize + 8, offset + 60, 0xffffff);
else
2014-02-05 08:28:53 -05:00
this.fontRendererObj.drawString(StatCollector.translateToLocal("gui.partcrafter10") + attack / 2f + heart, xSize + 8, offset + 60, 0xffffff);
}
offset = 90;
if (hasBottom)
{
2014-02-05 08:28:53 -05:00
this.drawCenteredString(fontRendererObj, otherTitle, xSize + 63, offset, 16777215);
this.fontRendererObj.drawString(StatCollector.translateToLocal("gui.partcrafter4") + bottomEnum.durability(), xSize + 8, offset + 16, 16777215);
this.fontRendererObj.drawString(StatCollector.translateToLocal("gui.partcrafter5") + bottomEnum.handleDurability() + "x", xSize + 8, offset + 27, 16777215);
this.fontRendererObj.drawString(StatCollector.translateToLocal("gui.partcrafter6") + bottomEnum.toolSpeed() / 100f, xSize + 8, offset + 38, 16777215);
this.fontRendererObj.drawString(StatCollector.translateToLocal("gui.partcrafter7") + HarvestLevels.getHarvestLevelName(bottomEnum.harvestLevel()), xSize + 8, offset + 49, 16777215);
int attack = bottomEnum.attack();
2013-12-01 21:42:03 +00:00
String heart = attack == 2 ? StatCollector.translateToLocal("gui.partcrafter8") : StatCollector.translateToLocal("gui.partcrafter9");
if (attack % 2 == 0)
2014-02-05 08:28:53 -05:00
this.fontRendererObj.drawString(StatCollector.translateToLocal("gui.partcrafter10") + attack / 2 + heart, xSize + 8, offset + 60, 0xffffff);
else
2014-02-05 08:28:53 -05:00
this.fontRendererObj.drawString(StatCollector.translateToLocal("gui.partcrafter10") + attack / 2f + heart, xSize + 8, offset + 60, 0xffffff);
}
if (!hasTop && !hasBottom)
drawDefaultInformation();
}
private static final ResourceLocation background = new ResourceLocation("tinker", "textures/gui/toolparts.png");
private static final ResourceLocation minichest = new ResourceLocation("tinker", "textures/gui/patternchestmini.png");
private static final ResourceLocation description = new ResourceLocation("tinker", "textures/gui/description.png");
2014-02-17 00:31:43 -05:00
@Override
protected void drawGuiContainerBackgroundLayer (float par1, int par2, int par3)
{
// Draw the background
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
2014-02-05 08:28:53 -05:00
this.mc.getTextureManager().bindTexture(background);
2014-09-23 23:34:30 +02:00
this.drawTexturedModalRect(craftingLeft, craftingTop, 0, 0, 176, 166);
// Draw Slots
2014-09-23 23:34:30 +02:00
this.drawTexturedModalRect(craftingLeft + 39, craftingTop + 26, 0, 166, 98, 36);
if (!logic.isStackInSlot(0))
{
2014-09-23 23:34:30 +02:00
this.drawTexturedModalRect(craftingLeft + 39, craftingTop + 26, 176, 0, 18, 18);
}
if (!logic.isStackInSlot(2))
{
2014-09-23 23:34:30 +02:00
this.drawTexturedModalRect(craftingLeft + 57, craftingTop + 26, 176, 18, 18, 18);
}
if (!logic.isStackInSlot(1))
{
2014-09-23 23:34:30 +02:00
this.drawTexturedModalRect(craftingLeft + 39, craftingTop + 44, 176, 0, 18, 18);
}
if (!logic.isStackInSlot(3))
{
2014-09-23 23:34:30 +02:00
this.drawTexturedModalRect(craftingLeft + 57, craftingTop + 44, 176, 36, 18, 18);
}
// Draw chest
if (drawChestPart)
{
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
2014-02-05 08:28:53 -05:00
this.mc.getTextureManager().bindTexture(minichest);
2014-09-23 23:34:30 +02:00
this.drawTexturedModalRect(chestLeft, chestTop, 0, 0, 122, 114);
}
// Draw description
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
2014-02-05 08:28:53 -05:00
this.mc.getTextureManager().bindTexture(description);
2014-09-23 23:34:30 +02:00
this.drawTexturedModalRect(descLeft, descTop, 126, 0, 126, this.ySize);
}
2014-02-17 01:27:15 -05:00
}