    001    package net.minecraft.src;
    002
    003    import cpw.mods.fml.common.Side;
    004    import cpw.mods.fml.common.asm.SideOnly;
    005    import java.util.List;
    006    import net.minecraft.client.Minecraft;
    007    import org.lwjgl.input.Keyboard;
    008    import org.lwjgl.opengl.GL11;
    009
    010    @SideOnly(Side.CLIENT)
    011    public class GuiRepair extends GuiContainer implements ICrafting
    012    {
    013        private ContainerRepair field_82327_o;
    014        private GuiTextField field_82326_p;
    015        private InventoryPlayer field_82325_q;
    016
    017        public GuiRepair(InventoryPlayer par1, World par2World, int par3, int par4, int par5)
    018        {
    019            super(new ContainerRepair(par1, par2World, par3, par4, par5, Minecraft.getMinecraft().thePlayer));
    020            this.field_82325_q = par1;
    021            this.field_82327_o = (ContainerRepair)this.inventorySlots;
    022        }
    023
    024        /**
    025         * Adds the buttons (and other controls) to the screen in question.
    026         */
    027        public void initGui()
    028        {
    029            super.initGui();
    030            Keyboard.enableRepeatEvents(true);
    031            int var1 = (this.width - this.xSize) / 2;
    032            int var2 = (this.height - this.ySize) / 2;
    033            this.field_82326_p = new GuiTextField(this.fontRenderer, var1 + 62, var2 + 24, 103, 12);
    034            this.field_82326_p.setTextColor(-1);
    035            this.field_82326_p.func_82266_h(-1);
    036            this.field_82326_p.setEnableBackgroundDrawing(false);
    037            this.field_82326_p.setMaxStringLength(30);
    038            this.inventorySlots.func_82847_b(this);
    039            this.inventorySlots.addCraftingToCrafters(this);
    040        }
    041
    042        /**
    043         * Called when the screen is unloaded. Used to disable keyboard repeat events
    044         */
    045        public void onGuiClosed()
    046        {
    047            super.onGuiClosed();
    048            Keyboard.enableRepeatEvents(false);
    049            this.inventorySlots.func_82847_b(this);
    050        }
    051
    052        /**
    053         * Draw the foreground layer for the GuiContainer (everything in front of the items)
    054         */
    055        protected void drawGuiContainerForegroundLayer(int par1, int par2)
    056        {
    057            GL11.glDisable(GL11.GL_LIGHTING);
    058            this.fontRenderer.drawString(StatCollector.translateToLocal("container.repair"), 60, 6, 4210752);
    059
    060            if (this.field_82327_o.field_82854_e > 0)
    061            {
    062                int var3 = 8453920;
    063                boolean var4 = true;
    064                String var5 = StatCollector.translateToLocalFormatted("container.repair.cost", new Object[] {Integer.valueOf(this.field_82327_o.field_82854_e)});
    065
    066                if (this.field_82327_o.field_82854_e >= 40 && !this.mc.thePlayer.capabilities.isCreativeMode)
    067                {
    068                    var5 = StatCollector.translateToLocal("container.repair.expensive");
    069                    var3 = 16736352;
    070                }
    071                else if (!this.field_82327_o.getSlot(2).getHasStack())
    072                {
    073                    var4 = false;
    074                }
    075                else if (!this.field_82327_o.getSlot(2).func_82869_a(this.field_82325_q.player))
    076                {
    077                    var3 = 16736352;
    078                }
    079
    080                if (var4)
    081                {
    082                    int var6 = -16777216 | (var3 & 16579836) >> 2 | var3 & -16777216;
    083                    int var7 = this.xSize - 5 - this.fontRenderer.getStringWidth(var5);
    084                    byte var8 = 67;
    085
    086                    if (this.fontRenderer.func_82883_a())
    087                    {
    088                        drawRect(var7 - 2, var8 - 1, this.xSize - 8, var8 + 9, -12895429);
    089                    }
    090                    else
    091                    {
    092                        this.fontRenderer.drawString(var5, var7, var8 + 1, var6);
    093                        this.fontRenderer.drawString(var5, var7 + 1, var8, var6);
    094                        this.fontRenderer.drawString(var5, var7 + 1, var8 + 1, var6);
    095                    }
    096
    097                    this.fontRenderer.drawString(var5, var7, var8, var3);
    098                }
    099            }
    100
    101            GL11.glEnable(GL11.GL_LIGHTING);
    102        }
    103
    104        /**
    105         * Fired when a key is typed. This is the equivalent of KeyListener.keyTyped(KeyEvent e).
    106         */
    107        protected void keyTyped(char par1, int par2)
    108        {
    109            if (this.field_82326_p.textboxKeyTyped(par1, par2))
    110            {
    111                this.field_82327_o.func_82850_a(this.field_82326_p.getText());
    112                this.mc.thePlayer.sendQueue.addToSendQueue(new Packet250CustomPayload("MC|ItemName", this.field_82326_p.getText().getBytes()));
    113            }
    114            else
    115            {
    116                super.keyTyped(par1, par2);
    117            }
    118        }
    119
    120        /**
    121         * Called when the mouse is clicked.
    122         */
    123        protected void mouseClicked(int par1, int par2, int par3)
    124        {
    125            super.mouseClicked(par1, par2, par3);
    126            this.field_82326_p.mouseClicked(par1, par2, par3);
    127        }
    128
    129        /**
    130         * Draws the screen and all the components in it.
    131         */
    132        public void drawScreen(int par1, int par2, float par3)
    133        {
    134            super.drawScreen(par1, par2, par3);
    135            GL11.glDisable(GL11.GL_LIGHTING);
    136            this.field_82326_p.drawTextBox();
    137        }
    138
    139        /**
    140         * Draw the background layer for the GuiContainer (everything behind the items)
    141         */
    142        protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3)
    143        {
    144            int var4 = this.mc.renderEngine.getTexture("/gui/repair.png");
    145            GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
    146            this.mc.renderEngine.bindTexture(var4);
    147            int var5 = (this.width - this.xSize) / 2;
    148            int var6 = (this.height - this.ySize) / 2;
    149            this.drawTexturedModalRect(var5, var6, 0, 0, this.xSize, this.ySize);
    150            this.drawTexturedModalRect(var5 + 59, var6 + 20, 0, this.ySize + (this.field_82327_o.getSlot(0).getHasStack() ? 0 : 16), 110, 16);
    151
    152            if ((this.field_82327_o.getSlot(0).getHasStack() || this.field_82327_o.getSlot(1).getHasStack()) && !this.field_82327_o.getSlot(2).getHasStack())
    153            {
    154                this.drawTexturedModalRect(var5 + 99, var6 + 45, this.xSize, 0, 28, 21);
    155            }
    156        }
    157
    158        public void sendContainerAndContentsToPlayer(Container par1Container, List par2List)
    159        {
    160            this.updateCraftingInventorySlot(par1Container, 0, par1Container.getSlot(0).getStack());
    161        }
    162
    163        /**
    164         * inform the player of a change in a single slot
    165         */
    166        public void updateCraftingInventorySlot(Container par1Container, int par2, ItemStack par3ItemStack)
    167        {
    168            if (par2 == 0)
    169            {
    170                this.field_82326_p.setText(par3ItemStack == null ? "" : par3ItemStack.func_82833_r());
    171                this.field_82326_p.func_82265_c(par3ItemStack != null);
    172
    173                if (par3ItemStack != null)
    174                {
    175                    this.field_82327_o.func_82850_a(this.field_82326_p.getText());
    176                    this.mc.thePlayer.sendQueue.addToSendQueue(new Packet250CustomPayload("MC|ItemName", this.field_82326_p.getText().getBytes()));
    177                }
    178            }
    179        }
    180
    181        /**
    182         * send information about the crafting inventory to the client(currently only for furnace times)
    183         */
    184        public void updateCraftingInventoryInfo(Container par1Container, int par2, int par3) {}
    185    }