001    package net.minecraft.client.gui;
002    
003    import cpw.mods.fml.relauncher.Side;
004    import cpw.mods.fml.relauncher.SideOnly;
005    import java.util.List;
006    import net.minecraft.client.Minecraft;
007    import net.minecraft.client.gui.inventory.GuiContainer;
008    import net.minecraft.entity.player.InventoryPlayer;
009    import net.minecraft.inventory.Container;
010    import net.minecraft.inventory.ContainerRepair;
011    import net.minecraft.inventory.ICrafting;
012    import net.minecraft.item.ItemStack;
013    import net.minecraft.network.packet.Packet250CustomPayload;
014    import net.minecraft.util.StatCollector;
015    import net.minecraft.world.World;
016    import org.lwjgl.input.Keyboard;
017    import org.lwjgl.opengl.GL11;
018    
019    @SideOnly(Side.CLIENT)
020    public 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 var1 = (this.width - this.xSize) / 2;
041            int var2 = (this.height - this.ySize) / 2;
042            this.itemNameField = new GuiTextField(this.fontRenderer, var1 + 62, var2 + 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 var3 = 8453920;
072                boolean var4 = true;
073                String var5 = 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                    var5 = StatCollector.translateToLocal("container.repair.expensive");
078                    var3 = 16736352;
079                }
080                else if (!this.repairContainer.getSlot(2).getHasStack())
081                {
082                    var4 = false;
083                }
084                else if (!this.repairContainer.getSlot(2).canTakeStack(this.field_82325_q.player))
085                {
086                    var3 = 16736352;
087                }
088    
089                if (var4)
090                {
091                    int var6 = -16777216 | (var3 & 16579836) >> 2 | var3 & -16777216;
092                    int var7 = this.xSize - 8 - this.fontRenderer.getStringWidth(var5);
093                    byte var8 = 67;
094    
095                    if (this.fontRenderer.getUnicodeFlag())
096                    {
097                        drawRect(var7 - 3, var8 - 2, this.xSize - 7, var8 + 10, -16777216);
098                        drawRect(var7 - 2, var8 - 1, this.xSize - 8, var8 + 9, -12895429);
099                    }
100                    else
101                    {
102                        this.fontRenderer.drawString(var5, var7, var8 + 1, var6);
103                        this.fontRenderer.drawString(var5, var7 + 1, var8, var6);
104                        this.fontRenderer.drawString(var5, var7 + 1, var8 + 1, var6);
105                    }
106    
107                    this.fontRenderer.drawString(var5, var7, var8, var3);
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            int var4 = this.mc.renderEngine.getTexture("/gui/repair.png");
155            GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
156            this.mc.renderEngine.bindTexture(var4);
157            int var5 = (this.width - this.xSize) / 2;
158            int var6 = (this.height - this.ySize) / 2;
159            this.drawTexturedModalRect(var5, var6, 0, 0, this.xSize, this.ySize);
160            this.drawTexturedModalRect(var5 + 59, var6 + 20, 0, this.ySize + (this.repairContainer.getSlot(0).getHasStack() ? 0 : 16), 110, 16);
161    
162            if ((this.repairContainer.getSlot(0).getHasStack() || this.repairContainer.getSlot(1).getHasStack()) && !this.repairContainer.getSlot(2).getHasStack())
163            {
164                this.drawTexturedModalRect(var5 + 99, var6 + 45, this.xSize, 0, 28, 21);
165            }
166        }
167    
168        public void sendContainerAndContentsToPlayer(Container par1Container, List par2List)
169        {
170            this.sendSlotContents(par1Container, 0, par1Container.getSlot(0).getStack());
171        }
172    
173        /**
174         * Sends the contents of an inventory slot to the client-side Container. This doesn't have to match the actual
175         * contents of that slot. Args: Container, slot number, slot contents
176         */
177        public void sendSlotContents(Container par1Container, int par2, ItemStack par3ItemStack)
178        {
179            if (par2 == 0)
180            {
181                this.itemNameField.setText(par3ItemStack == null ? "" : par3ItemStack.getDisplayName());
182                this.itemNameField.func_82265_c(par3ItemStack != null);
183    
184                if (par3ItemStack != null)
185                {
186                    this.repairContainer.updateItemName(this.itemNameField.getText());
187                    this.mc.thePlayer.sendQueue.addToSendQueue(new Packet250CustomPayload("MC|ItemName", this.itemNameField.getText().getBytes()));
188                }
189            }
190        }
191    
192        /**
193         * Sends two ints to the client-side Container. Used for furnace burning time, smelting progress, brewing progress,
194         * and enchanting level. Normally the first int identifies which variable to update, and the second contains the new
195         * value. Both are truncated to shorts in non-local SMP.
196         */
197        public void sendProgressBarUpdate(Container par1Container, int par2, int par3) {}
198    }