001package net.minecraft.client.gui; 002 003import cpw.mods.fml.relauncher.Side; 004import cpw.mods.fml.relauncher.SideOnly; 005import java.util.List; 006import net.minecraft.client.Minecraft; 007import net.minecraft.client.gui.inventory.GuiContainer; 008import net.minecraft.entity.player.InventoryPlayer; 009import net.minecraft.inventory.Container; 010import net.minecraft.inventory.ContainerRepair; 011import net.minecraft.inventory.ICrafting; 012import net.minecraft.item.ItemStack; 013import net.minecraft.network.packet.Packet250CustomPayload; 014import net.minecraft.util.StatCollector; 015import net.minecraft.world.World; 016import org.lwjgl.input.Keyboard; 017import org.lwjgl.opengl.GL11; 018 019@SideOnly(Side.CLIENT) 020public class GuiRepair extends GuiContainer implements ICrafting 021{ 022 private ContainerRepair repairContainer; 023 private GuiTextField itemNameField; 024 private InventoryPlayer field_82325_q; 025 026 public GuiRepair(InventoryPlayer par1, World par2World, int par3, int par4, int par5) 027 { 028 super(new ContainerRepair(par1, par2World, par3, par4, par5, Minecraft.getMinecraft().thePlayer)); 029 this.field_82325_q = par1; 030 this.repairContainer = (ContainerRepair)this.inventorySlots; 031 } 032 033 /** 034 * Adds the buttons (and other controls) to the screen in question. 035 */ 036 public void initGui() 037 { 038 super.initGui(); 039 Keyboard.enableRepeatEvents(true); 040 int i = (this.width - this.xSize) / 2; 041 int j = (this.height - this.ySize) / 2; 042 this.itemNameField = new GuiTextField(this.fontRenderer, i + 62, j + 24, 103, 12); 043 this.itemNameField.setTextColor(-1); 044 this.itemNameField.func_82266_h(-1); 045 this.itemNameField.setEnableBackgroundDrawing(false); 046 this.itemNameField.setMaxStringLength(30); 047 this.inventorySlots.removeCraftingFromCrafters(this); 048 this.inventorySlots.addCraftingToCrafters(this); 049 } 050 051 /** 052 * Called when the screen is unloaded. Used to disable keyboard repeat events 053 */ 054 public void onGuiClosed() 055 { 056 super.onGuiClosed(); 057 Keyboard.enableRepeatEvents(false); 058 this.inventorySlots.removeCraftingFromCrafters(this); 059 } 060 061 /** 062 * Draw the foreground layer for the GuiContainer (everything in front of the items) 063 */ 064 protected void drawGuiContainerForegroundLayer(int par1, int par2) 065 { 066 GL11.glDisable(GL11.GL_LIGHTING); 067 this.fontRenderer.drawString(StatCollector.translateToLocal("container.repair"), 60, 6, 4210752); 068 069 if (this.repairContainer.maximumCost > 0) 070 { 071 int k = 8453920; 072 boolean flag = true; 073 String s = StatCollector.translateToLocalFormatted("container.repair.cost", new Object[] {Integer.valueOf(this.repairContainer.maximumCost)}); 074 075 if (this.repairContainer.maximumCost >= 40 && !this.mc.thePlayer.capabilities.isCreativeMode) 076 { 077 s = StatCollector.translateToLocal("container.repair.expensive"); 078 k = 16736352; 079 } 080 else if (!this.repairContainer.getSlot(2).getHasStack()) 081 { 082 flag = false; 083 } 084 else if (!this.repairContainer.getSlot(2).canTakeStack(this.field_82325_q.player)) 085 { 086 k = 16736352; 087 } 088 089 if (flag) 090 { 091 int l = -16777216 | (k & 16579836) >> 2 | k & -16777216; 092 int i1 = this.xSize - 8 - this.fontRenderer.getStringWidth(s); 093 byte b0 = 67; 094 095 if (this.fontRenderer.getUnicodeFlag()) 096 { 097 drawRect(i1 - 3, b0 - 2, this.xSize - 7, b0 + 10, -16777216); 098 drawRect(i1 - 2, b0 - 1, this.xSize - 8, b0 + 9, -12895429); 099 } 100 else 101 { 102 this.fontRenderer.drawString(s, i1, b0 + 1, l); 103 this.fontRenderer.drawString(s, i1 + 1, b0, l); 104 this.fontRenderer.drawString(s, i1 + 1, b0 + 1, l); 105 } 106 107 this.fontRenderer.drawString(s, i1, b0, k); 108 } 109 } 110 111 GL11.glEnable(GL11.GL_LIGHTING); 112 } 113 114 /** 115 * Fired when a key is typed. This is the equivalent of KeyListener.keyTyped(KeyEvent e). 116 */ 117 protected void keyTyped(char par1, int par2) 118 { 119 if (this.itemNameField.textboxKeyTyped(par1, par2)) 120 { 121 this.repairContainer.updateItemName(this.itemNameField.getText()); 122 this.mc.thePlayer.sendQueue.addToSendQueue(new Packet250CustomPayload("MC|ItemName", this.itemNameField.getText().getBytes())); 123 } 124 else 125 { 126 super.keyTyped(par1, par2); 127 } 128 } 129 130 /** 131 * Called when the mouse is clicked. 132 */ 133 protected void mouseClicked(int par1, int par2, int par3) 134 { 135 super.mouseClicked(par1, par2, par3); 136 this.itemNameField.mouseClicked(par1, par2, par3); 137 } 138 139 /** 140 * Draws the screen and all the components in it. 141 */ 142 public void drawScreen(int par1, int par2, float par3) 143 { 144 super.drawScreen(par1, par2, par3); 145 GL11.glDisable(GL11.GL_LIGHTING); 146 this.itemNameField.drawTextBox(); 147 } 148 149 /** 150 * Draw the background layer for the GuiContainer (everything behind the items) 151 */ 152 protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3) 153 { 154 GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); 155 this.mc.renderEngine.bindTexture("/gui/repair.png"); 156 int k = (this.width - this.xSize) / 2; 157 int l = (this.height - this.ySize) / 2; 158 this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize); 159 this.drawTexturedModalRect(k + 59, l + 20, 0, this.ySize + (this.repairContainer.getSlot(0).getHasStack() ? 0 : 16), 110, 16); 160 161 if ((this.repairContainer.getSlot(0).getHasStack() || this.repairContainer.getSlot(1).getHasStack()) && !this.repairContainer.getSlot(2).getHasStack()) 162 { 163 this.drawTexturedModalRect(k + 99, l + 45, this.xSize, 0, 28, 21); 164 } 165 } 166 167 public void sendContainerAndContentsToPlayer(Container par1Container, List par2List) 168 { 169 this.sendSlotContents(par1Container, 0, par1Container.getSlot(0).getStack()); 170 } 171 172 /** 173 * Sends the contents of an inventory slot to the client-side Container. This doesn't have to match the actual 174 * contents of that slot. Args: Container, slot number, slot contents 175 */ 176 public void sendSlotContents(Container par1Container, int par2, ItemStack par3ItemStack) 177 { 178 if (par2 == 0) 179 { 180 this.itemNameField.setText(par3ItemStack == null ? "" : par3ItemStack.getDisplayName()); 181 this.itemNameField.func_82265_c(par3ItemStack != null); 182 183 if (par3ItemStack != null) 184 { 185 this.repairContainer.updateItemName(this.itemNameField.getText()); 186 this.mc.thePlayer.sendQueue.addToSendQueue(new Packet250CustomPayload("MC|ItemName", this.itemNameField.getText().getBytes())); 187 } 188 } 189 } 190 191 /** 192 * Sends two ints to the client-side Container. Used for furnace burning time, smelting progress, brewing progress, 193 * and enchanting level. Normally the first int identifies which variable to update, and the second contains the new 194 * value. Both are truncated to shorts in non-local SMP. 195 */ 196 public void sendProgressBarUpdate(Container par1Container, int par2, int par3) {} 197}