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

293 lines
10 KiB
Java
Raw Normal View History

package tconstruct.tools.gui;
2013-08-07 19:06:26 -07:00
2013-12-06 11:37:06 -08:00
import java.math.RoundingMode;
import java.text.DecimalFormat;
2014-09-09 18:30:15 +10:00
import java.util.*;
2013-12-06 11:37:06 -08:00
import net.minecraft.client.gui.GuiTextField;
2013-08-07 19:06:26 -07:00
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.player.InventoryPlayer;
2013-12-06 11:37:06 -08:00
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
2015-04-02 19:14:51 +02:00
import net.minecraft.tileentity.TileEntity;
2014-09-09 18:30:15 +10:00
import net.minecraft.util.*;
2013-12-06 11:37:06 -08:00
import net.minecraft.world.World;
2013-08-07 19:06:26 -07:00
import org.lwjgl.opengl.GL11;
import codechicken.nei.VisiblityData;
import codechicken.nei.api.INEIGuiHandler;
import codechicken.nei.api.TaggedInventoryArea;
import cpw.mods.fml.common.Optional;
import tconstruct.library.TConstructRegistry;
import tconstruct.library.accessory.AccessoryCore;
2013-12-12 21:05:26 -08:00
import tconstruct.library.armor.ArmorCore;
import tconstruct.library.crafting.PatternBuilder;
2014-10-28 17:56:29 +01:00
import tconstruct.library.modifier.IModifyable;
2014-09-09 18:30:15 +10:00
import tconstruct.library.tools.*;
2014-09-01 22:19:43 +02:00
import tconstruct.library.util.HarvestLevels;
2015-04-02 19:14:51 +02:00
import tconstruct.mechworks.logic.TileEntityLandmine;
2014-06-04 21:44:48 -08:00
import tconstruct.tools.logic.CraftingStationLogic;
2013-08-07 19:06:26 -07:00
@Optional.Interface(iface = "codechicken.nei.api.INEIGuiHandler", modid = "NotEnoughItems")
public class CraftingStationGui extends GuiContainer implements INEIGuiHandler
2013-08-07 19:06:26 -07:00
{
2013-12-06 11:37:06 -08:00
public boolean active;
public String toolName;
public GuiTextField text;
public String title, body = "";
CraftingStationLogic logic;
public static final int CHEST_WIDTH = 116;
// Panel positions
private int craftingLeft = 0;
private int craftingTop = 0;
private int craftingTextLeft = 0;
private int descLeft = 0;
private int descTop = 0;
private int descTextLeft = 0;
private int chestLeft = 0;
private int chestTop = 0;
2013-12-06 11:37:06 -08:00
public CraftingStationGui(InventoryPlayer inventory, CraftingStationLogic logic, World world, int x, int y, int z)
2013-08-07 19:06:26 -07:00
{
2013-12-06 11:37:06 -08:00
super(logic.getGuiContainer(inventory, world, x, y, z));
this.logic = logic;
2014-02-16 14:23:50 -05:00
// text = new GuiTextField(this.fontRendererObj, this.xSize / 2 - 5, 8,
// 30, 12);
// this.text.setText("");
2014-02-04 21:21:50 -05:00
title = "\u00A7n" + StatCollector.translateToLocal("gui.toolforge1");
body = StatCollector.translateToLocal("gui.toolforge2");
2013-12-06 11:37:06 -08:00
toolName = "";
}
2013-08-07 19:06:26 -07: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;
if (logic.tinkerTable)
{
this.descLeft = this.guiLeft + 176;
this.descTop = this.craftingTop;
}
if (logic.chest != null)
{
this.xSize += CHEST_WIDTH;
this.guiLeft -= CHEST_WIDTH;
this.chestLeft = this.guiLeft;
this.chestTop = this.craftingTop;
if (logic.doubleChest != null)
this.ySize = 187;
}
this.craftingTextLeft = this.craftingLeft - this.guiLeft;
this.descTextLeft = this.descLeft - this.guiLeft;
}
2013-08-07 19:06:26 -07:00
@Override
2014-02-05 08:28:53 -05:00
protected void drawGuiContainerForegroundLayer (int par1, int par2)
2013-08-07 19:06:26 -07:00
{
2013-12-06 11:37:06 -08:00
if (logic.chest != null)
{
2015-04-02 19:14:51 +02:00
if(logic.chest.get() instanceof TileEntity) {
TileEntity te = (TileEntity)logic.chest.get();
if(te.getWorldObj().getTileEntity(te.xCoord, te.yCoord, te.zCoord) == null && te.getWorldObj().isRemote)
{
mc.thePlayer.closeScreen();
return;
}
}
this.fontRendererObj.drawString(StatCollector.translateToLocal(logic.chest.get().getInventoryName()), 8, 6, 0x202020);
}
this.fontRendererObj.drawString(StatCollector.translateToLocal(logic.tinkerTable ? "crafters.TinkerTable" : logic.getInvName()), craftingTextLeft + 8, 6, 0x202020);
this.fontRendererObj.drawString(StatCollector.translateToLocal("container.inventory"), craftingTextLeft + 8, 72, 0x202020);
2014-02-16 14:23:50 -05:00
// this.fontRendererObj.drawString(toolName + "_", this.xSize / 2 - 18,
// 8, 0xffffff);
2013-12-06 11:37:06 -08:00
if (logic.tinkerTable)
{
if (logic.isStackInSlot(0)) // output slot = modified item
drawToolStats(logic.getStackInSlot(0));
else if (logic.isStackInSlot(5)) // center slot if no output item
{
// other slots empty?
if(!logic.isStackInSlot(1) && !logic.isStackInSlot(2) && !logic.isStackInSlot(3) && !logic.isStackInSlot(4)
&& !logic.isStackInSlot(6) && !logic.isStackInSlot(7) && !logic.isStackInSlot(8) && !logic.isStackInSlot(9))
drawToolStats(logic.getStackInSlot(5));
else
drawToolInformation();
}
2013-12-12 03:08:05 -08:00
else
drawToolInformation();
2013-12-06 11:37:06 -08:00
}
2013-08-07 19:06:26 -07:00
}
2013-08-31 05:13:31 -07:00
void drawToolStats (ItemStack stack)
2013-12-06 11:37:06 -08:00
{
2014-10-28 17:56:29 +01:00
if(stack.getItem() instanceof IModifyable)
ToolStationGuiHelper.drawToolStats(stack, descTextLeft + 10, 0);
2013-12-06 11:37:06 -08:00
2014-10-28 17:56:29 +01:00
int matID = PatternBuilder.instance.getPartID(stack);
2014-10-28 17:56:29 +01:00
if (matID != Short.MAX_VALUE && matID > 0)
{
ToolMaterial material = TConstructRegistry.getMaterial(matID);
2014-10-28 17:56:29 +01:00
if(material != null)
drawMaterialStats(material);
2013-12-12 21:05:26 -08:00
}
2013-12-06 11:37:06 -08:00
}
2014-10-28 17:56:29 +01:00
protected void drawMaterialStats(ToolMaterial materialEnum)
{
final int baseX = descTextLeft + 8;
2014-10-28 17:56:29 +01:00
final int baseY = 8;
String centerTitle = "\u00A7n" + materialEnum.localizedName();
drawCenteredString(this.fontRendererObj, centerTitle, baseX + 55, baseY, 16777215);
this.fontRendererObj.drawString(StatCollector.translateToLocal("gui.partcrafter4") + materialEnum.durability(), baseX, baseY + 16, 16777215);
this.fontRendererObj.drawString(StatCollector.translateToLocal("gui.partcrafter5") + materialEnum.handleDurability() + "x", baseX, baseY + 27, 16777215);
this.fontRendererObj.drawString(StatCollector.translateToLocal("gui.partcrafter6") + materialEnum.toolSpeed() / 100f, baseX, baseY + 38, 16777215);
this.fontRendererObj.drawString(StatCollector.translateToLocal("gui.partcrafter7") + HarvestLevels.getHarvestLevelName(materialEnum.harvestLevel()), baseX, baseY + 49, 16777215);
int attack = materialEnum.attack();
String heart = attack == 2 ? StatCollector.translateToLocal("gui.partcrafter8") : StatCollector.translateToLocal("gui.partcrafter9");
if (attack % 2 == 0)
this.fontRendererObj.drawString(StatCollector.translateToLocal("gui.partcrafter10") + attack / 2 + heart, baseX, baseY + 60, 0xffffff);
else
this.fontRendererObj.drawString(StatCollector.translateToLocal("gui.partcrafter10") + attack / 2f + heart, baseX, baseY + 60, 0xffffff);
}
2013-12-06 11:37:06 -08:00
void drawToolInformation ()
{
int offsetX = descTextLeft + 63;
this.drawCenteredString(fontRendererObj, title, offsetX, 8, 0xffffff);
fontRendererObj.drawSplitString(body, offsetX - 56, 24, 115, 0xffffff);
2013-12-06 11:37:06 -08:00
}
private static final ResourceLocation background = new ResourceLocation("tinker", "textures/gui/tinkertable.png");
private static final ResourceLocation description = new ResourceLocation("tinker", "textures/gui/description.png");
private static final ResourceLocation icons = new ResourceLocation("tinker", "textures/gui/icons.png");
private static final ResourceLocation chest = new ResourceLocation("tinker", "textures/gui/chestside.png");
@Override
2014-02-05 08:28:53 -05:00
protected void drawGuiContainerBackgroundLayer (float par1, int par2, int par3)
2013-12-06 11:37:06 -08:00
{
// Draw the background
2013-08-07 19:06:26 -07:00
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
2014-02-05 08:28:53 -05:00
this.mc.getTextureManager().bindTexture(background);
this.drawTexturedModalRect(this.craftingLeft, this.craftingTop, 0, 0, 176, 166);
2013-12-06 11:37:06 -08:00
if (active)
{
this.drawTexturedModalRect(this.craftingLeft + 62, this.craftingTop, 0, 166, 112, 22);
2013-12-06 11:37:06 -08:00
}
2014-02-05 08:28:53 -05:00
this.mc.getTextureManager().bindTexture(icons);
2013-12-06 11:37:06 -08:00
// Draw the slots
if (logic.tinkerTable && !logic.isStackInSlot(5))
this.drawTexturedModalRect(this.craftingLeft + 47, this.craftingTop + 33, 0, 233, 18, 18);
2013-12-06 11:37:06 -08:00
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
2014-02-05 08:28:53 -05:00
this.mc.getTextureManager().bindTexture(icons);
2013-12-06 11:37:06 -08:00
2014-02-16 14:23:50 -05:00
// Draw chest side
2013-12-06 11:37:06 -08:00
if (logic.chest != null)
{
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
2014-02-05 08:28:53 -05:00
this.mc.getTextureManager().bindTexture(chest);
2013-12-06 11:37:06 -08:00
if (logic.doubleChest == null)
this.drawTexturedModalRect(this.chestLeft, this.chestTop, 0, 0, 122, 114);
2013-12-06 11:37:06 -08:00
else
this.drawTexturedModalRect(this.chestLeft, this.chestTop, 125, 0, 122, 187);
2013-12-06 11:37:06 -08:00
}
// Draw description
if (logic.tinkerTable)
{
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
2014-02-05 08:28:53 -05:00
this.mc.getTextureManager().bindTexture(description);
this.drawTexturedModalRect(this.descLeft, this.descTop, 0, 0, 126, 172);
2013-12-06 11:37:06 -08:00
}
2013-08-07 19:06:26 -07:00
}
2013-12-06 11:37:06 -08:00
@Override
public VisiblityData modifyVisiblity (GuiContainer gui, VisiblityData currentVisibility)
{
if (width - xSize < 107)
{
currentVisibility.showWidgets = false;
}
else
{
currentVisibility.showWidgets = true;
}
if (guiLeft < 58)
{
currentVisibility.showStateButtons = false;
}
return currentVisibility;
}
@Override
public Iterable<Integer> getItemSpawnSlots (GuiContainer gui, ItemStack item)
{
return null;
}
@Override
public List<TaggedInventoryArea> getInventoryAreas (GuiContainer gui)
{
return Collections.emptyList();
}
@Override
public boolean handleDragNDrop (GuiContainer gui, int mousex, int mousey, ItemStack draggedStack, int button)
{
return false;
}
@Override
public boolean hideItemPanelSlot (GuiContainer gui, int x, int y, int w, int h)
{
if (y + h - 4 < guiTop || y + 4 > guiTop + ySize)
return false;
if (x + 4 > guiLeft + xSize + (logic.tinkerTable ? 126 : 0))
return false;
return true;
}
public boolean hasChest()
{
return logic.chest != null;
}
2013-08-07 19:06:26 -07:00
}