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 - 8 - this.fontRenderer.getStringWidth(var5);
084 byte var8 = 67;
085
086 if (this.fontRenderer.func_82883_a())
087 {
088 drawRect(var7 - 3, var8 - 2, this.xSize - 7, var8 + 10, -16777216);
089 drawRect(var7 - 2, var8 - 1, this.xSize - 8, var8 + 9, -12895429);
090 }
091 else
092 {
093 this.fontRenderer.drawString(var5, var7, var8 + 1, var6);
094 this.fontRenderer.drawString(var5, var7 + 1, var8, var6);
095 this.fontRenderer.drawString(var5, var7 + 1, var8 + 1, var6);
096 }
097
098 this.fontRenderer.drawString(var5, var7, var8, var3);
099 }
100 }
101
102 GL11.glEnable(GL11.GL_LIGHTING);
103 }
104
105 /**
106 * Fired when a key is typed. This is the equivalent of KeyListener.keyTyped(KeyEvent e).
107 */
108 protected void keyTyped(char par1, int par2)
109 {
110 if (this.field_82326_p.textboxKeyTyped(par1, par2))
111 {
112 this.field_82327_o.func_82850_a(this.field_82326_p.getText());
113 this.mc.thePlayer.sendQueue.addToSendQueue(new Packet250CustomPayload("MC|ItemName", this.field_82326_p.getText().getBytes()));
114 }
115 else
116 {
117 super.keyTyped(par1, par2);
118 }
119 }
120
121 /**
122 * Called when the mouse is clicked.
123 */
124 protected void mouseClicked(int par1, int par2, int par3)
125 {
126 super.mouseClicked(par1, par2, par3);
127 this.field_82326_p.mouseClicked(par1, par2, par3);
128 }
129
130 /**
131 * Draws the screen and all the components in it.
132 */
133 public void drawScreen(int par1, int par2, float par3)
134 {
135 super.drawScreen(par1, par2, par3);
136 GL11.glDisable(GL11.GL_LIGHTING);
137 this.field_82326_p.drawTextBox();
138 }
139
140 /**
141 * Draw the background layer for the GuiContainer (everything behind the items)
142 */
143 protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3)
144 {
145 int var4 = this.mc.renderEngine.getTexture("/gui/repair.png");
146 GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
147 this.mc.renderEngine.bindTexture(var4);
148 int var5 = (this.width - this.xSize) / 2;
149 int var6 = (this.height - this.ySize) / 2;
150 this.drawTexturedModalRect(var5, var6, 0, 0, this.xSize, this.ySize);
151 this.drawTexturedModalRect(var5 + 59, var6 + 20, 0, this.ySize + (this.field_82327_o.getSlot(0).getHasStack() ? 0 : 16), 110, 16);
152
153 if ((this.field_82327_o.getSlot(0).getHasStack() || this.field_82327_o.getSlot(1).getHasStack()) && !this.field_82327_o.getSlot(2).getHasStack())
154 {
155 this.drawTexturedModalRect(var5 + 99, var6 + 45, this.xSize, 0, 28, 21);
156 }
157 }
158
159 public void sendContainerAndContentsToPlayer(Container par1Container, List par2List)
160 {
161 this.updateCraftingInventorySlot(par1Container, 0, par1Container.getSlot(0).getStack());
162 }
163
164 /**
165 * inform the player of a change in a single slot
166 */
167 public void updateCraftingInventorySlot(Container par1Container, int par2, ItemStack par3ItemStack)
168 {
169 if (par2 == 0)
170 {
171 this.field_82326_p.setText(par3ItemStack == null ? "" : par3ItemStack.func_82833_r());
172 this.field_82326_p.func_82265_c(par3ItemStack != null);
173
174 if (par3ItemStack != null)
175 {
176 this.field_82327_o.func_82850_a(this.field_82326_p.getText());
177 this.mc.thePlayer.sendQueue.addToSendQueue(new Packet250CustomPayload("MC|ItemName", this.field_82326_p.getText().getBytes()));
178 }
179 }
180 }
181
182 /**
183 * send information about the crafting inventory to the client(currently only for furnace times)
184 */
185 public void updateCraftingInventoryInfo(Container par1Container, int par2, int par3) {}
186 }